Skip to content

Commit

Permalink
Make QgsSQLComposerDialog implement QgsSubsetStringEditorInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault authored and nyalldawson committed Nov 16, 2020
1 parent 6a53ae7 commit 1bd83fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/gui/qgssqlcomposerdialog.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -221,6 +227,10 @@ void QgsSQLComposerDialog::accept()
QMessageBox::warning( this, tr( "SQL Evaluation" ), warningMsg );
}
}
if ( mLayer )
{
mLayer->setSubsetString( sql() );
}
QDialog::accept();
}

Expand Down
18 changes: 17 additions & 1 deletion src/gui/qgssqlcomposerdialog.h
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1bd83fb

Please sign in to comment.