Skip to content

Commit

Permalink
Fix various models failing qt model test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 21, 2014
1 parent 1f12d00 commit 0b96d5a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
8 changes: 0 additions & 8 deletions src/core/composer/qgscomposerattributetablemodel.cpp
Expand Up @@ -36,14 +36,6 @@ QgsComposerAttributeTableColumnModel::~QgsComposerAttributeTableColumnModel()

QModelIndex QgsComposerAttributeTableColumnModel::index( int row, int column, const QModelIndex &parent ) const
{
Q_UNUSED( parent );
if ( row < 0 || row >= rowCount()
|| column < 0 || column >= columnCount() )
{
//invalid row
return QModelIndex();
}

if ( hasIndex( row, column, parent ) )
{
if (( *mComposerTable->columns() )[row] )
Expand Down
15 changes: 10 additions & 5 deletions src/gui/qgsfieldmodel.cpp
Expand Up @@ -135,11 +135,12 @@ void QgsFieldModel::removeExpression()

QModelIndex QgsFieldModel::index( int row, int column, const QModelIndex &parent ) const
{
Q_UNUSED( parent );
if ( row < 0 || row >= rowCount() )
return QModelIndex();
if ( hasIndex( row, column, parent ) )
{
return createIndex( row, column, row );
}

return createIndex( row, column, row );
return QModelIndex();
}

QModelIndex QgsFieldModel::parent( const QModelIndex &child ) const
Expand All @@ -150,7 +151,11 @@ QModelIndex QgsFieldModel::parent( const QModelIndex &child ) const

int QgsFieldModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );
if ( parent.isValid() )
{
return 0;
}

return mAllowExpression ? mFields.count() + mExpression.count() : mFields.count();
}

Expand Down
20 changes: 12 additions & 8 deletions src/gui/qgsmaplayermodel.cpp
Expand Up @@ -105,11 +105,13 @@ void QgsMapLayerModel::addLayers( QList<QgsMapLayer *> layers )

QModelIndex QgsMapLayerModel::index( int row, int column, const QModelIndex &parent ) const
{
Q_UNUSED( parent );
if ( row < 0 || row >= mLayers.length() )
return QModelIndex();
if ( hasIndex( row, column, parent ) )
{
return createIndex( row, column, mLayers[row] );
}

return QModelIndex();

return createIndex( row, column, mLayers[row] );
}

QModelIndex QgsMapLayerModel::parent( const QModelIndex &child ) const
Expand All @@ -118,11 +120,10 @@ QModelIndex QgsMapLayerModel::parent( const QModelIndex &child ) const
return QModelIndex();
}


int QgsMapLayerModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );

return mLayers.length();
return parent.isValid() ? 0 : mLayers.length();
}

int QgsMapLayerModel::columnCount( const QModelIndex &parent ) const
Expand Down Expand Up @@ -213,7 +214,10 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const

Qt::ItemFlags QgsMapLayerModel::flags( const QModelIndex &index ) const
{
Q_UNUSED( index );
if ( !index.isValid() )
{
return 0;
}

Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if ( mItemCheckable )
Expand Down
10 changes: 9 additions & 1 deletion src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Expand Up @@ -87,6 +87,11 @@ QgsRendererCategoryV2 QgsCategorizedSymbolRendererV2Model::category( const QMode

Qt::ItemFlags QgsCategorizedSymbolRendererV2Model::flags( const QModelIndex & index ) const
{
if ( !index.isValid() )
{
return Qt::ItemIsDropEnabled;
}

Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
if ( index.column() == 1 || index.column() == 2 )
{
Expand Down Expand Up @@ -186,7 +191,10 @@ QVariant QgsCategorizedSymbolRendererV2Model::headerData( int section, Qt::Orien

int QgsCategorizedSymbolRendererV2Model::rowCount( const QModelIndex &parent ) const
{
if ( parent.column() > 0 || !mRenderer ) return 0;
if ( parent.isValid() || !mRenderer )
{
return 0;
}
return mRenderer->categories().size();
}

Expand Down
10 changes: 9 additions & 1 deletion src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Expand Up @@ -93,6 +93,11 @@ QgsRendererRangeV2 QgsGraduatedSymbolRendererV2Model::rendererRange( const QMode

Qt::ItemFlags QgsGraduatedSymbolRendererV2Model::flags( const QModelIndex & index ) const
{
if ( !index.isValid() )
{
return Qt::ItemIsDropEnabled;
}

Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;

if ( index.column() == 2 )
Expand Down Expand Up @@ -178,7 +183,10 @@ QVariant QgsGraduatedSymbolRendererV2Model::headerData( int section, Qt::Orienta

int QgsGraduatedSymbolRendererV2Model::rowCount( const QModelIndex &parent ) const
{
if ( parent.column() > 0 || !mRenderer ) return 0;
if ( parent.isValid() || !mRenderer )
{
return 0;
}
return mRenderer->ranges().size();
}

Expand Down

0 comments on commit 0b96d5a

Please sign in to comment.