Skip to content

Commit 1622bed

Browse files
committed
Merge branch 'master' into CategorizedRendererUpdate
2 parents acae80e + 11be64d commit 1622bed

File tree

81 files changed

+6862
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+6862
-319
lines changed

python/core/composer/qgscomposerattributetable.sip

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,4 @@ class QgsComposerAttributeTable : QgsComposerTable
232232
*/
233233
// bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
234234

235-
236-
signals:
237-
/**This signal is emitted if the maximum number of feature changes (interactively)*/
238-
void maximumNumberOfFeaturesChanged( int n );
239235
};

python/core/composer/qgscomposerattributetablemodel.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class QgsComposerAttributeTableColumnModel: QAbstractTableModel
1919
* @param composerTable QgsComposerAttributeTable the model is attached to
2020
* @param parent optional parent
2121
*/
22-
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent = 0 );
22+
QgsComposerAttributeTableColumnModel( QgsComposerAttributeTable *composerTable, QObject *parent /TransferThis/ = 0 );
2323
virtual ~QgsComposerAttributeTableColumnModel();
2424

2525
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
@@ -114,7 +114,7 @@ class QgsComposerTableSortColumnsProxyModel : QSortFilterProxyModel
114114
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown
115115
* @param parent optional parent
116116
*/
117-
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent = 0 );
117+
QgsComposerTableSortColumnsProxyModel( QgsComposerAttributeTable *composerTable, ColumnFilterType filterType, QObject *parent /TransferThis/ = 0 );
118118

