2010-07-12 11:33 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbqt/tests/testres.prg
  + contrib/hbqt/tests/testqaim.prg
  * contrib/hbqt/hbqt_hbqabstractitemmodel.cpp
    + Added patch from Bacco.
    ! Fixed indentation, formatting, whitespaces, SVN ID, using hb_ntos(), 
      END -> ENDSEQUENCE.
      Pls check my diff to adapt to the style.

  * contrib/hbqt/hbqt.ch
  * contrib/hbqt/hbqt.h
  * contrib/hbqt/hbqt_hbqabstractitemmodel.cpp
  * contrib/hbqt/tests/testqaim.prg
  * contrib/hbxbp/xbpbrowse.prg
    * Renamed QT_QAIM_* to HBQT_QAIM_*.
      These don't look like QT contants, pls tell me if I'm wrong.
This commit is contained in:
Viktor Szakats
2010-07-12 09:34:10 +00:00
parent 9ea0595e69
commit e7c3c7ef66
7 changed files with 224 additions and 59 deletions

View File

@@ -16,6 +16,23 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-07-12 11:33 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbqt/tests/testres.prg
+ contrib/hbqt/tests/testqaim.prg
* contrib/hbqt/hbqt_hbqabstractitemmodel.cpp
+ Added patch from Bacco.
! Fixed indentation, formatting, whitespaces, SVN ID, using hb_ntos(),
END -> ENDSEQUENCE.
Pls check my diff to adapt to the style.
* contrib/hbqt/hbqt.ch
* contrib/hbqt/hbqt.h
* contrib/hbqt/hbqt_hbqabstractitemmodel.cpp
* contrib/hbqt/tests/testqaim.prg
* contrib/hbxbp/xbpbrowse.prg
* Renamed QT_QAIM_* to HBQT_QAIM_*.
These don't look like QT contants, pls tell me if I'm wrong.
2010-07-12 10:04 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbqt/hbqt_hbqabstractitemmodel.cpp
! Fixed formatting.

View File

@@ -66,6 +66,7 @@
/*----------------------------------------------------------------------*/
#ifndef _HBQT_CH
#define _HBQT_CH
/*----------------------------------------------------------------------*/
@@ -2250,12 +2251,10 @@
* QT_(Qt class initials)_(Qt overloaded member)
*/
#define QT_QAIM_data 1001
#define QT_QAIM_flags 1003
#define QT_QAIM_headerData 2001
#define QT_QAIM_rowCount 3001
#define QT_QAIM_columnCount 3002
#define HBQT_QAIM_data 1001
#define HBQT_QAIM_flags 1003
#define HBQT_QAIM_headerData 2001
#define HBQT_QAIM_rowCount 3001
#define HBQT_QAIM_columnCount 3002
#define _HBQT_CH
#endif

View File

@@ -726,10 +726,10 @@ extern void * hbqt_pPtrFromItem( PHB_ITEM pObj );
* QT_(Qt class initials)_(Qt overloaded member)
*/
#define QT_QAIM_data 1001
#define QT_QAIM_flags 1003
#define QT_QAIM_headerData 2001
#define QT_QAIM_rowCount 3001
#define QT_QAIM_columnCount 3002
#define HBQT_QAIM_data 1001
#define HBQT_QAIM_flags 1003
#define HBQT_QAIM_headerData 2001
#define HBQT_QAIM_rowCount 3001
#define HBQT_QAIM_columnCount 3002
#endif /* __HBQT_H */

View File

@@ -6,6 +6,7 @@
* Harbour Project source code:
*
*
* Copyright 2009 Pritpal Bedi <pritpal@vouchcac.com>
* Copyright 2010 Carlos Bacco <carlosbacco at gmail.com>
* www - http://harbour-project.org
*
@@ -151,12 +152,11 @@ Qt::ItemFlags HBQAbstractItemModel::flags( const QModelIndex & index ) const
if( ! index.isValid() )
return 0;
QVariant ret = hbqt_fetchData( block, QT_QAIM_flags, 0, index.column(), index.row() );
if( ret == NULL )
QVariant ret = hbqt_fetchData( block, HBQT_QAIM_flags, 0, index.column(), index.row() );
if( ! ret.isValid() )
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
/* TODO: Fix return ret ; */
return ( QFlags<Qt::ItemFlag> ) ret.toInt();
}
QVariant HBQAbstractItemModel::data( const QModelIndex & index, int role ) const
@@ -164,32 +164,28 @@ QVariant HBQAbstractItemModel::data( const QModelIndex & index, int role ) const
if( !index.isValid() )
return QVariant();
QVariant ret = hbqt_fetchData( block, QT_QAIM_data, role, index.column(), index.row() );
if( ret == NULL )
return QVariant();
QVariant ret = hbqt_fetchData( block, HBQT_QAIM_data, role, index.column(), index.row() );
return ret;
}
QVariant HBQAbstractItemModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
QVariant ret = hbqt_fetchData( block, QT_QAIM_headerData, role, orientation, section );
if( ret == NULL )
return QVariant();
QVariant ret = hbqt_fetchData( block, HBQT_QAIM_headerData, role, orientation, section );
return ret;
}
int HBQAbstractItemModel::rowCount( const QModelIndex & /*parent = QModelIndex()*/ ) const
{
QVariant ret = hbqt_fetchData( block, QT_QAIM_rowCount , 0, 0, 0);
QVariant ret = hbqt_fetchData( block, HBQT_QAIM_rowCount, 0, 0, 0 );
return ret.toInt() ;
}
int HBQAbstractItemModel::columnCount( const QModelIndex & /*parent = QModelIndex()*/ ) const
{
QVariant ret = hbqt_fetchData( block, QT_QAIM_columnCount , 0, 0, 0);
QVariant ret = hbqt_fetchData( block, HBQT_QAIM_columnCount, 0, 0, 0 );
return ret.toInt() ;
}

