QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
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 "ui_qgsquerybuilderbase.h"
18
19#include <map>
20#include <vector>
21
22#include "qgis_gui.h"
23#include "qgis_sip.h"
24#include "qgsguiutils.h"
26
27#include <QModelIndex>
28#include <QSortFilterProxyModel>
29#include <QStandardItem>
30#include <QStandardItemModel>
31
32class QgsVectorLayer;
33class QgsCodeEditor;
35
48class GUI_EXPORT QgsQueryBuilder : public QgsSubsetStringEditorInterface, private Ui::QgsQueryBuilderBase
49{
50 Q_OBJECT
51 public:
59 QgsQueryBuilder( QgsVectorLayer *layer, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
60
61 void showEvent( QShowEvent *event ) override;
62
64 QString sql() const;
65
67 void setSql( const QString &sqlStatement );
68
69 QString subsetString() const override { return sql(); }
70 void setSubsetString( const QString &subsetString ) override { setSql( subsetString ); }
71
72#ifdef SIP_RUN
73 SIP_IF_FEATURE( HAVE_QSCI_SIP )
74
75
79 QgsCodeEditor *codeEditorWidget() const;
81 SIP_IF_FEATURE( !HAVE_QSCI_SIP )
82
83
87 QWidget *codeEditorWidget() const;
89#else
90
95 QgsCodeEditor *codeEditorWidget() const { return mTxtSql; }
96#endif
97
102 static bool saveQueryToFile( const QString &subset );
103
108 static bool loadQueryFromFile( QString &subset );
109
110 public slots:
111 void accept() override;
112 void reject() override;
113 void clear();
114
122 virtual void test();
123
128 void saveQuery();
129
134 void loadQuery();
135
136 void setDatasourceDescription( const QString &uri );
137
138 private slots:
139 void btnEqual_clicked();
140 void btnLessThan_clicked();
141 void btnGreaterThan_clicked();
142 void btnPct_clicked();
143 void btnIn_clicked();
144 void btnNotIn_clicked();
145 void btnLike_clicked();
146 void btnILike_clicked();
147 void lstFields_clicked( const QModelIndex &index );
148 void lstFields_doubleClicked( const QModelIndex &index );
149 void lstValues_doubleClicked( const QModelIndex &index );
150 void btnLessEqual_clicked();
151 void btnGreaterEqual_clicked();
152 void btnNotEqual_clicked();
153 void btnAnd_clicked();
154 void btnNot_clicked();
155 void btnOr_clicked();
156 void onTextChanged( const QString &text );
157 void layerSubsetStringChanged();
158
163 void btnGetAllValues_clicked();
164
170 void btnSampleValues_clicked();
171
172 private:
173 void showHelp();
174
178 void setupGuiViews();
179 void fillValues( const QString &field, int limit );
180
181 // private members
183 QgsFieldProxyModel *mModelFields = nullptr;
185 QStandardItemModel *mModelValues = nullptr;
187 QSortFilterProxyModel *mProxyValues = nullptr;
189 int mPreviousFieldRow = -1;
190
192 QgsVectorLayer *mLayer = nullptr;
193
195 QString mOrigSubsetString;
196
198 bool mIgnoreLayerSubsetStringChangedSignal = false;
199
201};
202#endif //QGSQUERYBUILDER_H
A text editor based on QScintilla2.
A proxy model to filter the list of fields of a layer.
friend class TestQgsQueryBuilder
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.
void setSql(const QString &sqlStatement)
Set the sql statement to display in the dialog.
void showEvent(QShowEvent *event) override
QgsQueryBuilder(QgsVectorLayer *layer, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
This constructor is used when the query builder is called from the vector layer properties dialog.
QString sql() const
Returns the sql statement entered in the dialog.
QgsCodeEditor * codeEditorWidget() const
Returns the code editor widget for the SQL.
QgsSubsetStringEditorInterface(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor.
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_IF_FEATURE(feature)
Definition qgis_sip.h:189
#define SIP_END
Definition qgis_sip.h:216