28 : mCurrentSortColumn( 0 ), mAscending( true )
35 return ( mAscending ?
qgsVariantLessThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] )
44 , mVectorLayer( nullptr )
45 , mComposerMap( nullptr )
46 , mMaximumNumberOfFeatures( 5 )
47 , mShowOnlyVisibleFeatures( false )
48 , mFilterFeatures( false )
49 , mFeatureFilter(
"" )
54 for ( ; mapIt != layerMap.
constEnd(); ++mapIt )
85 if ( mComposerMap && mComposerMap->
isDrawing() )
98 if ( layer == mVectorLayer )
110 mVectorLayer = layer;
133 for (
int idx = 0; idx < fields.
count(); ++idx )
145 if ( map == mComposerMap )
167 if ( features == mMaximumNumberOfFeatures )
172 mMaximumNumberOfFeatures = features;
178 if ( visibleOnly == mShowOnlyVisibleFeatures )
183 mShowOnlyVisibleFeatures = visibleOnly;
189 if ( filter == mFilterFeatures )
194 mFilterFeatures = filter;
200 if ( expression == mFeatureFilter )
205 mFeatureFilter = expression;
211 return fieldsToDisplay().
toSet();
230 for ( ; attIt != attr.
constEnd(); ++attIt )
232 int attrIdx = ( *attIt );
233 if ( !fields.
exists( attrIdx ) )
247 for (
int idx = 0; idx < fields.
count(); ++idx )
270 int attrIdx = mVectorLayer->
fieldNameIndex(( *columnIt )->attribute() );
271 fieldAliasMap.
insert( attrIdx, ( *columnIt )->heading() );
286 int attrIdx = mVectorLayer->
fieldNameIndex(( *columnIt )->attribute() );
289 ( *columnIt )->setHeading( map.
value( attrIdx ) );
301 restoreFieldAliasMap( map );
305 QList<int> QgsComposerAttributeTable::fieldsToDisplay()
const 313 int idx = mVectorLayer->
fieldNameIndex(( *columnIt )->attribute() );
327 context->setFields( mVectorLayer->
fields() );
329 attributeMaps.
clear();
333 bool activeFilter =
false;
334 if ( mFilterFeatures && !mFeatureFilter.
isEmpty() )
337 if ( !filterExpression->hasParserError() )
344 if ( mComposerMap && mShowOnlyVisibleFeatures )
364 if ( !selectionRect.
isEmpty() )
373 while ( fit.
nextFeature( f ) && counter < mMaximumNumberOfFeatures )
375 context->setFeature( f );
377 if ( activeFilter && !filterExpression.
isNull() )
379 QVariant result = filterExpression->evaluate( context.
data() );
393 int idx = mVectorLayer->
fieldNameIndex(( *columnIt )->attribute() );
402 context->lastScope()->setVariable(
QString(
"row_number" ), counter + 1 );
416 for (
int i = sortColumns.
size() - 1; i >= 0; --i )
420 qStableSort( attributeMaps.
begin(), attributeMaps.
end(), c );
427 void QgsComposerAttributeTable::removeLayer(
const QString& layerId )
431 if ( layerId == mVectorLayer->
id() )
433 mVectorLayer =
nullptr;
463 for ( ; sortedColumnIt != att.
constEnd(); ++sortedColumnIt )
469 mColumns.
at(( *sortedColumnIt ).first )->setSortByRank( rank );
470 mColumns.
at(( *sortedColumnIt ).first )->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
479 return a.second->sortByRank() < b.second->sortByRank();
490 if (( *columnIt )->sortByRank() > 0 )
492 sortedColumns.
append( qMakePair( idx, *columnIt ) );
503 for ( ; sortedColumnIt != sortedColumns.
constEnd(); ++sortedColumnIt )
506 attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
507 ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
509 return attributesBySortRank;
515 composerTableElem.
setAttribute(
"showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
516 composerTableElem.
setAttribute(
"maxFeatures", mMaximumNumberOfFeatures );
517 composerTableElem.
setAttribute(
"filterFeatures", mFilterFeatures ?
"true" :
"false" );
518 composerTableElem.
setAttribute(
"featureFilter", mFeatureFilter );
522 composerTableElem.
setAttribute(
"composerMap", mComposerMap->
id() );
530 composerTableElem.
setAttribute(
"vectorLayer", mVectorLayer->
id() );
551 mShowOnlyVisibleFeatures = itemElem.
attribute(
"showOnlyVisibleFeatures",
"1" ).
toInt();
552 mFilterFeatures = itemElem.
attribute(
"filterFeatures",
"false" ) ==
"true" ? true :
false;
553 mFeatureFilter = itemElem.
attribute(
"featureFilter",
"" );
556 int composerMapId = itemElem.
attribute(
"composerMap",
"-1" ).
toInt();
557 if ( composerMapId == -1 )
559 mComposerMap =
nullptr;
568 mComposerMap =
nullptr;
579 if ( layerId ==
"not_existing" )
581 mVectorLayer =
nullptr;
600 if ( !displayAttributeList.
isEmpty() )
604 for (
int i = 0; i < attributeEntryList.
size(); ++i )
610 displayAttributes.
insert( index );
619 if ( !aliasMapNodeList.
isEmpty() )
623 for (
int i = 0; i < aliasMepEntryList.
size(); ++i )
628 fieldAliasMap.
insert( key, value );
630 restoreFieldAliasMap( fieldAliasMap );
635 if ( !sortColumnsElem.
isNull() && mVectorLayer )
640 for (
int i = 0; i < columns.
size(); ++i )
644 Qt::SortOrder order = columnElem.
attribute(
"ascending" ) ==
"true" ? Qt::AscendingOrder : Qt::DescendingOrder;
648 if ( column->
attribute() == fields[attribute].name() )
659 mMaximumNumberOfFeatures = itemElem.
attribute(
"maxFeatures",
"5" ).
toInt();
Class for parsing and evaluation of expressions (formerly called "search strings").
void setSceneRect(const QRectF &rectangle) override
Adapts mMaximumNumberOfFeatures depending on the rectangle height.
Wrapper for iterator of features from vector data provider or vector layer.
QDomNodeList elementsByTagName(const QString &tagname) const
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column's values.
A rectangle specified with double values.
Base class for all map layer types.
QgsAttributes attributes() const
Returns the feature's attributes.
void setAscending(bool asc)
Sets sort order for column sorting.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
Q_DECL_DEPRECATED void setSortAttributes(const QList< QPair< int, bool > > &att)
Sets the attributes to use to sort the table's features.
bool contains(const Key &key) const
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
QMap< int, QVariant > QgsAttributeMap
QDomNode appendChild(const QDomNode &newChild)
void append(const T &value)
Use exact geometry intersection (slower) instead of bounding boxes.
void push_back(const T &value)
QString attribute(const QString &name, const QString &defValue) const
bool tableWriteXML(QDomElement &itemElem, QDomDocument &doc) const
Writes common table properties to xml for storage.
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
bool exists(int i) const
Return if a field index is valid.
void itemChanged()
Emitted when the item changes.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void setComposerMap(const QgsComposerMap *map)
Sets the composer map to use to limit the extent of features shown in the attribute table...
const_iterator constEnd() const
const_iterator constBegin() const
const T & at(int i) const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps) override
Queries the attribute table's vector layer for attributes to show in the table.
int id() const
Get identification number.
Container of fields for a vector layer.
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
const_iterator insert(const T &value)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
void setDisplayAttributes(const QSet< int > &attr, bool refresh=true)
Sets the attributes to display in the table.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the item's current state.
int count() const
Return number of items.
bool operator()(const QgsAttributeMap &m1, const QgsAttributeMap &m2)
void setFilterFeatures(bool filter)
Sets whether the feature filter is active for the attribute table.
void setDisplayOnlyVisibleFeatures(bool visibleOnly)
Sets attribute table to only show features which are visible in a composer map item.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
A class to display feature attributes in the print composer.
QgsFields fields() const
Returns the list of fields of this layer.
QDomElement toElement() const
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Reads the properties specific to an attribute table from xml.
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table's features.
const char * name() const
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
void append(const T &value)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void setHeading(const QString &heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
bool isEmpty() const
test if rectangle is empty.
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
const_iterator constEnd() const
static bool columnsBySortRank(QPair< int, QgsComposerTableColumn * > a, QPair< int, QgsComposerTableColumn * > b)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setMaximumNumberOfFeatures(int features)
Sets the maximum number of features shown by the table.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
const_iterator constEnd() const
Q_DECL_DEPRECATED void setFieldAliasMap(const QMap< int, QString > &map)
Sets the attribute field aliases, which control how fields are named in the table's header row...
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
QgsComposerAttributeTable(QgsComposition *composition)
Stores properties of a column in a QgsComposerTable.
bool isDrawing() const
True if a draw is already in progress.
Graphics scene for map printing.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
Object representing map window.
QgsComposerAttributeTableCompare()
QList< QgsComposerTableColumn * > mColumns
const_iterator constBegin() const
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
QgsComposition * mComposition
virtual void refreshAttributes()
Refreshes the attributes shown in the table by querying the vector layer for new data.
const T & at(int i) const
const_iterator constBegin() const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
const QgsComposition * composition() const
Returns the composition the item is attached to.
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the table's common properties from xml.
virtual void adjustFrameToSize()
Adapts the size of the frame to match the content.
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order for the column.
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Writes properties specific to attribute tables.
void setSortColumn(int col)
Sets column number to sort by.
QDomElement firstChildElement(const QString &tagName) const
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...
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
QString attribute() const
Returns the attribute name or expression used for the column's values.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint.
~QgsComposerAttributeTable()
QgsAtlasComposition & atlasComposition()
iterator insert(const Key &key, const T &value)
Custom exception class for Coordinate Reference System related exceptions.
Q_DECL_DEPRECATED QSet< int > displayAttributes() const
Returns the attributes fields which are shown by the table.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
Helper class for sorting tables, takes into account sorting column and ascending / descending...
Q_DECL_DEPRECATED QMap< int, QString > fieldAliasMap() const
Returns the attribute field aliases, which control how fields are named in the table's header row...
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
void setSortByRank(int sortByRank)
Sets the sort rank for the column.
QDomNode at(int index) const
const T value(const Key &key) const