119119
virtual ~QgsComposerTableSortColumnsProxyModel();
120120

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/**A model for displaying columns shown in a QgsComposerAttributeTableV2*/
2+
class QgsComposerAttributeTableColumnModelV2: QAbstractTableModel
3+
{
4+
%TypeHeaderCode
5+
#include <qgscomposerattributetablemodelv2.h>
6+
%End
7+
8+
public:
9+
10+
/*! Controls whether a row/column is shifted up or down
11+
*/
12+
enum ShiftDirection
13+
{
14+
ShiftUp, /*!< shift the row/column up */
15+
ShiftDown /*!< shift the row/column down */
16+
};
17+
18+
/**Constructor for QgsComposerAttributeTableColumnModel.
19+
/**Constructor for QgsComposerAttributeTableColumnModel.
20+
* @param composerTable QgsComposerAttributeTable the model is attached to
21+
* @param parent optional parent
22+
*/
23+
QgsComposerAttributeTableColumnModelV2( QgsComposerAttributeTableV2 *composerTable, QObject *parent /TransferThis/ = 0 );
24+
virtual ~QgsComposerAttributeTableColumnModelV2();
25+
26+
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
27+
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
28+
virtual QVariant data( const QModelIndex &index, int role ) const;
29+
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
30+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
31+
Qt::ItemFlags flags( const QModelIndex &index ) const;
32+
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
33+
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() );
34+
QModelIndex index( int row, int column, const QModelIndex &parent ) const;
35+
QModelIndex parent( const QModelIndex &child ) const;
36+
37+
/**Moves the specified row up or down in the model. Used for rearranging the attribute tables
38+
* columns.
39+
* @returns true if the move is allowed
40+
* @param row row in model representing attribute table column to move
41+
* @param direction direction to move the attribute table column
42+
* @note added in 2.3
43+
*/
44+
bool moveRow( int row , ShiftDirection direction );
45+
46+
/**Resets the attribute table's columns to match the source layer's fields. Remove all existing
47+
* attribute table columns and column customisations.
48+
* @note added in 2.3
49+
*/
50+
void resetToLayer();
51+
52+
/**Returns the QgsComposerTableColumn corresponding to an index in the model.
53+
* @returns QgsComposerTableColumn for specified index
54+
* @param index a QModelIndex
55+
* @note added in 2.3
56+
* @see indexFromColumn
57+
*/
58+
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
59+
60+
/**Returns a QModelIndex corresponding to a QgsComposerTableColumn in the model.
61+
* @returns QModelIndex for specified QgsComposerTableColumn
62+
* @param column a QgsComposerTableColumn
63+
* @note added in 2.3
64+
* @see columnFromIndex
65+
*/
66+
QModelIndex indexFromColumn( QgsComposerTableColumn *column );
67+
68+
/**Sets a specified column as a sorted column in the QgsComposerAttributeTable. The column will be
69+
* added to the end of the sort rank list, ie it will take the next largest available sort rank.
70+
* @param column a QgsComposerTableColumn
71+
* @param order sort order for column
72+
* @note added in 2.3
73+
* @see removeColumnFromSort
74+
* @see moveColumnInSortRank
75+
*/
76+
void setColumnAsSorted( QgsComposerTableColumn *column, Qt::SortOrder order );
77+
78+
/**Sets a specified column as an unsorted column in the QgsComposerAttributeTable. The column will be
79+
* removed from the sort rank list.
80+
* @param column a QgsComposerTableColumn
81+
* @note added in 2.3
82+
* @see setColumnAsSorted
83+
*/
84+
void setColumnAsUnsorted( QgsComposerTableColumn * column );
85+
86+
/**Moves a column up or down in the sort rank for the QgsComposerAttributeTable.
87+
* @param column a QgsComposerTableColumn
88+
* @param direction direction to move the column in the sort rank list
89+
* @note added in 2.3
90+
* @see setColumnAsSorted
91+
*/
92+
bool moveColumnInSortRank( QgsComposerTableColumn * column, ShiftDirection direction );
93+
94+
};
95+
96+
/**Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted*/
97+
class QgsComposerTableSortColumnsProxyModelV2 : QSortFilterProxyModel
98+
{
99+
%TypeHeaderCode
100+
#include <qgscomposerattributetablemodelv2.h>
101+
%End
102+
103+
public:
104+
105+
/*! Controls whether the proxy model shows sorted or unsorted columns
106+
*/
107+
enum ColumnFilterType
108+
{
109+
ShowSortedColumns, /*!< show only sorted columns */
110+
ShowUnsortedColumns/*!< show only unsorted columns */
111+
};
112+
113+
/**Constructor for QgsComposerTableSortColumnsProxyModel.
114+
* @param composerTable QgsComposerAttributeTable the model is attached to
115+
* @param filterType filter for columns, controls whether sorted or unsorted columns are shown
116+
* @param parent optional parent
117+
*/
118+
QgsComposerTableSortColumnsProxyModelV2( QgsComposerAttributeTableV2 *composerTable, ColumnFilterType filterType, QObject *parent /TransferThis/ = 0 );
119+
120+
virtual ~QgsComposerTableSortColumnsProxyModelV2();
121+
122+
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
123+
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
124+
virtual QVariant data( const QModelIndex &index, int role ) const;
125+
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
126+
Qt::ItemFlags flags( const QModelIndex &index ) const;
127+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
128+
129+
/**Returns the QgsComposerTableColumn corresponding to a row in the proxy model.
130+
* @returns QgsComposerTableColumn for specified row
131+
* @param row a row number
132+
* @note added in 2.3
133+
* @see columnFromIndex
134+
*/
135+
QgsComposerTableColumn* columnFromRow( int row );
136+
137+
/**Returns the QgsComposerTableColumn corresponding to an index in the proxy model.
138+
* @returns QgsComposerTableColumn for specified index
139+
* @param index a QModelIndex
140+
* @note added in 2.3
141+
* @see columnFromRow
142+
* @see columnFromSourceIndex
143+
*/
144+
QgsComposerTableColumn* columnFromIndex( const QModelIndex & index ) const;
145+
146+
/**Returns the QgsComposerTableColumn corresponding to an index from the source
147+
* QgsComposerAttributeTableColumnModel model.
148+
* @returns QgsComposerTableColumn for specified index from QgsComposerAttributeTableColumnModel
149+
* @param sourceIndex a QModelIndex
150+
* @note added in 2.3
151+
* @see columnFromRow
152+
* @see columnFromIndex
153+
*/
154+
QgsComposerTableColumn* columnFromSourceIndex( const QModelIndex& sourceIndex ) const;
155+
156+
/**Invalidates the current filter used by the proxy model
157+
* @note added in 2.3
158+
*/
159+
void resetFilter();
160+
161+
protected:
162+
bool filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const;
163+
164+
};
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
2+
/**Helper class for sorting tables, takes into account sorting column and ascending / descending*/
3+
class QgsComposerAttributeTableCompareV2
4+
{
5+
%TypeHeaderCode
6+
#include <qgscomposerattributetablev2.h>
7+
%End
8+
9+
public:
10+
11+
QgsComposerAttributeTableCompareV2();
12+
13+
bool operator()( const QgsComposerTableRow& m1, const QgsComposerTableRow& m2 );
14+
15+
/**Sets column number to sort by
16+
* @param col column number for sorting
17+
*/
18+
void setSortColumn( int col );
19+
20+
/**Sets sort order for column sorting
21+
* @param asc set to true to sort in ascending order, false to sort in descending order
22+
*/
23+
void setAscending( bool asc );
24+
25+
};
26+
27+
/**A table that displays attributes from a vector layer*/
28+
class QgsComposerAttributeTableV2 : QgsComposerTableV2
29+
{
30+
%TypeHeaderCode
31+
#include <qgscomposerattributetablev2.h>
32+
%End
33+
34+
public:
35+
36+
QgsComposerAttributeTableV2( QgsComposition* composition, bool createUndoCommands );
37+
~QgsComposerAttributeTableV2();
38+
39+
/**Writes properties specific to attribute tables
40+
* @param elem an existing QDomElement in which to store the attribute table's properties.
41+
* @param doc QDomDocument for the destination xml.
42+
* @see readXML
43+
*/
44+
virtual bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
45+
46+
/**Reads the properties specific to an attribute table from xml.
47+
* @param itemElem a QDomElement holding the attribute table's desired properties.
48+
* @param doc QDomDocument for the source xml.
49+
* @see writeXML
50+
*/
51+
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
52+
53+
virtual void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
54+
55+
/**Sets the vector layer from which to display feature attributes
56+
* @param layer Vector layer for attribute table
57+
* @see vectorLayer
58+
*/
59+
void setVectorLayer( QgsVectorLayer* layer );
60+
61+
/**Returns the vector layer the attribute table is currently using
62+
* @returns attribute table's current vector layer
63+
* @see setVectorLayer
64+
*/
65+
QgsVectorLayer* vectorLayer() const;
66+
67+
/**Resets the attribute table's columns to match the vector layer's fields
68+
* @see setVectorLayer
69+
*/
70+
void resetColumns();
71+
72+
/**Sets the composer map to use to limit the extent of features shown in the
73+
* attribute table. This setting only has an effect if setDisplayOnlyVisibleFeatures is
74+
* set to true. Changing the composer map forces the table to refetch features from its
75+
* vector layer, and may result in the table changing size to accommodate the new displayed
76+
* feature attributes.
77+
* @param map QgsComposerMap which drives the extents of the table's features
78+
* @see composerMap
79+
* @see setDisplayOnlyVisibleFeatures
80+
*/
81+
void setComposerMap( const QgsComposerMap* map );
82+
83+
/**Returns the composer map whose extents are controlling the features shown in the
84+
* table. The extents of the map are only used if displayOnlyVisibleFeatures() is true.
85+
* @returns composer map controlling the attribute table
86+
* @see setComposerMap
87+
* @see displayOnlyVisibleFeatures
88+
*/
89+
const QgsComposerMap* composerMap() const;
90+
91+
/**Sets the maximum number of features shown by the table. Changing this setting may result
92+
* in the attribute table changing its size to accommodate the new number of rows, and requires
93+
* the table to refetch features from its vector layer.
94+
* @param features maximum number of features to show in the table
95+
* @see maximumNumberOfFeatures
96+
*/
97+
void setMaximumNumberOfFeatures( int features );
98+
99+
/**Returns the maximum number of features to be shown by the table.
100+
* @returns maximum number of features
101+
* @see setMaximumNumberOfFeatures
102+
*/
103+
int maximumNumberOfFeatures() const;
104+
105+
/**Sets attribute table to only show features which are visible in a composer map item. Changing
106+
* this setting forces the table to refetch features from its vector layer, and may result in
107+
* the table changing size to accommodate the new displayed feature attributes.
108+
* @param visibleOnly set to true to show only visible features
109+
* @see displayOnlyVisibleFeatures
110+
* @see setComposerMap
111+
*/
112+
void setDisplayOnlyVisibleFeatures( bool visibleOnly );
113+
114+
/**Returns true if the table is set to show only features visible on a corresponding
115+
* composer map item.
116+
* @returns true if table only shows visible features
117+
* @see composerMap
118+
* @see setDisplayOnlyVisibleFeatures
119+
*/
120+
bool displayOnlyVisibleFeatures() const;
121+
122+
/**Returns true if a feature filter is active on the attribute table
123+
* @returns bool state of the feature filter
124+
* @see setFilterFeatures
125+
* @see featureFilter
126+
*/
127+
bool filterFeatures() const;
128+
129+
/**Sets whether the feature filter is active for the attribute table. Changing
130+
* this setting forces the table to refetch features from its vector layer, and may result in
131+
* the table changing size to accommodate the new displayed feature attributes.
132+
* @param filter Set to true to enable the feature filter
133+
* @see filterFeatures
134+
* @see setFeatureFilter
135+
*/
136+
void setFilterFeatures( bool filter );
137+
138+
/**Returns the current expression used to filter features for the table. The filter is only
139+
* active if filterFeatures() is true.
140+
* @returns feature filter expression
141+
* @see setFeatureFilter
142+
* @see filterFeatures
143+
*/
144+
QString featureFilter() const;
145+
146+
/**Sets the expression used for filtering features in the table. The filter is only
147+
* active if filterFeatures() is set to true. Changing this setting forces the table
148+
* to refetch features from its vector layer, and may result in
149+
* the table changing size to accommodate the new displayed feature attributes.
150+
* @param expression filter to use for selecting which features to display in the table
151+
* @see featureFilter
152+
* @see setFilterFeatures
153+
*/
154+
void setFeatureFilter( const QString& expression );
155+
156+
/**Sets the attributes to display in the table.
157+
* @param attr QSet of integer values refering to the attributes from the vector layer to show.
158+
* Set to an empty QSet to show all feature attributes.
159+
* @param refresh set to true to force the table to refetch features from its vector layer
160+
* and immediately update the display of the table. This may result in the table changing size
161+
* to accommodate the new displayed feature attributes.
162+
* @see displayAttributes
163+
*/
164+
void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
165+
166+
/**Returns the attributes used to sort the table's features.
167+
* @returns a QList of integer/bool pairs, where the integer refers to the attribute index and
168+
* the bool to the sort order for the attribute. If true the attribute is sorted ascending,
169+
* if false, the attribute is sorted in descending order.
170+
* @note not available in python bindings
171+
*/
172+
//QList<QPair<int, bool> > sortAttributes() const;
173+
174+
/**Queries the attribute table's vector layer for attributes to show in the table.
175+
* @param attributeMaps list of QgsAttributeMaps where the fetched feature attributes will be stored
176+
* @returns true if attributes were successfully fetched
177+
* @note not available in python bindings
178+
*/
179+
bool getTableContents( QgsComposerTableContents &contents );
180+
181+
};

0 commit comments

Comments
 (0)