@@ -93,7 +93,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
93
93
94
94
QgsBrowserTreeFilterProxyModel ( QObject *parent )
95
95
: QSortFilterProxyModel( parent ), mModel ( 0 )
96
- , mFilter ( " " ), mPatternSyntax ( QRegExp::Wildcard )
96
+ , mFilter ( " " ), mPatternSyntax ( " normal " ), mCaseSensitivity ( Qt::CaseInsensitive )
97
97
{
98
98
setDynamicSortFilter ( true );
99
99
}
@@ -104,9 +104,9 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
104
104
setSourceModel ( model );
105
105
}
106
106
107
- void setFilterSyntax ( const QRegExp::PatternSyntax & syntax )
107
+ void setFilterSyntax ( const QString & syntax )
108
108
{
109
- QgsDebugMsg ( QString ( " syntax = %1" ).arg (( int ) mPatternSyntax ) );
109
+ QgsDebugMsg ( QString ( " syntax = %1" ).arg ( syntax ) );
110
110
if ( mPatternSyntax == syntax )
111
111
return ;
112
112
mPatternSyntax = syntax;
@@ -122,24 +122,41 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
122
122
updateFilter ();
123
123
}
124
124
125
+ void setCaseSensitive ( bool caseSensitive )
126
+ {
127
+ mCaseSensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
128
+ updateFilter ();
129
+ }
130
+
125
131
void updateFilter ( )
126
132
{
127
- QgsDebugMsg ( QString ( " filter = %1 syntax = %2" ).arg ( mFilter ).arg (( int ) mPatternSyntax ) );
133
+ QgsDebugMsg ( QString ( " filter = %1 syntax = %2" ).arg ( mFilter ).arg ( mPatternSyntax ) );
128
134
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" )
131
146
{
132
147
foreach ( QString f, mFilter .split ( " |" ) )
133
148
{
134
149
QRegExp rx ( f.trimmed () );
135
- rx.setPatternSyntax ( mPatternSyntax );
150
+ rx.setPatternSyntax ( QRegExp::Wildcard );
151
+ rx.setCaseSensitivity ( mCaseSensitivity );
136
152
mREList .append ( rx );
137
153
}
138
154
}
139
155
else
140
156
{
141
157
QRegExp rx ( mFilter .trimmed () );
142
- rx.setPatternSyntax ( mPatternSyntax );
158
+ rx.setPatternSyntax ( QRegExp::RegExp );
159
+ rx.setCaseSensitivity ( mCaseSensitivity );
143
160
mREList .append ( rx );
144
161
}
145
162
invalidateFilter ();
@@ -150,12 +167,12 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
150
167
QgsBrowserModel* mModel ;
151
168
QString mFilter ; // filter string provided
152
169
QVector<QRegExp> mREList ; // list of filters, separated by "|"
153
- QRegExp::PatternSyntax mPatternSyntax ;
170
+ QString mPatternSyntax ;
171
+ Qt::CaseSensitivity mCaseSensitivity ;
154
172
155
173
bool filterAcceptsString ( const QString & value ) const
156
174
{
157
- if ( mPatternSyntax == QRegExp::Wildcard ||
158
- mPatternSyntax == QRegExp::WildcardUnix )
175
+ if ( mPatternSyntax == " normal" || mPatternSyntax == " wildcard" )
159
176
{
160
177
foreach ( QRegExp rx, mREList )
161
178
{
@@ -235,17 +252,27 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QString name, QWidget * parent ) :
235
252
QMenu* menu = new QMenu ( this );
236
253
menu->setSeparatorsCollapsible ( false );
237
254
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 );
238
261
QActionGroup* group = new QActionGroup ( menu );
239
- QAction* action = new QAction ( tr ( " Filter Pattern Syntax" ), group );
262
+ action = new QAction ( tr ( " Filter Pattern Syntax" ), group );
240
263
action->setSeparator ( true );
241
264
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 " );
244
267
action->setCheckable ( true );
245
268
action->setChecked ( true );
246
269
menu->addAction ( action );
270
+ action = new QAction ( tr ( " Wildcard(s)" ), group );
271
+ action->setData ( " wildcard" );
272
+ action->setCheckable ( true );
273
+ menu->addAction ( action );
247
274
action = new QAction ( tr ( " Regular Expression" ), group );
248
- action->setData ( QVariant (( int ) QRegExp::RegExp ) );
275
+ action->setData ( " regexp " );
249
276
action->setCheckable ( true );
250
277
menu->addAction ( action );
251
278
@@ -637,5 +664,12 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
637
664
{
638
665
if ( !action || ! mProxyModel )
639
666
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 );
641
675
}
0 commit comments