Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][composer] Rework attribute tables to make tables more flexi…
…ble. - Add support for reordering columns in a table (fix #5942) - Add support for expression based columns - Add support for setting column alignment (fix #2957) - Add support for setting column header alignment - Make sorting in tables correctly handle nulls, dates, times, locale aware string sorting This work also paves the way for future expansion of attribute tables to allow for setting column widths, column colors, etc.
- Loading branch information
1 parent
fa0f0bd
commit dc905ac
Showing
24 changed files
with
2,985 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
python/core/composer/qgscomposerattributetablemodel.sip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/**A model for displaying columns shown in a QgsComposerAttributeTable*/ | ||
class QgsComposerAttributeTableColumnModel: public QAbstractTableModel | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscomposerattributetablemodel.h> | ||
%End | ||
|
||
public: | ||
|
||
/*! Controls whether a row/column is shifted up or down | ||
*/ | ||
enum ShiftDirection | ||
{ | ||
ShiftUp, /*!< shift the row/column up */ | ||
ShiftDown /*!< shift the row/column down */ | ||
}; | ||
|
||
/**Constructor for QgsComposerAttributeTableColumnModel. | ||
* @param composerTable QgsComposerAttributeTable the model is attached to | ||
*/ | ||
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent = 0 ); | ||
virtual ~QgsComposerAttributeTableColumnModel(); | ||
|
||
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; | ||
int columnCount( const QModelIndex &parent = QModelIndex() ) const; | ||
virtual QVariant data( const QModelIndex &index, int role ) const; | ||
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | ||
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); | ||
Qt::ItemFlags flags( const QModelIndex &index ) const; | ||
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ); | ||
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ); | ||
QModelIndex index( int row, int column, const QModelIndex &parent ) const; | ||
|
||
/**Moves the specified row up or down in the model. Used for rearranging the attribute tables | ||
* columns. | ||
* @returns true if the move is allowed | ||
* @param row row in model representing attribute table column to move | ||
* @param direction direction to move the attribute table column | ||
* @note added in 2.3 | ||
*/ | ||
bool moveRow( int row , ShiftDirection direction ); | ||
|
||
/**Resets the attribute table's columns to match the source layer's fields. Remove all existing | ||
* attribute table columns and column customisations. | ||
* @note added in 2.3 | ||
*/ | ||
void resetToLayer(); | ||
|
||
/**Returns the QgsComposerTableColumn corresponding to an index in the model. | ||
* @returns QgsComposerTableColumn for specified index | ||
* @param index a QModelIndex | ||
* @note added in 2.3 | ||
* @see indexFromColumn | ||
*/ | ||
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const; | ||
|
||
/**Returns a QModelIndex corresponding to a QgsComposerTableColumn in the model. | ||
* @returns QModelIndex for specified QgsComposerTableColumn | ||
* @param column a QgsComposerTableColumn | ||
* @note added in 2.3 | ||
* @see columnFromIndex | ||
*/ | ||
QModelIndex indexFromColumn( QgsComposerTableColumn *column ); | ||
|
||
/**Sets a specified column as a sorted column in the QgsComposerAttributeTable. The column will be | ||
* added to the end of the sort rank list, ie it will take the next largest available sort rank. | ||
* @param column a QgsComposerTableColumn | ||
* @param order sort order for column | ||
* @note added in 2.3 | ||
* @see removeColumnFromSort | ||
* @see moveColumnInSortRank | ||
*/ | ||
void setColumnAsSorted( QgsComposerTableColumn *column, Qt::SortOrder order ); | ||
|
||
/**Sets a specified column as an unsorted column in the QgsComposerAttributeTable. The column will be | ||
* removed from the sort rank list. | ||
* @param column a QgsComposerTableColumn | ||
* @note added in 2.3 | ||
* @see setColumnAsSorted | ||
*/ | ||
void setColumnAsUnsorted( QgsComposerTableColumn * column ); | ||
|
||
/**Moves a column up or down in the sort rank for the QgsComposerAttributeTable. | ||
* @param column a QgsComposerTableColumn | ||
* @param direction direction to move the column in the sort rank list | ||
* @note added in 2.3 | ||
* @see setColumnAsSorted | ||
*/ | ||
bool moveColumnInSortRank( QgsComposerTableColumn * column, ShiftDirection direction ); | ||
|
||
}; | ||
|
||
/**Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted*/ | ||
class QgsComposerTableSortColumnsProxyModel : public QSortFilterProxyModel | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscomposerattributetablemodel.h> | ||
%End | ||
|
||
public: | ||
/*! Controls whether the proxy model shows sorted or unsorted columns | ||
*/ | ||
enum ColumnFilterType | ||
{ | ||
ShowSortedColumns, /*!< show only sorted columns */ | ||
ShowUnsortedColumns/*!< show only unsorted columns */ | ||
}; | ||
|
||
/**Constructor for QgsComposerTableSortColumnsProxyModel. | ||
* @param composerTable QgsComposerAttributeTable the model is attached to | ||
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown | ||
*/ | ||
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent = 0 ); | ||
|
||
virtual ~QgsComposerTableSortColumnsProxyModel(); | ||
|
||
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const; | ||
int columnCount( const QModelIndex &parent = QModelIndex() ) const; | ||
virtual QVariant data( const QModelIndex &index, int role ) const; | ||
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | ||
Qt::ItemFlags flags( const QModelIndex &index ) const; | ||
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); | ||
|
||
/**Returns the QgsComposerTableColumn corresponding to a row in the proxy model. | ||
* @returns QgsComposerTableColumn for specified row | ||
* @param row a row number | ||
* @note added in 2.3 | ||
* @see columnFromIndex | ||
*/ | ||
QgsComposerTableColumn* columnFromRow( int row ); | ||
|
||
/**Returns the QgsComposerTableColumn corresponding to an index in the proxy model. | ||
* @returns QgsComposerTableColumn for specified index | ||
* @param index a QModelIndex | ||
* @note added in 2.3 | ||
* @see columnFromRow | ||
* @see columnFromSourceIndex | ||
*/ | ||
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const; | ||
|
||
|
||
/**Returns the QgsComposerTableColumn corresponding to an index from the source | ||
* QgsComposerAttributeTableColumnModel model. | ||
* @returns QgsComposerTableColumn for specified index from QgsComposerAttributeTableColumnModel | ||
* @param index a QModelIndex | ||
* @note added in 2.3 | ||
* @see columnFromRow | ||
* @see columnFromIndex | ||
*/ | ||
QgsComposerTableColumn* columnFromSourceIndex( const QModelIndex& sourceIndex ) const; | ||
|
||
protected: | ||
|
||
bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const; | ||
|
||
}; |
Oops, something went wrong.