33 : mCurrentSortColumn( 0 ), mAscending( true )
40 return ( mAscending ?
qgsVariantLessThan( m1[mCurrentSortColumn], m2[mCurrentSortColumn] )
50 , mSource( LayerAttributes )
51 , mVectorLayer( nullptr )
52 , mCurrentAtlasLayer( nullptr )
53 , mComposerMap( nullptr )
54 , mMaximumNumberOfFeatures( 30 )
55 , mShowUniqueRowsOnly( false )
56 , mShowOnlyVisibleFeatures( false )
57 , mFilterToAtlasIntersection( false )
58 , mFilterFeatures( false )
59 , mFeatureFilter(
"" )
64 for ( ; mapIt != layerMap.
constEnd(); ++mapIt )
101 return tr(
"<attribute table>" );
106 if ( layer == mVectorLayer )
113 mVectorLayer = layer;
136 if ( relationId == mRelationId )
166 void QgsComposerAttributeTableV2::atlasLayerChanged(
QgsVectorLayer *layer )
175 if ( mCurrentAtlasLayer )
181 mCurrentAtlasLayer = layer;
205 for (
int idx = 0; idx < fields.
count(); ++idx )
217 if ( map == mComposerMap )
240 if ( features == mMaximumNumberOfFeatures )
245 mMaximumNumberOfFeatures = features;
252 if ( uniqueOnly == mShowUniqueRowsOnly )
257 mShowUniqueRowsOnly = uniqueOnly;
264 if ( visibleOnly == mShowOnlyVisibleFeatures )
269 mShowOnlyVisibleFeatures = visibleOnly;
276 if ( filterToAtlas == mFilterToAtlasIntersection )
281 mFilterToAtlasIntersection = filterToAtlas;
288 if ( filter == mFilterFeatures )
293 mFilterFeatures = filter;
300 if ( expression == mFeatureFilter )
305 mFeatureFilter = expression;
327 for ( ; attIt != attr.
constEnd(); ++attIt )
329 int attrIdx = ( *attIt );
330 if ( !fields.
exists( attrIdx ) )
344 for (
int idx = 0; idx < fields.
count(); ++idx )
360 void QgsComposerAttributeTableV2::restoreFieldAliasMap(
const QMap<int, QString>& map )
371 int attrIdx = source->
fieldNameIndex(( *columnIt )->attribute() );
374 ( *columnIt )->setHeading( map.
value( attrIdx ) );
403 context->setFields( layer->
fields() );
407 bool activeFilter =
false;
408 if ( mFilterFeatures && !mFeatureFilter.
isEmpty() )
411 if ( !filterExpression->hasParserError() )
418 if ( mComposerMap && mShowOnlyVisibleFeatures )
446 if ( !selectionRect.
isEmpty() )
463 while ( fit.
nextFeature( f ) && counter < mMaximumNumberOfFeatures )
465 context->setFeature( f );
467 if ( activeFilter && !filterExpression.
isNull() )
469 QVariant result = filterExpression->evaluate( context.
data() );
477 if ( mFilterToAtlasIntersection )
500 currentRow << replaceWrapChar( f.
attributes().
at( idx ) );
515 contents << currentRow;
523 for (
int i = sortColumns.
size() - 1; i >= 0; --i )
527 qStableSort( contents.
begin(), contents.
end(), c );
546 QVariant QgsComposerAttributeTableV2::replaceWrapChar(
const QVariant &variant )
const 553 replaced.
replace( mWrapString,
"\n" );
574 void QgsComposerAttributeTableV2::removeLayer(
const QString& layerId )
578 if ( layerId == mVectorLayer->
id() )
580 mVectorLayer =
nullptr;
590 return a.second->sortByRank() < b.second->sortByRank();
601 if (( *columnIt )->sortByRank() > 0 )
603 sortedColumns.
append( qMakePair( idx, *columnIt ) );
614 for ( ; sortedColumnIt != sortedColumns.
constEnd(); ++sortedColumnIt )
617 attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
618 ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
620 return attributesBySortRank;
625 if ( wrapString == mWrapString )
639 composerTableElem.
setAttribute(
"relationId", mRelationId );
640 composerTableElem.
setAttribute(
"showUniqueRowsOnly", mShowUniqueRowsOnly );
641 composerTableElem.
setAttribute(
"showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
642 composerTableElem.
setAttribute(
"filterToAtlasIntersection", mFilterToAtlasIntersection );
643 composerTableElem.
setAttribute(
"maxFeatures", mMaximumNumberOfFeatures );
644 composerTableElem.
setAttribute(
"filterFeatures", mFilterFeatures ?
"true" :
"false" );
645 composerTableElem.
setAttribute(
"featureFilter", mFeatureFilter );
646 composerTableElem.
setAttribute(
"wrapString", mWrapString );
650 composerTableElem.
setAttribute(
"composerMap", mComposerMap->
id() );
658 composerTableElem.
setAttribute(
"vectorLayer", mVectorLayer->
id() );
689 mRelationId = itemElem.
attribute(
"relationId",
"" );
696 mShowUniqueRowsOnly = itemElem.
attribute(
"showUniqueRowsOnly",
"0" ).
toInt();
697 mShowOnlyVisibleFeatures = itemElem.
attribute(
"showOnlyVisibleFeatures",
"1" ).
toInt();
698 mFilterToAtlasIntersection = itemElem.
attribute(
"filterToAtlasIntersection",
"0" ).
toInt();
699 mFilterFeatures = itemElem.
attribute(
"filterFeatures",
"false" ) ==
"true" ? true :
false;
700 mFeatureFilter = itemElem.
attribute(
"featureFilter",
"" );
701 mMaximumNumberOfFeatures = itemElem.
attribute(
"maxFeatures",
"5" ).
toInt();
702 mWrapString = itemElem.
attribute(
"wrapString" );
705 int composerMapId = itemElem.
attribute(
"composerMap",
"-1" ).
toInt();
706 if ( composerMapId == -1 )
708 mComposerMap =
nullptr;
717 mComposerMap =
nullptr;
728 if ( layerId ==
"not_existing" )
730 mVectorLayer =
nullptr;
759 if ( recalcFrameSizes )
767 if ( source == mSource )
776 if ( newLayer != prevLayer )
788 mCurrentAtlasLayer = newLayer;
void setFilterToAtlasFeature(const bool filterToAtlas)
Sets attribute table to only show features which intersect the current atlas feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
void setAttribute(const QString &attribute)
Sets the attribute name or expression used for the column's values.
Single variable definition for use within a QgsExpressionContextScope.
QgsVectorLayer * sourceLayer()
Returns the source layer for the table, considering the table source mode.
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the objects' current state.
A rectangle specified with double values.
Base class for all map layer types.
QgsAttributes attributes() const
Returns the feature's attributes.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
bool intersects(const QgsRectangle &r) const
Test for intersection with a rectangle (uses GEOS)
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
Helper class for sorting tables, takes into account sorting column and ascending / descending...
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
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.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void setWrapString(const QString &wrapString)
Sets a string to wrap the contents of the table cells by.
const_iterator constEnd() const
const_iterator constBegin() const
const T & at(int i) const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
int id() const
Get identification number.
Container of fields for a vector layer.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Writes properties specific to attribute tables.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
void setComposerMap(const QgsComposerMap *map)
Sets the composer map to use to limit the extent of features shown in the attribute table...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsRelationManager * relationManager() const
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
int count() const
Return number of items.
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads the properties specific to an attribute table from xml.
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.
QgsFields fields() const
Returns the list of fields of this layer.
const char * name() const
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
QString number(int n, int base)
void append(const T &value)
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
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...
void setFilterFeatures(const bool filter)
Sets whether the feature filter is active for the attribute table.
bool isEmpty() const
test if rectangle is empty.
void setAttribute(const QString &name, const QString &value)
void setSortColumn(int col)
Sets column number to sort by.
int toInt(bool *ok, int base) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QList< QgsComposerFrame * > mFrameItems
const_iterator constEnd() const
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
void addComposerTableFrame(QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame)
Adds composer tablev2 frame and advises composer to create a widget for it (through signal) ...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
A class to display a table in the print composer, and allow the table to span over multiple frames...
ContentSource source() const
Returns the source for attributes shown in the table body.
void recalculateFrameSizes() override
const_iterator constEnd() const
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
bool operator()(const QgsComposerTableRow &m1, const QgsComposerTableRow &m2)
void setRelationId(const QString &relationId)
Sets the relation id from which to display child features.
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
Stores properties of a column in a QgsComposerTable.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
Graphics scene for map printing.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
Object representing map window.
Frame item for a composer multiframe item.
QgsFeatureId id() const
Get the feature ID for this feature.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void setDisplayAttributes(const QSet< int > &attr, bool refresh=true)
Sets the attributes to display in the table.
void setSource(const ContentSource source)
Sets the source for attributes to show in table body.
bool getTableContents(QgsComposerTableContents &contents) override
Queries the attribute table's vector layer for attributes to show in the table.
const_iterator constBegin() const
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table's features.
QgsComposition * mComposition
~QgsComposerAttributeTableV2()
QString & replace(int position, int n, QChar after)
QgsComposerTableColumns mColumns
Columns to show in table.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
const T & at(int i) const
QgsComposerAttributeTableCompareV2()
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
const_iterator constBegin() const
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true) override
Adds a frame to the multiframe.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
ContentSource
Specifies the content source for the attribute table.
void setMaximumNumberOfFeatures(const int features)
Sets the maximum number of features shown by the table.
QgsComposition * composition()
Returns the parent composition for the multiframe.
virtual void refreshAttributes()
Refreshes the contents shown in the table by querying for new data.
static bool columnsBySortRank(QPair< int, QgsComposerTableColumn * > a, QPair< int, QgsComposerTableColumn * > b)
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
access to canonical QgsProject instance
void setUniqueRowsOnly(const bool uniqueOnly)
Sets attribute table to only show unique rows.
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
QString relationId() const
Returns the relation id which the table displays child features from.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QgsAtlasComposition & atlasComposition()
QgsFeature feature() const
Returns the current atlas feature.
QString wrapString() const
Returns the string used to wrap the contents of the table cells by.
Custom exception class for Coordinate Reference System related exceptions.
void setAscending(bool asc)
Sets sort order for column sorting.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
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.
QgsComposerTableContents * contents()
Returns the current contents of the table.
QgsComposerFrame * frame(int i) const
Returns a child frame from the multiframe.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
virtual QString displayName() const override
Get multiframe display name.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void setDisplayOnlyVisibleFeatures(const bool visibleOnly)
Sets attribute table to only show features which are visible in a composer map item.
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.
bool enabled() const
Returns whether the atlas generation is enabled.
virtual QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the objects' current state.
QgsComposerAttributeTableV2(QgsComposition *composition, bool createUndoCommands)
void changed()
Emitted when the properties of a multi frame have changed, and the GUI item widget must be updated...
const T value(const Key &key) const