2012-07-10 02:04 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)

* contrib/hbqt/qtgui/hbqtgui.hbm
  * contrib/hbqt/qtgui/hbqtgui.hbx
  - contrib/hbqt/qtgui/THbQtUI.prg
    - Removed: class HbQtUi() no longer required.

  * contrib/hbqt/hbmk2_qt.hb
    + Implemented: .ui manipulation as proper class object.
       Now any object of interface can be accessed by its objectName
       given in the Qt Creator. To keep compatibility with old 
       code, the "q_" prefix is also retained. User will see no 
       difference in his code but is encouraged to use new syntax
       which is mode in line with a true object.
        For example: oUI := hbqtui_uifilename( oParent )
                     oUI:q_btnClose:connect( ...)
                        =>
                     oUI := ui_uifilename():new( oParent )
                     oUI:btnClose:connect( ... )
  ; INCOMPATIBLE: to access qObj[ cObjectName ] is no more available.
                  Please update your code to honor new syntax.
This commit is contained in:
Pritpal Bedi
2012-07-10 09:14:28 +00:00
parent 0a497134fe
commit 6a7bda8518
5 changed files with 134 additions and 205 deletions

View File

@@ -16,6 +16,27 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-07-10 02:04 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtgui/hbqtgui.hbm
* contrib/hbqt/qtgui/hbqtgui.hbx
- contrib/hbqt/qtgui/THbQtUI.prg
- Removed: class HbQtUi() no longer required.
* contrib/hbqt/hbmk2_qt.hb
+ Implemented: .ui manipulation as proper class object.
Now any object of interface can be accessed by its objectName
given in the Qt Creator. To keep compatibility with old
code, the "q_" prefix is also retained. User will see no
difference in his code but is encouraged to use new syntax
which is mode in line with a true object.
For example: oUI := hbqtui_uifilename( oParent )
oUI:q_btnClose:connect( ...)
=>
oUI := ui_uifilename():new( oParent )
oUI:btnClose:connect( ... )
; INCOMPATIBLE: to access qObj[ cObjectName ] is no more available.
Please update your code to honor new syntax.
2012-07-10 02:02 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtopengl/hbqtopengl.hbc
* contrib/hbqt/qtscript/hbqtscript.hbc

View File

