Skip to content

Commit dbe54d0

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

File tree

7 files changed

+82
-127
lines changed

7 files changed

+82
-127
lines changed
 

‎images/images.qrc

Lines changed: 0 additions & 1 deletion
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

Lines changed: 17 additions & 28 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

‎src/ui/qgsbrowserdockwidgetbase.ui

Lines changed: 59 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@
6868
</property>
6969
</widget>
7070
</item>
71-
<item>
72-
<widget class="Line" name="line_3">
73-
<property name="orientation">
74-
<enum>Qt::Vertical</enum>
75-
</property>
76-
</widget>
77-
</item>
7871
<item>
7972
<widget class="QToolButton" name="mBtnAddLayers">
8073
<property name="toolTip">
@@ -96,53 +89,39 @@
9689
</widget>
9790
</item>
9891
<item>
99-
<widget class="Line" name="line">
100-
<property name="orientation">
101-
<enum>Qt::Vertical</enum>
102-
</property>
103-
</widget>
104-
</item>
105-
<item>
106-
<widget class="QToolButton" name="mBtnCollapse">
92+
<widget class="QToolButton" name="mBtnFilterShow">
10793
<property name="toolTip">
108-
<string>Collapse All</string>
94+
<string>FIlter Files</string>
10995
</property>
11096
<property name="text">
11197
<string>...</string>
11298
</property>
11399
<property name="icon">
114100
<iconset resource="../../images/images.qrc">
115-
<normaloff>:/images/themes/default/mActionCollapseTree.png</normaloff>:/images/themes/default/mActionCollapseTree.png</iconset>
101+
<normaloff>:/images/themes/default/mActionFilter.png</normaloff>:/images/themes/default/mActionFilter.png</iconset>
116102
</property>
117-
<property name="autoRaise">
103+
<property name="checkable">
118104
<bool>true</bool>
119105
</property>
120-
</widget>
121-
</item>
122-
<item>
123-
<widget class="Line" name="line_2">
124-
<property name="orientation">
125-
<enum>Qt::Vertical</enum>
106+
<property name="checked">
107+
<bool>false</bool>
108+
</property>
109+
<property name="autoRaise">
110+
<bool>true</bool>
126111
</property>
127112
</widget>
128113
</item>
129114
<item>
130-
<widget class="QToolButton" name="mBtnFilterShow">
115+
<widget class="QToolButton" name="mBtnCollapse">
131116
<property name="toolTip">
132-
<string>FIlter Files</string>
117+
<string>Collapse All</string>
133118
</property>
134119
<property name="text">
135120
<string>...</string>
136121
</property>
137122
<property name="icon">
138123
<iconset resource="../../images/images.qrc">
139-
<normaloff>:/images/themes/default/mActionFilter.png</normaloff>:/images/themes/default/mActionFilter.png</iconset>
140-
</property>
141-
<property name="checkable">
142-
<bool>true</bool>
143-
</property>
144-
<property name="checked">
145-
<bool>false</bool>
124+
<normaloff>:/images/themes/default/mActionCollapseTree.png</normaloff>:/images/themes/default/mActionCollapseTree.png</iconset>
146125
</property>
147126
<property name="autoRaise">
148127
<bool>true</bool>
@@ -192,45 +171,40 @@
192171
</property>
193172
<layout class="QHBoxLayout" name="horizontalLayout_3">
194173
<property name="spacing">
195-
<number>5</number>
174+
<number>2</number>
196175
</property>
197176
<property name="leftMargin">
198-
<number>5</number>
177+
<number>2</number>
199178
</property>
200179
<property name="topMargin">
201180
<number>0</number>
202181
</property>
203182
<property name="rightMargin">
204-
<number>5</number>
183+
<number>2</number>
205184
</property>
206185
<property name="bottomMargin">
207186
<number>0</number>
208187
</property>
209188
<item>
210-
<widget class="QLineEdit" name="mLeFilter">
211-
<property name="sizePolicy">
212-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
213-
<horstretch>0</horstretch>
214-
<verstretch>0</verstretch>
215-
</sizepolicy>
189+
<widget class="QToolButton" name="mBtnFilterOptions">
190+
<property name="toolTip">
191+
<string>Options</string>
216192
</property>
217-
<property name="minimumSize">
218-
<size>
219-
<width>50</width>
220-
<height>0</height>
221-
</size>
193+
<property name="text">
194+
<string/>
222195
</property>
223-
<property name="maximumSize">
224-
<size>
225-
<width>200</width>
226-
<height>16777215</height>
227-
</size>
196+
<property name="icon">
197+
<iconset resource="../../images/images.qrc">
198+
<normaloff>:/images/themes/default/mActionOptions.png</normaloff>:/images/themes/default/mActionOptions.png</iconset>
228199
</property>
229-
<property name="baseSize">
230-
<size>
231-
<width>0</width>
232-
<height>0</height>
233-
</size>
200+
<property name="popupMode">
201+
<enum>QToolButton::InstantPopup</enum>
202+
</property>
203+
<property name="toolButtonStyle">
204+
<enum>Qt::ToolButtonIconOnly</enum>
205+
</property>
206+
<property name="autoRaise">
207+
<bool>true</bool>
234208
</property>
235209
</widget>
236210
</item>
@@ -258,51 +232,34 @@
258232
</widget>
259233
</item>
260234
<item>
261-
<widget class="QToolButton" name="mBtnFilterClear">
262-
<property name="toolTip">
263-
<string>Clear Filter</string>
264-
</property>
265-
<property name="text">
266-
<string/>
267-
</property>
268-
<property name="icon">
269-
<iconset resource="../../images/images.qrc">
270-
<normaloff>:/images/themes/default/mActionFilterDelete.png</normaloff>:/images/themes/default/mActionFilterDelete.png</iconset>
271-
</property>
272-
<property name="autoRaise">
273-
<bool>true</bool>
274-
</property>
275-
</widget>
276-
</item>
277-
<item>
278-
<widget class="QToolButton" name="mBtnFilterOptions">
279-
<property name="toolTip">
280-
<string>Options</string>
281-
</property>
282-
<property name="text">
283-
<string/>
284-
</property>
285-
<property name="icon">
286-
<iconset resource="../../images/images.qrc">
287-
<normaloff>:/images/themes/default/mActionOptions.png</normaloff>:/images/themes/default/mActionOptions.png</iconset>
235+
<widget class="QgsFilterLineEdit" name="mLeFilter">
236+
<property name="sizePolicy">
237+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
238+
<horstretch>0</horstretch>
239+
<verstretch>0</verstretch>
240+
</sizepolicy>
288241
</property>
289-
<property name="popupMode">
290-
<enum>QToolButton::InstantPopup</enum>
242+
<property name="minimumSize">
243+
<size>
244+
<width>0</width>
245+
<height>0</height>
246+
</size>
291247
</property>
292-
<property name="toolButtonStyle">
293-
<enum>Qt::ToolButtonIconOnly</enum>
248+
<property name="maximumSize">
249+
<size>
250+
<width>200</width>
251+
<height>16777215</height>
252+
</size>
294253
</property>
295-
<property name="autoRaise">
296-
<bool>true</bool>
254+
<property name="baseSize">
255+
<size>
256+
<width>0</width>
257+
<height>0</height>
258+
</size>
297259
</property>
298260
</widget>
299261
</item>
300262
</layout>
301-
<zorder>mBtnFilter</zorder>
302-
<zorder>mBtnFilter</zorder>
303-
<zorder>mLeFilter</zorder>
304-
<zorder>mBtnFilterClear</zorder>
305-
<zorder>mBtnFilterOptions</zorder>
306263
</widget>
307264
</item>
308265
<item>
@@ -334,6 +291,13 @@
334291
</layout>
335292
</widget>
336293
</widget>
294+
<customwidgets>
295+
<customwidget>
296+
<class>QgsFilterLineEdit</class>
297+
<extends>QLineEdit</extends>
298+
<header>qgsfilterlineedit.h</header>
299+
</customwidget>
300+
</customwidgets>
337301
<resources>
338302
<include location="../../images/images.qrc"/>
339303
</resources>

0 commit comments

Comments
 (0)
Please sign in to comment.