QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerattributetable.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerattributetable.h
3  ---------------------------
4  begin : April 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco at hugis dot net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOMPOSERATTRIBUTETABLE_H
19 #define QGSCOMPOSERATTRIBUTETABLE_H
20 
21 #include "qgscomposertable.h"
22 
23 class QgsComposerMap;
24 class QgsVectorLayer;
25 
28 {
29  public:
31  bool operator()( const QgsAttributeMap& m1, const QgsAttributeMap& m2 );
32  void setSortColumn( int col ) { mCurrentSortColumn = col; }
33  void setAscending( bool asc ) { mAscending = asc; }
34  private:
36  bool mAscending;
37 };
38 
41 {
42  Q_OBJECT
43  public:
46 
48  virtual int type() const { return ComposerAttributeTable; }
49 
51  virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
52 
53  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
54  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
55 
61  void setVectorLayer( QgsVectorLayer* layer );
62  /*Returns the vector layer the attribute table is currently using
63  * @returns attribute table's current vector layer
64  * @note added in 2.3
65  * @see setVectorLayer
66  */
67  QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
68 
79  void setComposerMap( const QgsComposerMap* map );
80  /*Returns the composer map whose extents are controlling the features shown in the
81  * table. The extents of the map are only used if displayOnlyVisibleFeatures() is true.
82  * @returns composer map controlling the attribute table
83  * @note added in 2.3
84  * @see setComposerMap
85  * @see displayOnlyVisibleFeatures
86  */
87  const QgsComposerMap* composerMap() const { return mComposerMap; }
88 
96  void setMaximumNumberOfFeatures( int features );
97  /*Returns the maximum number of features to be shown by the table.
98  * @returns maximum number of features
99  * @note added in 2.3
100  * @see setMaximumNumberOfFeatures
101  */
102  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
103 
112  void setDisplayOnlyVisibleFeatures( bool visibleOnly );
113  /*Returns true if the table is set to show only features visible on a corresponding
114  * composer map item.
115  * @returns true if table only shows visible features
116  * @note added in 2.3
117  * @see composerMap
118  * @see setDisplayOnlyVisibleFeatures
119  */
120  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
121 
122  /*Returns true if a feature filter is active on the attribute table
123  * @returns bool state of the feature filter
124  * @note added in 2.3
125  * @see setFilterFeatures
126  * @see featureFilter
127  */
128  bool filterFeatures() const { return mFilterFeatures; }
137  void setFilterFeatures( bool filter );
138 
139  /*Returns the current expression used to filter features for the table. The filter is only
140  * active if filterFeatures() is true.
141  * @returns feature filter expression
142  * @note added in 2.3
143  * @see setFeatureFilter
144  * @see filterFeatures
145  */
146  QString featureFilter() const { return mFeatureFilter; }
156  void setFeatureFilter( const QString& expression );
157 
158  /*Returns the attributes fields which are shown by the table.
159  * @returns a QSet of integers refering to the attributes in the vector layer
160  * @see setDisplayAttributes
161  */
162  QSet<int> displayAttributes() const { return mDisplayAttributes; }
170  void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
171 
172  /*Returns the attribute field aliases, which control how fields are named in the table's
173  * header row.
174  * @returns a QMap of integers to strings, where the string is the field's alias.
175  * @see setFieldAliasMap
176  */
177  QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
178 
188  void setFieldAliasMap( const QMap<int, QString>& map, bool refresh = true );
189 
196  void setSceneRect( const QRectF& rectangle );
197 
210  void setSortAttributes( const QList<QPair<int, bool> > att, bool refresh = true );
211 
212  /*Returns the attributes used to sort the table's features.
213  * @returns a QList of integer/bool pairs, where the integer refers to the attribute index and
214  * the bool to the sort order for the attribute. If true the attribute is sorted ascending,
215  * if false, the attribute is sorted in descending order.
216  * @see setSortAttributes
217  * @note not available in python bindings
218  */
219  QList<QPair<int, bool> > sortAttributes() const { return mSortInformation; }
220 
221  protected:
225  bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
226 
228  QMap<int, QString> getHeaderLabels() const;
229 
230  private:
237 
240 
241  // feature filtering
243  // feature expression filter
244  QString mFeatureFilter;
245 
249  QMap<int, QString> mFieldAliasMap;
250 
252  QList< QPair<int, bool> > mSortInformation;
253 
255  void initializeAliasMap();
256 
264  QString attributeDisplayName( int attributeIndex, const QString& name ) const;
265 
266  private slots:
268  void removeLayer( QString layerId );
269 
270  signals:
272  void maximumNumberOfFeaturesChanged( int n );
273 };
274 
275 #endif // QGSCOMPOSERATTRIBUTETABLE_H
QMap< int, QString > mFieldAliasMap
Map of attribute name aliases.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:98
virtual int type() const
return correct graphics item type.
QList< QPair< int, bool > > sortAttributes() const
virtual QMap< int, QString > getHeaderLabels() const
QMap< int, QString > fieldAliasMap() const
QSet< int > mDisplayAttributes
List of attribute indices to display (or all attributes if list is empty)
QgsVectorLayer * vectorLayer() const
const QgsComposerMap * mComposerMap
Associated composer map (used to display the visible features)
A class to display feature attributes in the print composer.
QgsVectorLayer * mVectorLayer
Associated vector layer.
QList< QPair< int, bool > > mSortInformation
Contains information about sort attribute index / ascending (true/false).
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
const QgsComposerMap * composerMap() const
Graphics scene for map printing.
Object representing map window.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element
virtual bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Retrieves feature attributes.
A table class that displays a vector attribute table.
QSet< int > displayAttributes() const
int mMaximumNumberOfFeatures
Maximum number of features that is displayed.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)=0
sets state from Dom document
bool mShowOnlyVisibleFeatures
Shows only the features that are visible in the associated composer map (true by default) ...
Represents a vector layer which manages a vector based data sets.
Helper class for sorting, takes into account sorting column and ascending / descending.