2012-06-13 21:03 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)

* contrib/hbqt/tests/dbfbrowser.prg
  * contrib/hbqt/tests/dbfbrowserclass.prg
    ! replaced: new code provided by Bacco.

  * contrib/hbxbp/xbplistbox.prg
  * contrib/hbxbp/xbpwindow.prg
    - removed: :hasValidPointer() calls.
This commit is contained in:
Pritpal Bedi
2012-06-14 04:07:04 +00:00
parent aff16f921f
commit c79d7b7806
5 changed files with 57 additions and 42 deletions

View File

@@ -16,6 +16,15 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-06-13 21:03 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/tests/dbfbrowser.prg
* contrib/hbqt/tests/dbfbrowserclass.prg
! replaced: new code provided by Bacco.
* contrib/hbxbp/xbplistbox.prg
* contrib/hbxbp/xbpwindow.prg
- removed: :hasValidPointer() calls.
2012-06-13 19:47 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtcore/hbqt_bind.cpp
! Normalized: hbqt_bindDestroyHbObject().

View File

@@ -14,6 +14,7 @@
PROCEDURE Main()
LOCAL oWid
LOCAL oLabel1
LOCAL oButton1
LOCAL oButton2
LOCAL oTable1
@@ -23,28 +24,28 @@ PROCEDURE Main()
Set( _SET_EXACT, .T. )
oWid := QWidget()
oWid:setWindowTitle( "DBF Browser" )
oWid:setWindowTitle( "Simple DBF Browser/Editor" )
oTable1 := QDBFBrowser()
oLabel1 := QLabel()
oLabel1:setText( 'Click in "Open DBF" to start' )
// NOTE: QDBFBrowser inherits QTableView, so we can use the methods below.
oTable1 := QDBFBrowser() // QDBFBrowser inherits QTableView, so we can use the methods below.
oTable1:setAlternatingRowColors( .T. )
oTable1:setShowGrid( .F. )
oTable1:setTabKeyNavigation( .F. )
oTable1:verticalHeader():setSelectionBehavior( QAbstractItemView_SelectRows )
oTable1:verticalHeader():setSelectionMode( QAbstractItemView_SingleSelection )
// ENDNOTE
oButton1 := QPushButton()
oButton1:setText( "Open DBF" )
oButton1:connect( "clicked()", {|| OpenDBF( oWid, oTable1 ) } )
oButton1:connect( "clicked()", {|| OpenDBF( oWid, oTable1, oLabel1 ) } )
oButton2 := QPushButton()
oButton2:setText( "Close DBF" )
oButton2:connect( "clicked()", {|| CloseDBF( oTable1 ) } )
oButton2:connect( "clicked()", {|| CloseDBF( oTable1, oLabel1 ) } )
oLay1 := QVBoxLayout( oWid )
oLay1:addWidget( oLabel1 )
oLay1:addWidget( oTable1 )
olay1:addLayout( oLay2 := QHBoxLayout() )
oLay2:addWidget( oButton1 )
@@ -52,37 +53,41 @@ PROCEDURE Main()
oWid:Show()
QApplication():exec()
oTable1:destroy() // Mainly to disconnect signals
oButton1:disconnect( "clicked()" ) // The only way for GC to resolve
oTable1:detach()
oButton1:disconnect( "clicked()" )
oButton2:disconnect( "clicked()" )
RETURN
PROCEDURE OpenDBF( oWid, oTable )
PROCEDURE OpenDBF( oWid, oTable, oLabel )
STATIC cDir := "."
LOCAL cFile
cFile := QFileDialog():getOpenFileName( oWid, "Open file", cDir, "DBF files (*.dbf);;All files (*.*)" )
Local cName
cFile := QFileDialog():getOpenFileName( oWid, "Select database", cDir, "DBF files (*.dbf);;All files (*.*)" )
IF cFile == ""
RETURN
END
ENDIF
cDir := hb_FNameDir( cFile ) // To remember last used dir
cName := hb_FNameNameExt( cFile )
CloseDBF( oTable )
CloseDBF( oTable, oLabel )
BEGIN SEQUENCE WITH {||.F.}
DBUseArea( .T., NIL, cFile, NIL, .F., .F. )
END SEQUENCE
IF Used()
oTable:attach()
ENDIF
oLabel:setText( "Database: " + cName )
ELSE
oLabel:setText( "Could not open " + cName )
ENDIF
RETURN
PROCEDURE CloseDBF( oTable )
PROCEDURE CloseDBF( oTable , oLabel )
oTable:detach()
oLabel:setText( "" )
DBCloseArea()
RETURN

View File

