27 : mCurrentSortColumn( 0 ), mAscending( true )
40 if ( v1.isNull() && v2.isNull() )
44 else if ( v1.isNull() )
48 else if ( v2.isNull() )
59 case QVariant::LongLong:
60 case QVariant::ULongLong:
61 less = v1.toLongLong() < v2.toLongLong();
64 case QVariant::Double:
65 less = v1.toDouble() < v2.toDouble();
69 less = v1.toDate() < v2.toDate();
72 case QVariant::DateTime:
73 less = v1.toDateTime() < v2.toDateTime();
77 less = v1.toTime() < v2.toTime();
82 less = v1.toString().localeAwareCompare( v2.toString() ) < 0;
97 , mMaximumNumberOfFeatures( 5 )
98 , mShowOnlyVisibleFeatures( false )
99 , mFilterFeatures( false )
100 , mFeatureFilter(
"" )
104 QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();
105 for ( ; mapIt != layerMap.constEnd(); ++mapIt )
180 for (
int idx = 0; idx < fields.
count(); ++idx )
276 QSet<int>::const_iterator attIt = attr.constBegin();
277 for ( ; attIt != attr.constEnd(); ++attIt )
279 int attrIdx = ( *attIt );
280 if ( !fields.
exists( attrIdx ) )
294 for (
int idx = 0; idx < fields.
count(); ++idx )
314 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
315 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
318 fieldAliasMap.insert( attrIdx, ( *columnIt )->heading() );
330 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
331 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
334 if ( map.contains( attrIdx ) )
336 ( *columnIt )->setHeading( map.value( attrIdx ) );
357 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
358 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
361 fields.append( idx );
373 attributeMaps.clear();
376 std::auto_ptr<QgsExpression> filterExpression;
377 bool activeFilter =
false;
381 if ( !filterExpression->hasParserError() )
408 if ( !selectionRect.
isEmpty() )
424 if ( !result.toBool() )
432 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
434 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
439 attributeMaps.last().insert( i, f.
attributes()[idx] );
447 QVariant value = expression->
evaluate( f ) ;
448 attributeMaps.last().insert( i, value.toString() );
459 for (
int i = sortColumns.size() - 1; i >= 0; --i )
463 qStableSort( attributeMaps.begin(), attributeMaps.end(), c );
486 if (( rectangle.height() - titleHeight ) > 0 )
505 QList<QgsComposerTableColumn*>::iterator columnIt =
mColumns.begin();
506 for ( ; columnIt !=
mColumns.end(); ++columnIt )
508 ( *columnIt )->setSortByRank( 0 );
512 QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
514 for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
516 if (( *sortedColumnIt ).first >=
mColumns.length() )
520 mColumns[( *sortedColumnIt ).first ]->setSortByRank( rank );
521 mColumns[( *sortedColumnIt ).first ]->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
528 static bool columnsBySortRank( QPair<int, QgsComposerTableColumn* > a, QPair<int, QgsComposerTableColumn* > b )
530 return a.second->sortByRank() < b.second->sortByRank();
536 QList< QPair<int, QgsComposerTableColumn* > > sortedColumns;
537 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
539 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
541 if (( *columnIt )->sortByRank() > 0 )
543 sortedColumns.append( qMakePair( idx, *columnIt ) );
552 QList<QPair<int, bool> > attributesBySortRank;
553 QList< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
554 for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
557 attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
558 ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
560 return attributesBySortRank;
565 QDomElement composerTableElem = doc.createElement(
"ComposerAttributeTable" );
568 composerTableElem.setAttribute(
"filterFeatures",
mFilterFeatures ?
"true" :
"false" );
569 composerTableElem.setAttribute(
"featureFilter",
mFeatureFilter );
573 composerTableElem.setAttribute(
"composerMap",
mComposerMap->
id() );
577 composerTableElem.setAttribute(
"composerMap", -1 );
581 composerTableElem.setAttribute(
"vectorLayer",
mVectorLayer->
id() );
584 elem.appendChild( composerTableElem );
591 if ( itemElem.isNull() )
603 mFilterFeatures = itemElem.attribute(
"filterFeatures",
"false" ) ==
"true" ?
true :
false;
607 int composerMapId = itemElem.attribute(
"composerMap",
"-1" ).toInt();
608 if ( composerMapId == -1 )
629 QString layerId = itemElem.attribute(
"vectorLayer",
"not_existing" );
630 if ( layerId ==
"not_existing" )
650 QDomNodeList displayAttributeList = itemElem.elementsByTagName(
"displayAttributes" );
651 if ( displayAttributeList.size() > 0 )
653 QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
654 QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName(
"attributeEntry" );
655 for (
int i = 0; i < attributeEntryList.size(); ++i )
657 QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
658 int index = attributeEntryElem.attribute(
"index",
"-1" ).toInt();
661 displayAttributes.insert( index );
669 QDomNodeList aliasMapNodeList = itemElem.elementsByTagName(
"attributeAliasMap" );
670 if ( aliasMapNodeList.size() > 0 )
672 QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
673 QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName(
"aliasEntry" );
674 for (
int i = 0; i < aliasMepEntryList.size(); ++i )
676 QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
677 int key = aliasEntryElem.attribute(
"key",
"-1" ).toInt();
678 QString value = aliasEntryElem.attribute(
"value",
"" );
679 fieldAliasMap.insert( key, value );
685 QDomElement sortColumnsElem = itemElem.firstChildElement(
"sortColumns" );
688 QDomNodeList
columns = sortColumnsElem.elementsByTagName(
"column" );
691 for (
int i = 0; i < columns.size(); ++i )
693 QDomElement columnElem = columns.
at( i ).toElement();
694 int attribute = columnElem.attribute(
"index" ).toInt();
695 Qt::SortOrder order = columnElem.attribute(
"ascending" ) ==
"true" ? Qt::AscendingOrder : Qt::DescendingOrder;
697 QList<QgsComposerTableColumn*>::iterator columnIt =
mColumns.begin();
698 for ( ; columnIt !=
mColumns.end(); ++columnIt )
700 if (( *columnIt )->attribute() == fields[attribute].name() )
702 ( *columnIt )->setSortByRank( i + 1 );
703 ( *columnIt )->setSortOrder( order );
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Base class for all map layer types.
QList< QPair< int, bool > > sortAttributes() const
Returns the attributes used to sort the table's features.
bool isEmpty() const
test if rectangle is empty.
void setAscending(bool asc)
Sets sort order for column sorting.
QMap< int, QVariant > QgsAttributeMap
void setAttribute(QString attribute)
Sets the attribute name or expression used for the column's values.
Use exact geometry intersection (slower) instead of bounding boxes.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
bool getFeatureAttributes(QList< QgsAttributeMap > &attributeMaps)
Queries the attribute table's vector layer for attributes to show in the table.
Q_DECL_DEPRECATED QSet< int > displayAttributes() const
Returns the attributes fields which are shown by the table.
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
QString mFeatureFilter
Feature filter expression.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
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...
void maximumNumberOfFeaturesChanged(int n)
This signal is emitted if the maximum number of feature changes (interactively)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the properties specific to an attribute table from xml.
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Writes properties specific to attribute tables.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
Container of fields for a vector layer.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QList< QgsComposerTableColumn * > * columns()
Returns a pointer to the list of QgsComposerTableColumns shown in the table.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setHeading(QString heading)
Sets the heading for a column, which is the value displayed in the columns header cell...
void setDisplayAttributes(const QSet< int > &attr, bool refresh=true)
Sets the attributes to display in the table.
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.
const QgsComposerMap * mComposerMap
Associated composer map (used to display the visible features)
A class to display feature attributes in the print composer.
bool isDrawing() const
True if a draw is already in progress.
void itemChanged()
Used e.g.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
bool exists(int i) const
Return if a field index is valid.
Q_DECL_DEPRECATED void setSortAttributes(const QList< QPair< int, bool > > att)
Sets the attributes to use to sort the table's features.
QgsVectorLayer * mVectorLayer
Associated vector layer.
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
void setSceneRect(const QRectF &rectangle)
Adapts mMaximumNumberOfFeatures depending on the rectangle height.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
static bool columnsBySortRank(QPair< int, QgsComposerTableColumn * > a, QPair< int, QgsComposerTableColumn * > b)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
bool tableWriteXML(QDomElement &itemElem, QDomDocument &doc) const
Writes common table properties to xml for storage.
void restoreFieldAliasMap(const QMap< int, QString > &map)
Restores a field alias map from a pre 2.4 format project file format.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
void setMaximumNumberOfFeatures(int features)
Sets the maximum number of features shown by the table.
const QgsAttributes & attributes() const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
int count() const
Return number of items.
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...
QgsComposerAttributeTable(QgsComposition *composition)
QList< int > fieldsToDisplay() const
Returns a list of attribute indices corresponding to displayed fields in the table.
Stores properties of a column in a QgsComposerTable.
void setCurrentRowNumber(int rowNumber)
Set the number for $rownum special column.
QgsComposition * mComposition
Graphics scene for map printing.
void resetColumns()
Resets the attribute table's columns to match the vector layer's fields.
Object representing map window.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
QgsComposerAttributeTableCompare()
QList< QgsComposerTableColumn * > mColumns
void setFeatureFilter(const QString &expression)
Sets the expression used for filtering features in the table.
int id() const
Get identification number.
virtual void refreshAttributes()
Refreshes the attributes shown in the table by querying the vector layer for new data.
void removeLayer(QString layerId)
Checks if this vector layer will be removed (and sets mVectorLayer to 0 if yes)
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
bool mFilterFeatures
True if feature filtering enabled.
int mMaximumNumberOfFeatures
Maximum number of features that is displayed.
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...
bool tableReadXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads the table's common properties from xml.
void setSortColumn(int col)
Sets column number to sort by.
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 QgsComposition * composition() const
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
double mLineTextDistance
Distance between table lines and text.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
~QgsComposerAttributeTable()
QgsAtlasComposition & atlasComposition()
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
Custom exception class for Coordinate Reference System related exceptions.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
bool nextFeature(QgsFeature &f)
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.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
const QgsComposerMap * getComposerMapById(int id) const
Returns the composer map with specified id.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
Helper class for sorting tables, takes into account sorting column and ascending / descending...
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...