Skip to content
Permalink
Browse files

[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)
  • Loading branch information
nyalldawson committed Nov 30, 2017
1 parent f6ffb00 commit ded892eaee37fbd816f8c68878a2b1dc108396e7
@@ -1208,6 +1208,24 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
toggleSnapping->setProperty( "Icon", QgsApplication::getThemeIcon( QStringLiteral( "/mIconSnapping.svg" ) ) );
connect( toggleSnapping, &QShortcut::activated, mSnappingUtils, &QgsSnappingUtils::toggleEnabled );

QShortcut *attributeTableSelected = new QShortcut( QKeySequence( tr( "Shift+F6" ) ), this );
attributeTableSelected->setObjectName( QStringLiteral( "attributeTableSelectedFeatures" ) );
attributeTableSelected->setWhatsThis( tr( "Open Attribute Table (Selected Features)" ) );
attributeTableSelected->setProperty( "Icon", QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ) );
connect( attributeTableSelected, &QShortcut::activated, this, [ = ]
{
attributeTable( QgsAttributeTableFilterModel::ShowSelected );
} );

QShortcut *attributeTableVisible = new QShortcut( QKeySequence( tr( "Ctrl+F6" ) ), this );
attributeTableVisible->setObjectName( QStringLiteral( "attributeTableVisibleFeatures" ) );
attributeTableVisible->setWhatsThis( tr( "Open Attribute Table (Visible Features)" ) );
attributeTableVisible->setProperty( "Icon", QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ) );
connect( attributeTableVisible, &QShortcut::activated, this, [ = ]
{
attributeTable( QgsAttributeTableFilterModel::ShowVisible );
} );

if ( ! QTouchDevice::devices().isEmpty() )
{
//add reacting to long click in touch
@@ -1934,7 +1952,12 @@ void QgisApp::createActions()
connect( mActionAddAmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgismapserver" ) ); } );
connect( mActionAddDelimitedText, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "delimitedtext" ) ); } );
connect( mActionAddVirtualLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "virtual" ) ); } );
connect( mActionOpenTable, &QAction::triggered, this, &QgisApp::attributeTable );
connect( mActionOpenTable, &QAction::triggered, this, [ = ]
{
QgsSettings settings;
QgsAttributeTableFilterModel::FilterMode initialMode = static_cast< QgsAttributeTableFilterModel::FilterMode>( settings.value( QStringLiteral( "qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll ).toInt() );
attributeTable( initialMode );
} );
connect( mActionOpenFieldCalc, &QAction::triggered, this, &QgisApp::fieldCalculator );
connect( mActionToggleEditing, &QAction::triggered, this, [ = ] { toggleEditing(); } );
connect( mActionSaveLayerEdits, &QAction::triggered, this, &QgisApp::saveActiveLayerEdits );
@@ -6688,15 +6711,15 @@ void QgisApp::fieldCalculator()
}
}

void QgisApp::attributeTable()
void QgisApp::attributeTable( QgsAttributeTableFilterModel::FilterMode filter )
{
QgsVectorLayer *myLayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
if ( !myLayer )
{
return;
}

QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer );
QgsAttributeTableDialog *mDialog = new QgsAttributeTableDialog( myLayer, filter );
mDialog->show();
// the dialog will be deleted by itself on close
}
@@ -149,7 +149,7 @@ class QgsGeoCmsProviderRegistry;
#include "qgsrasterminmaxorigin.h"
#include "qgsmaplayeractionregistry.h"
#include "qgsoptionswidgetfactory.h"

#include "qgsattributetablefiltermodel.h"
#include "ui_qgisapp.h"
#include "qgis_app.h"

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

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

void fieldCalculator();

@@ -531,7 +531,7 @@ QDialog *QgisAppInterface::showAttributeTable( QgsVectorLayer *l, const QString
{
if ( l )
{
QgsAttributeTableDialog *dialog = new QgsAttributeTableDialog( l );
QgsAttributeTableDialog *dialog = new QgsAttributeTableDialog( l, QgsAttributeTableFilterModel::ShowFilteredList );
dialog->setFilterExpression( filterExpression );
dialog->show();
return dialog;
@@ -80,7 +80,7 @@ void QgsAttributeTableDialog::updateMultiEditButtonState()
}
}

QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QWidget *parent, Qt::WindowFlags flags )
QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttributeTableFilterModel::FilterMode initialMode, QWidget *parent, Qt::WindowFlags flags )
: QDialog( parent, flags )
, mLayer( layer )

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

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

// Load default attribute table filter
QgsAttributeTableFilterModel::FilterMode defaultFilterMode = ( QgsAttributeTableFilterModel::FilterMode ) settings.value( QStringLiteral( "qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll ).toInt();

switch ( defaultFilterMode )
switch ( initialMode )
{
case QgsAttributeTableFilterModel::ShowVisible:
filterVisible();
@@ -47,10 +47,12 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
/**
* Constructor
* \param layer layer pointer
* \param initialMode initial filter for dialog
* \param parent parent object
* \param flags window flags
*/
QgsAttributeTableDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::Window );
QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttributeTableFilterModel::FilterMode initialMode = QgsAttributeTableFilterModel::ShowAll, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::Window );

~QgsAttributeTableDialog();

QgsExpressionContext createExpressionContext() const override;
@@ -99,7 +99,7 @@ void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer *layer, const QLi
}
filter = filter.replace( QRegExp( ",$" ), QStringLiteral( ")" ) );

QgsAttributeTableDialog *tableDialog = new QgsAttributeTableDialog( vl );
QgsAttributeTableDialog *tableDialog = new QgsAttributeTableDialog( vl, QgsAttributeTableFilterModel::ShowFilteredList );
tableDialog->setFilterExpression( filter );
tableDialog->show();
}
@@ -69,8 +69,6 @@ void TestQgsAttributeTable::initTestCase()
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST" ) );

QSettings().setValue( QStringLiteral( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
}

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

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

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

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

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

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

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

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

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

0 comments on commit ded892e

Please sign in to comment.
You can’t perform that action at this time.