QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsquerybuilder.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquerybuilder.h - query builder
3  --------------------------------------
4  Date : 2004-11-19
5  Copyright : (C) 2004 by Gary E.Sherman
6  Email : sherman at mrcc.com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSQUERYBUILDER_H
16 #define QGSQUERYBUILDER_H
17 #include <map>
18 #include "qgis_sip.h"
19 #include <vector>
20 #include <QStandardItemModel>
21 #include <QSortFilterProxyModel>
22 #include <QStandardItem>
23 #include <QModelIndex>
24 #include "ui_qgsquerybuilderbase.h"
25 #include "qgsguiutils.h"
26 #include "qgis_gui.h"
28 
29 class QgsVectorLayer;
30 class QgsCodeEditor;
31 
44 class GUI_EXPORT QgsQueryBuilder : public QgsSubsetStringEditorInterface, private Ui::QgsQueryBuilderBase
45 {
46  Q_OBJECT
47  public:
48 
56  QgsQueryBuilder( QgsVectorLayer *layer, QWidget *parent SIP_TRANSFERTHIS = nullptr,
57  Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
58 
59  void showEvent( QShowEvent *event ) override;
60 
62  QString sql() const;
63 
65  void setSql( const QString &sqlStatement );
66 
67  QString subsetString() const override { return sql(); }
68  void setSubsetString( const QString &subsetString ) override { setSql( subsetString ); }
69 
70 #ifdef SIP_RUN
71  SIP_IF_FEATURE( HAVE_QSCI_SIP )
72 
73 
77  QgsCodeEditor *codeEditorWidget() const;
78  SIP_END
79  SIP_IF_FEATURE( !HAVE_QSCI_SIP )
80 
81 
85  QWidget *codeEditorWidget() const;
86  SIP_END
87 #else
88 
93  QgsCodeEditor *codeEditorWidget() const { return mTxtSql; }
94 #endif
95 
96  public slots:
97  void accept() override;
98  void reject() override;
99  void clear();
100 
108  virtual void test();
109 
114  void saveQuery();
115 
120  void loadQuery();
121 
122  void setDatasourceDescription( const QString &uri );
123 
124  private slots:
125  void btnEqual_clicked();
126  void btnLessThan_clicked();
127  void btnGreaterThan_clicked();
128  void btnPct_clicked();
129  void btnIn_clicked();
130  void btnNotIn_clicked();
131  void btnLike_clicked();
132  void btnILike_clicked();
133  void lstFields_clicked( const QModelIndex &index );
134  void lstFields_doubleClicked( const QModelIndex &index );
135  void lstValues_doubleClicked( const QModelIndex &index );
136  void btnLessEqual_clicked();
137  void btnGreaterEqual_clicked();
138  void btnNotEqual_clicked();
139  void btnAnd_clicked();
140  void btnNot_clicked();
141  void btnOr_clicked();
142  void onTextChanged( const QString &text );
143  void layerSubsetStringChanged();
144 
149  void btnGetAllValues_clicked();
150 
156  void btnSampleValues_clicked();
157 
158  private:
159 
163  void populateFields();
164 
165  void showHelp();
166 
170  void setupGuiViews();
171  void setupLstFieldsModel();
172  void fillValues( int idx, int limit );
173 
174  // private members
176  QStandardItemModel *mModelFields = nullptr;
178  QStandardItemModel *mModelValues = nullptr;
180  QSortFilterProxyModel *mProxyValues = nullptr;
182  int mPreviousFieldRow;
183 
185  QgsVectorLayer *mLayer = nullptr;
186 
188  QString mOrigSubsetString;
189 
191  bool mIgnoreLayerSubsetStringChangedSignal = false;
192 
193  friend class TestQgsQueryBuilder;
194 };
195 #endif //QGSQUERYBUILDER_H
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:42
Query Builder for layers.
QString subsetString() const override
Returns the subset string entered in the dialog.
void setSubsetString(const QString &subsetString) override
Sets a subset string into the dialog.
QgsCodeEditor * codeEditorWidget() const
Returns the code editor widget for the SQL.
Interface for a dialog that can edit subset strings.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:167
#define SIP_END
Definition: qgis_sip.h:194