Skip to content

Commit d17481e

Browse files
committed
[FEATURE][needs-docs] add filter line edit to query builder
1 parent cc7c935 commit d17481e

File tree

3 files changed

+95
-36
lines changed

3 files changed

+95
-36
lines changed

src/gui/qgsquerybuilder.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ QgsQueryBuilder::QgsQueryBuilder( QgsVectorLayer *layer,
7373
lblDataUri->setText( tr( "Set provider filter on %1" ).arg( layer->name() ) );
7474
txtSQL->setText( mOrigSubsetString );
7575

76+
mFilterLineEdit->setPlaceholderText( tr( "Search" ) );
77+
connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, &QgsQueryBuilder::onTextChanged );
78+
7679
populateFields();
7780
}
7881

@@ -118,6 +121,8 @@ void QgsQueryBuilder::setupGuiViews()
118121
//Initialize the models
119122
mModelFields = new QStandardItemModel();
120123
mModelValues = new QStandardItemModel();
124+
mProxyValues = new QSortFilterProxyModel();
125+
mProxyValues->setSourceModel( mModelValues );
121126
// Modes
122127
lstFields->setViewMode( QListView::ListMode );
123128
lstValues->setViewMode( QListView::ListMode );
@@ -177,7 +182,7 @@ void QgsQueryBuilder::btnSampleValues_clicked()
177182
lstValues->setModel( tmp );
178183
//Clear and fill the mModelValues
179184
fillValues( mModelFields->data( lstFields->currentIndex(), Qt::UserRole + 1 ).toInt(), 25 );
180-
lstValues->setModel( mModelValues );
185+
lstValues->setModel( mProxyValues );
181186
//delete the tmp
182187
delete tmp;
183188

@@ -204,7 +209,7 @@ void QgsQueryBuilder::btnGetAllValues_clicked()
204209
lstValues->setModel( tmp );
205210
//Clear and fill the mModelValues
206211
fillValues( mModelFields->data( lstFields->currentIndex(), Qt::UserRole + 1 ).toInt(), -1 );
207-
lstValues->setModel( mModelValues );
212+
lstValues->setModel( mProxyValues );
208213
//delete the tmp
209214
delete tmp;
210215

@@ -340,6 +345,7 @@ void QgsQueryBuilder::lstFields_clicked( const QModelIndex &index )
340345
btnGetAllValues->setEnabled( true );
341346

342347
mModelValues->clear();
348+
mFilterLineEdit->clear();
343349
}
344350
}
345351

@@ -351,7 +357,7 @@ void QgsQueryBuilder::lstFields_doubleClicked( const QModelIndex &index )
351357

352358
void QgsQueryBuilder::lstValues_doubleClicked( const QModelIndex &index )
353359
{
354-
QVariant value = mModelValues->data( index, Qt::UserRole + 1 );
360+
QVariant value = index.data( Qt::DisplayRole );
355361
if ( value.isNull() )
356362
txtSQL->insertText( QStringLiteral( "NULL" ) );
357363
else if ( value.type() == QVariant::Date && mLayer->providerType() == QLatin1String( "ogr" ) && mLayer->storageType() == QLatin1String( "ESRI Shapefile" ) )
@@ -400,6 +406,12 @@ void QgsQueryBuilder::btnOr_clicked()
400406
txtSQL->setFocus();
401407
}
402408

