Skip to content
Permalink
Browse files

browser dock search: add normal syntax (with wildcards at begin and e…

…nd) and case insensitive search, both default (implements #9493)
  • Loading branch information
etiennesky committed Feb 22, 2014
1 parent cf22e15 commit ececdb71aec28882c49eab4acd0fcdb31b8155ff
Showing with 51 additions and 16 deletions.
  1. +50 −16 src/app/qgsbrowserdockwidget.cpp
  2. +1 −0 src/app/qgsbrowserdockwidget.h
@@ -93,7 +93,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel

QgsBrowserTreeFilterProxyModel( QObject *parent )
: QSortFilterProxyModel( parent ), mModel( 0 )
, mFilter( "" ), mPatternSyntax( QRegExp::Wildcard )
, mFilter( "" ), mPatternSyntax( "normal" ), mCaseSensitivity( Qt::CaseInsensitive )
{
setDynamicSortFilter( true );
}
@@ -104,9 +104,9 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
setSourceModel( model );
}

void setFilterSyntax( const QRegExp::PatternSyntax & syntax )
void setFilterSyntax( const QString & syntax )
{
QgsDebugMsg( QString( "syntax = %1" ).arg(( int ) mPatternSyntax ) );
QgsDebugMsg( QString( "syntax = %1" ).arg( syntax ) );
if ( mPatternSyntax == syntax )
return;
mPatternSyntax = syntax;
@@ -122,24 +122,41 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
updateFilter();
}

void setCaseSensitive( bool caseSensitive )
{
mCaseSensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
updateFilter();
}

void updateFilter( )
{
QgsDebugMsg( QString( "filter = %1 syntax = %2" ).arg( mFilter ).arg(( int ) mPatternSyntax ) );
QgsDebugMsg( QString( "filter = %1 syntax = %2" ).arg( mFilter ).arg( mPatternSyntax ) );
mREList.clear();
if ( mPatternSyntax == QRegExp::Wildcard ||
mPatternSyntax == QRegExp::WildcardUnix )
if ( mPatternSyntax == "normal" )
{
foreach ( QString f, mFilter.split( "|" ) )
{
QRegExp rx( QString( "*%1*" ).arg( f.trimmed() ) );
rx.setPatternSyntax( QRegExp::Wildcard );
rx.setCaseSensitivity( mCaseSensitivity );
mREList.append( rx );
}
}
else if ( mPatternSyntax == "wildcard" )
{
foreach ( QString f, mFilter.split( "|" ) )
{
QRegExp rx( f.trimmed() );
rx.setPatternSyntax( mPatternSyntax );
rx.setPatternSyntax( QRegExp::Wildcard );
rx.setCaseSensitivity( mCaseSensitivity );
mREList.append( rx );
}
}
else
{
QRegExp rx( mFilter.trimmed() );
rx.setPatternSyntax( mPatternSyntax );
rx.setPatternSyntax( QRegExp::RegExp );
rx.setCaseSensitivity( mCaseSensitivity );
mREList.append( rx );
}
invalidateFilter();
@@ -150,12 +167,12 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
QgsBrowserModel* mModel;
QString mFilter; //filter string provided
QVector<QRegExp> mREList; //list of filters, separated by "|"
QRegExp::PatternSyntax mPatternSyntax;
QString mPatternSyntax;
Qt::CaseSensitivity mCaseSensitivity;

bool filterAcceptsString( const QString & value ) const
{
if ( mPatternSyntax == QRegExp::Wildcard ||
mPatternSyntax == QRegExp::WildcardUnix )
if ( mPatternSyntax == "normal" || mPatternSyntax == "wildcard" )
{
foreach ( QRegExp rx, mREList )
{
@@ -235,17 +252,27 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
QMenu* menu = new QMenu( this );
menu->setSeparatorsCollapsible( false );
mBtnFilterOptions->setMenu( menu );
QAction* action = new QAction( tr( "Case Sensitive" ), menu );
action->setData( "case" );
action->setCheckable( true );
action->setChecked( false );
connect( action, SIGNAL( toggled( bool ) ), this, SLOT( setCaseSensitive( bool ) ) );
menu->addAction( action );
QActionGroup* group = new QActionGroup( menu );
QAction* action = new QAction( tr( "Filter Pattern Syntax" ), group );
action = new QAction( tr( "Filter Pattern Syntax" ), group );
action->setSeparator( true );
menu->addAction( action );
action = new QAction( tr( "Wildcard(s)" ), group );
action->setData( QVariant(( int ) QRegExp::Wildcard ) );
action = new QAction( tr( "Normal" ), group );
action->setData( "normal" );
action->setCheckable( true );
action->setChecked( true );
menu->addAction( action );
action = new QAction( tr( "Wildcard(s)" ), group );
action->setData( "wildcard" );
action->setCheckable( true );
menu->addAction( action );
action = new QAction( tr( "Regular Expression" ), group );
action->setData( QVariant(( int ) QRegExp::RegExp ) );
action->setData( "regexp" );
action->setCheckable( true );
menu->addAction( action );

@@ -637,5 +664,12 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
{
if ( !action || ! mProxyModel )
return;
mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() );
mProxyModel->setFilterSyntax( action->data().toString() );
}

void QgsBrowserDockWidget::setCaseSensitive( bool caseSensitive )
{
if ( ! mProxyModel )
return;
mProxyModel->setCaseSensitive( caseSensitive );
}
@@ -44,6 +44,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows

void showFilterWidget( bool visible );
void setFilterSyntax( QAction * );
void setCaseSensitive( bool caseSensitive );
void setFilter();

// layer menu items

0 comments on commit ececdb7

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