18 #include <QHeaderView> 20 #include <QToolButton> 21 #include <QHBoxLayout> 39 , mFilterModel( nullptr )
40 , mFeatureSelectionModel( nullptr )
41 , mFeatureSelectionManager( nullptr )
42 , mActionPopup( nullptr )
43 , mRowSectionAnchor( 0 )
67 connect(
horizontalHeader(), SIGNAL( sectionResized(
int,
int,
int ) ),
this, SLOT( columnSizeChanged(
int,
int,
int ) ) );
68 connect(
horizontalHeader(), SIGNAL( sortIndicatorChanged(
int, Qt::SortOrder ) ),
this, SLOT( showHorizontalSortIndicator() ) );
76 switch ( event->
type() )
78 case QEvent::MouseButtonPress:
82 case QEvent::MouseButtonRelease:
101 if ( columnConfig.
width >= 0 )
115 mFilterModel = filterModel;
120 connect( mFilterModel, SIGNAL(
destroyed() ),
this, SLOT( modelDeleted() ) );
124 delete mFeatureSelectionModel;
125 mFeatureSelectionModel =
nullptr;
129 if ( !mFeatureSelectionManager )
134 mFeatureSelectionModel =
new QgsFeatureSelectionModel( mFilterModel, mFilterModel, mFeatureSelectionManager, mFilterModel );
137 connect( mFeatureSelectionModel, SIGNAL( requestRepaint( QModelIndexList ) ),
this, SLOT(
repaintRequested( QModelIndexList ) ) );
144 if ( mFeatureSelectionManager )
145 delete mFeatureSelectionManager;
147 mFeatureSelectionManager = featureSelectionManager;
149 if ( mFeatureSelectionModel )
164 toolButton->
setPopupMode( QToolButton::MenuButtonPopup );
165 container = toolButton;
175 QAction* defaultAction =
nullptr;
179 for (
int i = 0; i < actions->
size(); ++i )
192 connect( act, SIGNAL( triggered(
bool ) ),
this, SLOT( actionTriggered() ) );
205 action->
setData(
"map_layer_action" );
208 action->
setProperty(
"action", qVariantFromValue( qobject_cast<QObject *>( mapLayerAction ) ) );
209 connect( action, SIGNAL( triggered() ),
this, SLOT( actionTriggered() ) );
210 actionList << action;
212 if ( !defaultAction &&
214 defaultAction = action;
217 if ( !defaultAction && !actionList.
isEmpty() )
218 defaultAction = actionList.
at( 0 );
220 Q_FOREACH (
QAction* act, actionList )
226 if ( act == defaultAction )
229 container = toolButton;
280 switch ( event->
key() )
317 mFeatureSelectionModel->
selectFeatures( selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
323 mActionPopup =
nullptr;
335 mActionPopup =
new QMenu(
this );
337 mActionPopup->
addAction(
tr(
"Select All" ),
this, SLOT(
selectAll() ), QKeySequence::SelectAll );
342 if ( !mActionPopup->
actions().isEmpty() )
358 void QgsAttributeTableView::modelDeleted()
360 mFilterModel =
nullptr;
361 mFeatureSelectionManager =
nullptr;
362 mFeatureSelectionModel =
nullptr;
372 if ( row >= 0 && row <
model()->rowCount() )
378 if (( anchor && !( command & QItemSelectionModel::Current ) )
380 mRowSectionAnchor = row;
383 && command.testFlag( QItemSelectionModel::Toggle ) )
386 mCtrlDragSelectionFlag = mFeatureSelectionModel->
isSelected( index )
387 ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
389 command |= mCtrlDragSelectionFlag;
391 command |= QItemSelectionModel::Current;
403 void QgsAttributeTableView::showHorizontalSortIndicator()
408 void QgsAttributeTableView::actionTriggered()
420 else if ( action->
data().
toString() ==
"map_layer_action" )
431 void QgsAttributeTableView::columnSizeChanged(
int index,
int oldWidth,
int newWidth )
437 void QgsAttributeTableView::onActionColumnItemPainted(
const QModelIndex&
index )
442 mActionWidgets.
insert( index, widget );
447 void QgsAttributeTableView::recreateActionWidgets()
451 for ( ; it != mActionWidgets.
constEnd(); ++it )
453 it.
value()->deleteLater();
458 mActionWidgets = newWidgets;
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
qlonglong toLongLong(bool *ok) const
QgsActionManager * actions()
Get all layer actions defined on this layer.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
void setDirtyRegion(const QRegion ®ion)
virtual QVariant data(const QModelIndex &index, int role) const override
QByteArray toByteArray() const
void setColumnWidth(int column, int width)
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
void willShowContextMenu(QMenu *menu, const QModelIndex &atIndex)
Is emitted, in order to provide a hook to add aditional menu entries to the context menu...
virtual void setSelection(const QRect &rect, QFlags< QItemSelectionModel::SelectionFlag > flags)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QgsAttributeTableView(QWidget *parent=nullptr)
QItemSelectionModel * selectionModel() const
int defaultAction() const
Returns the index of the default action, or -1 if no default action is available. ...
const_iterator constBegin() const
const T & at(int i) const
void setSortingEnabled(bool enable)
void columnResized(int column, int width)
Emitted when a column in the view has been resized.
virtual bool eventFilter(QObject *object, QEvent *event) override
This event filter is installed on the verticalHeader to intercept mouse press and release events...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString shortTitle() const
The short title is used to label user interface elements like buttons.
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
virtual void selectAll() override
QString tr(const char *sourceText, const char *disambiguation, int n)
void enableSync(bool enable)
Enables or disables synchronisation to the QgsVectorLayer When synchronisation is disabled...
virtual void mouseReleaseEvent(QMouseEvent *event)
const QgsAction & at(int idx) const
Get the action at the specified index.
virtual int rowCount(const QModelIndex &parent) const
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
void mouseReleaseEvent(QMouseEvent *event) override
Called for mouse release events on a table cell.
Get the feature id of the feature in this row.
void setValue(const QString &key, const QVariant &value)
virtual QModelIndex indexAt(const QPoint &pos) const
ActionWidgetStyle actionWidgetStyle() const
Get the style of the action widget.
void append(const T &value)
virtual void setModel(QAbstractItemModel *model)
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
QVariant property(const char *name) const
void installEventFilter(QObject *filterObj)
int toInt(bool *ok) const
Utility class that encapsulates an action based on vector attributes.
const_iterator constEnd() const
void setItemDelegate(QAbstractItemDelegate *delegate)
void mousePressEvent(QMouseEvent *event) override
Called for mouse press events on a table cell.
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)...
virtual void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
void setEditTriggers(QFlags< QAbstractItemView::EditTrigger > triggers)
Storage and management of actions associated with a layer.
QIcon icon() const
The icon.
QString name() const
The name of the action. This may be a longer description.
bool showInAttributeTable() const
Whether this action should be shown on the attribute table.
void setMargin(int margin)
virtual void setModel(QgsAttributeTableFilterModel *filterModel)
void setData(const QVariant &userData)
void mouseMoveEvent(QMouseEvent *event) override
Called for mouse move events on a table cell.
QVector< ColumnConfig > columns() const
Get the list with all columns and their configuration.
virtual QRect visualRect(const QModelIndex &index) const=0
virtual void mouseMoveEvent(QMouseEvent *event)
virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, const QEvent *event) const
QgsAttributeTableConfig attributeTableConfig() const
Get the attribute table configuration object.
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual bool event(QEvent *event)
int width
Width of column, or -1 for default width.
virtual void selectFeatures(const QItemSelection &selection, const SelectionFlags &command)
Select features on this table.
static QgsMapLayerActionRegistry * instance()
Returns the instance pointer, creating the object on the first call.
virtual void mousePressEvent(QMouseEvent *event)
A tool button with a dropdown to select the current action.
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
setFeatureSelectionManager
A delegate item class for QgsAttributeTable (see Qt documentation for QItemDelegate).
void setAttributeTableConfig(const QgsAttributeTableConfig &config)
Set the attribute table config which should be used to control the appearance of the attribute table...
Defines the configuration of a column in the attribute table.
virtual void selectRow(int row)
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
bool setProperty(const char *name, const QVariant &value)
iterator insert(const Key &key, const T &value)
virtual void keyPressEvent(QKeyEvent *event)
virtual void _q_selectRow(int row)
bool nextFeature(QgsFeature &f)
This is a container for configuration of the attribute table.
QAbstractItemModel * model() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Is an interface class to abstract feature selection handling.
void closeEvent(QCloseEvent *event) override
Saves geometry to the settings on close.
Represents a vector layer which manages a vector based data sets.
int size() const
Get the number of actions managed by this.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
void doAction(int index, const QgsFeature &feat, int defaultValueIndex=0, const QgsExpressionContextScope &scope=QgsExpressionContextScope())
Does the given action.
void triggerForFeature(QgsMapLayer *layer, const QgsFeature *feature)
Triggers the action with the specified layer and feature.
An action which can run on map layers.
void destroyed(QObject *obj)
void keyPressEvent(QKeyEvent *event) override
Called for key press events Disables selection change by only pressing an arrow key.
void contextMenuEvent(QContextMenuEvent *event) override
Is called when the context menu will be shown.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.