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 
56  void setVectorLayer( QgsVectorLayer* vl );
57  QgsVectorLayer* vectorLayer() const { return mVectorLayer; }
58 
59  void setComposerMap( const QgsComposerMap* map );
60  const QgsComposerMap* composerMap() const { return mComposerMap; }
61 
62  void setMaximumNumberOfFeatures( int nr ) { mMaximumNumberOfFeatures = nr; }
63  int maximumNumberOfFeatures() const { return mMaximumNumberOfFeatures; }
64 
65  void setDisplayOnlyVisibleFeatures( bool b ) { mShowOnlyVisibleFeatures = b; }
66  bool displayOnlyVisibleFeatures() const { return mShowOnlyVisibleFeatures; }
67 
68  /*Returns true if a feature filter is active on the attribute table
69  * @returns bool state of the feature filter
70  * @note added in 2.3
71  * @see setFilterFeatures
72  * @see featureFilter
73  */
74  bool filterFeatures() const { return mFilterFeatures; }
81  void setFilterFeatures( bool filter ) { mFilterFeatures = filter; }
82 
83  /*Returns the current expression used to filter features for the table. The filter is only
84  * active if filterFeatures() is true.
85  * @returns feature filter expression
86  * @note added in 2.3
87  * @see setFeatureFilter
88  * @see filterFeatures
89  */
90  QString featureFilter() const { return mFeatureFilter; }
98  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
99 
100  QSet<int> displayAttributes() const { return mDisplayAttributes; }
101  void setDisplayAttributes( const QSet<int>& attr ) { mDisplayAttributes = attr; }
102 
103  QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
104  void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
105 
107  void setSceneRect( const QRectF& rectangle );
108 
109  // @note not available in python bindings
110  void setSortAttributes( const QList<QPair<int, bool> > att ) { mSortInformation = att; }
111 
112  // @note not available in python bindings
113  QList<QPair<int, bool> > sortAttributes() const { return mSortInformation; }
114 
115  protected:
119  bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
120 
122  QMap<int, QString> getHeaderLabels() const;
123 
124  private:
131 
134 
135  // feature filtering
137  // feature expression filter
138  QString mFeatureFilter;
139 
143  QMap<int, QString> mFieldAliasMap;
144 
146  QList< QPair<int, bool> > mSortInformation;
147 
149  void initializeAliasMap();
151  QString attributeDisplayName( int attributeIndex, const QString& name ) const;
152 
153  private slots:
155  void removeLayer( QString layerId );
156 
157  signals:
159  void maximumNumberOfFeaturesChanged( int n );
160 };
161 
162 #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
void setFilterFeatures(bool filter)
Sets whether the feature filter is active for the attribute table.
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.
void setSortAttributes(const QList< QPair< int, bool > > att)
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
void setFieldAliasMap(const QMap< int, QString > &map)
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.
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
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...
void setDisplayAttributes(const QSet< int > &attr)
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.