@@ -21,9 +21,8 @@ RETURN B2_QDBFBrowser():new( ... ):init()
CREATE CLASS B2QDBFBrowser INHERIT HB_QTableView FUNCTION B2_QDBFBrowser
METHOD init()
METHOD attach()
METHOD detach()
METHOD destroy()
METHOD attach() // Activate the browser and attach to current active area
METHOD detach() // Deactivate the browser
VAR oModel
VAR nArea INIT 0
@@ -32,41 +31,42 @@ CREATE CLASS B2QDBFBrowser INHERIT HB_QTableView FUNCTION B2_QDBFBrowser
VAR oItemDgt
ENDCLASS
METHOD init()
::oModel := HBQAbstractItemModel( {| t, r, x, y| B2_QDBFBrowse( Self, t, r, x, y ) } )
::setModel( ::oModel )
::oItemDgt := ::itemDelegate()
::oItemDgt:connect( "commitData(QWidget*)", {|oWidget| B2_QDBFCommit( Self, oWidget ) } )
RETURN Self
METHOD B2QDBFBrowser:destroy()
::oItemDgt:disconnect( "commitData(QWidget*)" )
::oModel:reset()
::nArea := 0
IF Select() > 0
DbCloseArea()
ENDIF
RETURN NIL
METHOD B2QDBFBrowser:attach()
::detach()
IF ( ::nArea := Select() ) > 0
::aStru := DBStruct()
::oModel:reset()
::oItemDgt := ::itemDelegate()
::oItemDgt:connect( "commitData(QWidget*)", {|oWidget| B2_QDBFCommit( Self, oWidget ) } )
ENDIF
RETURN NIL
METHOD B2QDBFBrowser:detach()
If ::nArea > 0
::oItemDgt:disconnect( "commitData(QWidget*)" )
::oItemDgt := NIL
ENDIF
::nArea := 0
::oModel:reset()
RETURN NIL
PROCEDURE B2_QDBFCommit( o, oWidget )
LOCAL oIndex := o:currentIndex()
LOCAL nCX := oIndex:column()
LOCAL nCY := oIndex:row()
LOCAL nOldArea := Select()
LOCAL cData := oWidget:property( "text" ):toString()
DBSelectArea( o:nArea )
DBGoto( nCY + 1 )
@@ -107,7 +107,7 @@ FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY )
CASE Qt_DisplayRole
DBSelectArea( o:nArea )
DBGoto( nY + 1 )
xRet := "?"
SWITCH o:aStru[ nX + 1, 2 ]
CASE "C"
@@ -130,7 +130,7 @@ FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY )
CASE Qt_EditRole /* Here we can specify different formats for editing*/
DBSelectArea( o:nArea )
DBGoto( nY + 1 )
xRet := ""
SWITCH o:aStru[ nX + 1, 2 ]
CASE "C"
@@ -156,10 +156,10 @@ FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY )
RETURN Qt_AlignVCenter + Qt_AlignLeft
CASE "N"
RETURN Qt_AlignVCenter + Qt_AlignRight
ENDSWITCH
RETURN Qt_AlignCenter
ENDSWITCH
RETURN NIL
@@ -187,9 +187,10 @@ FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY )
CASE HBQT_QAIM_columnCount
RETURN Len( o:aStru )
ENDSWITCH
RETURN NIL
#endif /* HB_QDBFBROWSER_CH_ */
#endif /* HB_QDBFBROWSER_PRG_ */

View File

@@ -261,7 +261,7 @@ METHOD XbpListBox:execSlot( cSlot, p )
IF cSlot == "customContextMenuRequested(QPoint)"
IF HB_ISBLOCK( ::hb_contextMenu )
qPos := p
IF ( qItm := ::oWidget:itemAt( qPos ) ):hasValidPointer()
IF ! empty( qItm := ::oWidget:itemAt( qPos ) )
IF ( n := ascan( ::aItems, {|o| hbqt_IsEqual( o, qItm ) } ) ) > 0
qPt := ::oWidget:mapToGlobal( QPoint( p ) )
eval( ::hb_contextMenu, { qPt:x(), qPt:y() }, NIL, ::aItems[ n ] )
@@ -352,7 +352,7 @@ METHOD XbpListBox:clear( lConnect )
qItm := NIL
NEXT
::aItems := {}
IF ::oWidget:hasValidPointer()
IF ! empty( ::oWidget )
IF lConnect
::oWidget:clear()
ENDIF

View File

@@ -405,7 +405,7 @@ METHOD XbpWindow:setQtProperty( cProperty )
METHOD XbpWindow:postCreate()
::status := iif( ::oWidget:hasValidPointer(), XBP_STAT_CREATE, XBP_STAT_FAILURE )
::status := iif( ! empty( ::oWidget ), XBP_STAT_CREATE, XBP_STAT_FAILURE )
IF ! empty( ::toolTipText ) .AND. HB_ISSTRING( ::toolTipText )
::oWidget:setTooltip( ::toolTipText )