|
| 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