View File

@@ -0,0 +1,153 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
*
* Copyright 2010 Carlos Bacco <carlosbacco at gmail.com>
* www - http://harbour-project.org
*
*/
#include "hbqt.ch"
#include "common.ch"
STATIC qApp
STATIC oWnd
STATIC oDA, oForeColor, oAlphaColor, oBackBrush, oSize, oPixmap, oIcon, oFont
REQUEST HB_QT
INIT PROCEDURE Qt_Start()
qApp := QApplication():new()
RETURN
EXIT PROCEDURE Qt_End()
qApp:quit()
RETURN
PROCEDURE Main()
LOCAL oDA, tb1, mo1, lay1, lay2, bt1, bt2, bt3
oWnd := QMainWindow():new()
oWnd:resize(600,400 )
oDA := QWidget():new()
oWnd:setCentralWidget( oDA )
lay1 := QVBoxLayout():new( oDA )
/* Here we define some HBQt objects to use in the callback */
oForeColor := QColor():new( 0, 50, 100 ) // Solid blue
oAlphaColor := QColor():new( 255, 0, 0 ) // Transparent Red
oAlphaColor:setAlpha( 128 )
oBackBrush := QBrush():new( QColor():new( 255, 255, 100 ), Qt_BDiagPattern ) // Yellow Diagonal lines
oSize := QSize():new( 80, 30 ) // Default header sizes
oPixmap := QPixMap():new( "harbour-icon.png" ) // Image
oIcon := QIcon():new( oPixMap ) // Icon (reusing the image)
oFont := QFont():new() // Bold Italic font
oFont:setBold( .T. )
oFont:setItalic( .T. )
/* ------------------------------------------------------- */
tb1 := QTableView():new()
mo1 := HBQAbstractItemModel():New( {| t, r, x, y| my_aim( t, r, x, y ) } )
tb1:setModel( mo1 )
lay1:addWidget( tb1 )
lay2 := QHBoxLayout():new()
lay1:addlayout( lay2 )
( bt1 := QPushButton():new() ):SetText( "Dummy 1" )
( bt2 := QPushButton():new() ):SetText( "Dummy 2" )
( bt3 := QPushButton():new() ):SetText( "Dummy 3" )
lay2:addWidget( bt1 )
lay2:addStretch()
lay2:addWidget( bt2 )
lay2:addWidget( bt3 )
oWnd:Show()
qApp:exec()
RETURN
STATIC FUNCTION my_aim( t, role, x, y )
SWITCH t
CASE HBQT_QAIM_data
SWITCH role
CASE Qt_DisplayRole
IF x == 2 .AND. y == 6
RETURN "Unselectable"
ENDIF
RETURN hb_ntos( x ) + "," + hb_ntos( y )
CASE Qt_ForegroundRole
IF x == 7
RETURN oAlphaColor
ENDIF
RETURN oForeColor /* Here we are sending a QColor */
CASE Qt_BackgroundRole
IF x == 2
RETURN oBackBrush /* Here we are sending a QBrush */
ENDIF
RETURN NIL
CASE Qt_TextAlignmentRole
RETURN Qt_AlignCenter
CASE Qt_DecorationRole
IF ( x % 4 ) == 0 .AND. ( y % 4 ) == 0
RETURN oPixmap /* Here we are sending a QPixmap */
ELSEIF x == 2 .AND. y > 4 .AND. y < 10
RETURN oIcon /* Here we are sending a QIcon */
ELSEIF x == 2 .AND. y == 3
RETURN oAlphaColor /* Same role, other type */
ELSEIF x == 2 .AND. y == 4
RETURN oForeColor /* Same role, other type */
ENDIF
CASE Qt_FontRole
IF x == 1
RETURN oFont
ENDIF
RETURN NIL
ENDSWITCH
RETURN NIL
CASE HBQT_QAIM_flags
IF x == 2 .AND. y == 6
RETURN 0 /* cell is unselectable */
ENDIF
RETURN NIL
CASE HBQT_QAIM_headerData
SWITCH role
CASE Qt_DisplayRole
RETURN iif( x == Qt_Horizontal, "H", "V" ) + hb_ntos( y )
CASE Qt_TextAlignmentRole
RETURN Qt_AlignCenter
CASE Qt_SizeHintRole
RETURN oSize /* Finally we are sending a QSize */
ENDSWITCH
BREAK
CASE HBQT_QAIM_rowCount
RETURN 50000
CASE HBQT_QAIM_columnCount
RETURN 1000
ENDSWITCH
RETURN NIL

