27 , mComposerTable( composerTable )
39 if ( hasIndex( row, column, parent ) )
57 if ( parent.isValid() )
71 if ( !index.isValid() ||
72 ( role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::UserRole ) )
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" );
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 )
184 switch ( index.column() )
191 emit dataChanged( createIndex( index.row(), 1, 0 ), createIndex( index.row(), 1, 0 ) );
194 emit dataChanged( index, index );
198 emit dataChanged( index, index );
202 emit dataChanged( index, index );
213 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
215 if ( index.isValid() )
217 return flags | Qt::ItemIsEditable;
230 beginRemoveRows( QModelIndex(), row, maxRow );
232 for (
int i = maxRow; i >= row; --i )
244 beginInsertRows( QModelIndex(), row, row + count - 1 );
246 for (
int i = row; i < row + count; ++i )
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 );
297 return QModelIndex();
302 QModelIndex idx =
index( r, 0, QModelIndex() );
308 return QModelIndex();
323 highestRank = qMax( highestRank, ( *columnIt )->sortByRank() );
330 emit dataChanged( idx, idx );
342 emit dataChanged( idx, idx );
364 QList<QgsComposerTableColumn*> sortedColumns;
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" );
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" ) );
552 Qt::ItemFlags
flags = QAbstractItemModel::flags( index );
554 if ( index.column() == 1 )
557 flags |= Qt::ItemIsEditable;
565 if ( !index.isValid() || role != Qt::EditRole )
579 if ( index.column() == 1 )
582 emit dataChanged( index, index );
591 QModelIndex proxyIndex =
index( row, 0 );
QgsComposerAttributeTable * mComposerTable
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
QgsComposerTableColumn * columnFromRow(int row)
Returns the QgsComposerTableColumn corresponding to a row in the proxy model.
void setAttribute(QString attribute)
Sets the attribute name or expression used for the column's values.
QgsComposerAttributeTable * mComposerTable
virtual QVariant data(const QModelIndex &index, int role) const
QModelIndex index(int row, int column, const QModelIndex &parent) const
int sortByRank() const
Returns the sort rank for the column.
QgsComposerAttributeTableColumnModel(QgsComposerAttributeTable *composerTable, QObject *parent=0)
Constructor for QgsComposerAttributeTableColumnModel.
void setColumnAsSorted(QgsComposerTableColumn *column, Qt::SortOrder order)
Sets a specified column as a sorted column in the QgsComposerAttributeTable.
Qt::SortOrder sortOrder() const
Returns the sort order for the column.
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
void setHAlignment(Qt::AlignmentFlag alignment)
Sets the horizontal alignment for a column, which controls the alignment used for drawing column valu...
bool moveRow(int row, ShiftDirection direction)
Moves the specified row up or down in the model.
QgsComposerTableColumn * columnFromSourceIndex(const QModelIndex &sourceIndex) const
Returns the QgsComposerTableColumn corresponding to an index from the source QgsComposerAttributeTabl...
Qt::ItemFlags flags(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
QModelIndex parent(const QModelIndex &child) const
static bool columnsBySortRank(QgsComposerTableColumn *a, QgsComposerTableColumn *b)
virtual ~QgsComposerAttributeTableColumnModel()
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Qt::ItemFlags flags(const QModelIndex &index) const
QgsComposerTableColumn * columnFromIndex(const QModelIndex &index) const
Returns the QgsComposerTableColumn corresponding to an index in the model.
virtual QVariant data(const QModelIndex &index, int role) const
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 bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
ColumnFilterType mFilterType
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.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
A table class that displays a vector attribute table.
bool moveColumnInSortRank(QgsComposerTableColumn *column, ShiftDirection direction)
Moves a column up or down in the sort rank for the QgsComposerAttributeTable.
QString heading() const
Returns the heading for a column, which is the value displayed in the columns header cell...
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order for the column.
Qt::AlignmentFlag hAlignment() const
Returns the horizontal alignment for a column, which controls the alignment used for drawing column v...
QString attribute() const
Returns the attribute name or expression used for the column's values.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
QgsComposerTableSortColumnsProxyModel(QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent=0)
Constructor for QgsComposerTableSortColumnsProxyModel.
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
virtual ~QgsComposerTableSortColumnsProxyModel()
void setColumnAsUnsorted(QgsComposerTableColumn *column)
Sets a specified column as an unsorted column in the QgsComposerAttributeTable.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
void resetFilter()
Invalidates the current filter used by the proxy model.