From c79d7b7806e3c7a087ed876f09ec3af600f04e0b Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 14 Jun 2012 04:07:04 +0000 Subject: [PATCH] 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. --- harbour/ChangeLog | 9 ++++ harbour/contrib/hbqt/tests/dbfbrowser.prg | 41 ++++++++++-------- .../contrib/hbqt/tests/dbfbrowserclass.prg | 43 ++++++++++--------- harbour/contrib/hbxbp/xbplistbox.prg | 4 +- harbour/contrib/hbxbp/xbpwindow.prg | 2 +- 5 files changed, 57 insertions(+), 42 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 679220101a..d81b27c338 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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(). diff --git a/harbour/contrib/hbqt/tests/dbfbrowser.prg b/harbour/contrib/hbqt/tests/dbfbrowser.prg index 73937d4191..001eae2e69 100644 --- a/harbour/contrib/hbqt/tests/dbfbrowser.prg +++ b/harbour/contrib/hbqt/tests/dbfbrowser.prg @@ -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 diff --git a/harbour/contrib/hbqt/tests/dbfbrowserclass.prg b/harbour/contrib/hbqt/tests/dbfbrowserclass.prg index 6653839dac..8234d71858 100644 --- a/harbour/contrib/hbqt/tests/dbfbrowserclass.prg +++ b/harbour/contrib/hbqt/tests/dbfbrowserclass.prg @@ -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_ */ + diff --git a/harbour/contrib/hbxbp/xbplistbox.prg b/harbour/contrib/hbxbp/xbplistbox.prg index 6dc9609c2c..06e6f83e68 100644 --- a/harbour/contrib/hbxbp/xbplistbox.prg +++ b/harbour/contrib/hbxbp/xbplistbox.prg @@ -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 diff --git a/harbour/contrib/hbxbp/xbpwindow.prg b/harbour/contrib/hbxbp/xbpwindow.prg index d3df6b9b58..2df70768df 100644 --- a/harbour/contrib/hbxbp/xbpwindow.prg +++ b/harbour/contrib/hbxbp/xbpwindow.prg @@ -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 )