@@ -587,7 +587,6 @@ STATIC FUNCTION hbqtui_gen_prg( cFile, cFuncName )
LOCAL cText
LOCAL cCmd
LOCAL aReg
LOCAL item
LOCAL aLinesPRG
LOCAL regEx := hb_regexComp( "\bQ[A-Za-z_]+ \b" )
@@ -630,6 +629,7 @@ STATIC FUNCTION hbqtui_gen_prg( cFile, cFuncName )
/* Replace Qt::* with actual values */
hbqtui_replaceConstants( @s )
hbqtui_QAppTranslate( @s )
IF "setupUi" $ s
lCreateFinished := .T.
@@ -711,36 +711,91 @@ STATIC FUNCTION hbqtui_gen_prg( cFile, cFuncName )
AAdd( aLinesPRG, "/* WARNING: Automatically generated source file. DO NOT EDIT! */" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, '#include "hbqtgui.ch"' )
AAdd( aLinesPRG, '#include "hbclass.ch"' )
AAdd( aLinesPRG, '#include "error.ch"' )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, "FUNCTION " + cFuncName + "( qParent )" )
AAdd( aLinesPRG, " LOCAL oRootWidget" )
AAdd( aLinesPRG, " LOCAL hWidget := { => }" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, " hb_hCaseMatch( hWidget, .F. )" )
AAdd( aLinesPRG, " hb_hKeepOrder( hWidget, .T. )" )
AAdd( aLinesPRG, " RETURN " + StrTran( cFuncName, "hbqtui_", "ui_" ) + "():new( qParent )" )
AAdd( aLinesPRG, "" )
hbqtui_buildClassCode( cFuncName, cMCls, aWidgets, aCommands, aLinesPRG )
RETURN aLinesPRG
STATIC FUNCTION hbqtui_buildClassCode( cFuncName, cMCls, aWidgets, aCommands, aLinesPRG )
LOCAL item, cClass, cNam, cCmd, s//, n
cClass := strtran( cFuncName, "hbqtui_", "ui_" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, "CREATE CLASS " + cClass )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, " VAR oWidget" )
AAdd( aLinesPRG, "" )
FOR EACH item IN aWidgets
AAdd( aLinesPRG, " VAR " + item[ 2 ] )
NEXT
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, " METHOD init( oParent )" )
AAdd( aLinesPRG, " ERROR HANDLER __OnError( ... )" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, " ENDCLASS" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, 'METHOD ' + cClass + ':__OnError( ... )' )
AAdd( aLinesPRG, ' LOCAL cMsg := __GetMessage()' )
AAdd( aLinesPRG, ' LOCAL oError' )
AAdd( aLinesPRG, '' )
AAdd( aLinesPRG, ' IF SubStr( cMsg, 1, 1 ) == "_"' )
AAdd( aLinesPRG, ' cMsg := SubStr( cMsg, 2 )' )
AAdd( aLinesPRG, ' ENDIF' )
AAdd( aLinesPRG, '' )
AAdd( aLinesPRG, ' IF Left( cMsg, 2 ) == "Q_"' )
AAdd( aLinesPRG, ' IF __objHasMsg( Self, SubStr( cMsg, 3 ) )' )
AAdd( aLinesPRG, ' cMsg := SubStr( cMsg, 3 )' )
AAdd( aLinesPRG, ' RETURN ::&cMsg' )
AAdd( aLinesPRG, ' ELSE' )
AAdd( aLinesPRG, ' oError := ErrorNew()' )
AAdd( aLinesPRG, ' oError:severity := ES_ERROR' )
AAdd( aLinesPRG, ' oError:genCode := EG_ARG' )
AAdd( aLinesPRG, ' oError:subSystem := "HBQT" ' )
AAdd( aLinesPRG, ' oError:subCode := 1001' )
AAdd( aLinesPRG, ' oError:canRetry := .F.' )
AAdd( aLinesPRG, ' oError:canDefault := .F.' )
AAdd( aLinesPRG, ' oError:Args := hb_AParams()' )
AAdd( aLinesPRG, ' oError:operation := ProcName()' )
AAdd( aLinesPRG, ' oError:Description := "Control <" + substr( cMsg, 3 ) + "> does not exist"' )
AAdd( aLinesPRG, '' )
AAdd( aLinesPRG, ' Eval( ErrorBlock(), oError )' )
AAdd( aLinesPRG, ' ENDIF' )
AAdd( aLinesPRG, ' ELSEIF ! empty( ::oWidget )' )
AAdd( aLinesPRG, ' RETURN ::oWidget:&cMsg( ... )' )
AAdd( aLinesPRG, ' ENDIF' )
AAdd( aLinesPRG, '' )
AAdd( aLinesPRG, ' RETURN NIL' )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, "METHOD " + cClass + ":" + "init( oParent )" )
AAdd( aLinesPRG, "" )
SWITCH cMCls
CASE "QDialog"
AAdd( aLinesPRG, " oRootWidget := QDialog( qParent )" )
AAdd( aLinesPRG, " ::oWidget := QDialog( oParent )" )
EXIT
CASE "QWidget"
AAdd( aLinesPRG, " oRootWidget := QWidget( qParent )" )
AAdd( aLinesPRG, " ::oWidget := QWidget( oParent )" )
EXIT
CASE "QMainWindow"
AAdd( aLinesPRG, " oRootWidget := QMainWindow( qParent )" )
AAdd( aLinesPRG, " ::oWidget := QMainWindow( oParent )" )
EXIT
ENDSWITCH
AAdd( aLinesPRG, " " )
AAdd( aLinesPRG, " oRootWidget:setObjectName( " + HBQTUI_STRINGIFY( cMNam ) + " )" )
AAdd( aLinesPRG, " " )
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cMNam ) ) + " ] := oRootWidget" )
AAdd( aLinesPRG, " " )
AAdd( aLinesPRG, "" )
FOR EACH item IN aWidgets
IF item:__enumIndex() > 1
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( item[ 2 ] ) ) + " ] := " + StrTran( item[ 4 ], "o[", "hWidget[" ) )
AAdd( aLinesPRG, " ::" + pad( item[ 2 ],34 ) + " := " + hbqtui_hashToObj( item[ 4 ] ) )
ELSE
AAdd( aLinesPRG, " ::" + pad( item[ 2 ],34 ) + " := " + "::oWidget" )
ENDIF
NEXT
AAdd( aLinesPRG, "" )
@@ -751,39 +806,21 @@ STATIC FUNCTION hbqtui_gen_prg( cFile, cFuncName )
cCmd := StrTran( cCmd, "true" , ".T." )
cCmd := StrTran( cCmd, "false", ".F." )
IF "addWidget" $ cCmd
IF hbqtui_occurs( cCmd, "," ) >= 4
cCmd := StrTran( cCmd, "addWidget", "addWidget" )
ENDIF
ELSEIF "addLayout" $ cCmd
IF hbqtui_occurs( cCmd, "," ) >= 4
cCmd := StrTran( cCmd, "addLayout", "addLayout" )
ENDIF
ENDIF
IF "setToolTip(" $ cCmd
s := hbqtui_pullToolTip( cCmd )
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:setToolTip( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
AAdd( aLinesPRG, " ::" + HBQTUI_PAD_30( cNam ) + ": setToolTip( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ELSEIF "setPlainText(" $ cCmd
s := hbqtui_pullToolTip( cCmd )
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:setPlainText( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
AAdd( aLinesPRG, " ::" + HBQTUI_PAD_30( cNam ) + ": setPlainText( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ELSEIF "setStyleSheet(" $ cCmd
s := hbqtui_pullToolTip( cCmd )
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:setStyleSheet( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ELSEIF "setText(" $ cCmd
s := hbqtui_pullToolTip( cCmd )
IF hbqtui_pullColumn( cCmd, @n )
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:setText( " + hb_ntos( n ) + ", [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ELSE
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:setText( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ENDIF
AAdd( aLinesPRG, " ::" + HBQTUI_PAD_30( cNam ) + ": setStyleSheet( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ELSEIF "setWhatsThis(" $ cCmd
s := hbqtui_pullToolTip( cCmd )
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:setWhatsThis( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
AAdd( aLinesPRG, " ::" + HBQTUI_PAD_30( cNam ) + ": setWhatsThis( [" + HBQTUI_STRIP_SQ( s ) + "] )" )
ELSEIF "header()->" $ cCmd
// TODO: how to handle : __qtreeviewitem->header()->setVisible( .F. )
@@ -792,15 +829,34 @@ STATIC FUNCTION hbqtui_gen_prg( cFile, cFuncName )
// Nothing TO DO
ELSE
AAdd( aLinesPRG, " hWidget[ " + HBQTUI_PAD_30( HBQTUI_STRINGIFY( cNam ) ) + " ]:" + StrTran( cCmd, "o[", "hWidget[" ) )
AAdd( aLinesPRG, " ::" + HBQTUI_PAD_30( cNam ) + ": " + hbqtui_hashToObj( cCmd ) )
ENDIF
NEXT
AAdd( aLinesPRG, "" )
AAdd( aLinesPRG, " RETURN HbQtUI():new( oRootWidget, hWidget )" )
AAdd( aLinesPRG, " RETURN Self" )
AAdd( aLinesPRG, "" )
RETURN aLinesPRG
RETURN NIL
STATIC FUNCTION hbqtui_hashToObj( cCmd )
LOCAL n, n1
DO WHILE .t.
IF ( n := at( 'o[ "', cCmd ) ) == 0
EXIT
ENDIF
n1 := hb_at( '" ]', cCmd, n )
cCmd := substr( cCmd, 1, n-1 ) + ' ::' + substr( cCmd, n + 4, n1 - n - 4 ) + ' ' + substr( cCmd, n1 + 3 )
ENDDO
RETURN cCmd
STATIC FUNCTION hbqtui_QAppTranslate( cCmd )
IF "QApplication_translate" $ cCmd
cCmd := hbqtui_pullTranslate( cCmd )
ENDIF
RETURN cCmd
STATIC FUNCTION hbqtui_formatCommand( cCmd, lText, widgets )
LOCAL regDefine
@@ -816,7 +872,7 @@ STATIC FUNCTION hbqtui_formatCommand( cCmd, lText, widgets )
lText := .T.
ENDIF
cCmd := StrTran( cCmd, "QApplication_translate" , "q__tr" )
//cCmd := StrTran( cCmd, "QApplication_translate" , "q__tr" )
cCmd := StrTran( cCmd, "QApplication::UnicodeUTF8", '"UTF8"' )
cCmd := StrTran( cCmd, "QString()" , '""' )
cCmd := StrTran( cCmd, "QSize(" , "QSize(" )
@@ -846,6 +902,22 @@ STATIC FUNCTION hbqtui_formatCommand( cCmd, lText, widgets )
RETURN cCmd
STATIC FUNCTION hbqtui_pullTranslate( cCmd )
LOCAL n, n1, n2, n3, n4, cArgs, cText
IF ( n := at( "QApplication_translate", cCmd ) ) > 0
n1 := hb_at( "(", cCmd, n )
n2 := hb_rat( ")", cCmd )
cArgs := SubStr( cCmd, n1 + 1, n2 - n1 - 2 )
n3 := at( ',', cArgs )
n4 := hb_at( ',', cArgs, n3+1 )
cText := StrTran( AllTrim( substr( cArgs, n3 + 1, n4 - n3 - 2 ) ), '"' )
cCmd := substr( cCmd, 1, n-1 ) + ' "' + cText + '" ' + ")"
ENDIF
RETURN cCmd
STATIC FUNCTION hbqtui_isNonImplementedMethod( cString )
LOCAL cMethod, aMethods := {}

View File

@@ -1,160 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* THbQtUI class
*
* Copyright 2010 Pritpal Bedi <pritpal@vouchcac.com>
* http://harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*
* EkOnkar
* ( The LORD is ONE )
*
* Harbour Parts HbQtUI Class
*
* Pritpal Bedi <pritpal@vouchcac.com>
* 28Jan2010
*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
#include "hbclass.ch"
#include "error.ch"
#include "hbtrace.ch"
#define Qt_WA_DeleteOnClose 55
/*----------------------------------------------------------------------*/
CREATE CLASS HbQtUI
VAR oWidget /* TOFIX: User code uses this directly. Then rename this to __oRootWidget and make it PROTECTED. */
VAR qObj INIT { => } /* TOFIX: User code uses this directly. Then rename this to __hWidget and make it PROTECTED. */
METHOD new( oRootWidget, hWidget )
METHOD destroy()
ERROR HANDLER __OnError( ... )
ENDCLASS
/*----------------------------------------------------------------------*/
METHOD HbQtUI:new( oRootWidget, hWidget )
::oWidget := oRootWidget
::qObj := hWidget
::oWidget:setAttribute( Qt_WA_DeleteOnClose, .f. )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD HbQtUI:destroy()
LOCAL oObj
IF !empty( ::oWidget )
::oWidget := NIL
FOR EACH oObj IN ::qObj DESCEND
oObj := NIL
NEXT
::qObj := NIL
ENDIF
RETURN NIL
/*----------------------------------------------------------------------*/
METHOD HbQtUI:__OnError( ... )
LOCAL cMsg := __GetMessage()
LOCAL oError
IF SubStr( cMsg, 1, 1 ) == "_"
cMsg := SubStr( cMsg, 2 )
ENDIF
IF Left( cMsg, 2 ) == "Q_"
IF SubStr( cMsg, 3 ) $ ::qObj
RETURN ::qObj[ SubStr( cMsg, 3 ) ]
ELSE
oError := ErrorNew()
oError:severity := ES_ERROR
oError:genCode := EG_ARG
oError:subSystem := "HBQT"
oError:subCode := 1001
oError:canRetry := .F.
oError:canDefault := .F.
oError:Args := hb_AParams()
oError:operation := ProcName()
oError:Description := "Control <" + substr( cMsg, 3 ) + "> does not exist"
Eval( ErrorBlock(), oError )
ENDIF
ELSEIF ! empty( ::oWidget )
RETURN ::oWidget:&cMsg( ... )
ENDIF
RETURN NIL
/*----------------------------------------------------------------------*/
FUNCTION q__tr( p1, p2, p3, p4 )
HB_SYMBOL_UNUSED( p1 )
HB_SYMBOL_UNUSED( p3 )
HB_SYMBOL_UNUSED( p4 )
RETURN p2
/*----------------------------------------------------------------------*/

View File

@@ -25,6 +25,4 @@ hbqt_hbqtableview.h
hbqt_errorsys.prg
THbQtUI.prg
../qtcore/hbqtcore.hbc

View File

@@ -32,7 +32,6 @@ DYNAMIC HBQPLAINTEXTEDIT
DYNAMIC HBQSYNTAXHIGHLIGHTER
DYNAMIC HBQTABLEVIEW
DYNAMIC HBQTEXTBLOCKUSERDATA
DYNAMIC HBQTUI
DYNAMIC HBQT_ERRORSYS
DYNAMIC HBQT_ISACTIVEAPPLICATION
DYNAMIC HBQT_QMAINWINDOW_RESTSETTINGS
@@ -566,7 +565,6 @@ DYNAMIC QWINDOWSSTYLE
DYNAMIC QWINDOWSTATECHANGEEVENT
DYNAMIC QWIZARD
DYNAMIC QWIZARDPAGE
DYNAMIC Q__TR
DYNAMIC __HBQTGUI
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__HBQTGUI__REQUEST )