QGIS API Documentation 3.29.0-Master (19d7edcfed)
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
29class QgsVectorLayer;
30class QgsCodeEditor;
31
44class 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;
79 SIP_IF_FEATURE( !HAVE_QSCI_SIP )
80
81
85 QWidget *codeEditorWidget() const;
87#else
88
93 QgsCodeEditor *codeEditorWidget() const { return mTxtSql; }
94#endif
95
100 static bool saveQueryToFile( const QString &subset );
101
106 static bool loadQueryFromFile( QString &subset );
107
108 public slots:
109 void accept() override;
110 void reject() override;
111 void clear();
112
120 virtual void test();
121
126 void saveQuery();
127
132 void loadQuery();
133
134 void setDatasourceDescription( const QString &uri );
135
136 private slots:
137 void btnEqual_clicked();
138 void btnLessThan_clicked();
139 void btnGreaterThan_clicked();
140 void btnPct_clicked();
141 void btnIn_clicked();
142 void btnNotIn_clicked();
143 void btnLike_clicked();
144 void btnILike_clicked();
145 void lstFields_clicked( const QModelIndex &index );
146 void lstFields_doubleClicked( const QModelIndex &index );
147 void lstValues_doubleClicked( const QModelIndex &index );
148 void btnLessEqual_clicked();
149 void btnGreaterEqual_clicked();
150 void btnNotEqual_clicked();
151 void btnAnd_clicked();
152 void btnNot_clicked();
153 void btnOr_clicked();
154 void onTextChanged( const QString &text );
155 void layerSubsetStringChanged();
156
161 void btnGetAllValues_clicked();
162
168 void btnSampleValues_clicked();
169
170 private:
171
175 void populateFields();
176
177 void showHelp();
178
182 void setupGuiViews();
183 void setupLstFieldsModel();
184 void fillValues( int idx, int limit );
185
186 // private members
188 QStandardItemModel *mModelFields = nullptr;
190 QStandardItemModel *mModelValues = nullptr;
192 QSortFilterProxyModel *mProxyValues = nullptr;
194 int mPreviousFieldRow;
195
197 QgsVectorLayer *mLayer = nullptr;
198
200 QString mOrigSubsetString;
201
203 bool mIgnoreLayerSubsetStringChangedSignal = false;
204
205 friend class TestQgsQueryBuilder;
206};
207#endif //QGSQUERYBUILDER_H
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:93
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:176
#define SIP_END
Definition: qgis_sip.h:203