-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgscomposerattributetable.h
162 lines (131 loc) · 6.64 KB
/
qgscomposerattributetable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/***************************************************************************
qgscomposerattributetable.h
---------------------------
begin : April 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco at hugis dot net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSCOMPOSERATTRIBUTETABLE_H
#define QGSCOMPOSERATTRIBUTETABLE_H
#include "qgscomposertable.h"
class QgsComposerMap;
class QgsVectorLayer;
/**Helper class for sorting, takes into account sorting column and ascending / descending*/
class CORE_EXPORT QgsComposerAttributeTableCompare
{
public:
QgsComposerAttributeTableCompare();
bool operator()( const QgsAttributeMap& m1, const QgsAttributeMap& m2 );
void setSortColumn( int col ) { mCurrentSortColumn = col; }
void setAscending( bool asc ) { mAscending = asc; }
private:
int mCurrentSortColumn;
bool mAscending;
};
/**A table class that displays a vector attribute table*/
class CORE_EXPORT QgsComposerAttributeTable: public QgsComposerTable
{
Q_OBJECT
public:
QgsComposerAttributeTable( QgsComposition* composition );
~QgsComposerAttributeTable();
/** return correct graphics item type. Added in v1.7 */
virtual int type() const { return ComposerAttributeTable; }
/** \brief Reimplementation of QCanvasItem::paint*/
virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
void setVectorLayer( QgsVectorLayer* vl );
QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
void setComposerMap( const QgsComposerMap* map );
const QgsComposerMap* composerMap() const { return mComposerMap; }
void setMaximumNumberOfFeatures( int nr ) { mMaximumNumberOfFeatures = nr; }
int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
void setDisplayOnlyVisibleFeatures( bool b ) { mShowOnlyVisibleFeatures = b; }
bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
/*Returns true if a feature filter is active on the attribute table
* @returns bool state of the feature filter
* @note added in 2.3
* @see setFilterFeatures
* @see featureFilter
*/
bool filterFeatures() const { return mFilterFeatures; }
/**Sets whether the feature filter is active for the attribute table
* @param filter Set to true to enable the feature filter
* @note added in 2.3
* @see filterFeatures
* @see setFeatureFilter
*/
void setFilterFeatures( bool filter ) { mFilterFeatures = filter; }
/*Returns the current expression used to filter features for the table. The filter is only
* active if filterFeatures() is true.
* @returns feature filter expression
* @note added in 2.3
* @see setFeatureFilter
* @see filterFeatures
*/
QString featureFilter() const { return mFeatureFilter; }
/**Sets the expression used for filtering features in the table. The filter is only
* active if filterFeatures() is set to true.
* @param expression filter to use for selecting which features to display in the table
* @note added in 2.3
* @see featureFilter
* @see setFilterFeatures
*/
void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
QSet<int> displayAttributes() const { return mDisplayAttributes; }
void setDisplayAttributes( const QSet<int>& attr ) { mDisplayAttributes = attr; }
QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
/**Adapts mMaximumNumberOfFeatures depending on the rectangle height*/
void setSceneRect( const QRectF& rectangle );
// @note not available in python bindings
void setSortAttributes( const QList<QPair<int, bool> > att ) { mSortInformation = att; }
// @note not available in python bindings
QList<QPair<int, bool> > sortAttributes() const { return mSortInformation; }
protected:
/**Retrieves feature attributes
* @note not available in python bindings
*/
bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
//! @note not available in python bindings
QMap<int, QString> getHeaderLabels() const;
private:
/**Associated vector layer*/
QgsVectorLayer* mVectorLayer;
/**Associated composer map (used to display the visible features)*/
const QgsComposerMap* mComposerMap;
/**Maximum number of features that is displayed*/
int mMaximumNumberOfFeatures;
/**Shows only the features that are visible in the associated composer map (true by default)*/
bool mShowOnlyVisibleFeatures;
// feature filtering
bool mFilterFeatures;
// feature expression filter
QString mFeatureFilter;
/**List of attribute indices to display (or all attributes if list is empty)*/
QSet<int> mDisplayAttributes;
/**Map of attribute name aliases. The aliases might be different to those of QgsVectorLayer (but those from the vector layer are the default)*/
QMap<int, QString> mFieldAliasMap;
/**Contains information about sort attribute index / ascending (true/false). First entry has the highest priority*/
QList< QPair<int, bool> > mSortInformation;
/**Inserts aliases from vector layer as starting configuration to the alias map*/
void initializeAliasMap();
/**Returns the attribute name to display in the item (attribute name or an alias if present)*/
QString attributeDisplayName( int attributeIndex, const QString& name ) const;
private slots:
/**Checks if this vector layer will be removed (and sets mVectorLayer to 0 if yes) */
void removeLayer( QString layerId );
signals:
/**This signal is emitted if the maximum number of feature changes (interactively)*/
void maximumNumberOfFeaturesChanged( int n );
};
#endif // QGSCOMPOSERATTRIBUTETABLE_H