Skip to content
Permalink
Browse files

Make QgsSQLComposerDialog implement QgsSubsetStringEditorInterface

  • Loading branch information
rouault authored and nyalldawson committed Nov 16, 2020
1 parent 6a53ae7 commit 1bd83fb8eb4a8803b2e7d82e15b9b0af01907d8d
Showing with 28 additions and 2 deletions.
  1. +11 −1 src/gui/qgssqlcomposerdialog.cpp
  2. +17 −1 src/gui/qgssqlcomposerdialog.h
@@ -21,14 +21,20 @@ email : even.rouault at spatialys.com
#include "qgssqlcomposerdialog.h"
#include "qgssqlstatement.h"
#include "qgshelp.h"
#include "qgsvectorlayer.h"

#include <QMessageBox>
#include <QKeyEvent>

#include <Qsci/qscilexer.h>

QgsSQLComposerDialog::QgsSQLComposerDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
: QgsSQLComposerDialog( nullptr, parent, fl )
{}

QgsSQLComposerDialog::QgsSQLComposerDialog( QgsVectorLayer *layer, QWidget *parent, Qt::WindowFlags fl )
: QgsSubsetStringEditorInterface( parent, fl )
, mLayer( layer )
{
setupUi( this );
connect( mTablesCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSQLComposerDialog::mTablesCombo_currentIndexChanged );
@@ -221,6 +227,10 @@ void QgsSQLComposerDialog::accept()
QMessageBox::warning( this, tr( "SQL Evaluation" ), warningMsg );
}
}
if ( mLayer )
{
mLayer->setSubsetString( sql() );
}
QDialog::accept();
}

@@ -27,15 +27,18 @@ email : even.rouault at spatialys.com
#include <QStringList>
#include <QSet>
#include "qgis_gui.h"
#include "qgssubsetstringeditorinterface.h"

SIP_NO_FILE

class QgsVectorLayer;

/**
* \ingroup gui
* SQL composer dialog
* \note not available in Python bindings
*/
class GUI_EXPORT QgsSQLComposerDialog : public QDialog, private Ui::QgsSQLComposerDialogBase
class GUI_EXPORT QgsSQLComposerDialog : public QgsSubsetStringEditorInterface, private Ui::QgsSQLComposerDialogBase
{
Q_OBJECT

@@ -109,6 +112,15 @@ class GUI_EXPORT QgsSQLComposerDialog : public QDialog, private Ui::QgsSQLCompos

//! constructor
explicit QgsSQLComposerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

/**
* This constructor is used on an existing layer. On successful accept, it will update the layer subset string.
* \param layer existing vector layer
* \param parent Parent widget
* \param fl dialog flags
*/
QgsSQLComposerDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

~QgsSQLComposerDialog() override;

//! initialize the SQL statement
@@ -117,6 +129,9 @@ class GUI_EXPORT QgsSQLComposerDialog : public QDialog, private Ui::QgsSQLCompos
//! Gets the SQL statement
QString sql() const;

QString subsetString() const override { return sql(); }
void setSubsetString( const QString &subsetString ) override { setSql( subsetString ); }

//! add a list of table names
void addTableNames( const QStringList &list );
//! add a list of table names
@@ -174,6 +189,7 @@ class GUI_EXPORT QgsSQLComposerDialog : public QDialog, private Ui::QgsSQLCompos
void splitSQLIntoFields();

private:
QgsVectorLayer *mLayer = nullptr;
QStringList mApiList;
QSet<QString> mAlreadySelectedTables;
TableSelectedCallback *mTableSelectedCallback = nullptr;

0 comments on commit 1bd83fb

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