Skip to content

Commit dbe54d0

Browse files
committed
browser dock filter: use QgsFilterLineEdit, ui and code cleanup ; add QgsFilterLineEdit::cleared() signal
1 parent e3ccde1 commit dbe54d0

7 files changed

+82
-127
lines changed

images/images.qrc

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
<file>themes/default/mActionFileSave.png</file>
7979
<file>themes/default/mActionFileSmall.png</file>
8080
<file>themes/default/mActionFilter.png</file>
81-
<file>themes/default/mActionFilterDelete.png</file>
8281
<file>themes/default/mActionFolder.png</file>
8382
<file>themes/default/mActionFormAnnotation.png</file>
8483
<file>themes/default/mActionFromSelectedFeature.png</file>
-2.11 KB
Binary file not shown.

src/app/qgsbrowserdockwidget.cpp

+17-28
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class QgsBrowserTreeView : public QTreeView
8383
}
8484
};
8585

86+
/**
87+
Utility class for filtering browser items
88+
*/
8689
class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
8790
{
8891
public:
@@ -125,7 +128,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
125128
if ( mPatternSyntax == QRegExp::Wildcard ||
126129
mPatternSyntax == QRegExp::WildcardUnix )
127130
{
128-
foreach( QString f, mFilter.split( "|" ) )
131+
foreach ( QString f, mFilter.split( "|" ) )
129132
{
130133
QRegExp rx( f.trimmed() );
131134
rx.setPatternSyntax( mPatternSyntax );
@@ -150,11 +153,10 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
150153

151154
bool filterAcceptsString( const QString & value ) const
152155
{
153-
// return ( filterRegExp().exactMatch( fileInfo.fileName() ) );
154156
if ( mPatternSyntax == QRegExp::Wildcard ||
155157
mPatternSyntax == QRegExp::WildcardUnix )
156158
{
157-
foreach( QRegExp rx, mREList )
159+
foreach ( QRegExp rx, mREList )
158160
{
159161
QgsDebugMsg( QString( "value: [%1] rx: [%2] match: %3" ).arg( value ).arg( rx.pattern() ).arg( rx.exactMatch( value ) ) );
160162
if ( rx.exactMatch( value ) )
@@ -163,15 +165,9 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
163165
}
164166
else
165167
{
166-
foreach( QRegExp rx, mREList )
168+
foreach ( QRegExp rx, mREList )
167169
{
168170
QgsDebugMsg( QString( "value: [%1] rx: [%2] match: %3" ).arg( value ).arg( rx.pattern() ).arg( rx.indexIn( value ) ) );
169-
QRegExp rx2( "\\b(mail|letter|correspondence)\\b" );
170-
QgsDebugMsg( QString( "value: [%1] rx2: [%2] match: %3" ).arg( value ).arg( rx2.pattern() ).arg( rx2.indexIn( value ) ) );
171-
QgsDebugMsg( QString( "T1 %1" ).arg( rx2.indexIn( "I sent you an email" ) ) ); // returns -1 (no match)
172-
QgsDebugMsg( QString( "T2 %2" ).arg( rx2.indexIn( "Please write the letter" ) ) ); // returns -1 (no match)
173-
QgsDebugMsg( QString( "T3 %2" ).arg( rx.indexIn( "Please write the letter" ) ) ); // returns -1 (no match)
174-
175171
if ( rx.indexIn( value ) != -1 )
176172
return true;
177173
}
@@ -226,15 +222,14 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
226222
mBrowserView = new QgsBrowserTreeView( this );
227223
mLayoutBrowser->addWidget( mBrowserView );
228224

229-
mBtnRefresh->setIcon( QgisApp::instance()->getThemeIcon( "mActionRefresh.png" ) );
230-
mBtnAddLayers->setIcon( QgisApp::instance()->getThemeIcon( "mActionAdd.png" ) );
231-
mBtnCollapse->setIcon( QgisApp::instance()->getThemeIcon( "mActionCollapseTree.png" ) );
225+
mBtnRefresh->setIcon( QgsApplication::getThemeIcon( "mActionRefresh.png" ) );
226+
mBtnAddLayers->setIcon( QgsApplication::getThemeIcon( "mActionAdd.png" ) );
227+
mBtnCollapse->setIcon( QgsApplication::getThemeIcon( "mActionCollapseTree.png" ) );
232228

233229
mWidgetFilter->hide();
234230
// icons from http://www.fatcow.com/free-icons License: CC Attribution 3.0
235-
mBtnFilterShow->setIcon( QgisApp::instance()->getThemeIcon( "mActionFilter.png" ) );
236-
mBtnFilter->setIcon( QgisApp::instance()->getThemeIcon( "mActionFilter.png" ) );
237-
mBtnFilterClear->setIcon( QgisApp::instance()->getThemeIcon( "mActionFilterDelete.png" ) );
231+
mBtnFilterShow->setIcon( QgsApplication::getThemeIcon( "mActionFilter.png" ) );
232+
mBtnFilter->setIcon( QgsApplication::getThemeIcon( "mActionFilter.png" ) );
238233

239234
QMenu* menu = new QMenu( this );
240235
menu->setSeparatorsCollapsible( false );
@@ -243,27 +238,24 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
243238
QAction* action = new QAction( tr( "Filter Pattern Syntax" ), group );
244239
action->setSeparator( true );
245240
menu->addAction( action );
246-
// group->addAction( action );
247241
action = new QAction( tr( "Wildcard(s)" ), group );
248242
action->setData( QVariant(( int ) QRegExp::Wildcard ) );
249243
action->setCheckable( true );
250244
action->setChecked( true );
251245
menu->addAction( action );
252-
// group->addAction( action );
253-
// menu->addSeparator()->setText( tr( "Pattern Syntax" ) );
254246
action = new QAction( tr( "Regular Expression" ), group );
255247
action->setData( QVariant(( int ) QRegExp::RegExp ) );
256248
action->setCheckable( true );
257249
menu->addAction( action );
258-
// group->addAction( action );
259250

260251
connect( mBtnRefresh, SIGNAL( clicked() ), this, SLOT( refresh() ) );
261252
connect( mBtnAddLayers, SIGNAL( clicked() ), this, SLOT( addSelectedLayers() ) );
262253
connect( mBtnCollapse, SIGNAL( clicked() ), mBrowserView, SLOT( collapseAll() ) );
263254
connect( mBtnFilterShow, SIGNAL( toggled( bool ) ), this, SLOT( showFilterWidget( bool ) ) );
264255
connect( mBtnFilter, SIGNAL( clicked() ), this, SLOT( setFilter() ) );
265256
connect( mLeFilter, SIGNAL( returnPressed() ), this, SLOT( setFilter() ) );
266-
connect( mBtnFilterClear, SIGNAL( clicked() ), this, SLOT( clearFilter() ) );
257+
connect( mLeFilter, SIGNAL( cleared() ), this, SLOT( setFilter() ) );
258+
// connect( mLeFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( setFilter() ) );
267259
connect( group, SIGNAL( triggered( QAction * ) ), this, SLOT( setFilterSyntax( QAction * ) ) );
268260

269261
connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
@@ -624,7 +616,10 @@ void QgsBrowserDockWidget::showFilterWidget( bool visible )
624616
{
625617
mWidgetFilter->setVisible( visible );
626618
if ( ! visible )
627-
clearFilter();
619+
{
620+
mLeFilter->setText( "" );
621+
setFilter();
622+
}
628623
}
629624

630625
void QgsBrowserDockWidget::setFilter( )
@@ -641,12 +636,6 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
641636
mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() );
642637
}
643638

644-
void QgsBrowserDockWidget::clearFilter( )
645-
{
646-
mLeFilter->setText( "" );
647-
setFilter();
648-
}
649-
650639
QgsDataItem* QgsBrowserDockWidget::dataItem( const QModelIndex& index )
651640
{
652641
if ( ! mProxyModel )

src/app/qgsbrowserdockwidget.h

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrowserDockWidge
4646
void showFilterWidget( bool visible );
4747
void setFilterSyntax( QAction * );
4848
void setFilter();
49-
void clearFilter();
5049

5150
// layer menu items
5251
void addCurrentLayer();

src/gui/qgsfilterlineedit.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ QgsFilterLineEdit::QgsFilterLineEdit( QWidget* parent ) : QLineEdit( parent )
2525
{
2626
btnClear = new QToolButton( this );
2727
btnClear->setIcon( QgsApplication::getThemeIcon( "/mIconClear.png" ) );
28-
btnClear->setCursor(Qt::ArrowCursor);
28+
btnClear->setCursor( Qt::ArrowCursor );
2929
btnClear->setStyleSheet( "QToolButton { border: none; padding: 0px; }" );
3030
btnClear->hide();
3131

3232
connect( btnClear, SIGNAL( clicked() ), this, SLOT( clear() ) );
33+
connect( btnClear, SIGNAL( clicked() ), this, SIGNAL( cleared() ) );
3334
connect( this, SIGNAL( textChanged( const QString& ) ), this,
3435
SLOT( toggleClearButton( const QString& ) ) );
3536

3637
int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
3738
setStyleSheet( QString( "QLineEdit { padding-right: %1px; } " )
38-
.arg( btnClear->sizeHint().width() + frameWidth + 1 ) );
39+
.arg( btnClear->sizeHint().width() + frameWidth + 1 ) );
3940

4041
QSize msz = minimumSizeHint();
4142
setMinimumSize( qMax( msz.width(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ),

src/gui/qgsfilterlineedit.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
3131
public:
3232
QgsFilterLineEdit( QWidget* parent = 0 );
3333

34+
signals:
35+
void cleared();
36+
3437
protected:
3538
void resizeEvent( QResizeEvent * );
3639

0 commit comments

Comments
 (0)