Skip to content
Permalink
Browse files

[FEATURE] Make 'Add Filter' context menu entry and 'Edit query' in ve…

…ctor layer properties dialog use the subset string provider registry
  • Loading branch information
rouault authored and nyalldawson committed Nov 16, 2020
1 parent 24eb319 commit 6a53ae79756a85b580f50347b545547e464c5819
Showing with 14 additions and 9 deletions.
  1. +6 −3 src/app/qgisapp.cpp
  2. +8 −6 src/gui/vector/qgsvectorlayerproperties.cpp
@@ -339,6 +339,9 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsstatusbarmagnifierwidget.h"
#include "qgsstatusbarscalewidget.h"
#include "qgsstyle.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgssubsetstringeditorprovider.h"
#include "qgssubsetstringeditorinterface.h"
#include "qgssvgannotation.h"
#include "qgstaskmanager.h"
#include "qgstaskmanagerwidget.h"
@@ -11496,16 +11499,16 @@ void QgisApp::layerSubsetString( QgsMapLayer *mapLayer )
}

// launch the query builder
std::unique_ptr<QgsQueryBuilder> qb( new QgsQueryBuilder( vlayer, this ) );
std::unique_ptr<QgsSubsetStringEditorInterface> qb( QgsGui::subsetStringEditorProviderRegistry()->createDialog( vlayer, this ) );
QString subsetBefore = vlayer->subsetString();

// Set the sql in the query builder to the same in the prop dialog
// (in case the user has already changed it)
qb->setSql( vlayer->subsetString() );
qb->setSubsetString( vlayer->subsetString() );
// Open the query builder and refresh symbology if sql has changed
// Note: repaintRequested is emitted directly from QgsQueryBuilder
// when the sql is set in the layer.
if ( qb->exec() && ( subsetBefore != qb->sql() ) && mLayerTreeView )
if ( qb->exec() && ( subsetBefore != qb->subsetString() ) && mLayerTreeView )
{
mLayerTreeView->refreshLayerSymbology( vlayer->id() );
activateDeactivateLayerRelatedActions( vlayer );
@@ -46,7 +46,9 @@
#include "qgsvectorlayerproperties.h"
#include "qgsconfig.h"
#include "qgsvectordataprovider.h"
#include "qgsquerybuilder.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgssubsetstringeditorprovider.h"
#include "qgssubsetstringeditorinterface.h"
#include "qgsdatasourceuri.h"
#include "qgsrenderer.h"
#include "qgsexpressioncontext.h"
@@ -844,24 +846,24 @@ void QgsVectorLayerProperties::urlClicked( const QUrl &url )
void QgsVectorLayerProperties::pbnQueryBuilder_clicked()
{
// launch the query builder
QgsQueryBuilder *qb = new QgsQueryBuilder( mLayer, this );
QgsSubsetStringEditorInterface *dialog = QgsGui::subsetStringEditorProviderRegistry()->createDialog( mLayer, this );

// Set the sql in the query builder to the same in the prop dialog
// (in case the user has already changed it)
qb->setSql( txtSubsetSQL->text() );
dialog->setSubsetString( txtSubsetSQL->text() );
// Open the query builder
if ( qb->exec() )
if ( dialog->exec() )
{
// if the sql is changed, update it in the prop subset text box
txtSubsetSQL->setText( qb->sql() );
txtSubsetSQL->setText( dialog->subsetString() );
//TODO If the sql is changed in the prop dialog, the layer extent should be recalculated

// The datasource for the layer needs to be updated with the new sql since this gets
// saved to the project file. This should happen at the map layer level...

}
// delete the query builder object
delete qb;
delete dialog;
}

void QgsVectorLayerProperties::pbnIndex_clicked()

0 comments on commit 6a53ae7

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