33 : mCurrentSortColumn( 0 ), mAscending( true )
40 QVariant v1 = m1[mCurrentSortColumn];
41 QVariant v2 = m2[mCurrentSortColumn];
65 case QVariant::LongLong:
66 case QVariant::ULongLong:
70 case QVariant::Double:
78 case QVariant::DateTime:
93 return ( mAscending ? less : !less );
102 , mSource( LayerAttributes )
104 , mCurrentAtlasLayer( 0 )
106 , mMaximumNumberOfFeatures( 30 )
107 , mShowUniqueRowsOnly( false )
108 , mShowOnlyVisibleFeatures( false )
109 , mFilterToAtlasIntersection( false )
110 , mFilterFeatures( false )
111 , mFeatureFilter(
"" )
116 for ( ; mapIt != layerMap.
constEnd(); ++mapIt )
153 return tr(
"<attribute table>" );
158 if ( layer == mVectorLayer )
165 mVectorLayer = layer;
188 if ( relationId == mRelationId )
218 void QgsComposerAttributeTableV2::atlasLayerChanged(
QgsVectorLayer *layer )
227 if ( mCurrentAtlasLayer )
233 mCurrentAtlasLayer = layer;
257 for (
int idx = 0; idx < fields.
count(); ++idx )
269 if ( map == mComposerMap )
292 if ( features == mMaximumNumberOfFeatures )
297 mMaximumNumberOfFeatures = features;
304 if ( uniqueOnly == mShowUniqueRowsOnly )
309 mShowUniqueRowsOnly = uniqueOnly;
316 if ( visibleOnly == mShowOnlyVisibleFeatures )
321 mShowOnlyVisibleFeatures = visibleOnly;
328 if ( filterToAtlas == mFilterToAtlasIntersection )
333 mFilterToAtlasIntersection = filterToAtlas;
340 if ( filter == mFilterFeatures )
345 mFilterFeatures = filter;
352 if ( expression == mFeatureFilter )
357 mFeatureFilter = expression;
379 for ( ; attIt != attr.
constEnd(); ++attIt )
381 int attrIdx = ( *attIt );
382 if ( !fields.
exists( attrIdx ) )
396 for (
int idx = 0; idx < fields.
count(); ++idx )
412 void QgsComposerAttributeTableV2::restoreFieldAliasMap(
const QMap<int, QString>& map )
423 int attrIdx = source->
fieldNameIndex(( *columnIt )->attribute() );
426 ( *columnIt )->setHeading( map.
value( attrIdx ) );
456 bool activeFilter =
false;
457 if ( mFilterFeatures && !mFeatureFilter.
isEmpty() )
460 if ( !filterExpression->hasParserError() )
467 if ( mComposerMap && mShowOnlyVisibleFeatures )
503 if ( !selectionRect.
isEmpty() )
528 while ( fit.
nextFeature( f ) && counter < mMaximumNumberOfFeatures )
531 if ( activeFilter && !filterExpression.
isNull() )
541 if ( mFilterToAtlasIntersection )
579 contents << currentRow;
587 for (
int i = sortColumns.
size() - 1; i >= 0; --i )
591 qStableSort( contents.
begin(), contents.
end(), c );
615 void QgsComposerAttributeTableV2::removeLayer(
QString layerId )
619 if ( layerId == mVectorLayer->
id() )
631 return a.second->sortByRank() < b.second->sortByRank();
642 if (( *columnIt )->sortByRank() > 0 )
644 sortedColumns.
append( qMakePair( idx, *columnIt ) );
655 for ( ; sortedColumnIt != sortedColumns.
constEnd(); ++sortedColumnIt )
658 attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
659 ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
661 return attributesBySortRank;
668 composerTableElem.
setAttribute(
"relationId", mRelationId );
669 composerTableElem.
setAttribute(
"showUniqueRowsOnly", mShowUniqueRowsOnly );
670 composerTableElem.
setAttribute(
"showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
671 composerTableElem.
setAttribute(
"filterToAtlasIntersection", mFilterToAtlasIntersection );
672 composerTableElem.
setAttribute(
"maxFeatures", mMaximumNumberOfFeatures );
673 composerTableElem.
setAttribute(
"filterFeatures", mFilterFeatures ?
"true" :
"false" );
674 composerTableElem.
setAttribute(
"featureFilter", mFeatureFilter );
678 composerTableElem.
setAttribute(
"composerMap", mComposerMap->
id() );
686 composerTableElem.
setAttribute(
"vectorLayer", mVectorLayer->
id() );
717 mRelationId = itemElem.
attribute(
"relationId",
"" );
724 mShowUniqueRowsOnly = itemElem.
attribute(
"showUniqueRowsOnly",
"0" ).
toInt();
725 mShowOnlyVisibleFeatures = itemElem.
attribute(
"showOnlyVisibleFeatures",
"1" ).
toInt();
726 mFilterToAtlasIntersection = itemElem.
attribute(
"filterToAtlasIntersection",
"0" ).
toInt();
727 mFilterFeatures = itemElem.
attribute(
"filterFeatures",
"false" ) ==
"true" ?
true :
false;
728 mFeatureFilter = itemElem.
attribute(
"featureFilter",
"" );
729 mMaximumNumberOfFeatures = itemElem.
attribute(
"maxFeatures",
"5" ).
toInt();
732 int composerMapId = itemElem.
attribute(
"composerMap",
"-1" ).
toInt();
733 if ( composerMapId == -1 )
755 if ( layerId ==
"not_existing" )
786 if ( recalcFrameSizes )
794 if ( source == mSource )
803 if ( newLayer != prevLayer )
815 mCurrentAtlasLayer = newLayer;
QgsFeatureId id() const
Get the feature ID for this feature.
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").
qlonglong toLongLong(bool *ok) const
Wrapper for iterator of features from vector data provider or vector layer.
QgsVectorLayer * sourceLayer()
Returns the source layer for the table, considering the table source mode.
A rectangle specified with double values.
Base class for all map layer types.
bool isEmpty() const
test if rectangle is empty.
bool contains(const Key &key) const
int localeAwareCompare(const QString &other) const
Helper class for sorting tables, takes into account sorting column and ascending / descending...
void setAttribute(QString attribute)
Sets the attribute name or expression used for the column's values.
QDomNode appendChild(const QDomNode &newChild)
Use exact geometry intersection (slower) instead of bounding boxes.
void push_back(const T &value)
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
QString attribute(const QString &name, const QString &defValue) const
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
QDateTime toDateTime() const
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
const_iterator constBegin() const
const T & at(int i) const
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
bool enabled() const
Returns whether the atlas generation is enabled.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
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.
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...
void recalculateTableSize()
Recalculates and updates the size of the table and all table frames.
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
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.
const char * name() const
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Set feature ID that should be fetched.
bool exists(int i) const
Return if a field index is valid.
QString number(int n, int base)
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table's features.
void append(const T &value)
bool contentsContainsRow(const QgsComposerTableContents &contents, const QgsComposerTableRow &row) const
Checks whether a table contents contains a given row.
void setFilterFeatures(const bool filter)
Sets whether the feature filter is active for the attribute table.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
QgsAttributes attributes() const
Returns the feature's attributes.
void setAttribute(const QString &name, const QString &value)
void setSortColumn(int col)
Sets column number to sort by.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
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...
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void recalculateFrameSizes() override
const_iterator constEnd() const
int count() const
Return number of items.
bool operator()(const QgsComposerTableRow &m1, const QgsComposerTableRow &m2)
Stores properties of a column in a QgsComposerTable.
void setCurrentRowNumber(int rowNumber)
Set the number for $rownum special column.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
Object representing map window.
Frame item for a composer multiframe item.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
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
void setRelationId(const QString relationId)
Sets the relation id from which to display child features.
int id() const
Get identification number.
QgsComposition * mComposition
~QgsComposerAttributeTableV2()
QgsComposerTableColumns mColumns
Columns to show in table.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
QgsComposerAttributeTableCompareV2()
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.
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)
static QgsProject * instance()
access to canonical QgsProject instance
void setUniqueRowsOnly(const bool uniqueOnly)
Sets attribute table to only show unique rows.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
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.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QgsAtlasComposition & atlasComposition()
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
double toDouble(bool *ok) const
Custom exception class for Coordinate Reference System related exceptions.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void setAscending(bool asc)
Sets sort order for column sorting.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool intersects(const QgsRectangle &r) const
Test for intersection with a rectangle (uses GEOS)
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
QgsRelationManager * relationManager() const
ContentSource source() const
Returns the source for attributes shown in the table body.
virtual QString displayName() const override
Get multiframe display name.
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.
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