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" );
124 if ( role == Qt::DisplayRole )
126 return column->
width() <= 0 ?
tr(
"Automatic" ) : QString(
tr(
"%1 mm" ) ).arg( column->
width(), 0,
'f', 2 );
131 return column->
width();
142 if ( !mComposerTable )
147 if ( role == Qt::DisplayRole )
149 if ( orientation == Qt::Vertical )
151 return QVariant( section );
158 return QVariant(
tr(
"Attribute" ) );
161 return QVariant(
tr(
"Heading" ) );
164 return QVariant(
tr(
"Alignment" ) );
167 return QVariant(
tr(
"Width" ) );
182 if ( !index.isValid() || role != Qt::EditRole || !mComposerTable )
186 if ( index.row() >= mComposerTable->
columns()->length() )
198 switch ( index.column() )
205 emit dataChanged( createIndex( index.row(), 1 ), createIndex( index.row(), 1 ) );
208 emit dataChanged( index, index );
212 emit dataChanged( index, index );
216 emit dataChanged( index, index );
219 column->
setWidth( value.toDouble() );
220 emit dataChanged( index, index );
233 if ( index.isValid() )
235 return flags | Qt::ItemIsEditable;
247 int maxRow = qMin( row + count - 1, mComposerTable->
columns()->length() - 1 );
248 beginRemoveRows( QModelIndex(), row, maxRow );
250 for (
int i = maxRow; i >= row; --i )
252 delete( *mComposerTable->
columns() )[i];
253 mComposerTable->
columns()->removeAt( i );
262 beginInsertRows( QModelIndex(), row, row + count - 1 );
264 for (
int i = row; i < row + count; ++i )
267 mComposerTable->
columns()->insert( i, col );
275 if (( direction ==
ShiftUp && row <= 0 ) ||
283 int swapWithRow = direction ==
ShiftUp ? row - 1 : row + 1;
286 beginRemoveRows( QModelIndex(), swapWithRow, swapWithRow );
291 beginInsertRows( QModelIndex(), row, row );
292 mComposerTable->
columns()->insert( row, temp );
313 if ( !mComposerTable )
315 return QModelIndex();
318 int r = mComposerTable->
columns()->indexOf( column );
320 QModelIndex idx =
index( r, 0, QModelIndex() );
326 return QModelIndex();
331 if ( !column || !mComposerTable )
338 QList<QgsComposerTableColumn*>::const_iterator columnIt = mComposerTable->
columns()->constBegin();
339 for ( ; columnIt != mComposerTable->
columns()->constEnd(); ++columnIt )
341 highestRank = qMax( highestRank, ( *columnIt )->sortByRank() );
348 emit dataChanged( idx, idx );
353 if ( !mComposerTable || !column )
360 emit dataChanged( idx, idx );
370 if ( !mComposerTable || !column )
382 QList<QgsComposerTableColumn*> sortedColumns;
383 QList<QgsComposerTableColumn*>::iterator columnIt = mComposerTable->
columns()->begin();
384 for ( ; columnIt != mComposerTable->
columns()->end(); ++columnIt )
386 if (( *columnIt )->sortByRank() > 0 )
388 sortedColumns.append( *columnIt );
392 int columnPos = sortedColumns.indexOf( column );
394 if (( columnPos == 0 && direction ==
ShiftUp )
395 || (( columnPos == sortedColumns.length() - 1 ) && direction ==
ShiftDown ) )
402 sortedColumns[ columnPos - 1]
403 : sortedColumns[ columnPos + 1];
410 emit dataChanged( idx, idx );
413 emit dataChanged( idxSwap, idxSwap );
423 : QSortFilterProxyModel( parent )
424 , mComposerTable( composerTable )
425 , mFilterType( filterType )
427 setDynamicSortFilter(
true );
438 QModelIndex
index = sourceModel()->index( source_row, 0, source_parent );
461 QModelIndex sourceIndex = mapToSource( index );
468 QVariant columnAsVariant = sourceModel()->data( sourceIndex, Qt::UserRole );
496 if (( role != Qt::DisplayRole && role != Qt::EditRole ) || !index.isValid() )
507 switch ( index.column() )
512 if ( role == Qt::DisplayRole )
516 case Qt::DescendingOrder:
517 return tr(
"Descending" );
518 case Qt::AscendingOrder:
520 return tr(
"Ascending" );
536 if ( !mComposerTable )
541 if ( role == Qt::DisplayRole )
543 if ( orientation == Qt::Vertical )
545 return QVariant( section );
552 return QVariant(
tr(
"Attribute" ) );
555 return QVariant(
tr(
"Sort Order" ) );
572 if ( index.column() == 1 )
575 flags |= Qt::ItemIsEditable;
583 if ( !index.isValid() || role != Qt::EditRole )
586 if ( !mComposerTable )
597 if ( index.column() == 1 )
600 emit dataChanged( index, index );
609 QModelIndex proxyIndex =
index( row, 0 );