View File

@@ -5,7 +5,7 @@
/*
* Harbour Project source code:
*
* Copyright 2010 Bacco
* Copyright 2010 Carlos Bacco <carlosbacco at gmail.com>
* www - http://harbour-project.org
*
*/

View File

@@ -444,7 +444,7 @@ METHOD new( nTop, nLeft, nBottom, nRight ) CLASS XbpBrowse
::nRight := nRight
::colorSpec := SetColor()
::oDefaultCellSize := QSize():New(20,::nCellHeight)
RETURN Self
@@ -1023,100 +1023,100 @@ METHOD navigate( p1, p2 ) CLASS XbpBrowse
METHOD XbpBrowse:supplyInfo( nMode, nCall, nRole, nX, nY )
IF nCall == QT_QAIM_headerData .and. nX == Qt_Vertical
IF nCall == HBQT_QAIM_headerData .and. nX == Qt_Vertical
RETURN Nil
End
DO CASE
CASE nMode == 141 /* Main View Header|Data */
IF nCall == QT_QAIM_columnCount
IF nCall == HBQT_QAIM_columnCount
IF ::colCount > 0
::forceStable()
::setHorzScrollBarRange( .t. )
ENDIF
RETURN ::colCount
ELSEIF nCall == QT_QAIM_rowCount
ELSEIF nCall == HBQT_QAIM_rowCount
IF ::colCount > 0
::forceStable()
::setVertScrollBarRange( .f. )
ENDIF
RETURN ::rowCount
ELSEIF nCall == QT_QAIM_data
ELSEIF nCall == HBQT_QAIM_data
RETURN ::fetchColumnInfo( nCall,nRole, 0, nY+1, nX+1 )
ELSEIF nCall == QT_QAIM_headerData
ELSEIF nCall == HBQT_QAIM_headerData
RETURN ::fetchColumnInfo( nCall,nRole, 0, 0 , nY+1 )
ENDIF
RETURN nil
CASE nMode == 142 /* Main View Footer */
IF nCall == QT_QAIM_columnCount
IF nCall == HBQT_QAIM_columnCount
IF ::colCount > 0
::forceStable()
ENDIF
RETURN ::colCount
ELSEIF nCall == QT_QAIM_data
ELSEIF nCall == HBQT_QAIM_data
RETURN ::fetchColumnInfo( nCall,nRole, 1, nY+1, nX+1 )
ELSEIF nCall == QT_QAIM_headerData
ELSEIF nCall == HBQT_QAIM_headerData
RETURN ::fetchColumnInfo( nCall,nRole, 1, 0 , nY+1 )
ENDIF
RETURN nil
CASE nMode == 151 /* Left Frozen Header|Data */
IF nCall == QT_QAIM_columnCount
IF nCall == HBQT_QAIM_columnCount
IF ::nLeftFrozen > 0
::forceStable()
ENDIF
RETURN ::nLeftFrozen
ELSEIF nCall == QT_QAIM_rowCount
ELSEIF nCall == HBQT_QAIM_rowCount
IF ::nLeftFrozen > 0
::forceStable()
ENDIF
RETURN ::rowCount
ELSEIF nCall == QT_QAIM_data
ELSEIF nCall == HBQT_QAIM_data
RETURN ::fetchColumnInfo( nCall,nRole, 0, nY+1, ::aLeftFrozen[ nX+1 ] )
ELSEIF nCall == QT_QAIM_headerData
ELSEIF nCall == HBQT_QAIM_headerData
RETURN ::fetchColumnInfo( nCall,nRole, 0, 0, ::aLeftFrozen[ nY+1 ] )
ENDIF
RETURN nil
CASE nMode == 152 /* Left Frozen Footer */
IF nCall == QT_QAIM_columnCount
IF nCall == HBQT_QAIM_columnCount
IF ::nLeftFrozen > 0
::forceStable()
ENDIF
RETURN ::nLeftFrozen
ELSEIF nCall == QT_QAIM_data
ELSEIF nCall == HBQT_QAIM_data
RETURN ::fetchColumnInfo( nCall,nRole, 1, nY+1, ::aLeftFrozen[ nX+1 ] )
ELSEIF nCall == QT_QAIM_headerData
ELSEIF nCall == HBQT_QAIM_headerData
RETURN ::fetchColumnInfo( nCall,nRole, 1, 0, ::aLeftFrozen[ nY+1 ] )
ENDIF
CASE nMode == 161 /* Right Frozen Header|Data */
IF nCall == QT_QAIM_columnCount
IF nCall == HBQT_QAIM_columnCount
IF ::nRightFrozen > 0
::forceStable()
ENDIF
RETURN ::nRightFrozen
ELSEIF nCall == QT_QAIM_rowCount
ELSEIF nCall == HBQT_QAIM_rowCount
IF ::nRightFrozen > 0
::forceStable()
ENDIF
RETURN ::rowCount
ELSEIF nCall == QT_QAIM_data
ELSEIF nCall == HBQT_QAIM_data
RETURN ::fetchColumnInfo( nCall,nRole, 0, nY+1, ::aRightFrozen[ nX+1 ] )
ELSEIF nCall == QT_QAIM_headerData
ELSEIF nCall == HBQT_QAIM_headerData
RETURN ::fetchColumnInfo( nCall,nRole, 0, 0, ::aRightFrozen[ nY+1 ] )
ENDIF
CASE nMode == 162 /* Right Frozen Footer */
IF nCall == QT_QAIM_columnCount
IF nCall == HBQT_QAIM_columnCount
IF ::nRightFrozen > 0
::forceStable()
ENDIF
RETURN ::nRightFrozen
ELSEIF nCall == QT_QAIM_data
ELSEIF nCall == HBQT_QAIM_data
RETURN ::fetchColumnInfo( nCall,nRole, 1, nY+1, ::aRightFrozen[ nX+1 ] )
ELSEIF nCall == QT_QAIM_headerData
ELSEIF nCall == HBQT_QAIM_headerData
RETURN ::fetchColumnInfo( nCall,nRole, 1, 0, ::aRightFrozen[ nY+1 ] )
ENDIF
@@ -1131,7 +1131,7 @@ METHOD fetchColumnInfo( nCall, nRole, nArea, nRow, nCol ) CLASS XbpBrowse
LOCAL oCol := ::columns[ nCol ]
SWITCH nCall
CASE QT_QAIM_data
CASE HBQT_QAIM_data
SWITCH ( nRole )
CASE Qt_ForegroundRole
@@ -1145,7 +1145,7 @@ METHOD fetchColumnInfo( nCall, nRole, nArea, nRow, nCol ) CLASS XbpBrowse
ELSE
RETURN ::compatColor( oCol:dFgColor )
ENDIF
CASE Qt_BackgroundRole
IF hb_isBlock( oCol:colorBlock )
aColor := eval( oCol:colorBlock, ::cellValueA( nRow, nCol ) )
@@ -1157,16 +1157,16 @@ METHOD fetchColumnInfo( nCall, nRole, nArea, nRow, nCol ) CLASS XbpBrowse
ELSE
RETURN ::compatColor( oCol:dBgColor )
ENDIF
CASE Qt_TextAlignmentRole
RETURN oCol:dAlignment
CASE Qt_SizeHintRole
RETURN ::oDefaultCellSize
CASE Qt_DecorationRole
IF oCol:type == XBPCOL_TYPE_FILEICON
RETURN ::compatIcon( ::cellValue( nRow, nCol ) )
RETURN ::compatIcon( ::cellValue( nRow, nCol ) )
ELSE
RETURN nil
ENDIF
@@ -1178,8 +1178,8 @@ METHOD fetchColumnInfo( nCall, nRole, nArea, nRow, nCol ) CLASS XbpBrowse
ENDIF
ENDSWITCH
RETURN nil
CASE QT_QAIM_headerData
CASE HBQT_QAIM_headerData
IF nArea == 0 /* Header Area */
SWITCH nRole
CASE Qt_SizeHintRole
@@ -1211,12 +1211,12 @@ METHOD fetchColumnInfo( nCall, nRole, nArea, nRow, nCol ) CLASS XbpBrowse
ENDSWITCH
RETURN nil
// TODO: Review the color < 25 case when resolved in HBQt, and avoid unnecessary creation of new QColor/Qicon GC objects
// However, tested with medium data sets, seems not being a big issue by now
// Implementation choice will depend on planned HBQt evolution of pseudo casts and bypass functions (non GC QColor, QIcon, etc)
METHOD compatColor(nColor)
RETURN QColor():new( nColor )