QGIS API Documentation 4.3.0-Master (91d4a333d5d)
Loading...
Searching...
No Matches
qgsdualview.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdualview.cpp
3 --------------------------------------
4 Date : 10.2.2013
5 Copyright : (C) 2013 Matthias Kuhn
6 Email : matthias at opengis dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsdualview.h"
17
18#include "qgsactionmanager.h"
19#include "qgsactionmenu.h"
20#include "qgsapplication.h"
26#include "qgsfeaturelistmodel.h"
27#include "qgsfieldcalculator.h"
29#include "qgsgui.h"
31#include "qgsmapcanvas.h"
32#include "qgsmapcanvasutils.h"
33#include "qgsmaplayeraction.h"
34#include "qgsmessagebar.h"
36#include "qgsscrollarea.h"
37#include "qgssettings.h"
39#include "qgssettingstree.h"
40#include "qgsshortcutsmanager.h"
42#include "qgsvectorlayercache.h"
45
46#include <QClipboard>
47#include <QDialog>
48#include <QGroupBox>
49#include <QInputDialog>
50#include <QMenu>
51#include <QMessageBox>
52#include <QProgressDialog>
53#include <QShortcut>
54#include <QString>
55#include <QTimer>
56
57#include "moc_qgsdualview.cpp"
58
59using namespace Qt::StringLiterals;
60
62 = new QgsSettingsEntryBool( u"feature-list-highlight-feature"_s, QgsSettingsTree::sTreeAttributeTable, true, QObject::tr( "Whether to highlight/flash features in the feature list view" ) );
63
65 = new QgsSettingsEntryInteger( u"row-cache"_s, QgsSettingsTree::sTreeAttributeTable, 10000, QObject::tr( "Maximum number of rows to cache in the attribute table (0 means cache all rows)" ) );
66
67const std::unique_ptr<QgsSettingsEntryVariant> QgsDualView::conditionalFormattingSplitterState = std::make_unique<
68 QgsSettingsEntryVariant>( u"attribute-table-splitter-state"_s, QgsSettingsTree::sTreeWindowState, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), u"State of conditional formatting splitter's layout so it could be restored when opening attribute table view."_s );
69const std::unique_ptr<QgsSettingsEntryVariant> QgsDualView::attributeEditorSplitterState = std::make_unique<
70 QgsSettingsEntryVariant>( u"attribute-editor-splitter-state"_s, QgsSettingsTree::sTreeWindowState, QgsVariantUtils::createNullVariant( QMetaType::Type::QByteArray ), u"State of attribute editor splitter's layout so it could be restored when opening attribute editor view."_s );
71
72QgsDualView::QgsDualView( QWidget *parent )
73 : QStackedWidget( parent )
74{
75 setupUi( this );
76 connect( mFeatureListView, &QgsFeatureListView::aboutToChangeEditSelection, this, &QgsDualView::featureListAboutToChangeEditSelection );
77 connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionChanged, this, &QgsDualView::featureListCurrentEditSelectionChanged );
78 connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionProgressChanged, this, &QgsDualView::updateEditSelectionProgress );
79 connect( mFeatureListView, &QgsFeatureListView::willShowContextMenu, this, &QgsDualView::widgetWillShowContextMenu );
80
81 connect( mTableView, &QgsAttributeTableView::willShowContextMenu, this, &QgsDualView::viewWillShowContextMenu );
82 mTableView->horizontalHeader()->setContextMenuPolicy( Qt::CustomContextMenu );
83 connect( mTableView->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &QgsDualView::showViewHeaderMenu );
84 connect( mTableView, &QgsAttributeTableView::columnResized, this, &QgsDualView::tableColumnResized );
85
86 mConditionalFormatWidgetStack->hide();
87 mConditionalFormatWidget = new QgsFieldConditionalFormatWidget( this );
88 mConditionalFormatWidgetStack->setMainPanel( mConditionalFormatWidget );
89 mConditionalFormatWidget->setDockMode( true );
90
91 const QgsSettings settings;
92 // copy old setting
93 conditionalFormattingSplitterState->copyValueFromKey( u"/qgis/attributeTable/splitterState"_s, true );
94 mConditionalSplitter->restoreState( conditionalFormattingSplitterState->value().toByteArray() );
95 mAttributeEditorViewSplitter->restoreState( attributeEditorSplitterState->value().toByteArray() );
96
97 mPreviewColumnsMenu = new QMenu( this );
98 mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu );
99
100 // Set preview icon
101 mActionExpressionPreview->setIcon( QgsApplication::getThemeIcon( u"/mIconExpressionPreview.svg"_s ) );
102 mActionExpressionPreview->setText( tr( "Expression" ) );
103
104 // Connect layer list preview signals
105 connect( mActionExpressionPreview, &QAction::triggered, this, &QgsDualView::previewExpressionBuilder );
106 connect( mFeatureListView, &QgsFeatureListView::displayExpressionChanged, this, &QgsDualView::previewExpressionChanged );
107
108 // browsing toolbar
109 connect( mNextFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editNextFeature );
110 connect( mPreviousFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editPreviousFeature );
111 connect( mFirstFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editFirstFeature );
112 connect( mLastFeatureButton, &QToolButton::clicked, mFeatureListView, &QgsFeatureListView::editLastFeature );
113
114 auto createShortcuts = [this]( const QString &objectName, void ( QgsFeatureListView::*slot )() ) {
115 QShortcut *sc = QgsGui::shortcutsManager()->shortcutByName( objectName );
116 // do not assert for sc as it would lead to crashes in testing
117 // or when using custom widgets lib if built with Debug
118 if ( sc )
119 connect( sc, &QShortcut::activated, mFeatureListView, slot );
120 };
121 createShortcuts( u"mAttributeTableFirstEditedFeature"_s, &QgsFeatureListView::editFirstFeature );
122 createShortcuts( u"mAttributeTablePreviousEditedFeature"_s, &QgsFeatureListView::editPreviousFeature );
123 createShortcuts( u"mAttributeTableNextEditedFeature"_s, &QgsFeatureListView::editNextFeature );
124 createShortcuts( u"mAttributeTableLastEditedFeature"_s, &QgsFeatureListView::editLastFeature );
125
126 QButtonGroup *buttonGroup = new QButtonGroup( this );
127 buttonGroup->setExclusive( false );
128 buttonGroup->addButton( mAutoPanButton, PanToFeature );
129 buttonGroup->addButton( mAutoZoomButton, ZoomToFeature );
130 const FeatureListBrowsingAction action = QgsSettings().enumValue( u"/qgis/attributeTable/featureListBrowsingAction"_s, NoAction );
131 QAbstractButton *bt = buttonGroup->button( static_cast<int>( action ) );
132 if ( bt )
133 bt->setChecked( true );
134 connect( buttonGroup, qOverload<QAbstractButton *, bool>( &QButtonGroup::buttonToggled ), this, &QgsDualView::panZoomGroupButtonToggled );
135 mFlashButton->setChecked( settingsFeatureListHighlightFeature->value() );
136 connect( mFlashButton, &QToolButton::clicked, this, &QgsDualView::flashButtonClicked );
137}
138
141
142void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, const QgsAttributeEditorContext &context, bool loadFeatures, bool showFirstFeature )
143{
144 if ( !layer )
145 return;
146
147 delete mAttributeForm;
148 mAttributeForm = nullptr;
149
150 mLayer = layer;
151
152 // Keep fields order in sync: force config reset
153 connect( mLayer, &QgsVectorLayer::updatedFields, this, [this] {
154 // Prevent crash if a field was deleted when the sort expression contained a reference to it.
155 mConfig.update( mLayer->fields() );
156 mFilterModel->setAttributeTableConfig( attributeTableConfig(), /* force */ true );
157 } );
158
159 mEditorContext = context;
160
161 // create an empty form to find out if it needs geometry or not
162 const QgsAttributeForm emptyForm( mLayer, QgsFeature(), mEditorContext );
163
164 const QgsExpression sortingExpression = QgsExpression( mConfig.sortExpression() );
165
166 const bool needsGeometry = mLayer->conditionalStyles()->rulesNeedGeometry()
169 || emptyForm.needsGeometry()
170 || sortingExpression.needsGeometry();
171
172 initLayerCache( needsGeometry );
173 initModels( mapCanvas, request, loadFeatures );
174
175 mConditionalFormatWidget->setLayer( mLayer );
176
177 mTableView->setModel( mFilterModel );
178 mFeatureListView->setModel( mFeatureListModel );
179
180 connect( mFilterModel, &QgsAttributeTableFilterModel::sortColumnChanged, this, &QgsDualView::onSortColumnChanged );
181 connect( mLayer, &QgsVectorLayer::afterCommitChanges, this, [this] { mFeatureListView->setCurrentFeatureEdited( false ); } );
182
183 if ( mFeatureListPreviewButton->defaultAction() )
184 {
185 mFeatureListView->setDisplayExpression( mDisplayExpression );
186 }
187 else
188 {
189 columnBoxInit();
190 }
191
192 // This slows down load of the attribute table heaps and uses loads of memory.
193 //mTableView->resizeColumnsToContents();
194
195 if ( showFirstFeature && mFeatureListModel->rowCount() > 0 )
196 {
197 mFeatureListView->setEditSelection( QgsFeatureIds() << mFeatureListModel->data( mFeatureListModel->index( 0, 0 ), QgsFeatureListModel::Role::FeatureRole ).value<QgsFeature>().id() );
198 }
199 else
200 {
201 // Set attribute table config to allow for proper sorting ordering in feature list view
202 setAttributeTableConfig( mLayer->attributeTableConfig() );
203 }
204}
205
206void QgsDualView::initAttributeForm( const QgsFeature &feature )
207{
208 Q_ASSERT( !mAttributeForm );
209
210 mAttributeForm = new QgsAttributeForm( mLayer, feature, mEditorContext );
211 if ( !mEditorContext.parentContext() )
212 {
213 mAttributeEditorScrollArea = new QgsScrollArea();
214 mAttributeEditorScrollArea->setWidgetResizable( true );
215 mAttributeEditor->layout()->addWidget( mAttributeEditorScrollArea );
216 mAttributeEditorScrollArea->setWidget( mAttributeForm );
217 }
218 else
219 {
220 mAttributeEditor->layout()->addWidget( mAttributeForm );
221 }
222
223 // This is an arbitrary yet small value to fix issue GH #50181
224 // the default value is 0.
225 mAttributeForm->setMinimumWidth( 200 );
226
227 setAttributeTableConfig( mLayer->attributeTableConfig() );
228
229 connect( mAttributeForm, &QgsAttributeForm::widgetValueChanged, this, &QgsDualView::featureFormAttributeChanged );
230 connect( mAttributeForm, &QgsAttributeForm::modeChanged, this, &QgsDualView::formModeChanged );
232 connect( mAttributeForm, &QgsAttributeForm::flashFeatures, this, [this]( const QString &filter ) {
233 if ( QgsMapCanvas *canvas = mFilterModel->mapCanvas() )
234 {
235 QgsMapCanvasUtils::flashMatchingFeatures( canvas, mLayer, filter );
236 }
237 } );
238 connect( mAttributeForm, &QgsAttributeForm::zoomToFeatures, this, [this]( const QString &filter ) {
239 if ( QgsMapCanvas *canvas = mFilterModel->mapCanvas() )
240 {
241 QgsMapCanvasUtils::zoomToMatchingFeatures( canvas, mLayer, filter );
242 }
243 } );
244
245 connect( mMasterModel, &QgsAttributeTableModel::modelChanged, mAttributeForm, &QgsAttributeForm::refreshFeature );
246}
247
248void QgsDualView::columnBoxInit()
249{
250 // load fields
251 const QList<QgsField> fields = mLayer->fields().toList();
252 const QString displayExpression = mLayer->displayExpression();
253
254 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
255 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
256
257 QAction *defaultFieldAction = nullptr;
258 const auto constFields = fields;
259 for ( const QgsField &field : constFields )
260 {
261 const int fieldIndex = mLayer->fields().lookupField( field.name() );
262 if ( fieldIndex == -1 )
263 continue;
264
265 const QString fieldName = field.name();
266 if ( QgsGui::editorWidgetRegistry()->findBest( mLayer, fieldName ).type() != "Hidden"_L1 )
267 {
268 const QIcon fieldIcon = mLayer->fields().iconForField( fieldIndex );
269 const QString fieldDisplayName = mLayer->attributeDisplayName( fieldIndex );
270
271 // Generate action for the preview popup button of the feature list
272 QAction *previewAction = new QAction( fieldIcon, fieldDisplayName, mFeatureListPreviewButton );
273 connect( previewAction, &QAction::triggered, this, [this, previewAction, fieldName] { previewColumnChanged( previewAction, fieldName ); } );
274 mPreviewColumnsMenu->addAction( previewAction );
275
276 if ( fieldDisplayName == displayExpression
277 || u"COALESCE( \"%1\", '<NULL>' )"_s.arg( fieldDisplayName ) == displayExpression
278 || u"\"%1\""_s.arg( fieldDisplayName ) == displayExpression
279 || fieldName == displayExpression
280 || u"COALESCE( \"%1\", '<NULL>' )"_s.arg( fieldName ) == displayExpression
281 || u"\"%1\""_s.arg( fieldName ) == displayExpression )
282 {
283 defaultFieldAction = previewAction;
284 }
285 }
286 }
287
288 QMenu *sortMenu = new QMenu( this );
289 QAction *sortMenuAction = new QAction( QgsApplication::getThemeIcon( u"sort.svg"_s ), tr( "Sort…" ), this );
290 sortMenuAction->setMenu( sortMenu );
291
292 QAction *sortByPreviewExpressionAsc = new QAction( QgsApplication::getThemeIcon( u"sort.svg"_s ), tr( "By Display Name (Ascending)" ), this );
293 connect( sortByPreviewExpressionAsc, &QAction::triggered, this, [this]() { mFeatureListModel->setSortByDisplayExpression( true, Qt::AscendingOrder ); } );
294 sortMenu->addAction( sortByPreviewExpressionAsc );
295 QAction *sortByPreviewExpressionDesc = new QAction( QgsApplication::getThemeIcon( u"sort-reverse.svg"_s ), tr( "By Display Name (Descending)" ), this );
296 connect( sortByPreviewExpressionDesc, &QAction::triggered, this, [this]() { mFeatureListModel->setSortByDisplayExpression( true, Qt::DescendingOrder ); } );
297 sortMenu->addAction( sortByPreviewExpressionDesc );
298 QAction *sortByPreviewExpressionCustom = new QAction( QgsApplication::getThemeIcon( u"mIconExpressionPreview.svg"_s ), tr( "By Custom Expression" ), this );
299 connect( sortByPreviewExpressionCustom, &QAction::triggered, this, [this]() {
300 if ( modifySort() )
301 mFeatureListModel->setSortByDisplayExpression( false );
302 } );
303 sortMenu->addAction( sortByPreviewExpressionCustom );
304
305 mFeatureListPreviewButton->addAction( sortMenuAction );
306
307 QAction *separator = new QAction( mFeatureListPreviewButton );
308 separator->setSeparator( true );
309 mFeatureListPreviewButton->addAction( separator );
310 restoreRecentDisplayExpressions();
311
312 mSkipDisplayExpressionChangedSignal = true;
313 if ( defaultFieldAction )
314 {
315 mFeatureListPreviewButton->setDefaultAction( defaultFieldAction );
316 mFeatureListPreviewButton->defaultAction()->trigger();
317 }
318 else
319 {
320 mActionExpressionPreview->setToolTip( displayExpression );
321 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
322
323 mFeatureListView->setDisplayExpression( displayExpression );
324 setDisplayExpression( displayExpression.isEmpty() ? tr( "'[Please define preview text]'" ) : displayExpression );
325 }
326 mSkipDisplayExpressionChangedSignal = false;
327}
328
330{
331 setCurrentIndex( view );
332}
333
335{
336 return mFilterModel->filterMode();
337}
338
340{
341 return static_cast<QgsDualView::ViewMode>( currentIndex() );
342}
343
345{
346 // cleanup any existing connections
347 switch ( mFilterModel->filterMode() )
348 {
350 disconnect( mFilterModel->mapCanvas(), &QgsMapCanvas::extentsChanged, this, &QgsDualView::extentChanged );
352 break;
353
357 disconnect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
358 break;
359
362 disconnect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
363 disconnect( masterModel()->layer(), &QgsVectorLayer::layerModified, this, &QgsDualView::updateEditedAddedFeatures );
364 break;
365
367 disconnect( masterModel()->layer(), &QgsVectorLayer::selectionChanged, this, &QgsDualView::updateSelectedFeatures );
368 break;
369
371 mMasterModel->setShowValidityState( false );
372 break;
373 }
374
375 QgsFeatureRequest request = mMasterModel->request();
376
377 // create an empty form to find out if it needs geometry or not
378 const QgsAttributeForm emptyForm( mLayer, QgsFeature(), mEditorContext );
379 const bool needsGeometry = ( filterMode == Qgis::AttributeTableFilterMode::ShowVisible ) || emptyForm.needsGeometry() || QgsExpression( mConfig.sortExpression() ).needsGeometry();
380
381 const bool requiresTableReload = ( request.filterType() != Qgis::Qgis::FeatureRequestFilterType::NoFilter
382 || request.spatialFilterType() != Qgis::SpatialFilterType::NoFilter ) // previous request was subset
383 || ( needsGeometry && request.flags() & Qgis::FeatureRequestFlag::NoGeometry ) // no geometry for last request
384 || ( mMasterModel->rowCount() == 0 ); // no features
385
386 request.setFlags( request.flags().setFlag( Qgis::FeatureRequestFlag::NoGeometry, !needsGeometry ) );
387 request.setFilterFids( QgsFeatureIds() );
388 request.setFilterRect( QgsRectangle() );
389 request.disableFilter();
390
391 // setup new connections and filter request parameters
392 switch ( filterMode )
393 {
395 connect( mFilterModel->mapCanvas(), &QgsMapCanvas::extentsChanged, this, &QgsDualView::extentChanged );
396 if ( mFilterModel->mapCanvas() )
397 {
398 const QgsRectangle rect = mFilterModel->mapCanvas()->mapSettings().mapToLayerCoordinates( mLayer, mFilterModel->mapCanvas()->extent() );
399 request.setFilterRect( rect );
400 }
402 break;
403
405 request.setFilterFids( masterModel()->layer()->editBuffer() ? masterModel()->layer()->editBuffer()->allAddedOrEditedFeatures() : QgsFeatureIds() );
407 connect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
408 connect( masterModel()->layer(), &QgsVectorLayer::layerModified, this, &QgsDualView::updateEditedAddedFeatures );
409 break;
410
412 {
413 mMasterModel->setShowValidityState( true );
415 filterFeatures( u"is_feature_valid() = false"_s, context );
417 connect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
418 break;
419 }
420
423 {
424 const QString filterExpression = filterMode == Qgis::AttributeTableFilterMode::ShowFilteredList ? mFilterModel->filterExpression() : QString();
425 if ( !filterExpression.isEmpty() )
426 request.setFilterExpression( mFilterModel->filterExpression() );
428 connect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
429 break;
430 }
431
433 connect( masterModel()->layer(), &QgsVectorLayer::selectionChanged, this, &QgsDualView::updateSelectedFeatures );
434 request.setFilterFids( masterModel()->layer()->selectedFeatureIds() );
435 break;
436 }
437
438 // disable the browsing auto pan/scale if the list only shows visible items
439 switch ( filterMode )
440 {
442 setBrowsingAutoPanScaleAllowed( false );
443 break;
444
450 setBrowsingAutoPanScaleAllowed( true );
451 break;
452 }
453
454 if ( requiresTableReload )
455 {
456 //disconnect the connections of the current (old) filtermode before reload
457 mFilterModel->disconnectFilterModeConnections();
458
459 mMasterModel->setRequest( request );
460 whileBlocking( mLayerCache )->setCacheGeometry( needsGeometry );
461 mMasterModel->loadLayer();
462 }
463
464 //update filter model
465 mFilterModel->setFilterMode( filterMode );
466 emit filterChanged();
467}
468
469void QgsDualView::setSelectedOnTop( bool selectedOnTop )
470{
471 mFilterModel->setSelectedOnTop( selectedOnTop );
472}
473
474void QgsDualView::initLayerCache( bool cacheGeometry )
475{
476 // Initialize the cache
477 const int cacheSize = settingsAttributeTableRowCache->value();
478 mLayerCache = new QgsVectorLayerCache( mLayer, cacheSize, this );
479 mLayerCache->setCacheSubsetOfAttributes( requiredAttributes( mLayer ) );
480 mLayerCache->setCacheGeometry( cacheGeometry );
481 if ( 0 == cacheSize || !mLayer->dataProvider()->capabilities().testFlag( Qgis::VectorProviderCapability::SelectAtId ) )
482 {
483 connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsDualView::rebuildFullLayerCache );
484 rebuildFullLayerCache();
485 }
486}
487
488#ifdef ENABLE_MODELTEST
489#include <QAbstractItemModelTester>
490#endif
491
492void QgsDualView::initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures )
493{
494 delete mFeatureListModel;
495 delete mFilterModel;
496 delete mMasterModel;
497
498 mMasterModel = new QgsAttributeTableModel( mLayerCache, this );
499
500#ifdef ENABLE_MODELTEST
501 new QAbstractItemModelTester( mMasterModel, QAbstractItemModelTester::FailureReportingMode::Fatal, this );
502#endif
503
504 mMasterModel->setRequest( request );
505 mMasterModel->setEditorContext( mEditorContext );
506
507 connect( mMasterModel, &QgsAttributeTableModel::progress, this, &QgsDualView::progress );
508 connect( mMasterModel, &QgsAttributeTableModel::finished, this, &QgsDualView::finished );
509
511
512 if ( loadFeatures )
513 mMasterModel->loadLayer();
514
515 mFilterModel = new QgsAttributeTableFilterModel( mapCanvas, mMasterModel, mMasterModel );
516#ifdef ENABLE_MODELTEST
517 new QAbstractItemModelTester( mFilterModel, QAbstractItemModelTester::FailureReportingMode::Fatal, this );
518#endif
519
520 // The following connections to invalidate() are necessary to keep the filter model in sync
521 // see regression https://github.com/qgis/QGIS/issues/23890
522 connect( mMasterModel, &QgsAttributeTableModel::rowsRemoved, mFilterModel, &QgsAttributeTableFilterModel::invalidate );
523 connect( mMasterModel, &QgsAttributeTableModel::rowsInserted, mFilterModel, &QgsAttributeTableFilterModel::invalidate );
524
526
527 mFeatureListModel = new QgsFeatureListModel( mFilterModel, mFilterModel );
528 // TODO this test reveals deep issues in QgsFeatureListModel - these need to be fixed and the
529 // test re-enabled
530#if 0
531#ifdef ENABLE_MODELTEST
532 new QAbstractItemModelTester( mFeatureListModel, QAbstractItemModelTester::FailureReportingMode::Fatal, this );
533#endif
534#endif
535}
536
537void QgsDualView::restoreRecentDisplayExpressions()
538{
539 const QVariantList previewExpressions = mLayer->customProperty( u"dualview/previewExpressions"_s ).toList();
540
541 for ( const QVariant &previewExpression : previewExpressions )
542 {
543 insertRecentlyUsedDisplayExpression( previewExpression.toString() );
544 }
545}
546
547void QgsDualView::saveRecentDisplayExpressions() const
548{
549 if ( !mLayer )
550 {
551 return;
552 }
553 const QList<QAction *> actions = mFeatureListPreviewButton->actions();
554
555 // Remove existing same action
556 int index = actions.indexOf( mLastDisplayExpressionAction );
557 if ( index != -1 )
558 {
559 QVariantList previewExpressions;
560 for ( ; index < actions.length(); ++index )
561 {
562 QAction *action = actions.at( index );
563 previewExpressions << action->property( "previewExpression" );
564 }
565
566 mLayer->setCustomProperty( u"dualview/previewExpressions"_s, previewExpressions );
567 }
568}
569
570void QgsDualView::setDisplayExpression( const QString &expression )
571{
572 mDisplayExpression = expression;
573 insertRecentlyUsedDisplayExpression( expression );
574}
575
576void QgsDualView::insertRecentlyUsedDisplayExpression( const QString &expression )
577{
578 const QList<QAction *> actions = mFeatureListPreviewButton->actions();
579
580 // Remove existing same action
581 const int index = actions.indexOf( mLastDisplayExpressionAction );
582 if ( index != -1 )
583 {
584 for ( int i = 0; index + i < actions.length(); ++i )
585 {
586 QAction *action = actions.at( index );
587 if ( action->text() == expression || i >= 9 )
588 {
589 if ( action == mLastDisplayExpressionAction )
590 {
591 mLastDisplayExpressionAction = nullptr;
592 }
593 mFeatureListPreviewButton->removeAction( action );
594 }
595 else
596 {
597 if ( !mLastDisplayExpressionAction )
598 {
599 mLastDisplayExpressionAction = action;
600 }
601 }
602 }
603 }
604
605 QString name = expression;
606 QIcon icon = QgsApplication::getThemeIcon( u"/mIconExpressionPreview.svg"_s );
607 if ( expression.startsWith( "COALESCE( \""_L1 ) && expression.endsWith( ", '<NULL>' )"_L1 ) )
608 {
609 name = expression.mid( 11, expression.length() - 24 ); // Numbers calculated from the COALESCE / <NULL> parts
610
611 const int fieldIndex = mLayer->fields().indexOf( name );
612 if ( fieldIndex != -1 )
613 {
614 name = mLayer->attributeDisplayName( fieldIndex );
615 icon = mLayer->fields().iconForField( fieldIndex );
616 }
617 else
618 {
619 name = expression;
620 }
621 }
622
623 QAction *previewAction = new QAction( icon, name, mFeatureListPreviewButton );
624 previewAction->setProperty( "previewExpression", expression );
625 connect( previewAction, &QAction::triggered, this, [expression, this]( bool ) {
626 setDisplayExpression( expression );
627 mFeatureListPreviewButton->setText( tr( "Expression" ) );
628 mFeatureListPreviewButton->setToolTip( expression );
629 } );
630
631 mFeatureListPreviewButton->insertAction( mLastDisplayExpressionAction, previewAction );
632 mLastDisplayExpressionAction = previewAction;
633}
634
635void QgsDualView::updateEditSelectionProgress( int progress, int count )
636{
637 mProgressCount->setText( u"%1 / %2"_s.arg( progress + 1 ).arg( count ) );
638 mPreviousFeatureButton->setEnabled( progress > 0 );
639 mNextFeatureButton->setEnabled( progress + 1 < count );
640 mFirstFeatureButton->setEnabled( progress > 0 );
641 mLastFeatureButton->setEnabled( progress + 1 < count );
642 if ( mAttributeForm )
643 {
644 mAttributeForm->setVisible( count > 0 );
645 }
646}
647
648void QgsDualView::panOrZoomToFeature( const QgsFeatureIds &featureset )
649{
650 QgsMapCanvas *canvas = mFilterModel->mapCanvas();
651 if ( canvas && view() == AttributeEditor && featureset != mLastFeatureSet )
652 {
653 if ( mBrowsingAutoPanScaleAllowed )
654 {
655 if ( mAutoPanButton->isChecked() )
656 QTimer::singleShot( 0, this, [this, featureset, canvas]() { canvas->panToFeatureIds( mLayer, featureset, false ); } );
657 else if ( mAutoZoomButton->isChecked() )
658 QTimer::singleShot( 0, this, [this, featureset, canvas]() { canvas->zoomToFeatureIds( mLayer, featureset ); } );
659 }
660 if ( mFlashButton->isChecked() )
661 QTimer::singleShot( 0, this, [this, featureset, canvas]() { canvas->flashFeatureIds( mLayer, featureset ); } );
662 mLastFeatureSet = featureset;
663 }
664}
665
666void QgsDualView::setBrowsingAutoPanScaleAllowed( bool allowed )
667{
668 if ( mBrowsingAutoPanScaleAllowed == allowed )
669 return;
670
671 mBrowsingAutoPanScaleAllowed = allowed;
672
673 mAutoPanButton->setEnabled( allowed );
674 mAutoZoomButton->setEnabled( allowed );
675
676 const QString disabledHint = tr( "(disabled when attribute table only shows features visible in the current map canvas extent)" );
677
678 mAutoPanButton->setToolTip( tr( "Automatically pan to the current feature" ) + ( allowed ? QString() : QString( ' ' ) + disabledHint ) );
679 mAutoZoomButton->setToolTip( tr( "Automatically zoom to the current feature" ) + ( allowed ? QString() : QString( ' ' ) + disabledHint ) );
680}
681
682void QgsDualView::panZoomGroupButtonToggled( QAbstractButton *button, bool checked )
683{
684 if ( button == mAutoPanButton && checked )
685 {
686 QgsSettings().setEnumValue( u"/qgis/attributeTable/featureListBrowsingAction"_s, PanToFeature );
687 mAutoZoomButton->setChecked( false );
688 }
689 else if ( button == mAutoZoomButton && checked )
690 {
691 QgsSettings().setEnumValue( u"/qgis/attributeTable/featureListBrowsingAction"_s, ZoomToFeature );
692 mAutoPanButton->setChecked( false );
693 }
694 else
695 {
696 QgsSettings().setEnumValue( u"/qgis/attributeTable/featureListBrowsingAction"_s, NoAction );
697 }
698
699 if ( checked && mLayer->isSpatial() )
700 panOrZoomToFeature( mFeatureListView->currentEditSelection() );
701}
702
703void QgsDualView::flashButtonClicked( bool clicked )
704{
705 settingsFeatureListHighlightFeature->setValue( clicked );
706 if ( !clicked )
707 return;
708
709 QgsMapCanvas *canvas = mFilterModel->mapCanvas();
710
711 if ( canvas )
712 canvas->flashFeatureIds( mLayer, mFeatureListView->currentEditSelection() );
713}
714
715void QgsDualView::filterError( const QString &errorMessage )
716{
717 if ( mEditorContext.mainMessageBar() )
718 {
719 mEditorContext.mainMessageBar()->pushWarning( tr( "An error occurred while filtering features" ), errorMessage );
720 }
721}
722
723void QgsDualView::featureListAboutToChangeEditSelection( bool &ok )
724{
725 if ( !mAttributeForm )
726 return;
727
728 if ( mLayer->isEditable() && !mAttributeForm->save() )
729 ok = false;
730}
731
732void QgsDualView::featureListCurrentEditSelectionChanged( const QgsFeature &feat )
733{
734 if ( !mAttributeForm )
735 {
736 initAttributeForm( feat );
737 }
738 else if ( !mLayer->isEditable() || mAttributeForm->save() )
739 {
740 mAttributeForm->setFeature( feat );
741 QgsFeatureIds featureset;
742 featureset << feat.id();
743 setCurrentEditSelection( featureset );
744
745 if ( mLayer->isSpatial() )
746 panOrZoomToFeature( featureset );
747 }
748 else
749 {
750 // Couldn't save feature
751 }
752}
753
755{
756 mFeatureListView->setCurrentFeatureEdited( false );
757 mFeatureListView->setEditSelection( fids );
758}
759
761{
762 return mAttributeForm ? mAttributeForm->save() : false;
763}
764
766{
767 mConditionalFormatWidgetStack->setVisible( !mConditionalFormatWidgetStack->isVisible() );
768}
769
771{
772 if ( !mAttributeForm )
773 return;
774
775 if ( enabled )
776 {
777 mPreviousView = view();
779 }
780 else
781 {
782 setView( mPreviousView );
783 }
784
786}
787
789{
790 if ( !mAttributeForm )
791 return;
792
793 if ( enabled )
794 {
796 mAttributeForm->setMode( QgsAttributeEditorContext::SearchMode );
797 mAttributeForm->setVisible( true );
798 }
799 else
800 {
801 mAttributeForm->setMode( QgsAttributeEditorContext::SingleEditMode );
802 mAttributeForm->setVisible( mFilterModel->rowCount() > 0 );
803 }
804}
805
806void QgsDualView::previewExpressionBuilder()
807{
808 // Show expression builder
810
811 QgsExpressionBuilderDialog dlg( mLayer, mFeatureListView->displayExpression(), this, u"generic"_s, context );
812 dlg.setWindowTitle( tr( "Expression Based Preview" ) );
813 dlg.setExpressionText( mFeatureListView->displayExpression() );
814
815 if ( dlg.exec() == QDialog::Accepted )
816 {
817 mFeatureListView->setDisplayExpression( dlg.expressionText() );
818 mActionExpressionPreview->setToolTip( dlg.expressionText() );
819
820 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
821 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
822 }
823
824 setDisplayExpression( mFeatureListView->displayExpression() );
825}
826
827void QgsDualView::previewColumnChanged( QAction *previewAction, const QString &expression )
828{
829 if ( !mFeatureListView->setDisplayExpression( u"COALESCE( \"%1\", '<NULL>' )"_s.arg( expression ) ) )
830 {
831 QMessageBox::warning( this, tr( "Column Display Name" ), tr( "Could not set column '%1' as display name.\nParser error:\n%2" ).arg( previewAction->text(), mFeatureListView->parserErrorString() ) );
832 }
833 else
834 {
835 mFeatureListPreviewButton->setText( previewAction->text() );
836 mFeatureListPreviewButton->setIcon( previewAction->icon() );
837 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
838 }
839
840 setDisplayExpression( mFeatureListView->displayExpression() );
841}
842
844{
845 return mMasterModel->rowCount();
846}
847
849{
850 return mFilterModel->rowCount();
851}
852
854{
855 const QModelIndex currentIndex = mTableView->currentIndex();
856 if ( !currentIndex.isValid() )
857 {
858 return;
859 }
860
861 const QVariant var = mMasterModel->data( currentIndex, Qt::DisplayRole );
862 QApplication::clipboard()->setText( var.toString() );
863}
864
866{
867 if ( mProgressDlg )
868 mProgressDlg->cancel();
869}
870
871void QgsDualView::parentFormValueChanged( const QString &attribute, const QVariant &newValue )
872{
873 if ( mAttributeForm )
874 {
875 mAttributeForm->parentFormValueChanged( attribute, newValue );
876 }
877}
878
879void QgsDualView::hideEvent( QHideEvent *event )
880{
881 Q_UNUSED( event )
882 saveRecentDisplayExpressions();
883
884 // Better to save settings here than in destructor. This last can be called after a new
885 // project is loaded. So, when Qgis::ProjectFlag::RememberAttributeTableWindowsBetweenSessions is set,
886 // a new QgsDualView is created at project loading and we restore the old settings before saving the
887 // new one.
888 // And also, we override close event to just hide in QgsDockableWidgetHelper::eventFilter, that's why hideEvent
889 conditionalFormattingSplitterState->setValue( mConditionalSplitter->saveState() );
890 attributeEditorSplitterState->setValue( mAttributeEditorViewSplitter->saveState() );
891}
892
893void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &masterIndex )
894{
895 if ( !menu )
896 {
897 return;
898 }
899
900 const QVariant displayValue = mMasterModel->data( masterIndex, Qt::DisplayRole );
901
902 if ( displayValue.isValid() )
903 {
904 // get values for preview in menu
905 QString previewDisplayValue = displayValue.toString();
906 if ( previewDisplayValue.length() > 12 )
907 {
908 previewDisplayValue.truncate( 12 );
909 previewDisplayValue.append( u"…"_s );
910 }
911
912
913 QAction *copyContentAction = menu->addAction( tr( "Copy Cell Content (%1)" ).arg( previewDisplayValue ) );
914 menu->addAction( copyContentAction );
915 connect( copyContentAction, &QAction::triggered, this, [displayValue] { QApplication::clipboard()->setText( displayValue.toString() ); } );
916 }
917
918 const QVariant rawValue = mMasterModel->data( masterIndex, Qt::EditRole );
919 if ( rawValue.isValid() )
920 {
921 // get values for preview in menu
922 QString previewRawValue = rawValue.toString();
923 if ( previewRawValue.length() > 12 )
924 {
925 previewRawValue.truncate( 12 );
926 previewRawValue.append( u"…"_s );
927 }
928
929 QAction *copyRawContentAction = menu->addAction( tr( "Copy Raw Value (%1)" ).arg( previewRawValue ) );
930 menu->addAction( copyRawContentAction );
931 connect( copyRawContentAction, &QAction::triggered, this, [rawValue] { QApplication::clipboard()->setText( rawValue.toString() ); } );
932 }
933
934 QgsVectorLayer *vl = mFilterModel->layer();
935 QgsMapCanvas *canvas = mFilterModel->mapCanvas();
936 if ( canvas && vl && vl->isSpatial() )
937 {
938 QAction *zoomToFeatureAction = menu->addAction( tr( "Zoom to Feature" ) );
939 connect( zoomToFeatureAction, &QAction::triggered, this, &QgsDualView::zoomToCurrentFeature );
940
941 QAction *panToFeatureAction = menu->addAction( tr( "Pan to Feature" ) );
942 connect( panToFeatureAction, &QAction::triggered, this, &QgsDualView::panToCurrentFeature );
943
944 QAction *flashFeatureAction = menu->addAction( tr( "Flash Feature" ) );
945 connect( flashFeatureAction, &QAction::triggered, this, &QgsDualView::flashCurrentFeature );
946 }
947
948 //add user-defined actions to context menu
949 const QList<QgsAction> actions = mLayer->actions()->actions( u"Field"_s );
950 if ( !actions.isEmpty() )
951 {
952 QAction *a = menu->addAction( tr( "Run Layer Action" ) );
953 a->setEnabled( false );
954
955 for ( const QgsAction &action : actions )
956 {
957 if ( !action.runable() )
958 continue;
959
960 if ( vl && !vl->isEditable() && action.isEnabledOnlyWhenEditable() )
961 continue;
962
963 QgsAttributeTableAction *a = new QgsAttributeTableAction( action.name(), this, action.id(), masterIndex );
964 menu->addAction( action.name(), a, &QgsAttributeTableAction::execute );
965 }
966 }
967 const QModelIndex rowSourceIndex = mMasterModel->index( masterIndex.row(), 0 );
968 if ( !rowSourceIndex.isValid() )
969 {
970 return;
971 }
972
973 //add actions from QgsMapLayerActionRegistry to context menu
974 QgsMapLayerActionContext context;
975 const QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer, Qgis::MapLayerActionTarget::Layer | Qgis::MapLayerActionTarget::SingleFeature, context );
976 if ( !registeredActions.isEmpty() )
977 {
978 //add a separator between user defined and standard actions
979 menu->addSeparator();
980
981 for ( QgsMapLayerAction *action : registeredActions )
982 {
983 QgsAttributeTableMapLayerAction *a = new QgsAttributeTableMapLayerAction( action->text(), this, action, rowSourceIndex );
984 menu->addAction( action->text(), a, &QgsAttributeTableMapLayerAction::execute );
985 }
986 }
987
988 // entries for multiple features layer actions
989 // only show if the context menu is shown over a selected row
990 const QgsFeatureId currentFid = mMasterModel->rowToId( masterIndex.row() );
991 if ( mLayer->selectedFeatureCount() > 1 && mLayer->selectedFeatureIds().contains( currentFid ) )
992 {
993 const QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer, Qgis::MapLayerActionTarget::MultipleFeatures, context );
994 if ( !registeredActions.isEmpty() )
995 {
996 menu->addSeparator();
997 QAction *action = menu->addAction( tr( "Actions on Selection (%1)" ).arg( mLayer->selectedFeatureCount() ) );
998 action->setEnabled( false );
999
1000 QgsMapLayerActionContext context;
1001 for ( QgsMapLayerAction *action : registeredActions )
1002 {
1003 menu->addAction( action->text(), action, [this, action, context]() {
1004 Q_NOWARN_DEPRECATED_PUSH
1005 action->triggerForFeatures( mLayer, mLayer->selectedFeatures() );
1006 Q_NOWARN_DEPRECATED_POP
1007 action->triggerForFeatures( mLayer, mLayer->selectedFeatures(), context );
1008 } );
1009 }
1010 }
1011 }
1012
1013 menu->addSeparator();
1014 QgsAttributeTableAction *a = new QgsAttributeTableAction( tr( "Open Form" ), this, QUuid(), rowSourceIndex );
1015 menu->addAction( tr( "Open Form…" ), a, &QgsAttributeTableAction::featureForm );
1016}
1017
1018
1019void QgsDualView::widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex )
1020{
1021 emit showContextMenuExternally( menu, mFilterModel->rowToId( atIndex ) );
1022}
1023
1024
1025void QgsDualView::showViewHeaderMenu( QPoint point )
1026{
1027 const int col = mTableView->horizontalHeader()->visualIndex( mTableView->horizontalHeader()->logicalIndexAt( point ) );
1028
1029 delete mHorizontalHeaderMenu;
1030 mHorizontalHeaderMenu = new QMenu( this );
1031
1032 QAction *hide = new QAction( tr( "&Hide Column" ), mHorizontalHeaderMenu );
1033 connect( hide, &QAction::triggered, this, &QgsDualView::hideColumn );
1034 hide->setData( col );
1035 mHorizontalHeaderMenu->addAction( hide );
1036 QAction *setWidth = new QAction( tr( "&Set Width…" ), mHorizontalHeaderMenu );
1037 connect( setWidth, &QAction::triggered, this, &QgsDualView::resizeColumn );
1038 setWidth->setData( col );
1039 mHorizontalHeaderMenu->addAction( setWidth );
1040
1041 QAction *setWidthAllColumns = new QAction( tr( "&Set All Column Widths…" ), mHorizontalHeaderMenu );
1042 connect( setWidthAllColumns, &QAction::triggered, this, &QgsDualView::resizeAllColumns );
1043 setWidthAllColumns->setData( col );
1044 mHorizontalHeaderMenu->addAction( setWidthAllColumns );
1045
1046 QAction *optimizeWidth = new QAction( tr( "&Autosize" ), mHorizontalHeaderMenu );
1047 connect( optimizeWidth, &QAction::triggered, this, &QgsDualView::autosizeColumn );
1048 optimizeWidth->setData( col );
1049 mHorizontalHeaderMenu->addAction( optimizeWidth );
1050
1051 QAction *optimizeWidthAllColumns = new QAction( tr( "&Autosize All Columns" ), mHorizontalHeaderMenu );
1052 connect( optimizeWidthAllColumns, &QAction::triggered, this, &QgsDualView::autosizeAllColumns );
1053 mHorizontalHeaderMenu->addAction( optimizeWidthAllColumns );
1054
1055 mHorizontalHeaderMenu->addSeparator();
1056 QAction *organize = new QAction( tr( "&Organize Columns…" ), mHorizontalHeaderMenu );
1057 connect( organize, &QAction::triggered, this, &QgsDualView::organizeColumns );
1058 mHorizontalHeaderMenu->addAction( organize );
1059 QAction *sort = new QAction( tr( "&Sort…" ), mHorizontalHeaderMenu );
1060 connect( sort, &QAction::triggered, this, [this]() { modifySort(); } );
1061 mHorizontalHeaderMenu->addAction( sort );
1062
1063 mConfig.update( mLayer->fields() );
1064 // get layer field index from column name
1065 int fieldIndex = -1;
1067 if ( col < mLayer->fields().size() )
1068 {
1069 fieldIndex = col;
1070 fieldOrigin = mLayer->fields().fieldOrigin( fieldIndex );
1071 }
1072
1073 mHorizontalHeaderMenu->addSeparator();
1074
1075 const QgsVectorLayer *vl = mFilterModel->layer();
1076 const QgsVectorDataProvider *dataProvider = vl->dataProvider();
1077 const Qgis::VectorProviderCapabilities caps = dataProvider->capabilities();
1078 const bool layerIsReadOnly { vl->readOnly() };
1079 const bool canChangeAttributeValue = !layerIsReadOnly && ( caps & Qgis::VectorProviderCapability::ChangeAttributeValues );
1080
1081 bool fieldCalculatorEnabled = false;
1082
1083 switch ( fieldOrigin )
1084 {
1087 fieldCalculatorEnabled = canChangeAttributeValue;
1088 break;
1090 {
1091 int srcFieldIndex;
1092 const QgsVectorLayerJoinInfo *info = mLayer->joinBuffer()->joinForFieldIndex( fieldIndex, mLayer->fields(), srcFieldIndex );
1093 const QgsVectorLayer *joinedLayer = info->joinLayer();
1094 const QgsVectorDataProvider *joinedDataProvider = joinedLayer->dataProvider();
1095 const Qgis::VectorProviderCapabilities joinedCaps = joinedDataProvider->capabilities();
1096 const bool joinedLayerIsReadOnly { joinedLayer->readOnly() };
1097 const bool joinedLayerCanChangeAttributeValue = !joinedLayerIsReadOnly && ( joinedCaps & Qgis::VectorProviderCapability::ChangeAttributeValues );
1098 if ( info && info->isEditable() )
1099 fieldCalculatorEnabled = joinedLayerCanChangeAttributeValue;
1100 break;
1101 }
1104 break;
1105 default:
1106 break;
1107 }
1108
1109 QAction *fieldCalculator = new QAction( tr( "Open &Field Calculator…" ), mHorizontalHeaderMenu );
1110 connect( fieldCalculator, &QAction::triggered, this, &QgsDualView::fieldCalculator );
1111 fieldCalculator->setData( fieldIndex );
1112 mHorizontalHeaderMenu->addAction( fieldCalculator );
1113
1114 fieldCalculator->setEnabled( fieldCalculatorEnabled );
1115
1116 mHorizontalHeaderMenu->popup( mTableView->horizontalHeader()->mapToGlobal( point ) );
1117}
1118
1119void QgsDualView::organizeColumns()
1120{
1121 if ( !mLayer )
1122 {
1123 return;
1124 }
1125
1126 QgsOrganizeTableColumnsDialog dialog( mLayer, attributeTableConfig(), this );
1127 if ( dialog.exec() == QDialog::Accepted )
1128 {
1129 const QgsAttributeTableConfig config = dialog.config();
1130 setAttributeTableConfig( config );
1131 }
1132}
1133
1134void QgsDualView::tableColumnResized( int visualColumnIndex, int width )
1135{
1136 QgsAttributeTableConfig config = mConfig;
1137 if ( visualColumnIndex >= 0 && config.columnWidth( visualColumnIndex ) != width )
1138 {
1139 config.setColumnWidth( visualColumnIndex, width );
1140 setAttributeTableConfig( config );
1141 }
1142}
1143
1144void QgsDualView::hideColumn()
1145{
1146 QAction *action = qobject_cast<QAction *>( sender() );
1147 const int col = action->data().toInt();
1148 QgsAttributeTableConfig config = mConfig;
1149 if ( col >= 0 )
1150 {
1151 config.setColumnHidden( col, true );
1152 setAttributeTableConfig( config );
1153 }
1154}
1155
1156void QgsDualView::fieldCalculator()
1157{
1158 QAction *action = qobject_cast<QAction *>( sender() );
1159 const int fieldIndex = action->data().toInt();
1160 mConfig.update( mLayer->fields() );
1161 QgsFieldCalculator calc( mLayer, this, fieldIndex );
1162 if ( calc.exec() == QDialog::Accepted )
1163 {
1164 int col = mMasterModel->fieldCol( calc.changedAttributeId() );
1165
1166 if ( col >= 0 )
1167 mMasterModel->reload( mMasterModel->index( 0, col ), mMasterModel->index( mMasterModel->rowCount() - 1, col ) );
1168 }
1169}
1170
1171void QgsDualView::resizeColumn()
1172{
1173 QAction *action = qobject_cast<QAction *>( sender() );
1174 const int col = action->data().toInt();
1175 if ( col < 0 )
1176 return;
1177
1178 QgsAttributeTableConfig config = mConfig;
1179
1180 bool ok = false;
1181 const int width = QInputDialog::getInt( this, tr( "Set column width" ), tr( "Enter column width" ), mTableView->columnWidth( col ), 0, 1000, 10, &ok );
1182 if ( ok )
1183 {
1184 config.setColumnWidth( col, width );
1185 setAttributeTableConfig( config );
1186 }
1187}
1188
1189void QgsDualView::resizeAllColumns()
1190{
1191 QAction *action = qobject_cast<QAction *>( sender() );
1192 const int col = action->data().toInt();
1193 if ( col < 0 )
1194 return;
1195
1196 QgsAttributeTableConfig config = mConfig;
1197
1198 bool ok = false;
1199 const int width = QInputDialog::getInt( this, tr( "Set Column Width" ), tr( "Enter column width" ), mTableView->columnWidth( col ), 1, 1000, 10, &ok );
1200 if ( ok )
1201 {
1202 const int colCount = mTableView->model()->columnCount();
1203 if ( colCount > 0 )
1204 {
1205 for ( int i = 0; i < colCount; i++ )
1206 {
1207 config.setColumnWidth( i, width );
1208 }
1209 setAttributeTableConfig( config );
1210 }
1211 }
1212}
1213
1214void QgsDualView::autosizeColumn()
1215{
1216 QAction *action = qobject_cast<QAction *>( sender() );
1217 const int col = action->data().toInt();
1218 mTableView->resizeColumnToContents( col );
1219}
1220
1221void QgsDualView::autosizeAllColumns()
1222{
1223 mTableView->resizeColumnsToContents();
1224}
1225
1226bool QgsDualView::modifySort()
1227{
1228 if ( !mLayer )
1229 return false;
1230
1231 QgsAttributeTableConfig config = mConfig;
1232
1233 QDialog orderByDlg;
1234 orderByDlg.setWindowTitle( tr( "Configure Attribute Table Sort Order" ) );
1235 QDialogButtonBox *dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
1236 QGridLayout *layout = new QGridLayout();
1237 connect( dialogButtonBox, &QDialogButtonBox::accepted, &orderByDlg, &QDialog::accept );
1238 connect( dialogButtonBox, &QDialogButtonBox::rejected, &orderByDlg, &QDialog::reject );
1239 orderByDlg.setLayout( layout );
1240
1241 QGroupBox *sortingGroupBox = new QGroupBox();
1242 sortingGroupBox->setTitle( tr( "Defined sort order in attribute table" ) );
1243 sortingGroupBox->setCheckable( true );
1244 sortingGroupBox->setChecked( !sortExpression().isEmpty() );
1245 layout->addWidget( sortingGroupBox );
1246 sortingGroupBox->setLayout( new QGridLayout() );
1247
1248 QgsExpressionBuilderWidget *expressionBuilder = new QgsExpressionBuilderWidget();
1249 const QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
1250
1251 expressionBuilder->initWithLayer( mLayer, context, u"generic"_s );
1252 expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );
1253
1254 sortingGroupBox->layout()->addWidget( expressionBuilder );
1255
1256 QCheckBox *cbxSortAscending = new QCheckBox( tr( "Sort ascending" ) );
1257 cbxSortAscending->setChecked( config.sortOrder() == Qt::AscendingOrder );
1258 sortingGroupBox->layout()->addWidget( cbxSortAscending );
1259
1260 layout->addWidget( dialogButtonBox );
1261 if ( orderByDlg.exec() )
1262 {
1263 const Qt::SortOrder sortOrder = cbxSortAscending->isChecked() ? Qt::AscendingOrder : Qt::DescendingOrder;
1264 if ( sortingGroupBox->isChecked() )
1265 {
1266 setSortExpression( expressionBuilder->expressionText(), sortOrder );
1267 config.setSortExpression( expressionBuilder->expressionText() );
1268 config.setSortOrder( sortOrder );
1269 }
1270 else
1271 {
1272 setSortExpression( QString(), sortOrder );
1273 config.setSortExpression( QString() );
1274 }
1275
1276 return true;
1277 }
1278 else
1279 {
1280 return false;
1281 }
1282}
1283
1285{
1286 QSet<int> attributes;
1287
1288 const QgsAttributeTableConfig config { layer->attributeTableConfig() };
1289
1290 const QVector<QgsAttributeTableConfig::ColumnConfig> constColumnconfigs { config.columns() };
1291 for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : std::as_const( constColumnconfigs ) )
1292 {
1293 if ( columnConfig.type == QgsAttributeTableConfig::Type::Field && !columnConfig.hidden )
1294 {
1295 attributes.insert( layer->fields().lookupField( columnConfig.name ) );
1296 }
1297 }
1298
1299 const QSet<int> colAttrs { attributes };
1300 for ( const int attrIdx : std::as_const( colAttrs ) )
1301 {
1302 if ( layer->fields().fieldOrigin( attrIdx ) == Qgis::FieldOrigin::Expression )
1303 {
1304 attributes += QgsExpression( layer->expressionField( attrIdx ) ).referencedAttributeIndexes( layer->fields() );
1305 }
1306 }
1307
1308 QgsAttributeList attrs { attributes.values() };
1309 std::sort( attrs.begin(), attrs.end() );
1310 return attrs;
1311}
1312
1313void QgsDualView::zoomToCurrentFeature()
1314{
1315 const QModelIndex currentIndex = mTableView->currentIndex();
1316 if ( !currentIndex.isValid() )
1317 {
1318 return;
1319 }
1320
1321 QgsFeatureIds ids;
1322 ids.insert( mFilterModel->rowToId( currentIndex ) );
1323 QgsMapCanvas *canvas = mFilterModel->mapCanvas();
1324 if ( canvas )
1325 {
1326 canvas->zoomToFeatureIds( mLayer, ids );
1327 }
1328}
1329
1330void QgsDualView::panToCurrentFeature()
1331{
1332 const QModelIndex currentIndex = mTableView->currentIndex();
1333 if ( !currentIndex.isValid() )
1334 {
1335 return;
1336 }
1337
1338 QgsFeatureIds ids;
1339 ids.insert( mFilterModel->rowToId( currentIndex ) );
1340 QgsMapCanvas *canvas = mFilterModel->mapCanvas();
1341 if ( canvas )
1342 {
1343 canvas->panToFeatureIds( mLayer, ids );
1344 }
1345}
1346
1347void QgsDualView::flashCurrentFeature()
1348{
1349 const QModelIndex currentIndex = mTableView->currentIndex();
1350 if ( !currentIndex.isValid() )
1351 {
1352 return;
1353 }
1354
1355 QgsFeatureIds ids;
1356 ids.insert( mFilterModel->rowToId( currentIndex ) );
1357 QgsMapCanvas *canvas = mFilterModel->mapCanvas();
1358 if ( canvas )
1359 {
1360 canvas->flashFeatureIds( mLayer, ids );
1361 }
1362}
1363
1364void QgsDualView::rebuildFullLayerCache()
1365{
1366 connect( mLayerCache, &QgsVectorLayerCache::progress, this, &QgsDualView::progress, Qt::UniqueConnection );
1367 connect( mLayerCache, &QgsVectorLayerCache::finished, this, &QgsDualView::finished, Qt::UniqueConnection );
1368
1369 mLayerCache->setFullCache( true );
1370}
1371
1372void QgsDualView::previewExpressionChanged( const QString &expression )
1373{
1374 if ( !mSkipDisplayExpressionChangedSignal )
1375 {
1376 mLayer->setDisplayExpression( expression );
1377 }
1378}
1379
1380void QgsDualView::onSortColumnChanged()
1381{
1382 QgsAttributeTableConfig cfg = attributeTableConfig();
1383 if ( cfg.sortExpression() != mFilterModel->sortExpression() || cfg.sortOrder() != mFilterModel->sortOrder() )
1384 {
1385 cfg.setSortExpression( mFilterModel->sortExpression() );
1386 cfg.setSortOrder( mFilterModel->sortOrder() );
1388 }
1389}
1390
1391void QgsDualView::updateSelectedFeatures()
1392{
1393 QgsFeatureRequest r = mMasterModel->request();
1395 return; // already requested all features
1396
1397 r.setFilterFids( masterModel()->layer()->selectedFeatureIds() );
1398 mMasterModel->setRequest( r );
1399 mMasterModel->loadLayer();
1400 emit filterChanged();
1401}
1402
1403void QgsDualView::updateEditedAddedFeatures()
1404{
1405 QgsFeatureRequest r = mMasterModel->request();
1407 return; // already requested all features
1408
1409 r.setFilterFids( masterModel()->layer()->editBuffer() ? masterModel()->layer()->editBuffer()->allAddedOrEditedFeatures() : QgsFeatureIds() );
1410 mMasterModel->setRequest( r );
1411 mMasterModel->loadLayer();
1412 emit filterChanged();
1413}
1414
1415void QgsDualView::extentChanged()
1416{
1417 QgsFeatureRequest r = mMasterModel->request();
1418 if ( mFilterModel->mapCanvas() && ( r.filterType() != Qgis::FeatureRequestFilterType::NoFilter || !r.filterRect().isNull() ) )
1419 {
1420 const QgsRectangle rect = mFilterModel->mapCanvas()->mapSettings().mapToLayerCoordinates( mLayer, mFilterModel->mapCanvas()->extent() );
1421 r.setFilterRect( rect );
1422 mMasterModel->setRequest( r );
1423 mMasterModel->loadLayer();
1424 }
1425 emit filterChanged();
1426}
1427
1428void QgsDualView::featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged )
1429{
1430 Q_UNUSED( attribute )
1431 Q_UNUSED( value )
1432 if ( attributeChanged )
1433 {
1434 mFeatureListView->setCurrentFeatureEdited( true );
1435 mAttributeForm->save();
1436 }
1437}
1438
1440{
1441 mFilterModel->setFilteredFeatures( filteredFeatures );
1442}
1443
1444void QgsDualView::filterFeatures( const QgsExpression &filterExpression, const QgsExpressionContext &context )
1445{
1446 mFilterModel->setFilterExpression( filterExpression, context );
1447 mFilterModel->filterFeatures();
1448}
1449
1451{
1452 return mFilterModel->filteredFeatures();
1453}
1454
1455
1457{
1458 mMasterModel->setRequest( request );
1459}
1460
1462{
1463 mTableView->setFeatureSelectionManager( featureSelectionManager );
1464 mFeatureListView->setFeatureSelectionManager( featureSelectionManager );
1465
1466 if ( mFeatureSelectionManager && mFeatureSelectionManager->parent() == this )
1467 delete mFeatureSelectionManager;
1468
1469 mFeatureSelectionManager = featureSelectionManager;
1470}
1471
1473{
1474 mConfig = config;
1475 mConfig.update( mLayer->fields() );
1476 mLayer->setAttributeTableConfig( mConfig );
1477 mFilterModel->setAttributeTableConfig( mConfig );
1478 mTableView->setAttributeTableConfig( mConfig );
1479 const QgsAttributeList attributes { requiredAttributes( mLayer ) };
1480 QgsFeatureRequest request = mMasterModel->request();
1481 // if the sort expression needs geometry reset the flag
1482 if ( QgsExpression( config.sortExpression() ).needsGeometry() )
1483 {
1484 mLayerCache->setCacheGeometry( true );
1485 request.setFlags( request.flags().setFlag( Qgis::FeatureRequestFlag::NoGeometry, false ) );
1486 }
1487 request.setSubsetOfAttributes( attributes );
1488 mMasterModel->setRequest( request );
1489 mLayerCache->setCacheSubsetOfAttributes( attributes );
1490}
1491
1492void QgsDualView::setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder )
1493{
1494 if ( sortExpression.isNull() )
1495 mFilterModel->sort( -1 );
1496 else
1497 mFilterModel->sort( sortExpression, sortOrder );
1498
1499 mConfig.setSortExpression( sortExpression );
1500 mConfig.setSortOrder( sortOrder );
1501 setAttributeTableConfig( mConfig );
1502}
1503
1505{
1506 return mFilterModel->sortExpression();
1507}
1508
1510{
1511 return mConfig;
1512}
1513
1514void QgsDualView::progress( int i, bool &cancel )
1515{
1516 if ( !mProgressDlg )
1517 {
1518 mProgressDlg = new QProgressDialog( tr( "Loading features…" ), tr( "Abort" ), 0, 0, this );
1519 mProgressDlg->setWindowTitle( tr( "Attribute Table" ) );
1520 mProgressDlg->setWindowModality( Qt::WindowModal );
1521 mProgressDlg->show();
1522 }
1523
1524 mProgressDlg->setLabelText( tr( "%L1 features loaded." ).arg( i ) );
1525 QCoreApplication::processEvents();
1526
1527 cancel = mProgressDlg && mProgressDlg->wasCanceled();
1528}
1529
1530void QgsDualView::finished()
1531{
1532 delete mProgressDlg;
1533 mProgressDlg = nullptr;
1534}
1535
1536/*
1537 * QgsAttributeTableAction
1538 */
1539
1541{
1542 mDualView->masterModel()->executeAction( mAction, mFieldIdx );
1543}
1544
1546{
1547 QgsFeatureIds editedIds;
1548 editedIds << mDualView->masterModel()->rowToId( mFieldIdx.row() );
1549 mDualView->setCurrentEditSelection( editedIds );
1550 mDualView->setView( QgsDualView::AttributeEditor );
1551}
1552
1553/*
1554 * QgsAttributeTableMapLayerAction
1555 */
1556
1558{
1560 mDualView->masterModel()->executeMapLayerAction( mAction, mFieldIdx, context );
1561}
AttributeTableFilterMode
Defines how rows in attribute tables should be filtered.
Definition qgis.h:7318
@ ShowSelected
Show only selected features.
Definition qgis.h:7320
@ ShowAll
Show all features.
Definition qgis.h:7319
@ ShowInvalid
Show only features not respecting constraints.
Definition qgis.h:7324
@ ShowVisible
Show only visible features (depends on the map canvas).
Definition qgis.h:7321
@ ShowFilteredList
Show only features whose IDs are on the filter list.
Definition qgis.h:7322
@ ShowEdited
Show only features which have unsaved changes.
Definition qgis.h:7323
@ SelectAtId
Fast access to features using their ID.
Definition qgis.h:553
@ ChangeAttributeValues
Allows modification of attribute values.
Definition qgis.h:549
@ NoFilter
No filter is applied.
Definition qgis.h:2408
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Definition qgis.h:2380
@ NoFilter
No spatial filtering of features.
Definition qgis.h:2437
@ MultipleFeatures
Action targets multiple features from a layer.
Definition qgis.h:5180
@ Layer
Action targets a complete layer.
Definition qgis.h:5178
@ SingleFeature
Action targets a single feature from a layer.
Definition qgis.h:5179
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
Definition qgis.h:584
FieldOrigin
Field origin.
Definition qgis.h:1874
@ Provider
Field originates from the underlying data provider of the vector layer.
Definition qgis.h:1876
@ Edit
Field has been temporarily added in editing mode.
Definition qgis.h:1878
@ Unknown
The field origin has not been specified.
Definition qgis.h:1875
@ Expression
Field is calculated from an expression.
Definition qgis.h:1879
@ Join
Field originates from a joined layer.
Definition qgis.h:1877
A menu that is populated automatically with the actions defined for a given layer.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Contains context information for attribute editor widgets.
@ 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.
const QgsAttributeEditorContext * parentContext() const
The attribute form widget for vector layer features.
void refreshFeature()
reload current feature
bool needsGeometry() const
Returns true if any of the form widgets need feature geometry.
void filterExpressionSet(const QString &expression, QgsAttributeForm::FilterType type)
Emitted when a filter expression is set using the form.
void widgetValueChanged(const QString &attribute, const QVariant &value, bool attributeChanged)
Notifies about changes of attributes.
void flashFeatures(const QString &filter)
Emitted when the user chooses to flash a filtered set of features.
void modeChanged(QgsAttributeEditorContext::Mode mode)
Emitted when the form changes mode.
void zoomToFeatures(const QString &filter)
Emitted when the user chooses to zoom to a filtered set of features.
A container for configuration of the attribute table.
void setSortExpression(const QString &sortExpression)
Set the sort expression used for sorting.
@ Field
This column represents a field.
Qt::SortOrder sortOrder() const
Gets the sort order.
QVector< QgsAttributeTableConfig::ColumnConfig > columns() const
Gets the list with all columns and their configuration.
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.
void filterError(const QString &errorMessage)
Emitted when an error occurred while filtering features.
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 sortColumnChanged(int column, Qt::SortOrder order)
Emitted whenever the sort column is changed.
void fieldConditionalStyleChanged(const QString &fieldName)
Handles updating the model when the conditional style for a field changes.
void modelChanged()
Emitted when the model has been changed.
void progress(int i, bool &cancel)
void finished()
Emitted when the model has completely loaded all features.
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.
Qgis::AttributeTableFilterMode filterMode() const
Gets the filter mode.
void copyCellContent() const
Copy the content of the selected cell in the clipboard.
ViewMode
The view modes, in which this widget can present information.
Definition qgsdualview.h:63
@ AttributeEditor
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
Definition qgsdualview.h:75
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
Set the feature selection model.
void setFilterMode(Qgis::AttributeTableFilterMode filterMode)
Set the filter mode.
~QgsDualView() override
static QgsAttributeList requiredAttributes(const QgsVectorLayer *layer)
Returns the list of required attributes according to the attribute table configuration of the layer,...
void setMultiEditEnabled(bool enabled)
Sets whether multi edit mode is enabled.
void cancelProgress()
Cancel the progress dialog (if any).
void filterChanged()
Emitted whenever the filter changes.
static const QgsSettingsEntryBool * settingsFeatureListHighlightFeature
Definition qgsdualview.h:53
static const QgsSettingsEntryInteger * settingsAttributeTableRowCache
Definition qgsdualview.h:55
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.
QgsFeatureIds filteredFeatures() const
Gets a list of currently visible feature ids.
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.
Definition qgsdualview.h:82
@ NoAction
No action is done.
Definition qgsdualview.h:83
@ PanToFeature
The map is panned to the center of the feature bounding-box.
Definition qgsdualview.h:84
@ ZoomToFeature
The map is zoomed to contained the feature bounding-box.
Definition qgsdualview.h:85
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.
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext(), bool loadFeatures=true, bool showFirstFeature=true)
Has to be called to initialize the dual 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.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered).
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 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.
QString expressionText()
Gets the expression string that has been set in the expression area.
void setExpressionText(const QString &expression)
Sets the expression string for the widget.
void initWithLayer(QgsVectorLayer *layer, const QgsExpressionContext &context=QgsExpressionContext(), const QString &recentCollection=u"generic"_s, QgsExpressionBuilderWidget::Flags flags=LoadAll)
Initialize with a layer.
static std::vector< std::unique_ptr< 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...
Handles parsing and evaluation of expressions (formerly called "search strings").
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QSet< int > referencedAttributeIndexes(const QgsFields &fields) const
Returns a list of field name indexes obtained from the provided fields.
@ FeatureRole
Feature with all attributes and no geometry.
Shows a list of features and renders an 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)
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsRectangle filterRect() const
Returns the rectangle from which features will be taken.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
Qgis::FeatureRequestFilterType filterType() const
Returns the attribute/ID filter type which is currently set on this request.
Qgis::FeatureRequestFlags flags() const
Returns the flags which affect how features are fetched.
QgsFeatureRequest & disableFilter()
Disables any attribute/ID filtering.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Qgis::SpatialFilterType spatialFilterType() const
Returns the spatial filter type which is currently set on this request.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsFeatureId id
Definition qgsfeature.h:63
A widget for customizing conditional formatting options.
void rulesUpdated(const QString &fieldName)
Emitted when the conditional styling rules are updated.
Qgis::FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
Definition qgsgui.cpp:110
static QgsShortcutsManager * shortcutsManager()
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
Definition qgsgui.cpp:140
static QgsMapLayerActionRegistry * mapLayerActionRegistry()
Returns the global map layer action registry, used for registering map layer actions.
Definition qgsgui.cpp:150
Is an interface class to abstract feature selection handling.
static long zoomToMatchingFeatures(QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter)
Zooms a map canvas to features from the specified layer which match the given filter expression strin...
static long flashMatchingFeatures(QgsMapCanvas *canvas, QgsVectorLayer *layer, const QString &filter)
Flashes features from the specified layer which match the given filter expression string with a map c...
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.
Encapsulates the context in which a QgsMapLayerAction action is executed.
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, Qgis::MapLayerActionTargets targets=Qgis::MapLayerActionTarget::AllActions, const QgsMapLayerActionContext &context=QgsMapLayerActionContext())
Returns the map layer actions which can run on the specified layer.
void layerModified()
Emitted when modifications has been done on layer.
A rectangle specified with double values.
A QScrollArea subclass with improved scrolling behavior.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
A boolean settings entry.
An integer settings entry.
A variant settings entry.
static QgsSettingsTreeNode * sTreeAttributeTable
static QgsSettingsTreeNode * sTreeWindowState
Stores settings for use within QGIS.
Definition qgssettings.h:68
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.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
virtual Q_INVOKABLE Qgis::VectorProviderCapabilities capabilities() const
Returns flags containing the supported capabilities.
Caches features for a given QgsVectorLayer.
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 setCacheSubsetOfAttributes(const QgsAttributeList &attributes)
Set the list (possibly a subset) of attributes to be cached.
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.
bool isEditable() const
Returns whether joined fields may be edited through the form of the target layer.
QgsVectorLayer * joinLayer() const
Returns joined layer (may be nullptr if the reference was set by layer ID and not resolved yet).
Represents a vector layer which manages a vector based dataset.
bool isEditable() const final
Returns true if the provider is in editing mode.
bool isSpatial() const final
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QString expressionField(int index) const
Returns the expression used for a given expression field.
void afterCommitChanges()
Emitted after changes are committed to the data provider.
QgsAttributeTableConfig attributeTableConfig() const
Returns the attribute table configuration object.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
void updatedFields()
Emitted whenever the fields available from this layer have been changed.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:7705
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
Definition qgsfield.h:30
Defines the configuration of a column in the attribute table.