Skip to content

Commit 383fc05

Browse files
committed
Don't automatically turn column filter to extended filter
Now fields using text edit widgets will keep the column filter as the entered text. Additionally, the extended filter has been improved to always take the initial filter from the current filter, even if it's not an extended filter. (fix #12422)
1 parent e00ea61 commit 383fc05

8 files changed

+108
-6
lines changed

src/app/qgsattributetabledialog.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
166166

167167
// connect table info to window
168168
connect( mMainView, SIGNAL( filterChanged() ), this, SLOT( updateTitle() ) );
169-
connect( mMainView, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SLOT( setFilterExpression( QString, QgsAttributeForm::FilterType ) ) );
169+
connect( mMainView, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SLOT( formFilterSet( QString, QgsAttributeForm::FilterType ) ) );
170170
connect( mMainView, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ), this, SLOT( viewModeChanged( QgsAttributeForm::Mode ) ) );
171171

172172
// info from table to application
@@ -388,6 +388,11 @@ void QgsAttributeTableDialog::viewModeChanged( QgsAttributeForm::Mode mode )
388388
mSearchFormButton->setChecked( false );
389389
}
390390

391+
void QgsAttributeTableDialog::formFilterSet( const QString& filter, QgsAttributeForm::FilterType type )
392+
{
393+
setFilterExpression( filter, type, true );
394+
}
395+
391396
void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, const QString& fieldName, const QString& expression, const QgsFeatureIds& filteredIds )
392397
{
393398
QApplication::setOverrideCursor( Qt::WaitCursor );
@@ -524,7 +529,7 @@ void QgsAttributeTableDialog::filterExpressionBuilder()
524529

525530
if ( dlg.exec() == QDialog::Accepted )
526531
{
527-
setFilterExpression( dlg.expressionText() );
532+
setFilterExpression( dlg.expressionText(), QgsAttributeForm::ReplaceFilter, true );
528533
}
529534
}
530535

@@ -883,7 +888,8 @@ void QgsAttributeTableDialog::openConditionalStyles()
883888
mMainView->openConditionalStyles();
884889
}
885890