409+
void QgsQueryBuilder::onTextChanged( const QString &text )
410+
{
411+
mProxyValues->setFilterCaseSensitivity( Qt::CaseInsensitive );
412+
mProxyValues->setFilterWildcard( text );
413+
}
414+
403415
void QgsQueryBuilder::clear()
404416
{
405417
txtSQL->clear();

src/gui/qgsquerybuilder.h

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgis.h"
1919
#include <vector>
2020
#include <QStandardItemModel>
21+
#include <QSortFilterProxyModel>
2122
#include <QStandardItem>
2223
#include <QModelIndex>
2324
#include "ui_qgsquerybuilderbase.h"
@@ -94,6 +95,7 @@ class GUI_EXPORT QgsQueryBuilder : public QDialog, private Ui::QgsQueryBuilderBa
9495
void btnAnd_clicked();
9596
void btnNot_clicked();
9697
void btnOr_clicked();
98+
void onTextChanged( const QString &text );
9799

98100
/**
99101
* Get all distinct values for the field. Values are inserted
@@ -129,6 +131,8 @@ class GUI_EXPORT QgsQueryBuilder : public QDialog, private Ui::QgsQueryBuilderBa
129131
QStandardItemModel *mModelFields = nullptr;
130132
//! Model for values ListView
131133
QStandardItemModel *mModelValues = nullptr;
134+
//! Filter proxy Model for values ListView
135+
QSortFilterProxyModel *mProxyValues = nullptr;
132136
//! Previous field row to delete model
133137
int mPreviousFieldRow;
134138

src/ui/qgsquerybuilderbase.ui

+76-33
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
</property>
2424
<property name="windowIcon">
2525
<iconset>
26-
<normaloff/>
27-
</iconset>
26+
<normaloff>.</normaloff>.</iconset>
2827
</property>
2928
<property name="modal">
3029
<bool>true</bool>
@@ -57,7 +56,16 @@
5756
<string>Fields</string>
5857
</property>
5958
<layout class="QGridLayout">
60-
<property name="margin">
59+
<property name="leftMargin">
60+
<number>11</number>
61+
</property>
62+
<property name="topMargin">
63+
<number>11</number>
64+
</property>
65+
<property name="rightMargin">
66+
<number>11</number>
67+
</property>
68+
<property name="bottomMargin">
6169
<number>11</number>
6270
</property>
6371
<item row="0" column="0">
@@ -83,29 +91,42 @@ p, li { white-space: pre-wrap; }
8391
<string>Values</string>
8492
</property>
8593
<layout class="QGridLayout">
86-
<property name="margin">
94+
<property name="leftMargin">
8795
<number>11</number>
8896
</property>
89-
<item row="0" column="0" colspan="2">
90-
<widget class="QListView" name="lstValues">
91-
<property name="whatsThis">
97+
<property name="topMargin">
98+
<number>11</number>
99+
</property>
100+
<property name="rightMargin">
101+
<number>11</number>
102+
</property>
103+
<property name="bottomMargin">
104+
<number>11</number>
105+
</property>
106+
<item row="3" column="0" colspan="2">
107+
<widget class="QCheckBox" name="mUseUnfilteredLayer">
108+
<property name="enabled">
109+
<bool>false</bool>
110+
</property>
111+
<property name="text">
112+
<string>Use unfiltered layer</string>
113+
</property>
114+
</widget>
115+
</item>
116+
<item row="2" column="1">
117+
<widget class="QPushButton" name="btnGetAllValues">
118+
<property name="toolTip">
92119
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
93120
p, li { white-space: pre-wrap; }
94121
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
95-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;List of values for the current field.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
96-
</property>
97-
<property name="autoFillBackground">
98-
<bool>true</bool>
99-
</property>
100-
<property name="selectionBehavior">
101-
<enum>QAbstractItemView::SelectRows</enum>
122+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Retrieve &lt;span style=&quot; font-weight:600;&quot;&gt;all&lt;/span&gt; the record in the vector file (&lt;span style=&quot; font-style:italic;&quot;&gt;if the table is big, the operation can consume some time&lt;/span&gt;)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
102123
</property>
103-
<property name="uniformItemSizes">
104-
<bool>true</bool>
124+
<property name="text">
125+
<string>All</string>
105126
</property>
106127
</widget>
107128
</item>
108-
<item row="1" column="0">
129+
<item row="2" column="0">
109130
<widget class="QPushButton" name="btnSampleValues">
110131
<property name="toolTip">
111132
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
@@ -118,29 +139,28 @@ p, li { white-space: pre-wrap; }
118139
</property>
119140
</widget>
120141
</item>
121-
<item row="1" column="1">
122-
<widget class="QPushButton" name="btnGetAllValues">
123-
<property name="toolTip">
142+
<item row="1" column="0" colspan="2">
143+
<widget class="QListView" name="lstValues">
144+
<property name="whatsThis">
124145
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
125146
p, li { white-space: pre-wrap; }
126147
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
127-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Retrieve &lt;span style=&quot; font-weight:600;&quot;&gt;all&lt;/span&gt; the record in the vector file (&lt;span style=&quot; font-style:italic;&quot;&gt;if the table is big, the operation can consume some time&lt;/span&gt;)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
148+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;List of values for the current field.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
128149
</property>
129-
<property name="text">
130-
<string>All</string>
150+
<property name="autoFillBackground">
151+
<bool>true</bool>
131152
</property>
132-
</widget>
133-
</item>
134-
<item row="2" column="0" colspan="2">
135-
<widget class="QCheckBox" name="mUseUnfilteredLayer">
136-
<property name="enabled">
137-
<bool>false</bool>
153+
<property name="selectionBehavior">
154+
<enum>QAbstractItemView::SelectRows</enum>
138155
</property>
139-
<property name="text">
140-
<string>Use unfiltered layer</string>
156+
<property name="uniformItemSizes">
157+
<bool>true</bool>
141158
</property>
142159
</widget>
143160
</item>
161+
<item row="0" column="0" colspan="2">
162+
<widget class="QgsFilterLineEdit" name="mFilterLineEdit"/>
163+
</item>
144164
</layout>
145165
</widget>
146166
</widget>
@@ -152,7 +172,16 @@ p, li { white-space: pre-wrap; }
152172
<string>Operators</string>
153173
</property>
154174
<layout class="QGridLayout">
155-
<property name="margin">
175+
<property name="leftMargin">
176+
<number>11</number>
177+
</property>
178+
<property name="topMargin">
179+
<number>11</number>
180+
</property>
181+
<property name="rightMargin">
182+
<number>11</number>
183+
</property>
184+
<property name="bottomMargin">
156185
<number>11</number>
157186
</property>
158187
<item row="0" column="3">
@@ -281,7 +310,16 @@ p, li { white-space: pre-wrap; }
281310
<string>Provider specific filter expression</string>
282311
</property>
283312
<layout class="QGridLayout">
284-
<property name="margin">
313+
<property name="leftMargin">
314+
<number>11</number>
315+
</property>
316+
<property name="topMargin">
317+
<number>11</number>
318+
</property>
319+
<property name="rightMargin">
320+
<number>11</number>
321+
</property>
322+
<property name="bottomMargin">
285323
<number>11</number>
286324
</property>
287325
<item row="0" column="0">
@@ -308,6 +346,11 @@ p, li { white-space: pre-wrap; }
308346
</widget>
309347
<layoutdefault spacing="6" margin="11"/>
310348
<customwidgets>
349+
<customwidget>
350+
<class>QgsFilterLineEdit</class>
351+
<extends>QLineEdit</extends>
352+
<header>qgsfilterlineedit.h</header>
353+
</customwidget>
311354
<customwidget>
312355
<class>QgsCollapsibleGroupBox</class>
313356
<extends>QGroupBox</extends>

0 commit comments

Comments
 (0)