Skip to content
Permalink
Browse files

[FEATURE][needs-docs] add filter line edit to query builder

  • Loading branch information
slarosa committed Mar 28, 2018
1 parent cc7c935 commit d17481e3d2279a36e536821d21f0f709ba8bd534
Showing with 95 additions and 36 deletions.
  1. +15 −3 src/gui/qgsquerybuilder.cpp
  2. +4 −0 src/gui/qgsquerybuilder.h
  3. +76 −33 src/ui/qgsquerybuilderbase.ui
@@ -73,6 +73,9 @@ QgsQueryBuilder::QgsQueryBuilder( QgsVectorLayer *layer,
lblDataUri->setText( tr( "Set provider filter on %1" ).arg( layer->name() ) );
txtSQL->setText( mOrigSubsetString );

mFilterLineEdit->setPlaceholderText( tr( "Search" ) );
connect( mFilterLineEdit, &QgsFilterLineEdit::textChanged, this, &QgsQueryBuilder::onTextChanged );

populateFields();
}

@@ -118,6 +121,8 @@ void QgsQueryBuilder::setupGuiViews()
//Initialize the models
mModelFields = new QStandardItemModel();
mModelValues = new QStandardItemModel();
mProxyValues = new QSortFilterProxyModel();
mProxyValues->setSourceModel( mModelValues );
// Modes
lstFields->setViewMode( QListView::ListMode );
lstValues->setViewMode( QListView::ListMode );
@@ -177,7 +182,7 @@ void QgsQueryBuilder::btnSampleValues_clicked()
lstValues->setModel( tmp );
//Clear and fill the mModelValues
fillValues( mModelFields->data( lstFields->currentIndex(), Qt::UserRole + 1 ).toInt(), 25 );
lstValues->setModel( mModelValues );
lstValues->setModel( mProxyValues );
//delete the tmp
delete tmp;

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

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

mModelValues->clear();
mFilterLineEdit->clear();
}
}

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

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

void QgsQueryBuilder::onTextChanged( const QString &text )
{
mProxyValues->setFilterCaseSensitivity( Qt::CaseInsensitive );
mProxyValues->setFilterWildcard( text );
}

void QgsQueryBuilder::clear()
{
txtSQL->clear();
@@ -18,6 +18,7 @@
#include "qgis.h"
#include <vector>
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include <QStandardItem>
#include <QModelIndex>
#include "ui_qgsquerybuilderbase.h"
@@ -94,6 +95,7 @@ class GUI_EXPORT QgsQueryBuilder : public QDialog, private Ui::QgsQueryBuilderBa
void btnAnd_clicked();
void btnNot_clicked();
void btnOr_clicked();
void onTextChanged( const QString &text );

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

@@ -23,8 +23,7 @@
</property>
<property name="windowIcon">
<iconset>
<normaloff/>
</iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="modal">
<bool>true</bool>
@@ -57,7 +56,16 @@
<string>Fields</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item row="0" column="0">
@@ -83,29 +91,42 @@ p, li { white-space: pre-wrap; }
<string>Values</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>11</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QListView" name="lstValues">
<property name="whatsThis">
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mUseUnfilteredLayer">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Use unfiltered layer</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="btnGetAllValues">
<property name="toolTip">
<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;
p, li { white-space: pre-wrap; }
&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;
&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>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
&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>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
<property name="text">
<string>All</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QPushButton" name="btnSampleValues">
<property name="toolTip">
<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; }
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="btnGetAllValues">
<property name="toolTip">
<item row="1" column="0" colspan="2">
<widget class="QListView" name="lstValues">
<property name="whatsThis">
<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;
p, li { white-space: pre-wrap; }
&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;
&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>
&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>
</property>
<property name="text">
<string>All</string>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mUseUnfilteredLayer">
<property name="enabled">
<bool>false</bool>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="text">
<string>Use unfiltered layer</string>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QgsFilterLineEdit" name="mFilterLineEdit"/>
</item>
</layout>
</widget>
</widget>
@@ -152,7 +172,16 @@ p, li { white-space: pre-wrap; }
<string>Operators</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item row="0" column="3">
@@ -281,7 +310,16 @@ p, li { white-space: pre-wrap; }
<string>Provider specific filter expression</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item row="0" column="0">
@@ -308,6 +346,11 @@ p, li { white-space: pre-wrap; }
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>

0 comments on commit d17481e

Please sign in to comment.
You can’t perform that action at this time.