Skip to content

Commit

Permalink
Don't automatically turn column filter to extended filter
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nyalldawson committed May 23, 2016
1 parent e00ea61 commit 383fc05
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -166,7 +166,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid

// connect table info to window
connect( mMainView, SIGNAL( filterChanged() ), this, SLOT( updateTitle() ) );
connect( mMainView, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SLOT( setFilterExpression( QString, QgsAttributeForm::FilterType ) ) );
connect( mMainView, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SLOT( formFilterSet( QString, QgsAttributeForm::FilterType ) ) );
connect( mMainView, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ), this, SLOT( viewModeChanged( QgsAttributeForm::Mode ) ) );

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

void QgsAttributeTableDialog::formFilterSet( const QString& filter, QgsAttributeForm::FilterType type )
{
setFilterExpression( filter, type, true );
}

void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, const QString& fieldName, const QString& expression, const QgsFeatureIds& filteredIds )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
Expand Down Expand Up @@ -524,7 +529,7 @@ void QgsAttributeTableDialog::filterExpressionBuilder()

if ( dlg.exec() == QDialog::Accepted )
{
setFilterExpression( dlg.expressionText() );
setFilterExpression( dlg.expressionText(), QgsAttributeForm::ReplaceFilter, true );
}
}

Expand Down Expand Up @@ -883,7 +888,8 @@ void QgsAttributeTableDialog::openConditionalStyles()
mMainView->openConditionalStyles();
}