886-
void QgsAttributeTableDialog::setFilterExpression( const QString& filterString, QgsAttributeForm::FilterType type )
891+
void QgsAttributeTableDialog::setFilterExpression( const QString& filterString, QgsAttributeForm::FilterType type,
892+
bool alwaysShowFilter )
887893
{
888894
QString filter;
889895
if ( !mFilterQuery->text().isEmpty() && !filterString.isEmpty() )
@@ -913,9 +919,11 @@ void QgsAttributeTableDialog::setFilterExpression( const QString& filterString,
913919
return;
914920
}
915921

916-
if ( !mCurrentSearchWidgetWrapper || !mCurrentSearchWidgetWrapper->applyDirectly() )
922+
mFilterQuery->setText( filter );
923+
924+
if ( alwaysShowFilter || !mCurrentSearchWidgetWrapper || !mCurrentSearchWidgetWrapper->applyDirectly() )
917925
{
918-
mFilterQuery->setText( filter );
926+
919927
mFilterButton->setDefaultAction( mActionAdvancedFilter );
920928
mFilterButton->setPopupMode( QToolButton::MenuButtonPopup );
921929
mFilterQuery->setVisible( true );

src/app/qgsattributetabledialog.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
6666
* Sets the filter expression to filter visible features
6767
* @param filterString filter query string. QgsExpression compatible.
6868
*/
69-
void setFilterExpression( const QString& filterString, QgsAttributeForm::FilterType type = QgsAttributeForm::ReplaceFilter );
69+
void setFilterExpression( const QString& filterString,
70+
QgsAttributeForm::FilterType type = QgsAttributeForm::ReplaceFilter,
71+
bool alwaysShowFilter = false );
7072

7173
private slots:
7274
/**
@@ -213,6 +215,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
213215
void updateFieldFromExpression();
214216
void updateFieldFromExpressionSelected();
215217
void viewModeChanged( QgsAttributeForm::Mode mode );
218+
void formFilterSet( const QString& filter, QgsAttributeForm::FilterType type );
216219

217220
private:
218221
QMenu* mMenuActions;

src/gui/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ SET(QGIS_GUI_SRCS
133133
editorwidgets/qgsrelationreferencewidget.cpp
134134
editorwidgets/qgsrelationreferencewidgetwrapper.cpp
135135
editorwidgets/qgstexteditconfigdlg.cpp
136+
editorwidgets/qgstexteditsearchwidgetwrapper.cpp
136137
editorwidgets/qgstexteditwrapper.cpp
137138
editorwidgets/qgstexteditwidgetfactory.cpp
138139
editorwidgets/qgsuniquevaluesconfigdlg.cpp
@@ -554,6 +555,7 @@ SET(QGIS_GUI_MOC_HDRS
554555
editorwidgets/qgsspinbox.h
555556
editorwidgets/qgstexteditconfigdlg.h
556557
editorwidgets/qgstexteditwrapper.h
558+
editorwidgets/qgstexteditsearchwidgetwrapper.h
557559
editorwidgets/qgsuniquevaluesconfigdlg.h
558560
editorwidgets/qgsuniquevaluewidgetwrapper.h
559561
editorwidgets/qgsuuidwidgetwrapper.h

src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ void QgsDefaultSearchWidgetWrapper::setCaseString( int caseSensitiveCheckState )
4747
}
4848
// need to update also the line edit
4949
setExpression( mLineEdit->text() );
50+
51+
if ( applyDirectly() )
52+
emit expressionChanged( mExpression );
5053
}
5154

5255
void QgsDefaultSearchWidgetWrapper::setExpression( QString exp )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/***************************************************************************
2+
qgstexteditsearchwidgetwrapper.cpp
3+
---------------------------------
4+
Date : 2016-05-23
5+
Copyright : (C) 2016 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot 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+
16+
#include "qgstexteditsearchwidgetwrapper.h"
17+
18+
#include "qgsfield.h"
19+
#include "qgsvectorlayer.h"
20+
21+
QgsTextEditSearchWidgetWrapper::QgsTextEditSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
22+
: QgsDefaultSearchWidgetWrapper( vl, fieldIdx, parent )
23+
{
24+
}
25+
26+
bool QgsTextEditSearchWidgetWrapper::applyDirectly()
27+
{
28+
return true;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/***************************************************************************
2+
qgstexteditsearchwidgetwrapper.h
3+
-------------------------------
4+
Date : 2016-05-23
5+
Copyright : (C) 2016 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot 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+
16+
#ifndef QGSTEXTEDITSEARCHWIDGETWRAPPER_H
17+
#define QGSTEXTEDITSEARCHWIDGETWRAPPER_H
18+
19+
#include "qgsdefaultsearchwidgetwrapper.h"
20+
21+
class QgsTextEditWidgetFactory;
22+
23+
/** \ingroup gui
24+
* \class QgsTextEditSearchWidgetWrapper
25+
* Wraps a text edit widget for searching.
26+
* \note Added in version 2.16
27+
* \note not available in Python bindings
28+
*/
29+
30+
class GUI_EXPORT QgsTextEditSearchWidgetWrapper : public QgsDefaultSearchWidgetWrapper
31+
{
32+
Q_OBJECT
33+
34+
public:
35+
36+
/** Constructor for QgsTextEditSearchWidgetWrapper.
37+
* @param vl associated vector layer
38+
* @param fieldIdx index of associated field
39+
* @param parent parent widget
40+
*/
41+
explicit QgsTextEditSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent = nullptr );
42+
43+
bool applyDirectly() override;
44+
45+
private:
46+
47+
friend class QgsTextEditWidgetFactory;
48+
};
49+
50+
#endif // QGSTEXTEDITSEARCHWIDGETWRAPPER_H

src/gui/editorwidgets/qgstexteditwidgetfactory.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgstexteditwrapper.h"
1919
#include "qgstexteditconfigdlg.h"
20+
#include "qgstexteditsearchwidgetwrapper.h"
2021

2122
QgsTextEditWidgetFactory::QgsTextEditWidgetFactory( const QString& name )
2223
: QgsEditorWidgetFactory( name )
@@ -28,6 +29,11 @@ QgsEditorWidgetWrapper* QgsTextEditWidgetFactory::create( QgsVectorLayer* vl, in
2829
return new QgsTextEditWrapper( vl, fieldIdx, editor, parent );
2930
}
3031

32+
QgsSearchWidgetWrapper*QgsTextEditWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
33+
{
34+
return new QgsTextEditSearchWidgetWrapper( vl, fieldIdx, parent );
35+
}
36+
3137
QgsEditorConfigWidget* QgsTextEditWidgetFactory::configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
3238
{
3339
return new QgsTextEditConfigDlg( vl, fieldIdx, parent );

src/gui/editorwidgets/qgstexteditwidgetfactory.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class GUI_EXPORT QgsTextEditWidgetFactory : public QgsEditorWidgetFactory
3030
// QgsEditorWidgetFactory interface
3131
public:
3232
QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const override;
33+
QgsSearchWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
3334
QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
3435

3536
// QgsEditorWidgetFactory interface

0 commit comments

Comments
 (0)