19 #include <QMessageBox>
20 #include <QProgressDialog>
22 #include <QInputDialog>
51 : QStackedWidget( parent )
60 mTableView->horizontalHeader()->setContextMenuPolicy( Qt::CustomContextMenu );
61 connect( mTableView->horizontalHeader(), &QHeaderView::customContextMenuRequested,
this, &QgsDualView::showViewHeaderMenu );
64 mConditionalFormatWidgetStack->hide();
66 mConditionalFormatWidgetStack->setMainPanel( mConditionalFormatWidget );
70 mConditionalSplitter->restoreState( settings.
value( QStringLiteral(
"/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() );
72 mPreviewColumnsMenu =
new QMenu(
this );
73 mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu );
79 connect( mActionExpressionPreview, &QAction::triggered,
this, &QgsDualView::previewExpressionBuilder );
88 auto createShortcuts = [ = ](
const QString & objectName, void (
QgsFeatureListView::* slot )() )
94 connect( sc, &QShortcut::activated, mFeatureListView, slot );
101 QButtonGroup *buttonGroup =
new QButtonGroup(
this );
102 buttonGroup->setExclusive(
false );
106 QAbstractButton *bt = buttonGroup->button(
static_cast<int>( action ) );
108 bt->setChecked(
true );
109 connect( buttonGroup, qgis::overload< QAbstractButton *, bool >::of( &QButtonGroup::buttonToggled ),
this, &QgsDualView::panZoomGroupButtonToggled );
110 mFlashButton->setChecked(
QgsSettings().value( QStringLiteral(
"/qgis/attributeTable/featureListHighlightFeature" ),
true ).toBool() );
111 connect( mFlashButton, &QToolButton::clicked,
this, &QgsDualView::flashButtonClicked );
117 settings.
setValue( QStringLiteral(
"/qgis/attributeTable/splitterState" ), mConditionalSplitter->saveState() );
127 mEditorContext = context;
130 initModels( mapCanvas, request, loadFeatures );
132 mConditionalFormatWidget->
setLayer( mLayer );
134 mTableView->setModel( mFilterModel );
135 mFeatureListView->setModel( mFeatureListModel );
136 delete mAttributeForm;
137 mAttributeForm =
new QgsAttributeForm( mLayer, mTempAttributeFormFeature, mEditorContext );
142 mAttributeEditorScrollArea->setWidgetResizable(
true );
143 mAttributeEditor->layout()->addWidget( mAttributeEditorScrollArea );
144 mAttributeEditorScrollArea->setWidget( mAttributeForm );
148 mAttributeEditor->layout()->addWidget( mAttributeForm );
160 QgsMapCanvasUtils::flashMatchingFeatures( canvas, mLayer, filter );
167 QgsMapCanvasUtils::zoomToMatchingFeatures( canvas, mLayer, filter );
174 if ( mFeatureListPreviewButton->defaultAction() )
175 mFeatureListView->setDisplayExpression( mDisplayExpression );
182 if ( mFeatureListModel->
rowCount( ) > 0 )
183 mFeatureListView->setEditSelection(
QgsFeatureIds() << mFeatureListModel->
data( mFeatureListModel->index( 0, 0 ), QgsFeatureListModel::Role::FeatureRole ).value<
QgsFeature>().
id() );
187 void QgsDualView::columnBoxInit()
190 QList<QgsField> fields = mLayer->fields().toList();
192 QString defaultField;
195 QString displayExpression = mLayer->displayExpression();
197 if ( displayExpression.isEmpty() )
200 displayExpression = QStringLiteral(
"'[Please define preview text]'" );
203 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
204 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
206 const auto constFields = fields;
209 int fieldIndex = mLayer->fields().lookupField(
field.
name() );
210 if ( fieldIndex == -1 )
216 QIcon icon = mLayer->fields().iconForField( fieldIndex );
217 QString text = mLayer->attributeDisplayName( fieldIndex );
220 QAction *previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
221 connect( previewAction, &QAction::triggered,
this, [ = ] { previewColumnChanged( previewAction, fieldName ); } );
222 mPreviewColumnsMenu->addAction( previewAction );
224 if ( text == defaultField )
226 mFeatureListPreviewButton->setDefaultAction( previewAction );
231 QMenu *sortMenu =
new QMenu(
this );
233 sortMenuAction->setMenu( sortMenu );
235 QAction *sortByPreviewExpressionAsc =
new QAction(
QgsApplication::getThemeIcon( QStringLiteral(
"sort.svg" ) ), tr(
"By Preview Expression (ascending)" ),
this );
236 connect( sortByPreviewExpressionAsc, &QAction::triggered,
this, [ = ]()
240 sortMenu->addAction( sortByPreviewExpressionAsc );
241 QAction *sortByPreviewExpressionDesc =
new QAction(
QgsApplication::getThemeIcon( QStringLiteral(
"sort-reverse.svg" ) ), tr(
"By Preview Expression (descending)" ),
this );
242 connect( sortByPreviewExpressionDesc, &QAction::triggered,
this, [ = ]()
246 sortMenu->addAction( sortByPreviewExpressionDesc );
247 QAction *sortByPreviewExpressionCustom =
new QAction(
QgsApplication::getThemeIcon( QStringLiteral(
"mIconExpressionPreview.svg" ) ), tr(
"By Custom Expression" ),
this );
248 connect( sortByPreviewExpressionCustom, &QAction::triggered,
this, [ = ]()
253 sortMenu->addAction( sortByPreviewExpressionCustom );
255 mFeatureListPreviewButton->addAction( sortMenuAction );
257 QAction *separator =
new QAction( mFeatureListPreviewButton );
258 separator->setSeparator(
true );
259 mFeatureListPreviewButton->addAction( separator );
260 restoreRecentDisplayExpressions();
263 if ( !mFeatureListPreviewButton->defaultAction() )
265 mFeatureListView->setDisplayExpression( displayExpression );
266 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
267 setDisplayExpression( mFeatureListView->displayExpression() );
271 mFeatureListPreviewButton->defaultAction()->trigger();
277 setCurrentIndex(
view );
312 || ( mMasterModel->
rowCount() == 0 );
314 if ( !needsGeometry )
352 setBrowsingAutoPanScaleAllowed(
false );
359 setBrowsingAutoPanScaleAllowed(
true );
363 if ( requiresTableReload )
369 whileBlocking( mLayerCache )->setCacheGeometry( needsGeometry );
383 void QgsDualView::initLayerCache(
bool cacheGeometry )
387 int cacheSize = settings.
value( QStringLiteral(
"qgis/attributeTableRowCache" ),
"10000" ).toInt();
393 rebuildFullLayerCache();
399 delete mFeatureListModel;
420 connect( mMasterModel, &QgsAttributeTableModel::rowsRemoved, mFilterModel, &QgsAttributeTableFilterModel::invalidate );
421 connect( mMasterModel, &QgsAttributeTableModel::rowsInserted, mFilterModel, &QgsAttributeTableFilterModel::invalidate );
429 void QgsDualView::restoreRecentDisplayExpressions()
431 const QVariantList previewExpressions = mLayer->customProperty( QStringLiteral(
"dualview/previewExpressions" ) ).toList();
433 for (
const QVariant &previewExpression : previewExpressions )
434 insertRecentlyUsedDisplayExpression( previewExpression.toString() );
437 void QgsDualView::saveRecentDisplayExpressions()
const
443 QList<QAction *> actions = mFeatureListPreviewButton->actions();
446 int index = actions.indexOf( mLastDisplayExpressionAction );
449 QVariantList previewExpressions;
450 for ( ; index < actions.length(); ++index )
452 QAction *action = actions.at( index );
453 previewExpressions << action->property(
"previewExpression" );
456 mLayer->setCustomProperty( QStringLiteral(
"dualview/previewExpressions" ), previewExpressions );
460 void QgsDualView::setDisplayExpression(
const QString &expression )
462 mDisplayExpression = expression;
463 insertRecentlyUsedDisplayExpression( expression );
466 void QgsDualView::insertRecentlyUsedDisplayExpression(
const QString &expression )
468 QList<QAction *> actions = mFeatureListPreviewButton->actions();
471 int index = actions.indexOf( mLastDisplayExpressionAction );
474 for (
int i = 0; index + i < actions.length(); ++i )
476 QAction *action = actions.at( index );
477 if ( action->text() == expression || i >= 9 )
479 if ( action == mLastDisplayExpressionAction )
480 mLastDisplayExpressionAction =
nullptr;
481 mFeatureListPreviewButton->removeAction( action );
485 if ( !mLastDisplayExpressionAction )
486 mLastDisplayExpressionAction = action;
491 QString name = expression;
493 if ( expression.startsWith( QLatin1String(
"COALESCE( \"" ) ) && expression.endsWith( QLatin1String(
", '<NULL>' )" ) ) )
495 name = expression.mid( 11, expression.length() - 24 );
497 int fieldIndex = mLayer->fields().indexOf( name );
498 if ( fieldIndex != -1 )
500 name = mLayer->attributeDisplayName( fieldIndex );
501 icon = mLayer->fields().iconForField( fieldIndex );
509 QAction *previewAction =
new QAction( icon, name, mFeatureListPreviewButton );
510 previewAction->setProperty(
"previewExpression", expression );
511 connect( previewAction, &QAction::triggered,
this, [expression,
this](
bool )
513 setDisplayExpression( expression );
514 mFeatureListPreviewButton->setText( expression );
518 mFeatureListPreviewButton->insertAction( mLastDisplayExpressionAction, previewAction );
519 mLastDisplayExpressionAction = previewAction;
522 void QgsDualView::updateEditSelectionProgress(
int progress,
int count )
524 mProgressCount->setText( QStringLiteral(
"%1 / %2" ).arg( progress + 1 ).arg( count ) );
525 mPreviousFeatureButton->setEnabled( progress > 0 );
526 mNextFeatureButton->setEnabled( progress + 1 < count );
527 mFirstFeatureButton->setEnabled( progress > 0 );
528 mLastFeatureButton->setEnabled( progress + 1 < count );
531 void QgsDualView::panOrZoomToFeature(
const QgsFeatureIds &featureset )
536 if ( mBrowsingAutoPanScaleAllowed )
538 if ( mAutoPanButton->isChecked() )
539 QTimer::singleShot( 0,
this, [ = ]()
543 else if ( mAutoZoomButton->isChecked() )
544 QTimer::singleShot( 0,
this, [ = ]()
549 if ( mFlashButton->isChecked() )
550 QTimer::singleShot( 0,
this, [ = ]()
554 mLastFeatureSet = featureset;
558 void QgsDualView::setBrowsingAutoPanScaleAllowed(
bool allowed )
560 if ( mBrowsingAutoPanScaleAllowed == allowed )
563 mBrowsingAutoPanScaleAllowed = allowed;
565 mAutoPanButton->setEnabled( allowed );
566 mAutoZoomButton->setEnabled( allowed );
568 QString disabledHint = tr(
"(disabled when attribute table only shows features visible in the current map canvas extent)" );
570 mAutoPanButton->setToolTip( tr(
"Automatically pan to the current feature" ) + ( allowed ? QString() : QString(
' ' ) + disabledHint ) );
571 mAutoZoomButton->setToolTip( tr(
"Automatically zoom to the current feature" ) + ( allowed ? QString() : QString(
' ' ) + disabledHint ) );
574 void QgsDualView::panZoomGroupButtonToggled( QAbstractButton *button,
bool checked )
576 if ( button == mAutoPanButton && checked )
579 mAutoZoomButton->setChecked(
false );
581 else if ( button == mAutoZoomButton && checked )
584 mAutoPanButton->setChecked(
false );
591 if ( checked && mLayer->isSpatial() )
592 panOrZoomToFeature( mFeatureListView->currentEditSelection() );
595 void QgsDualView::flashButtonClicked(
bool clicked )
597 QgsSettings().
setValue( QStringLiteral(
"/qgis/attributeTable/featureListHighlightFeature" ), clicked );
604 canvas->
flashFeatureIds( mLayer, mFeatureListView->currentEditSelection() );
607 void QgsDualView::filterError(
const QString &errorMessage )
615 void QgsDualView::featureListAboutToChangeEditSelection(
bool &ok )
617 if ( mLayer->isEditable() && !mAttributeForm->
save() )
621 void QgsDualView::featureListCurrentEditSelectionChanged(
const QgsFeature &feat )
623 if ( !mAttributeForm )
625 mTempAttributeFormFeature = feat;
627 else if ( !mLayer->isEditable() || mAttributeForm->
save() )
631 featureset << feat.
id();
634 if ( mLayer->isSpatial() )
635 panOrZoomToFeature( featureset );
646 mFeatureListView->setCurrentFeatureEdited(
false );
647 mFeatureListView->setEditSelection( fids );
652 return mAttributeForm->
save();
657 mConditionalFormatWidgetStack->setVisible( !mConditionalFormatWidgetStack->isVisible() );
664 mPreviousView =
view();
686 void QgsDualView::previewExpressionBuilder()
692 dlg.setWindowTitle( tr(
"Expression Based Preview" ) );
693 dlg.setExpressionText( mFeatureListView->displayExpression() );
695 if ( dlg.exec() == QDialog::Accepted )
697 mFeatureListView->setDisplayExpression( dlg.expressionText() );
698 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
699 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
702 setDisplayExpression( mFeatureListView->displayExpression() );
705 void QgsDualView::previewColumnChanged( QAction *previewAction,
const QString &expression )
707 if ( !mFeatureListView->setDisplayExpression( QStringLiteral(
"COALESCE( \"%1\", '<NULL>' )" ).arg( expression ) ) )
709 QMessageBox::warning(
this,
710 tr(
"Column Preview" ),
711 tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
712 .arg( previewAction->text(), mFeatureListView->parserErrorString() )
717 mFeatureListPreviewButton->setText( previewAction->text() );
718 mFeatureListPreviewButton->setIcon( previewAction->icon() );
719 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
722 setDisplayExpression( mFeatureListView->displayExpression() );
732 return mFilterModel->rowCount();
737 const QModelIndex currentIndex = mTableView->currentIndex();
738 if ( !currentIndex.isValid() )
743 QVariant var = mMasterModel->
data( currentIndex, Qt::DisplayRole );
744 QApplication::clipboard()->setText( var.toString() );
750 mProgressDlg->cancel();
755 if ( mAttributeForm )
764 saveRecentDisplayExpressions();
767 void QgsDualView::viewWillShowContextMenu( QMenu *menu,
const QModelIndex &masterIndex )
774 QAction *copyContentAction = menu->addAction( tr(
"Copy Cell Content" ) );
775 menu->addAction( copyContentAction );
776 connect( copyContentAction, &QAction::triggered,
this, [masterIndex,
this]
778 QVariant var = mMasterModel->
data( masterIndex, Qt::DisplayRole );
779 QApplication::clipboard()->setText( var.toString() );
786 QAction *zoomToFeatureAction = menu->addAction( tr(
"Zoom to Feature" ) );
787 connect( zoomToFeatureAction, &QAction::triggered,
this, &QgsDualView::zoomToCurrentFeature );
789 QAction *panToFeatureAction = menu->addAction( tr(
"Pan to Feature" ) );
790 connect( panToFeatureAction, &QAction::triggered,
this, &QgsDualView::panToCurrentFeature );
792 QAction *flashFeatureAction = menu->addAction( tr(
"Flash Feature" ) );
793 connect( flashFeatureAction, &QAction::triggered,
this, &QgsDualView::flashCurrentFeature );
797 const QList<QgsAction> actions = mLayer->actions()->actions( QStringLiteral(
"Field" ) );
798 if ( !actions.isEmpty() )
800 QAction *a = menu->addAction( tr(
"Run Layer Action" ) );
801 a->setEnabled(
false );
803 for (
const QgsAction &action : actions )
805 if ( !action.runable() )
808 if ( vl && !vl->isEditable() && action.isEnabledOnlyWhenEditable() )
815 QModelIndex rowSourceIndex = mMasterModel->index( masterIndex.row(), 0 );
816 if ( ! rowSourceIndex.isValid() )
823 if ( !registeredActions.isEmpty() )
826 menu->addSeparator();
838 if ( mLayer->selectedFeatureCount() > 1 && mLayer->selectedFeatureIds().contains( currentFid ) )
841 if ( !registeredActions.isEmpty() )
843 menu->addSeparator();
844 QAction *action = menu->addAction( tr(
"Actions on Selection (%1)" ).arg( mLayer->selectedFeatureCount() ) );
845 action->setEnabled(
false );
849 menu->addAction( action->text(), action, [ = ]() {action->triggerForFeatures( mLayer, mLayer->selectedFeatures() );} );
854 menu->addSeparator();
860 void QgsDualView::widgetWillShowContextMenu(
QgsActionMenu *menu,
const QModelIndex &atIndex )
866 void QgsDualView::showViewHeaderMenu( QPoint point )
868 int col = mTableView->columnAt( point.x() );
870 delete mHorizontalHeaderMenu;
871 mHorizontalHeaderMenu =
new QMenu(
this );
873 QAction *hide =
new QAction( tr(
"&Hide Column" ), mHorizontalHeaderMenu );
874 connect( hide, &QAction::triggered,
this, &QgsDualView::hideColumn );
875 hide->setData( col );
876 mHorizontalHeaderMenu->addAction( hide );
877 QAction *setWidth =
new QAction( tr(
"&Set Width…" ), mHorizontalHeaderMenu );
878 connect( setWidth, &QAction::triggered,
this, &QgsDualView::resizeColumn );
879 setWidth->setData( col );
880 mHorizontalHeaderMenu->addAction( setWidth );
881 QAction *optimizeWidth =
new QAction( tr(
"&Autosize" ), mHorizontalHeaderMenu );
882 connect( optimizeWidth, &QAction::triggered,
this, &QgsDualView::autosizeColumn );
883 optimizeWidth->setData( col );
884 mHorizontalHeaderMenu->addAction( optimizeWidth );
886 mHorizontalHeaderMenu->addSeparator();
887 QAction *organize =
new QAction( tr(
"&Organize Columns…" ), mHorizontalHeaderMenu );
888 connect( organize, &QAction::triggered,
this, &QgsDualView::organizeColumns );
889 mHorizontalHeaderMenu->addAction( organize );
890 QAction *sort =
new QAction( tr(
"&Sort…" ), mHorizontalHeaderMenu );
891 connect( sort, &QAction::triggered,
this, [ = ]() {modifySort();} );
892 mHorizontalHeaderMenu->addAction( sort );
894 mHorizontalHeaderMenu->popup( mTableView->horizontalHeader()->mapToGlobal( point ) );
897 void QgsDualView::organizeColumns()
905 if ( dialog.exec() == QDialog::Accepted )
912 void QgsDualView::tableColumnResized(
int column,
int width )
916 if ( sourceCol >= 0 && config.
columnWidth( sourceCol ) != width )
923 void QgsDualView::hideColumn()
925 QAction *action = qobject_cast<QAction *>( sender() );
926 int col = action->data().toInt();
929 if ( sourceCol >= 0 )
936 void QgsDualView::resizeColumn()
938 QAction *action = qobject_cast<QAction *>( sender() );
939 int col = action->data().toInt();
945 if ( sourceCol >= 0 )
948 int width = QInputDialog::getInt(
this, tr(
"Set column width" ), tr(
"Enter column width" ),
949 mTableView->columnWidth( col ),
959 void QgsDualView::autosizeColumn()
961 QAction *action = qobject_cast<QAction *>( sender() );
962 int col = action->data().toInt();
963 mTableView->resizeColumnToContents( col );
966 bool QgsDualView::modifySort()
974 orderByDlg.setWindowTitle( tr(
"Configure Attribute Table Sort Order" ) );
975 QDialogButtonBox *dialogButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
976 QGridLayout *layout =
new QGridLayout();
977 connect( dialogButtonBox, &QDialogButtonBox::accepted, &orderByDlg, &QDialog::accept );
978 connect( dialogButtonBox, &QDialogButtonBox::rejected, &orderByDlg, &QDialog::reject );
979 orderByDlg.setLayout( layout );
981 QGroupBox *sortingGroupBox =
new QGroupBox();
982 sortingGroupBox->setTitle( tr(
"Defined sort order in attribute table" ) );
983 sortingGroupBox->setCheckable(
true );
985 layout->addWidget( sortingGroupBox );
986 sortingGroupBox->setLayout(
new QGridLayout() );
991 expressionBuilder->
initWithLayer( mLayer, context, QStringLiteral(
"generic" ) );
994 sortingGroupBox->layout()->addWidget( expressionBuilder );
996 QCheckBox *cbxSortAscending =
new QCheckBox( tr(
"Sort ascending" ) );
997 cbxSortAscending->setChecked( config.
sortOrder() == Qt::AscendingOrder );
998 sortingGroupBox->layout()->addWidget( cbxSortAscending );
1000 layout->addWidget( dialogButtonBox );
1001 if ( orderByDlg.exec() )
1003 Qt::SortOrder sortOrder = cbxSortAscending->isChecked() ? Qt::AscendingOrder : Qt::DescendingOrder;
1004 if ( sortingGroupBox->isChecked() )
1026 void QgsDualView::zoomToCurrentFeature()
1028 QModelIndex currentIndex = mTableView->currentIndex();
1029 if ( !currentIndex.isValid() )
1035 ids.insert( mFilterModel->
rowToId( currentIndex ) );
1043 void QgsDualView::panToCurrentFeature()
1045 QModelIndex currentIndex = mTableView->currentIndex();
1046 if ( !currentIndex.isValid() )
1052 ids.insert( mFilterModel->
rowToId( currentIndex ) );
1060 void QgsDualView::flashCurrentFeature()
1062 QModelIndex currentIndex = mTableView->currentIndex();
1063 if ( !currentIndex.isValid() )
1069 ids.insert( mFilterModel->
rowToId( currentIndex ) );
1077 void QgsDualView::rebuildFullLayerCache()
1085 void QgsDualView::previewExpressionChanged(
const QString &expression )
1087 mLayer->setDisplayExpression( expression );
1090 void QgsDualView::onSortColumnChanged()
1094 cfg.
sortOrder() != mFilterModel->sortOrder() )
1102 void QgsDualView::updateSelectedFeatures()
1114 void QgsDualView::extentChanged()
1127 void QgsDualView::featureFormAttributeChanged(
const QString &attribute,
const QVariant &value,
bool attributeChanged )
1129 Q_UNUSED( attribute )
1131 if ( attributeChanged )
1132 mFeatureListView->setCurrentFeatureEdited(
true );
1154 mTableView->setFeatureSelectionManager( featureSelectionManager );
1155 mFeatureListView->setFeatureSelectionManager( featureSelectionManager );
1157 if ( mFeatureSelectionManager && mFeatureSelectionManager->parent() ==
this )
1158 delete mFeatureSelectionManager;
1160 mFeatureSelectionManager = featureSelectionManager;
1166 mConfig.
update( mLayer->fields() );
1167 mLayer->setAttributeTableConfig( mConfig );
1169 mTableView->setAttributeTableConfig( mConfig );
1175 mFilterModel->
sort( -1 );
1194 void QgsDualView::progress(
int i,
bool &cancel )
1196 if ( !mProgressDlg )
1198 mProgressDlg =
new QProgressDialog( tr(
"Loading features…" ), tr(
"Abort" ), 0, 0,
this );
1199 mProgressDlg->setWindowTitle( tr(
"Attribute Table" ) );
1200 mProgressDlg->setWindowModality( Qt::WindowModal );
1201 mProgressDlg->show();
1204 mProgressDlg->setLabelText( tr(
"%1 features loaded." ).arg( i ) );
1205 QCoreApplication::processEvents();
1207 cancel = mProgressDlg && mProgressDlg->wasCanceled();
1210 void QgsDualView::finished()
1212 delete mProgressDlg;
1213 mProgressDlg =
nullptr;
Utility class that encapsulates an action based on vector attributes.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
This class contains context information for attribute editor widgets.
const QgsAttributeEditorContext * parentContext() const
QgsMessageBar * mainMessageBar()
Returns the main message bar.
@ SearchMode
Form values are used for searching/filtering the layer.
@ SingleEditMode
Single edit mode, for editing a single feature.
@ MultiEditMode
Multi edit mode, for editing fields of multiple features at once.
This is a container for configuration of the attribute table.
void setSortExpression(const QString &sortExpression)
Set the sort expression used for sorting.
Qt::SortOrder sortOrder() const
Gets the sort order.
int mapVisibleColumnToIndex(int visibleColumn) const
Maps a visible column index to its original column index.
void update(const QgsFields &fields)
Update the configuration with the given fields.
void setSortOrder(Qt::SortOrder sortOrder)
Set the sort order.
int columnWidth(int column) const
Returns the width of a column, or -1 if column should use default width.
void setColumnHidden(int column, bool hidden)
Sets whether the specified column should be hidden.
QString sortExpression() const
Gets the expression used for sorting.
void setColumnWidth(int column, int width)
Sets the width of a column.
QString sortExpression() const
The expression which is used to sort the attribute table.
FilterMode filterMode()
The current filterModel.
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Sort by the given column using the given order.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
void setFilterMode(FilterMode filterMode)
Set the filter mode the filter will use.
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
void disconnectFilterModeConnections()
Disconnect the connections set for the current filterMode.
void setAttributeTableConfig(const QgsAttributeTableConfig &config)
Set the attribute table configuration to control which fields are shown, in which order they are show...
FilterMode
The filter mode defines how the rows should be filtered.
@ ShowFilteredList
Show only features whose ids are on the filter list. {.
@ ShowVisible
Show only visible features (depends on the map canvas)
@ ShowSelected
Show only selected features.
@ ShowEdited
Show only features which have unsaved changes.
@ ShowAll
Show all features.
void filterError(const QString &errorMessage)
Emitted when an error occurred while filtering features.
void filterFeatures()
Updates the filtered features in the filter model.
void setFilterExpression(const QgsExpression &expression, const QgsExpressionContext &context)
Set the expression and the context to be stored in case of the features need to be filtered again (li...
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
QgsFeatureId rowToId(const QModelIndex &row)
Returns the feature id for a given model index.
void featuresFiltered()
Emitted when the filtering of the features has been done.
void visibleReloaded()
Emitted when the the visible features on extend are reloaded (the list is created)
void setSelectedOnTop(bool selectedOnTop)
Changes the sort order of the features.
void sortColumnChanged(int column, Qt::SortOrder order)
Emitted whenever the sort column is changed.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
const QgsFeatureRequest & request() const
Gets the the feature request.
void fieldConditionalStyleChanged(const QString &fieldName)
Handles updating the model when the conditional style for a field changes.
void modelChanged()
Model has been changed.
void progress(int i, bool &cancel)
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows.
void setEditorContext(const QgsAttributeEditorContext &context)
Sets the context in which this table is shown.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
QgsFeatureId rowToId(int row) const
Maps row to feature id.
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before using this model as source for any oth...
void setExtraColumns(int extraColumns)
Empty extra columns to announce from this model.
void executeAction(QUuid action, const QModelIndex &idx) const
Execute an action.
QVariant data(const QModelIndex &index, int role) const override
Returns data on the given index.
void willShowContextMenu(QMenu *menu, const QModelIndex &atIndex)
Emitted in order to provide a hook to add additional* menu entries to the context menu.
void columnResized(int column, int width)
Emitted when a column in the view has been resized.
void showContextMenuExternally(QgsActionMenu *menu, QgsFeatureId fid)
Emitted when selecting context menu on the feature list to create the context menu individually.
void copyCellContent() const
Copy the content of the selected cell in the clipboard.
ViewMode
The view modes, in which this widget can present information.
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
Set the feature selection model.
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
void setMultiEditEnabled(bool enabled)
Sets whether multi edit mode is enabled.
QgsFeatureIds filteredFeatures()
Gets a list of currently visible feature ids.
void cancelProgress()
Cancel the progress dialog (if any)
void filterChanged()
Emitted whenever the filter changes.
QgsDualView(QWidget *parent=nullptr)
Constructor.
void setAttributeTableConfig(const QgsAttributeTableConfig &config)
Set the attribute table config which should be used to control the appearance of the attribute table.
ViewMode view() const
Returns the current view mode.
int featureCount()
Returns the number of features on the layer.
Q_DECL_DEPRECATED void setFilteredFeatures(const QgsFeatureIds &filteredFeatures)
Set a list of currently visible features.
void formModeChanged(QgsAttributeEditorContext::Mode mode)
Emitted when the form changes mode.
FeatureListBrowsingAction
Action on the map canvas when browsing the list of features.
@ NoAction
No action is done.
@ PanToFeature
The map is panned to the center of the feature bounding-box.
@ ZoomToFeature
The map is zoomed to contained the feature bounding-box.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered)
void hideEvent(QHideEvent *event) override
QgsAttributeTableConfig attributeTableConfig() const
The config used for the attribute table.
void filterExpressionSet(const QString &expression, QgsAttributeForm::FilterType type)
Emitted when a filter expression is set using the view.
bool saveEditChanges()
saveEditChanges
void openConditionalStyles()
void toggleSearchMode(bool enabled)
Toggles whether search mode should be enabled in the form.
void displayExpressionChanged(const QString &expression)
Emitted whenever the display expression is successfully changed.
void setSortExpression(const QString &sortExpression, Qt::SortOrder sortOrder=Qt::AscendingOrder)
Set the expression used for sorting the table and feature list.
void setRequest(const QgsFeatureRequest &request)
Set the request.
void parentFormValueChanged(const QString &attribute, const QVariant &value)
Called in embedded forms when an attribute value in the parent form has changed.
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext(), bool loadFeatures=true)
Has to be called to initialize the dual view.
void setCurrentEditSelection(const QgsFeatureIds &fids)
Set the current edit selection in the AttributeEditor mode.
int filteredFeatureCount()
Returns the number of features which are currently visible, according to the filter restrictions.
QString sortExpression() const
Gets the expression used for sorting the table and feature list.
void setFilterMode(QgsAttributeTableFilterModel::FilterMode filterMode)
Set the filter mode.
void setView(ViewMode view)
Change the current view mode.
void setSelectedOnTop(bool selectedOnTop)
Toggle the selectedOnTop flag.
void filterFeatures(const QgsExpression &filterExpression, const QgsExpressionContext &context)
Sets the expression and Updates the filtered features in the filter model.
A generic dialog for building expression strings.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setSortByDisplayExpression(bool sortByDisplayExpression, Qt::SortOrder order=Qt::AscendingOrder)
Sort this model by its display expression.
QVariant data(const QModelIndex &index, int role) const override
Shows a list of features and renders a edit button next to each feature.
void currentEditSelectionProgressChanged(int progress, int count)
Emitted whenever the current edit selection has been changed.
void editNextFeature()
editNextFeature will try to edit next feature of the list
void editLastFeature()
editLastFeature will try to edit the last feature of the list
void editFirstFeature()
editFirstFeature will try to edit the first feature of the list
void displayExpressionChanged(const QString &expression)
Emitted whenever the display expression is successfully changed.
void editPreviousFeature()
editPreviousFeature will try to edit previous feature of the list
void willShowContextMenu(QgsActionMenu *menu, const QModelIndex &atIndex)
Emitted when the context menu is created to add the specific actions to it.
void currentEditSelectionChanged(QgsFeature &feat)
Emitted whenever the current edit selection has been changed.
void aboutToChangeEditSelection(bool &ok)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureRequest & disableFilter()
Disables filter conditions.
const QgsRectangle & filterRect() const
Returns the rectangle from which features will be taken.
FilterType filterType() const
Returns the filter type which is currently set on this request.
@ FilterNone
No filter is applied.
const Flags & flags() const
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Encapsulate a field in an attribute table or data source.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
static QgsShortcutsManager * shortcutsManager()
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
Is an interface class to abstract feature selection handling.
Map canvas is a class for displaying all GIS data types on a canvas.
void extentsChanged()
Emitted when the extents of the map change.
void panToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter=true)
Centers canvas extent to feature ids.
void flashFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids, const QColor &startColor=QColor(255, 0, 0, 255), const QColor &endColor=QColor(255, 0, 0, 0), int flashes=3, int duration=500)
Causes a set of features with matching ids from a vector layer to flash within the canvas.
void zoomToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids)
Set canvas extent to the bounding box of a set of features.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, QgsMapLayerAction::Targets targets=QgsMapLayerAction::AllActions)
Returns the map layer actions which can run on the specified layer.
An action which can run on map layers.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
void pushWarning(const QString &title, const QString &message)
Pushes a warning message with default timeout to the message bar.
Dialog for organising (hiding and reordering) columns in the attributes table.
A rectangle specified with double values.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setEnumValue(const QString &key, const T &value, const Section section=NoSection)
Set the value of a setting based on an enum.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
QShortcut * shortcutByName(const QString &name) const
Returns a shortcut by its name, or nullptr if nothing found.
@ SelectAtId
Fast access to features using their ID.
This class caches features of a given QgsVectorLayer.
void setFullCache(bool fullCache)
This enables or disables full caching.
void finished()
When filling the cache, this signal gets emitted once the cache is fully initialized.
void invalidated()
The cache has been invalidated and cleared.
void progress(int i, bool &cancel)
When filling the cache, this signal gets emitted periodically to notify about the progress and to be ...
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
Represents a vector layer which manages a vector based data sets.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features