void QgsAttributeTableDialog::setFilterExpression( const QString& filterString, QgsAttributeForm::FilterType type )
void QgsAttributeTableDialog::setFilterExpression( const QString& filterString, QgsAttributeForm::FilterType type,
bool alwaysShowFilter )
{
QString filter;
if ( !mFilterQuery->text().isEmpty() && !filterString.isEmpty() )
Expand Down Expand Up @@ -913,9 +919,11 @@ void QgsAttributeTableDialog::setFilterExpression( const QString& filterString,
return;
}

if ( !mCurrentSearchWidgetWrapper || !mCurrentSearchWidgetWrapper->applyDirectly() )
mFilterQuery->setText( filter );

if ( alwaysShowFilter || !mCurrentSearchWidgetWrapper || !mCurrentSearchWidgetWrapper->applyDirectly() )
{
mFilterQuery->setText( filter );

mFilterButton->setDefaultAction( mActionAdvancedFilter );
mFilterButton->setPopupMode( QToolButton::MenuButtonPopup );
mFilterQuery->setVisible( true );
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsattributetabledialog.h
Expand Up @@ -66,7 +66,9 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
* Sets the filter expression to filter visible features
* @param filterString filter query string. QgsExpression compatible.
*/
void setFilterExpression( const QString& filterString, QgsAttributeForm::FilterType type = QgsAttributeForm::ReplaceFilter );
void setFilterExpression( const QString& filterString,
QgsAttributeForm::FilterType type = QgsAttributeForm::ReplaceFilter,
bool alwaysShowFilter = false );

private slots:
/**
Expand Down Expand Up @@ -213,6 +215,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
void updateFieldFromExpression();
void updateFieldFromExpressionSelected();
void viewModeChanged( QgsAttributeForm::Mode mode );
void formFilterSet( const QString& filter, QgsAttributeForm::FilterType type );

private:
QMenu* mMenuActions;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -133,6 +133,7 @@ SET(QGIS_GUI_SRCS
editorwidgets/qgsrelationreferencewidget.cpp
editorwidgets/qgsrelationreferencewidgetwrapper.cpp
editorwidgets/qgstexteditconfigdlg.cpp
editorwidgets/qgstexteditsearchwidgetwrapper.cpp
editorwidgets/qgstexteditwrapper.cpp
editorwidgets/qgstexteditwidgetfactory.cpp
editorwidgets/qgsuniquevaluesconfigdlg.cpp
Expand Down Expand Up @@ -554,6 +555,7 @@ SET(QGIS_GUI_MOC_HDRS
editorwidgets/qgsspinbox.h
editorwidgets/qgstexteditconfigdlg.h
editorwidgets/qgstexteditwrapper.h
editorwidgets/qgstexteditsearchwidgetwrapper.h
editorwidgets/qgsuniquevaluesconfigdlg.h
editorwidgets/qgsuniquevaluewidgetwrapper.h
editorwidgets/qgsuuidwidgetwrapper.h
Expand Down
3 changes: 3 additions & 0 deletions src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp
Expand Up @@ -47,6 +47,9 @@ void QgsDefaultSearchWidgetWrapper::setCaseString( int caseSensitiveCheckState )
}
// need to update also the line edit
setExpression( mLineEdit->text() );

if ( applyDirectly() )
emit expressionChanged( mExpression );
}

void QgsDefaultSearchWidgetWrapper::setExpression( QString exp )
Expand Down
29 changes: 29 additions & 0 deletions src/gui/editorwidgets/qgstexteditsearchwidgetwrapper.cpp
@@ -0,0 +1,29 @@
/***************************************************************************
qgstexteditsearchwidgetwrapper.cpp
---------------------------------
Date : 2016-05-23
Copyright : (C) 2016 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgstexteditsearchwidgetwrapper.h"

#include "qgsfield.h"
#include "qgsvectorlayer.h"

QgsTextEditSearchWidgetWrapper::QgsTextEditSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
: QgsDefaultSearchWidgetWrapper( vl, fieldIdx, parent )
{
}

bool QgsTextEditSearchWidgetWrapper::applyDirectly()
{
return true;
}
50 changes: 50 additions & 0 deletions src/gui/editorwidgets/qgstexteditsearchwidgetwrapper.h
@@ -0,0 +1,50 @@
/***************************************************************************
qgstexteditsearchwidgetwrapper.h
-------------------------------
Date : 2016-05-23
Copyright : (C) 2016 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSTEXTEDITSEARCHWIDGETWRAPPER_H
#define QGSTEXTEDITSEARCHWIDGETWRAPPER_H

#include "qgsdefaultsearchwidgetwrapper.h"

class QgsTextEditWidgetFactory;

/** \ingroup gui
* \class QgsTextEditSearchWidgetWrapper
* Wraps a text edit widget for searching.
* \note Added in version 2.16
* \note not available in Python bindings
*/

class GUI_EXPORT QgsTextEditSearchWidgetWrapper : public QgsDefaultSearchWidgetWrapper
{
Q_OBJECT

public:

/** Constructor for QgsTextEditSearchWidgetWrapper.
* @param vl associated vector layer
* @param fieldIdx index of associated field
* @param parent parent widget
*/
explicit QgsTextEditSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent = nullptr );

bool applyDirectly() override;

private:

friend class QgsTextEditWidgetFactory;
};

#endif // QGSTEXTEDITSEARCHWIDGETWRAPPER_H
6 changes: 6 additions & 0 deletions src/gui/editorwidgets/qgstexteditwidgetfactory.cpp
Expand Up @@ -17,6 +17,7 @@

#include "qgstexteditwrapper.h"
#include "qgstexteditconfigdlg.h"
#include "qgstexteditsearchwidgetwrapper.h"

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

QgsSearchWidgetWrapper*QgsTextEditWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
{
return new QgsTextEditSearchWidgetWrapper( vl, fieldIdx, parent );
}

QgsEditorConfigWidget* QgsTextEditWidgetFactory::configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
{
return new QgsTextEditConfigDlg( vl, fieldIdx, parent );
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgstexteditwidgetfactory.h
Expand Up @@ -30,6 +30,7 @@ class GUI_EXPORT QgsTextEditWidgetFactory : public QgsEditorWidgetFactory
// QgsEditorWidgetFactory interface
public:
QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const override;
QgsSearchWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;

// QgsEditorWidgetFactory interface
Expand Down

0 comments on commit 383fc05

Please sign in to comment.