QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgssqlcomposerdialog.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssqlcomposerdialog.cpp
3 Dialog to compose SQL queries
4
5begin : Apr 2016
6copyright : (C) 2016 Even Rouault
7email : even.rouault at spatialys.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#ifndef QGSSQLCOMPOSERDIALOG_H
20#define QGSSQLCOMPOSERDIALOG_H
21
22#include "ui_qgssqlcomposerdialogbase.h"
23#include "qgis_sip.h"
24#include "qgsguiutils.h"
25
26#include <QPair>
27#include <QStringList>
28#include <QSet>
29#include "qgis_gui.h"
31
33
34class QgsVectorLayer;
35
41class GUI_EXPORT QgsSQLComposerDialog : public QgsSubsetStringEditorInterface, private Ui::QgsSQLComposerDialogBase
42{
43 Q_OBJECT
44
45 public:
47 typedef QPair<QString, QString> PairNameTitle;
48
50 typedef QPair<QString, QString> PairNameType;
51
57 class GUI_EXPORT TableSelectedCallback
58 {
59 public:
60 virtual ~TableSelectedCallback() = default;
62 virtual void tableSelected( const QString &name ) = 0;
63 };
64
70 class GUI_EXPORT SQLValidatorCallback
71 {
72 public:
73 virtual ~SQLValidatorCallback() = default;
75 virtual bool isValid( const QString &sql, QString &errorReason, QString &warningMsg ) = 0;
76 };
77
79 struct Argument
80 {
82 QString name;
84 QString type;
85
87 Argument( const QString &nameIn = QString(), const QString &typeIn = QString() )
88 : name( nameIn ), type( typeIn ) {}
89 };
90
92 struct Function
93 {
95 QString name;
97 QString returnType;
99 int minArgs = -1;
101 int maxArgs = -1;
103 QList<Argument> argumentList;
104
106 Function( const QString &nameIn, int args )
107 : name( nameIn ), minArgs( args ), maxArgs( args ) {}
109 Function( const QString &nameIn, int minArgs, int maxArgsIn )
110 : name( nameIn ), minArgs( minArgs ), maxArgs( maxArgsIn ) {}
111
112 Function() = default;
113 };
114
116 explicit QgsSQLComposerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
117
124 QgsSQLComposerDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
125
126 ~QgsSQLComposerDialog() override;
127
129 void setSql( const QString &sql );
130
132 QString sql() const;
133
134 QString subsetString() const override { return sql(); }
135 void setSubsetString( const QString &subsetString ) override { setSql( subsetString ); }
136
138 void addTableNames( const QStringList &list );
140 void addTableNames( const QList<PairNameTitle> &listNameTitle );
142 void addColumnNames( const QStringList &list, const QString &tableName );
144 void addColumnNames( const QList<PairNameType> &list, const QString &tableName );
146 void addOperators( const QStringList &list );
148 void addSpatialPredicates( const QStringList &list );
150 void addSpatialPredicates( const QList<Function> &list );
152 void addFunctions( const QStringList &list );
154 void addFunctions( const QList<Function> &list );
156 void addApis( const QStringList &list );
157
159 void setSupportMultipleTables( bool bMultipleTables, const QString &mainTypename = QString() );
160
166 void setTableSelectedCallback( TableSelectedCallback *tableSelectedCallback );
167
172 void setSQLValidatorCallback( SQLValidatorCallback *sqlValidatorCallback );
173
174 protected:
175 bool eventFilter( QObject *obj, QEvent *event ) override;
176
177 private slots:
178 void accept() override;
179
180 void mTablesCombo_currentIndexChanged( int );
181 void mColumnsCombo_currentIndexChanged( int );
182 void mSpatialPredicatesCombo_currentIndexChanged( int );
183 void mFunctionsCombo_currentIndexChanged( int );
184 void mOperatorsCombo_currentIndexChanged( int );
185 void mAddJoinButton_clicked();
186 void mRemoveJoinButton_clicked();
187 void mTableJoins_itemSelectionChanged();
188 void showHelp();
189 void reset();
190 void buildSQLFromFields();
191 void splitSQLIntoFields();
192
193 private:
194 QgsVectorLayer *mLayer = nullptr;
195 QStringList mApiList;
196 QSet<QString> mAlreadySelectedTables;
197 TableSelectedCallback *mTableSelectedCallback = nullptr;
198 SQLValidatorCallback *mSQLValidatorCallback = nullptr;
199 QObject *mFocusedObject = nullptr;
200 bool mAlreadyModifyingFields = false;
201 bool mDistinct = false;
202 QString mResetSql;
203 QMap<QString, QString> mapTableEntryTextToName;
204 QMap<QString, QString> mapColumnEntryTextToName;
205 QMap<QString, QString> mapSpatialPredicateEntryTextToName;
206 QMap<QString, QString> mapFunctionEntryTextToName;
207 QString lastSearchedText;
208
209
210 void loadTableColumns( const QString &table );
211 void functionCurrentIndexChanged( QComboBox *combo, const QMap<QString, QString> &mapEntryTextToName );
212 void getFunctionList( const QList<Function> &list, QStringList &listApi, QStringList &listCombo, QMap<QString, QString> &mapEntryTextToName );
213};
214
215#endif
Callback to do validation check on dialog validation.
virtual bool isValid(const QString &sql, QString &errorReason, QString &warningMsg)=0
method should return true if the SQL is valid. Otherwise return false and set the errorReason
Callback to do actions on table selection.
virtual void tableSelected(const QString &name)=0
method called when a table is selected
SQL composer dialog.
QString subsetString() const override
Returns the subset string entered in the dialog.
QPair< QString, QString > PairNameType
pair (name, type)
QPair< QString, QString > PairNameTitle
pair (name, title)
void setSubsetString(const QString &subsetString) override
Sets a subset string into the dialog.
Interface for a dialog that can edit subset strings.
Represents a vector layer which manages a vector based data sets.
#define SIP_NO_FILE
Argument(const QString &nameIn=QString(), const QString &typeIn=QString())
constructor
QString type
type, or empty if unknown
description of server functions
QString returnType
Returns type, or empty if unknown.
Function(const QString &nameIn, int args)
constructor with name and fixed number of arguments
QList< Argument > argumentList
list of arguments. May be empty despite minArgs > 0
Function(const QString &nameIn, int minArgs, int maxArgsIn)
constructor with name and min,max number of arguments