16 #include <QItemSelectionModel> 34 , mFilterMode( ShowAll )
35 , mSelectedOnTop( false )
40 connect(
layer(), SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) );
50 if ( leftSelected && !rightSelected )
54 else if ( rightSelected && !leftSelected )
56 return sortOrder() == Qt::DescendingOrder;
72 if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
73 order = Qt::AscendingOrder;
75 int myColumn = mColumnMapping.
at( column );
83 if ( mapColumnToSource( index.
column() ) == -1 )
101 if ( orientation == Qt::Horizontal )
103 if ( mColumnMapping.
at( section ) == -1 && role == Qt::DisplayRole )
104 return tr(
"Actions" );
110 if ( role == Qt::DisplayRole )
114 int sourceSection =
mapToSource(
index( section, ( !mColumnMapping.
isEmpty() && mColumnMapping.
at( 0 ) == -1 ) ? 1 : 0 ) ).row();
122 return mColumnMapping.
indexOf( -1 );
128 return mColumnMapping.
count();
141 if ( columnConfig.
hidden )
146 newColumnMapping << newValue;
149 if ( newColumnMapping != mColumnMapping )
151 bool requiresReset =
false;
152 int firstRemovedColumn = -1;
153 int removedColumnCount = 0;
156 for (
int i = 0; i < qMin( newColumnMapping.
size(), mColumnMapping.
size() - removedColumnCount ); ++i )
158 if ( newColumnMapping.
at( i ) == mColumnMapping.
at( i + removedColumnCount ) )
161 if ( firstRemovedColumn == -1 )
163 firstRemovedColumn = i;
165 while ( i < mColumnMapping.
size() - removedColumnCount && mColumnMapping.
at( i + removedColumnCount ) != newColumnMapping.
at( i ) )
167 ++removedColumnCount;
172 requiresReset =
true;
178 if ( firstRemovedColumn == -1 )
180 if ( newColumnMapping.
size() > mColumnMapping.
size() )
184 mColumnMapping = newColumnMapping;
191 mColumnMapping = newColumnMapping;
197 if ( newColumnMapping.
size() == mColumnMapping.
size() - removedColumnCount )
201 mColumnMapping = newColumnMapping;
206 requiresReset =
true;
213 mColumnMapping = newColumnMapping;
224 if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
225 order = Qt::AscendingOrder;
239 if ( mSelectedOnTop != selectedOnTop )
249 if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
250 order = Qt::AscendingOrder;
252 sort( column, order );
263 mColumnMapping.
append( i );
280 return mSelectedOnTop;
285 mFilteredFeatures = ids;
293 for (
int i = 0; i <
rowCount(); ++i )
303 if ( filterMode != mFilterMode )
322 Q_UNUSED( sourceParent );
323 switch ( mFilterMode )
364 void QgsAttributeTableFilterModel::selectionChanged()
370 else if ( mSelectedOnTop )
377 void QgsAttributeTableFilterModel::onColumnsChanged()
382 int QgsAttributeTableFilterModel::mapColumnToSource(
int column )
const 384 if ( mColumnMapping.
isEmpty() )
386 if ( column < 0 || column >= mColumnMapping.
size() )
389 return mColumnMapping.
at( column );
405 mFilteredFeatures.
clear();
454 mFilteredFeatures << f.
id();
457 if ( t.elapsed() > 5000 )
460 emit progress( i, cancel );
489 QModelIndexList indexes;
503 int sourceColumn = mapColumnToSource( proxyIndex.
column() );
507 if ( sourceColumn == -1 )
517 if ( proxyIndex.
column() < 0 )
520 int col = mapColumnToSource( proxyIndex.
column() );
530 if ( mapColumnToSource( index.
column() ) == -1 )
531 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
void generateListOfVisibleFeatures()
Updates the list of currently visible features on the map canvas.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
QgsFeatureId rowToId(const QModelIndex &row)
Returns the feature id for a given model index.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
Wrapper for iterator of features from vector data provider or vector layer.
virtual QVariant data(const QModelIndex &index, int role) const override
void setSortRole(int role)
int extraColumns() const
Empty extra columns to announce from this model.
A rectangle specified with double values.
void update(const QgsFields &fields)
Update the configuration with the given fields.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the source row will be accepted.
bool selectedOnTop()
Returns if selected features are currently shown on top.
void setAttributeTableConfig(const QgsAttributeTableConfig &config)
Set the attribute table configuration to control which fields are shown, in which order they are show...
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
void setSelectedOnTop(bool selectedOnTop)
Changes the sort order of the features.
virtual void sort(int column, Qt::SortOrder order)
void setFilterMode(FilterMode filterMode)
Set the filter mode the filter will use.
void append(const T &value)
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
int indexOf(const T &value, int from) const
void setRendererScale(double scale)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Used by the sorting algorithm.
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
void columnsRemoved(const QModelIndex &parent, int start, int end)
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
This column represents an action widget.
Type type
The type of this column.
depends on scale if feature will be rendered (rule based )
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Show only visible features (depends on the map canvas)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
const QgsRectangle & filterRect() const
Get the rectangle from which features will be taken.
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
Returns whether the renderer will render a feature or not.
QString tr(const char *sourceText, const char *disambiguation, int n)
void setExtent(const QgsRectangle &extent)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
Map canvas is a class for displaying all GIS data types on a canvas.
virtual int rowCount(const QModelIndex &parent) const
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
QgsAttributeTableFilterModel(QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent=nullptr)
Make sure, the master model is already loaded, so the selection will get synchronized.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
The QgsMapSettings class contains configuration for rendering of the map.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
Get the feature id of the feature in this row.
int actionColumnIndex() const
Get the index of the first column that contains an action widget.
QList< Key > keys() const
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
Show only selected features.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
FilterMode filterMode()
The current filterModel.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
FilterMode
The filter mode defines how the rows should be filtered.
double scale() const
Return the calculated scale of the map.
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
bool hidden
Flag that controls if the column is hidden.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsVectorLayerCache * layerCache() const
Returns the layer cache this model uses as backend.
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
void setDynamicSortFilter(bool enable)
virtual QVariant data(const QModelIndex &index, int role) const=0
Show only features which have unsaved changes.
QModelIndex parent() const
void columnsInserted(const QModelIndex &parent, int start, int end)
This column shows action buttons.
const QgsMapToPixel & mapToPixel() const
QString name
The name of the attribute if this column represents a field.
void setSourceModel(QgsAttributeTableModel *sourceModel)
Set the attribute table model that backs this model.
QgsFeatureId id() const
Get the feature ID for this feature.
void extentsChanged()
Is called upon every change of the visible extents on the map canvas.
QString sortExpression() const
The expression which is used to sort the attribute table.
void columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This column shows a field.
bool contains(const T &value) const
QgsExpressionContext & expressionContext()
Gets the expression context.
Show only features whose ids are on the filter list. {.
bool contains(const T &value) const
QVector< ColumnConfig > columns() const
Get the list with all columns and their configuration.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
const QgsFeatureMap & addedFeatures()
New features which are not commited.
const T & at(int i) const
Contains information about the context of a rendering operation.
QAbstractItemModel * sourceModel() const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Qt::SortOrder sortOrder() const
QVariant data(int role) const
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from output CRS to layer's CRS
virtual void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Sort by the given column using the given order.
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
int columnCount(const QModelIndex &parent) const override
int count(const T &value) const
void setMapToPixel(const QgsMapToPixel &mtp)
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Defines the configuration of a column in the attribute table.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
QString sortCacheExpression() const
The expression which was used to fill the sorting cache.
QgsFeatureIds filteredFeatures()
Get a list of currently filtered feature ids.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
features may be filtered, i.e. some features may not be rendered (categorized, rule based ...
This is a container for configuration of the attribute table.
Qt::SortOrder sortOrder() const
Get the sort order.
The type of a given column.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString sortExpression() const
Get the expression used for sorting.
void sortColumnChanged(int column, Qt::SortOrder order)
Is emitted whenever the sort column is changed.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
QModelIndexList fidToIndexList(QgsFeatureId fid)
void beginInsertColumns(const QModelIndex &parent, int first, int last)
void prefetchColumnData(int column)
Caches the entire data for one column.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
void prefetchSortData(const QString &expression)
Prefetches the entire data for one expression.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual QVariant data(const QModelIndex &index, int role) const
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the index.
QModelIndex fidToIndex(QgsFeatureId fid) override
void columnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
virtual Qt::ItemFlags flags(const QModelIndex &index) const override