Skip to content

Commit ded892e

Browse files
committedNov 30, 2017
[needs-docs] Add some shortcuts for opening the attribute table
Adds: - shift + f6: show table filtered to selected features - ctrl + f6: show table filtered to visible features (These are alongside the existing 'f6' shortcut which opens the table using the default mode set via the options dialog)
1 parent f6ffb00 commit ded892e

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,24 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
12081208
toggleSnapping->setProperty( "Icon", QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnapping.svg" ) ) );
12091209
connect( toggleSnapping, &QShortcut::activated, mSnappingUtils, &QgsSnappingUtils::toggleEnabled );
12101210

1211+
QShortcut *attributeTableSelected = new QShortcut( QKeySequence( tr( "Shift+F6" ) ), this );
1212+
attributeTableSelected->setObjectName( QStringLiteral( "attributeTableSelectedFeatures" ) );
1213+
attributeTableSelected->setWhatsThis( tr( "Open Attribute Table (Selected Features)" ) );
1214+
attributeTableSelected->setProperty( "Icon", QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ) );
1215+
connect( attributeTableSelected, &QShortcut::activated, this, [ = ]
1216+
{
1217+
attributeTable( QgsAttributeTableFilterModel::ShowSelected );
1218+
} );
1219+
1220+
QShortcut *attributeTableVisible = new QShortcut( QKeySequence( tr( "Ctrl+F6" ) ), this );
1221+
attributeTableVisible->setObjectName( QStringLiteral( "attributeTableVisibleFeatures" ) );
1222+
attributeTableVisible->setWhatsThis( tr( "Open Attribute Table (Visible Features)" ) );
1223+
attributeTableVisible->setProperty( "Icon", QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ) );
1224+
connect( attributeTableVisible, &QShortcut::activated, this, [ = ]
1225+
{
1226+
attributeTable( QgsAttributeTableFilterModel::ShowVisible );
1227+
} );
1228+
12111229
if ( ! QTouchDevice::devices().isEmpty() )
12121230
{
12131231
//add reacting to long click in touch
@@ -1934,7 +1952,12 @@ void QgisApp::createActions()
19341952
connect( mActionAddAmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgismapserver" ) ); } );
19351953
connect( mActionAddDelimitedText, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "delimitedtext" ) ); } );
19361954
connect( mActionAddVirtualLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "virtual" ) ); } );
1937-
connect( mActionOpenTable, &QAction::triggered, this, &QgisApp::attributeTable );
1955+
connect( mActionOpenTable, &QAction::triggered, this, [ = ]
1956+
{
1957+
QgsSettings settings;
1958+
QgsAttributeTableFilterModel::FilterMode initialMode = static_cast< QgsAttributeTableFilterModel::FilterMode>( settings.value( QStringLiteral( "qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll ).toInt() );
1959+
attributeTable( initialMode );
1960+
} );
19381961
connect( mActionOpenFieldCalc, &QAction::triggered, this, &QgisApp::fieldCalculator );
19391962
connect( mActionToggleEditing, &QAction::triggered, this, [ = ] { toggleEditing(); } );
19401963
connect( mActionSaveLayerEdits, &QAction::triggered, this, &QgisApp::saveActiveLayerEdits );
@@ -6688,15 +6711,15 @@ void QgisApp::fieldCalculator()
66886711
}
66896712
}
66906713

6691-
void QgisApp::attributeTable()
6714+
void QgisApp::attributeTable( QgsAttributeTableFilterModel::FilterMode filter )
66926715
{
66936716
QgsVectorLayer *myLayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
66946717
if ( !myLayer )
66956718
{
66966719
return;
66976720
}
66986721

6699-
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer );
6722+
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer, filter );
67006723
mDialog->show();
67016724
// the dialog will be deleted by itself on close
67026725
}

‎src/app/qgisapp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class QgsGeoCmsProviderRegistry;
149149
#include "qgsrasterminmaxorigin.h"
150150
#include "qgsmaplayeractionregistry.h"
151151
#include "qgsoptionswidgetfactory.h"
152-
152+
#include "qgsattributetablefiltermodel.h"
153153
#include "ui_qgisapp.h"
154154
#include "qgis_app.h"
155155

@@ -682,7 +682,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
682682
void layerProperties();
683683

684684
//! show the attribute table for the currently selected layer
685-
void attributeTable();
685+
void attributeTable( QgsAttributeTableFilterModel::FilterMode filter = QgsAttributeTableFilterModel::ShowAll );
686686

687687
void fieldCalculator();
688688

‎src/app/qgisappinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ QDialog *QgisAppInterface::showAttributeTable( QgsVectorLayer *l, const QString
531531
{
532532
if ( l )
533533
{
534-
QgsAttributeTableDialog *dialog = new QgsAttributeTableDialog( l );
534+
QgsAttributeTableDialog *dialog = new QgsAttributeTableDialog( l, QgsAttributeTableFilterModel::ShowFilteredList );
535535
dialog->setFilterExpression( filterExpression );
536536
dialog->show();
537537
return dialog;

‎src/app/qgsattributetabledialog.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void QgsAttributeTableDialog::updateMultiEditButtonState()
8080
}
8181
}
8282

83-
QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QWidget *parent, Qt::WindowFlags flags )
83+
QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttributeTableFilterModel::FilterMode initialMode, QWidget *parent, Qt::WindowFlags flags )
8484
: QDialog( parent, flags )
8585
, mLayer( layer )
8686

