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 );
231 Qt::ItemFlags
flags = QAbstractItemModel::flags( 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" ) );
570 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
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 );
QgsComposerTableColumn * columnFromRow(int row)
Returns the QgsComposerTableColumn corresponding to a row in the proxy model.
bool moveColumnInSortRank(QgsComposerTableColumn *column, ShiftDirection direction)
Moves a column up or down in the sort rank for the QgsComposerAttributeTable.
virtual QVariant data(const QModelIndex &index, int role) const override
void setColumnAsUnsorted(QgsComposerTableColumn *column)
Sets a specified column as an unsorted column in the QgsComposerAttributeTable.
void setAttribute(QString attribute)
Sets the attribute name or expression used for the column's values.
int sortByRank() const
Returns the sort rank for the column.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
static bool columnsBySortRank(QgsComposerTableColumn *a, QgsComposerTableColumn *b)
double width() const
Returns the width for a column.
Qt::SortOrder sortOrder() const
Returns the sort order for the column.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
QgsComposerTableColumn * columnFromIndex(const QModelIndex &index) const
Returns the QgsComposerTableColumn corresponding to an index in the model.
void setHAlignment(Qt::AlignmentFlag alignment)
Sets the horizontal alignment for a column, which controls the alignment used for drawing column valu...
QgsComposerTableSortColumnsProxyModelV2(QgsComposerAttributeTableV2 *composerTable, ColumnFilterType filterType, QObject *parent=0)
Constructor for QgsComposerTableSortColumnsProxyModel.
A table that displays attributes from a vector layer.
QModelIndex parent(const QModelIndex &child) const override
void resetToLayer()
Resets the attribute table's columns to match the source layer's fields.
QModelIndex indexFromColumn(QgsComposerTableColumn *column)
Returns a QModelIndex corresponding to a QgsComposerTableColumn in the model.
void setColumnAsSorted(QgsComposerTableColumn *column, Qt::SortOrder order)
Sets a specified column as a sorted column in the QgsComposerAttributeTable.
QgsComposerTableColumn * columnFromIndex(const QModelIndex &index) const
Returns the QgsComposerTableColumn corresponding to an index in the proxy model.
Stores properties of a column in a QgsComposerTable.
virtual ~QgsComposerTableSortColumnsProxyModelV2()
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
QgsComposerAttributeTableColumnModelV2(QgsComposerAttributeTableV2 *composerTable, QObject *parent=0)
Constructor for QgsComposerAttributeTableColumnModel.
Qt::ItemFlags flags(const QModelIndex &index) const override
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
bool moveRow(int row, ShiftDirection direction)
Moves the specified row up or down in the model.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QString heading() const
Returns the heading for a column, which is the value displayed in the columns header cell...
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order for the column.
QgsComposerTableColumn * columnFromSourceIndex(const QModelIndex &sourceIndex) const
Returns the QgsComposerTableColumn corresponding to an index from the source QgsComposerAttributeTabl...
Qt::AlignmentFlag hAlignment() const
Returns the horizontal alignment for a column, which controls the alignment used for drawing column v...
QgsComposerTableColumns * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
QString attribute() const
Returns the attribute name or expression used for the column's values.
virtual ~QgsComposerAttributeTableColumnModelV2()
void setWidth(const double width)
Sets the width for a column.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Qt::ItemFlags flags(const QModelIndex &index) const override
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void resetFilter()
Invalidates the current filter used by the proxy model.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
virtual QVariant data(const QModelIndex &index, int role) const override