27 , mComposerTable( composerTable )
39 if ( hasIndex( row, column, parent ) )
41 if (( *mComposerTable->
columns() )[row] )
43 return createIndex( row, column, ( *mComposerTable->
columns() )[row] );
57 if ( parent.isValid() )
60 return mComposerTable->
columns()->length();
71 if ( !index.isValid() ||
72 ( role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::UserRole ) )
77 if ( index.row() >= mComposerTable->
columns()->length() )
89 if ( role == Qt::UserRole )
92 return qVariantFromValue( qobject_cast<QObject *>( column ) );
95 switch ( index.column() )
103 if ( role == Qt::DisplayRole )
107 case Qt::AlignHCenter:
108 return tr(
"Center" );
110 return tr(
"Right" );
131 if ( !mComposerTable )
136 if ( role == Qt::DisplayRole )
138 if ( orientation == Qt::Vertical )
140 return QVariant( section );
147 return QVariant(
tr(
"Attribute" ) );
150 return QVariant(
tr(
"Heading" ) );
153 return QVariant(
tr(
"Alignment" ) );
168 if ( !index.isValid() || role != Qt::EditRole || !mComposerTable )
172 if ( index.row() >= mComposerTable->
columns()->length() )
184 switch ( index.column() )
191 emit dataChanged( createIndex( index.row(), 1 ), createIndex( index.row(), 1 ) );
194 emit dataChanged( index, index );
198 emit dataChanged( index, index );
202 emit dataChanged( index, index );
215 if ( index.isValid() )
217 return flags | Qt::ItemIsEditable;
229 int maxRow = qMin( row + count - 1, mComposerTable->
columns()->length() - 1 );
230 beginRemoveRows( QModelIndex(), row, maxRow );
232 for (
int i = maxRow; i >= row; --i )
234 delete( *mComposerTable->
columns() )[i];
235 mComposerTable->
columns()->removeAt( i );
244 beginInsertRows( QModelIndex(), row, row + count - 1 );
246 for (
int i = row; i < row + count; ++i )
249 mComposerTable->
columns()->insert( i, col );
257 if (( direction ==
ShiftUp && row <= 0 ) ||
265 int swapWithRow = direction ==
ShiftUp ? row - 1 : row + 1;
268 beginRemoveRows( QModelIndex(), swapWithRow, swapWithRow );
273 beginInsertRows( QModelIndex(), row, row );
274 mComposerTable->
columns()->insert( row, temp );
295 if ( !mComposerTable )
297 return QModelIndex();
300 int r = mComposerTable->
columns()->indexOf( column );
302 QModelIndex idx =
index( r, 0, QModelIndex() );
308 return QModelIndex();
313 if ( !column || !mComposerTable )
320 QList<QgsComposerTableColumn*>::const_iterator columnIt = mComposerTable->
columns()->constBegin();
321 for ( ; columnIt != mComposerTable->
columns()->constEnd(); ++columnIt )
323 highestRank = qMax( highestRank, ( *columnIt )->sortByRank() );
330 emit dataChanged( idx, idx );
335 if ( !mComposerTable || !column )
342 emit dataChanged( idx, idx );
352 if ( !mComposerTable || !column )
364 QList<QgsComposerTableColumn*> sortedColumns;
365 QList<QgsComposerTableColumn*>::iterator columnIt = mComposerTable->
columns()->begin();
366 for ( ; columnIt != mComposerTable->
columns()->end(); ++columnIt )
368 if (( *columnIt )->sortByRank() > 0 )
370 sortedColumns.append( *columnIt );
374 int columnPos = sortedColumns.indexOf( column );
376 if (( columnPos == 0 && direction ==
ShiftUp )
377 || (( columnPos == sortedColumns.length() - 1 ) && direction ==
ShiftDown ) )
384 sortedColumns[ columnPos - 1]
385 : sortedColumns[ columnPos + 1];
392 emit dataChanged( idx, idx );
395 emit dataChanged( idxSwap, idxSwap );
405 : QSortFilterProxyModel( parent )
406 , mComposerTable( composerTable )
407 , mFilterType( filterType )
409 setDynamicSortFilter(
true );
420 QModelIndex
index = sourceModel()->index( source_row, 0, source_parent );
443 QModelIndex sourceIndex = mapToSource( index );
450 QVariant columnAsVariant = sourceModel()->data( sourceIndex, Qt::UserRole );
478 if (( role != Qt::DisplayRole && role != Qt::EditRole ) || !index.isValid() )
489 switch ( index.column() )
494 if ( role == Qt::DisplayRole )
498 case Qt::DescendingOrder:
499 return tr(
"Descending" );
500 case Qt::AscendingOrder:
502 return tr(
"Ascending" );
518 if ( !mComposerTable )
523 if ( role == Qt::DisplayRole )
525 if ( orientation == Qt::Vertical )
527 return QVariant( section );
534 return QVariant(
tr(
"Attribute" ) );
537 return QVariant(
tr(
"Sort Order" ) );
554 if ( index.column() == 1 )
557 flags |= Qt::ItemIsEditable;
565 if ( !index.isValid() || role != Qt::EditRole )
568 if ( !mComposerTable )
579 if ( index.column() == 1 )
582 emit dataChanged( index, index );
591 QModelIndex proxyIndex =
index( row, 0 );