Skip to content

Commit bae196b

Browse files
committed
[composer] Small fixes to attribute table column model
1 parent eb5627c commit bae196b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/core/composer/qgscomposerattributetablemodel.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,34 @@ QgsComposerAttributeTableColumnModel::~QgsComposerAttributeTableColumnModel()
3737
QModelIndex QgsComposerAttributeTableColumnModel::index( int row, int column, const QModelIndex &parent ) const
3838
{
3939
Q_UNUSED( parent );
40-
if ( row < 0 || row >= mComposerTable->columns()->length() )
40+
if ( row < 0 || row >= rowCount()
41+
|| column < 0 || column >= columnCount() )
4142
{
4243
//invalid row
4344
return QModelIndex();
4445
}
4546

46-
return createIndex( row, column, ( *mComposerTable->columns() )[row] );
47+
if ( hasIndex( row, column, parent ) )
48+
{
49+
if (( *mComposerTable->columns() )[row] )
50+
{
51+
return createIndex( row, column, ( *mComposerTable->columns() )[row] );
52+
}
53+
}
54+
return QModelIndex();
55+
}
56+
57+
QModelIndex QgsComposerAttributeTableColumnModel::parent( const QModelIndex &child ) const
58+
{
59+
Q_UNUSED( child );
60+
return QModelIndex();
4761
}
4862

4963
int QgsComposerAttributeTableColumnModel::rowCount( const QModelIndex &parent ) const
5064
{
51-
Q_UNUSED( parent );
65+
if ( parent.isValid() )
66+
return 0;
67+
5268
return mComposerTable->columns()->length();
5369
}
5470

src/core/composer/qgscomposerattributetablemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CORE_EXPORT QgsComposerAttributeTableColumnModel: public QAbstractTableMod
5757
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
5858
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() );
5959
QModelIndex index( int row, int column, const QModelIndex &parent ) const;
60+
QModelIndex parent( const QModelIndex &child ) const;
6061

6162
/**Moves the specified row up or down in the model. Used for rearranging the attribute tables
6263
* columns.

0 commit comments

Comments
 (0)