QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgssqlcomposerdialog.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssqlcomposerdialog.cpp
3  Dialog to compose SQL queries
4 
5 begin : Apr 2016
6 copyright : (C) 2016 Even Rouault
7 email : 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"
30 
32 
38 class GUI_EXPORT QgsSQLComposerDialog : public QDialog, private Ui::QgsSQLComposerDialogBase
39 {
40  Q_OBJECT
41 
42  public:
43 
45  typedef QPair<QString, QString> PairNameTitle;
46 
48  typedef QPair<QString, QString> PairNameType;
49 
55  class GUI_EXPORT TableSelectedCallback
56  {
57  public:
58  virtual ~TableSelectedCallback() = default;
60  virtual void tableSelected( const QString &name ) = 0;
61  };
62 
68  class GUI_EXPORT SQLValidatorCallback
69  {
70  public:
71  virtual ~SQLValidatorCallback() = default;
73  virtual bool isValid( const QString &sql, QString &errorReason, QString &warningMsg ) = 0;
74  };
75 
77  struct Argument
78  {
80  QString name;
82  QString type;
83 
85  Argument( const QString &nameIn = QString(), const QString &typeIn = QString() ) : name( nameIn ), type( typeIn ) {}
86  };
87 
89  struct Function
90  {
92  QString name;
94  QString returnType;
96  int minArgs = -1;
98  int maxArgs = -1;
100  QList<Argument> argumentList;
101 
103  Function( const QString &nameIn, int args ) : name( nameIn ), minArgs( args ), maxArgs( args ) {}
105  Function( const QString &nameIn, int minArgs, int maxArgsIn ) : name( nameIn ), minArgs( minArgs ), maxArgs( maxArgsIn ) {}
107  Function() = default;
108  };
109 
111  explicit QgsSQLComposerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
112  ~QgsSQLComposerDialog() override;
113 
115  void setSql( const QString &sql );
116 
118  QString sql() const;
119 
121  void addTableNames( const QStringList &list );
123  void addTableNames( const QList<PairNameTitle> &listNameTitle );
125  void addColumnNames( const QStringList &list, const QString &tableName );
127  void addColumnNames( const QList<PairNameType> &list, const QString &tableName );
129  void addOperators( const QStringList &list );
131  void addSpatialPredicates( const QStringList &list );
133  void addSpatialPredicates( const QList<Function> &list );
135  void addFunctions( const QStringList &list );
137  void addFunctions( const QList<Function> &list );
139  void addApis( const QStringList &list );
140 
142  void setSupportMultipleTables( bool bMultipleTables, const QString &mainTypename = QString() );
143 
148  void setTableSelectedCallback( TableSelectedCallback *tableSelectedCallback );
149 
153  void setSQLValidatorCallback( SQLValidatorCallback *sqlValidatorCallback );
154 
155  protected:
156  bool eventFilter( QObject *obj, QEvent *event ) override;
157 
158  private slots:
159  void accept() override;
160 
161  void mTablesCombo_currentIndexChanged( int );
162  void mColumnsCombo_currentIndexChanged( int );
163  void mSpatialPredicatesCombo_currentIndexChanged( int );
164  void mFunctionsCombo_currentIndexChanged( int );
165  void mOperatorsCombo_currentIndexChanged( int );
166  void mAddJoinButton_clicked();
167  void mRemoveJoinButton_clicked();
168  void mTableJoins_itemSelectionChanged();
169  void showHelp();
170  void reset();
171  void buildSQLFromFields();
172  void splitSQLIntoFields();
173 
174  private:
175  QStringList mApiList;
176  QSet<QString> mAlreadySelectedTables;
177  TableSelectedCallback *mTableSelectedCallback = nullptr;
178  SQLValidatorCallback *mSQLValidatorCallback = nullptr;
179  QObject *mFocusedObject = nullptr;
180  bool mAlreadyModifyingFields = false;
181  bool mDistinct = false;
182  QString mResetSql;
183  QMap<QString, QString> mapTableEntryTextToName;
184  QMap<QString, QString> mapColumnEntryTextToName;
185  QMap<QString, QString> mapSpatialPredicateEntryTextToName;
186  QMap<QString, QString> mapFunctionEntryTextToName;
187  QString lastSearchedText;
188 
189 
190  void loadTableColumns( const QString &table );
191  void functionCurrentIndexChanged( QComboBox *combo,
192  const QMap<QString, QString> &mapEntryTextToName );
193  void getFunctionList( const QList<Function> &list,
194  QStringList &listApi,
195  QStringList &listCombo,
196  QMap<QString, QString> &mapEntryTextToName );
197 };
198 
199 #endif
QgsSQLComposerDialog::TableSelectedCallback
Definition: qgssqlcomposerdialog.h:69
QgsSQLComposerDialog::PairNameType
QPair< QString, QString > PairNameType
pair (name, type)
Definition: qgssqlcomposerdialog.h:62
QgsSQLComposerDialog::PairNameTitle
QPair< QString, QString > PairNameTitle
pair (name, title)
Definition: qgssqlcomposerdialog.h:59
qgis_sip.h
QgsSQLComposerDialog::Argument
argument of a function
Definition: qgssqlcomposerdialog.h:91
QgsSQLComposerDialog
Definition: qgssqlcomposerdialog.h:38
QgsSQLComposerDialog::Function
description of server functions
Definition: qgssqlcomposerdialog.h:103
SIP_NO_FILE
#define SIP_NO_FILE
Definition: qgis_sip.h:23
qgsguiutils.h
QgsSQLComposerDialog::SQLValidatorCallback
Definition: qgssqlcomposerdialog.h:82