@@ -150,7 +150,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QWidget
150150

151151
QgsFeatureRequest r;
152152
bool needsGeom = false;
153-
QgsAttributeTableFilterModel::FilterMode initialMode = static_cast< QgsAttributeTableFilterModel::FilterMode>( settings.value( QStringLiteral( "qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll ).toInt() );
154153
if ( mLayer->geometryType() != QgsWkbTypes::NullGeometry &&
155154
initialMode == QgsAttributeTableFilterModel::ShowVisible )
156155
{
@@ -277,10 +276,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QWidget
277276
mMainViewButtonGroup->setId( mTableViewButton, QgsDualView::AttributeTable );
278277
mMainViewButtonGroup->setId( mAttributeViewButton, QgsDualView::AttributeEditor );
279278

280-
// Load default attribute table filter
281-
QgsAttributeTableFilterModel::FilterMode defaultFilterMode = ( QgsAttributeTableFilterModel::FilterMode ) settings.value( QStringLiteral( "qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll ).toInt();
282-
283-
switch ( defaultFilterMode )
279+
switch ( initialMode )
284280
{
285281
case QgsAttributeTableFilterModel::ShowVisible:
286282
filterVisible();

‎src/app/qgsattributetabledialog.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
4747
/**
4848
* Constructor
4949
* \param layer layer pointer
50+
* \param initialMode initial filter for dialog
5051
* \param parent parent object
5152
* \param flags window flags
5253
*/
53-
QgsAttributeTableDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::Window );
54+
QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttributeTableFilterModel::FilterMode initialMode = QgsAttributeTableFilterModel::ShowAll, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::Window );
55+
5456
~QgsAttributeTableDialog();
5557

5658
QgsExpressionContext createExpressionContext() const override;

‎src/app/qgsmaptoolidentifyaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer *layer, const QLi
9999
}
100100
filter = filter.replace( QRegExp( ",$" ), QStringLiteral( ")" ) );
101101

102-
QgsAttributeTableDialog *tableDialog = new QgsAttributeTableDialog( vl );
102+
QgsAttributeTableDialog *tableDialog = new QgsAttributeTableDialog( vl, QgsAttributeTableFilterModel::ShowFilteredList );
103103
tableDialog->setFilterExpression( filter );
104104
tableDialog->show();
105105
}

‎tests/src/app/testqgsattributetable.cpp

100644100755
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ void TestQgsAttributeTable::initTestCase()
6969
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
7070
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
7171
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST" ) );
72-
73-
QSettings().setValue( QStringLiteral( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
7472
}
7573

7674
//runs after all tests
@@ -184,16 +182,14 @@ void TestQgsAttributeTable::testNoGeom()
184182
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
185183
QVERIFY( tempLayer->isValid() );
186184

187-
s.setValue( QStringLiteral( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
188-
std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.get() ) );
185+
std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.get(), QgsAttributeTableFilterModel::ShowAll ) );
189186

190187
QVERIFY( !dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
191188
QVERIFY( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry );
192189

193190
// but if we are requesting only visible features, then geometry must be fetched...
194191

195-
s.setValue( QStringLiteral( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowVisible );
196-
dlg.reset( new QgsAttributeTableDialog( tempLayer.get() ) );
192+
dlg.reset( new QgsAttributeTableDialog( tempLayer.get(), QgsAttributeTableFilterModel::ShowVisible ) );
197193
QVERIFY( dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
198194
QVERIFY( !( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry ) );
199195

@@ -222,8 +218,7 @@ void TestQgsAttributeTable::testSelected()
222218
QgsFeature f3( tempLayer->dataProvider()->fields(), 3 );
223219
QVERIFY( tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 ) );
224220

225-
s.setValue( QStringLiteral( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowSelected );
226-
std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.get() ) );
221+
std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.get(), QgsAttributeTableFilterModel::ShowSelected ) );
227222

228223
QVERIFY( !dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
229224
//should be nothing - because no selection!
@@ -236,7 +231,7 @@ void TestQgsAttributeTable::testSelected()
236231
QCOMPARE( dlg->mMainView->masterModel()->request().filterFids(), QgsFeatureIds() << 1 << 3 );
237232

238233
// another test - start with selection when dialog created
239-
dlg.reset( new QgsAttributeTableDialog( tempLayer.get() ) );
234+
dlg.reset( new QgsAttributeTableDialog( tempLayer.get(), QgsAttributeTableFilterModel::ShowSelected ) );
240235
QVERIFY( !dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
241236
QCOMPARE( dlg->mMainView->masterModel()->request().filterType(), QgsFeatureRequest::FilterFids );
242237
QCOMPARE( dlg->mMainView->masterModel()->request().filterFids(), QgsFeatureIds() << 1 << 3 );

0 commit comments

Comments
 (0)