QGIS API Documentation  2.2.0-Valmiera
 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  const 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  QSet<int> displayAttributes() const { return mDisplayAttributes; }
69  void setDisplayAttributes( const QSet<int>& attr ) { mDisplayAttributes = attr; }
70 
71  QMap<int, QString> fieldAliasMap() const { return mFieldAliasMap; }
72  void setFieldAliasMap( const QMap<int, QString>& map ) { mFieldAliasMap = map; }
73 
75  void setSceneRect( const QRectF& rectangle );
76 
77  // @note not available in python bindings
78  void setSortAttributes( const QList<QPair<int, bool> > att ) { mSortInformation = att; }
79 
80  // @note not available in python bindings
81  QList<QPair<int, bool> > sortAttributes() const { return mSortInformation; }
82 
83  protected:
87  bool getFeatureAttributes( QList<QgsAttributeMap>& attributeMaps );
88 
90  QMap<int, QString> getHeaderLabels() const;
91 
92  private:
99 
102 
106  QMap<int, QString> mFieldAliasMap;
107 
109  QList< QPair<int, bool> > mSortInformation;
110 
112  void initializeAliasMap();
114  QString attributeDisplayName( int attributeIndex, const QString& name ) const;
115 
116  private slots:
118  void removeLayer( QString layerId );
119 
120  signals:
122  void maximumNumberOfFeaturesChanged( int n );
123 };
124 
125 #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.
const QgsVectorLayer * vectorLayer() const
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)
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.
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.