Skip to content

Commit ececdb7

Browse files
committedFeb 22, 2014
browser dock search: add normal syntax (with wildcards at begin and end) and case insensitive search, both default (implements #9493)
1 parent cf22e15 commit ececdb7

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed
 

‎src/app/qgsbrowserdockwidget.cpp

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
9393

9494
QgsBrowserTreeFilterProxyModel( QObject *parent )
9595
: QSortFilterProxyModel( parent ), mModel( 0 )
96-
, mFilter( "" ), mPatternSyntax( QRegExp::Wildcard )
96+
, mFilter( "" ), mPatternSyntax( "normal" ), mCaseSensitivity( Qt::CaseInsensitive )
9797
{
9898
setDynamicSortFilter( true );
9999
}
@@ -104,9 +104,9 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
104104
setSourceModel( model );
105105
}
106106

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

125+
void setCaseSensitive( bool caseSensitive )
126+
{
127+
mCaseSensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
128+
updateFilter();
129+
}
130+
125131
void updateFilter( )
126132
{
127-
QgsDebugMsg( QString( "filter = %1 syntax = %2" ).arg( mFilter ).arg(( int ) mPatternSyntax ) );
133+
QgsDebugMsg( QString( "filter = %1 syntax = %2" ).arg( mFilter ).arg( mPatternSyntax ) );
128134
mREList.clear();
129-
if ( mPatternSyntax == QRegExp::Wildcard ||
130-
mPatternSyntax == QRegExp::WildcardUnix )
135+
if ( mPatternSyntax == "normal" )
136+
{
137+
foreach ( QString f, mFilter.split( "|" ) )
138+
{
139+
QRegExp rx( QString( "*%1*" ).arg( f.trimmed() ) );
140+
rx.setPatternSyntax( QRegExp::Wildcard );
141+
rx.setCaseSensitivity( mCaseSensitivity );
142+
mREList.append( rx );
143+
}
144+
}
145+
else if ( mPatternSyntax == "wildcard" )
131146
{
132147
foreach ( QString f, mFilter.split( "|" ) )
133148
{
134149
QRegExp rx( f.trimmed() );
135-
rx.setPatternSyntax( mPatternSyntax );
150+
rx.setPatternSyntax( QRegExp::Wildcard );
151+
rx.setCaseSensitivity( mCaseSensitivity );
136152
mREList.append( rx );
137153
}
138154
}
139155
else
140156
{
141157
QRegExp rx( mFilter.trimmed() );
142-
rx.setPatternSyntax( mPatternSyntax );
158+
rx.setPatternSyntax( QRegExp::RegExp );
159+
rx.setCaseSensitivity( mCaseSensitivity );
143160
mREList.append( rx );
144161
}
145162
invalidateFilter();
@@ -150,12 +167,12 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
150167
QgsBrowserModel* mModel;
151168
QString mFilter; //filter string provided
152169
QVector<QRegExp> mREList; //list of filters, separated by "|"
153-
QRegExp::PatternSyntax mPatternSyntax;
170+
QString mPatternSyntax;
171+
Qt::CaseSensitivity mCaseSensitivity;
154172

155173
bool filterAcceptsString( const QString & value ) const
156174
{
157-
if ( mPatternSyntax == QRegExp::Wildcard ||
158-
mPatternSyntax == QRegExp::WildcardUnix )
175+
if ( mPatternSyntax == "normal" || mPatternSyntax == "wildcard" )
159176
{
160177
foreach ( QRegExp rx, mREList )
161178
{
@@ -235,17 +252,27 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
235252
QMenu* menu = new QMenu( this );
236253
menu->setSeparatorsCollapsible( false );
237254
mBtnFilterOptions->setMenu( menu );
255+
QAction* action = new QAction( tr( "Case Sensitive" ), menu );
256+
action->setData( "case" );
257+
action->setCheckable( true );
258+
action->setChecked( false );
259+
connect( action, SIGNAL( toggled( bool ) ), this, SLOT( setCaseSensitive( bool ) ) );
260+
menu->addAction( action );
238261
QActionGroup* group = new QActionGroup( menu );
239-
QAction* action = new QAction( tr( "Filter Pattern Syntax" ), group );
262+
action = new QAction( tr( "Filter Pattern Syntax" ), group );
240263
action->setSeparator( true );
241264
menu->addAction( action );
242-
action = new QAction( tr( "Wildcard(s)" ), group );
243-
action->setData( QVariant(( int ) QRegExp::Wildcard ) );
265+
action = new QAction( tr( "Normal" ), group );
266+
action->setData( "normal" );
244267
action->setCheckable( true );
245268
action->setChecked( true );
246269
menu->addAction( action );
270+
action = new QAction( tr( "Wildcard(s)" ), group );
271+
action->setData( "wildcard" );
272+
action->setCheckable( true );
273+
menu->addAction( action );
247274
action = new QAction( tr( "Regular Expression" ), group );
248-
action->setData( QVariant(( int ) QRegExp::RegExp ) );
275+
action->setData( "regexp" );
249276
action->setCheckable( true );
250277
menu->addAction( action );
251278

@@ -637,5 +664,12 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
637664
{
638665
if ( !action || ! mProxyModel )
639666
return;
640-
mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() );
667+
mProxyModel->setFilterSyntax( action->data().toString() );
668+
}
669+
670+
void QgsBrowserDockWidget::setCaseSensitive( bool caseSensitive )
671+
{
672+
if ( ! mProxyModel )
673+
return;
674+
mProxyModel->setCaseSensitive( caseSensitive );
641675
}

‎src/app/qgsbrowserdockwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows
4444

4545
void showFilterWidget( bool visible );
4646
void setFilterSyntax( QAction * );
47+
void setCaseSensitive( bool caseSensitive );
4748
void setFilter();
4849

4950
// layer menu items

0 commit comments

Comments
 (0)
Please sign in to comment.