Skip to content
Permalink
Browse files

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)
  • Loading branch information
nyalldawson committed May 23, 2016
1 parent e00ea61 commit 383fc055ba4f9342c76317c2c5e7615d668dcb1e
@@ -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
@@ -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 );
@@ -524,7 +529,7 @@ void QgsAttributeTableDialog::filterExpressionBuilder()

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

@@ -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() )
@@ -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 );
@@ -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:
/**
@@ -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;
@@ -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
@@ -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
@@ -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 )
@@ -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;
}
@@ -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
@@ -17,6 +17,7 @@

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

QgsTextEditWidgetFactory::QgsTextEditWidgetFactory( const QString& name )
: QgsEditorWidgetFactory( name )
@@ -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 );
@@ -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

0 comments on commit 383fc05

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