Skip to content

Commit e049f84

Browse files
committed
[Plugin Manager] Simplify the filter behaviour: always search in names + descriptions + authors + tags. Additionally, a tag: prefix to search in tags only
1 parent 07efdbe commit e049f84

File tree

5 files changed

+38
-103
lines changed

5 files changed

+38
-103
lines changed

src/app/pluginmanager/qgspluginmanager.cpp

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
9393

9494
// Preset widgets
9595
leFilter->setFocus( Qt::MouseFocusReason );
96-
rbFilterNames->setChecked( true );
9796

9897
// Don't restore the last used tab from QSettings
9998
mOptionsListWidget->setCurrentRow( 0 );
@@ -107,8 +106,6 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
107106
setCurrentTab( 0 );
108107

109108
// Hide widgets only suitable with Python support enabled (they will be uncovered back in setPythonUtils)
110-
rbFilterTags->hide();
111-
rbFilterAuthors->hide();
112109
buttonUpgradeAll->hide();
113110
buttonInstall->hide();
114111
buttonUninstall->hide();
@@ -134,8 +131,6 @@ void QgsPluginManager::setPythonUtils( QgsPythonUtils* pythonUtils )
134131

135132
// Now enable Python support:
136133
// Show and preset widgets only suitable when Python support active
137-
rbFilterTags->show();
138-
rbFilterAuthors->show();
139134
buttonUpgradeAll->show();
140135
buttonInstall->show();
141136
buttonUninstall->show();
@@ -1075,51 +1070,22 @@ void QgsPluginManager::on_vwPlugins_doubleClicked( const QModelIndex & theIndex
10751070

10761071
void QgsPluginManager::on_leFilter_textChanged( QString theText )
10771072
{
1078-
QgsDebugMsg( "PluginManager filter changed to :" + theText );
1079-
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
1080-
Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
1081-
QRegExp myRegExp( theText, myCaseSensitivity, mySyntax );
1082-
mModelProxy->setFilterRegExp( myRegExp );
1083-
}
1084-
1085-
1086-
1087-
void QgsPluginManager::on_rbFilterNames_toggled( bool checked )
1088-
{
1089-
if ( checked )
1090-
{
1091-
mModelProxy->setFilterRole( Qt::DisplayRole );
1092-
}
1093-
}
1094-
1095-
1096-
1097-
void QgsPluginManager::on_rbFilterDescriptions_toggled( bool checked )
1098-
{
1099-
if ( checked )
1100-
{
1101-
mModelProxy->setFilterRole( PLUGIN_DESCRIPTION_ROLE );
1102-
}
1103-
}
1104-
1105-
1106-
1107-
void QgsPluginManager::on_rbFilterTags_toggled( bool checked )
1108-
{
1109-
if ( checked )
1073+
if ( theText.startsWith( "tag:", Qt::CaseInsensitive ) )
11101074
{
1075+
theText = theText.remove( "tag:" );
11111076
mModelProxy->setFilterRole( PLUGIN_TAGS_ROLE );
1077+
QgsDebugMsg( "PluginManager TAG filter changed to :" + theText );
11121078
}
1113-
}
1114-
1115-
1116-
1117-
void QgsPluginManager::on_rbFilterAuthors_toggled( bool checked )
1118-
{
1119-
if ( checked )
1079+
else
11201080
{
1121-
mModelProxy->setFilterRole( PLUGIN_AUTHOR_ROLE );
1081+
mModelProxy->setFilterRole( 0 );
1082+
QgsDebugMsg( "PluginManager filter changed to :" + theText );
11221083
}
1084+
1085+
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
1086+
Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
1087+
QRegExp myRegExp( theText, myCaseSensitivity, mySyntax );
1088+
mModelProxy->setFilterRegExp( myRegExp );
11231089
}
11241090

11251091

src/app/pluginmanager/qgspluginmanager.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,6 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
118118
//! Update the filter when user changes the filter expression
119119
void on_leFilter_textChanged( QString theText );
120120

121-
//! Set filter mode to filter by name
122-
void on_rbFilterNames_toggled( bool checked );
123-
124-
//! Set filter mode to filter by description
125-
void on_rbFilterDescriptions_toggled( bool checked );
126-
127-
//! Set filter mode to filter by tags
128-
void on_rbFilterTags_toggled( bool checked );
129-
130-
//! Set filter mode to filter by autor
131-
void on_rbFilterAuthors_toggled( bool checked );
132-
133121
//! Upgrade all upgradeable plugins
134122
void on_buttonUpgradeAll_clicked( );
135123

src/app/pluginmanager/qgspluginsortfilterproxymodel.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool QgsPluginSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QMode
3535
return ( filterByStatus( inx ) && mAcceptedStatuses.count() > 2 && sourceModel()->data( inx, SPACER_ROLE ).toString() == mAcceptedSpacers );
3636
}
3737

38-
return ( filterByStatus( inx ) && sourceModel()->data( inx, filterRole() ).toString().contains( filterRegExp() ) );
38+
return ( filterByStatus( inx ) && filterByPhrase( inx ) );
3939
}
4040

4141

@@ -81,6 +81,29 @@ bool QgsPluginSortFilterProxyModel::filterByStatus( QModelIndex &index ) const
8181

8282

8383

84+
bool QgsPluginSortFilterProxyModel::filterByPhrase( QModelIndex &index ) const
85+
{
86+
switch ( filterRole() )
87+
{
88+
case PLUGIN_TAGS_ROLE:
89+
// search in tags only
90+
return sourceModel()->data( index, PLUGIN_TAGS_ROLE ).toString().contains( filterRegExp() );
91+
break;
92+
case 0:
93+
// full search: name + description + tags + author
94+
return sourceModel()->data( index, PLUGIN_DESCRIPTION_ROLE ).toString().contains( filterRegExp() )
95+
|| sourceModel()->data( index, PLUGIN_AUTHOR_ROLE ).toString().contains( filterRegExp() )
96+
|| sourceModel()->data( index, Qt::DisplayRole ).toString().contains( filterRegExp() )
97+
|| sourceModel()->data( index, PLUGIN_TAGS_ROLE ).toString().contains( filterRegExp() );
98+
break;
99+
default:
100+
// unknown filter mode, return nothing
101+
return false;
102+
}
103+
}
104+
105+
106+
84107
int QgsPluginSortFilterProxyModel::countWithCurrentStatus( )
85108
{
86109
int result = 0;

src/app/pluginmanager/qgspluginsortfilterproxymodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class QgsPluginSortFilterProxyModel : public QSortFilterProxyModel
6363
//! Filter by status: this method is used in both filterAcceptsRow and countWithCurrentStatus.
6464
bool filterByStatus( QModelIndex &index ) const;
6565

66+
//! Filter by phrase: this method is used in filterAcceptsRow.
67+
bool filterByPhrase( QModelIndex &index ) const;
68+
6669
//! The main filter method
6770
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
6871

src/ui/qgspluginmanagerbase.ui

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -305,47 +305,6 @@
305305
</property>
306306
</widget>
307307
</item>
308-
<item>
309-
<widget class="QLabel" name="lblIn">
310-
<property name="sizePolicy">
311-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
312-
<horstretch>0</horstretch>
313-
<verstretch>0</verstretch>
314-
</sizepolicy>
315-
</property>
316-
<property name="text">
317-
<string>in:</string>
318-
</property>
319-
</widget>
320-
</item>
321-
<item>
322-
<widget class="QRadioButton" name="rbFilterNames">
323-
<property name="text">
324-
<string>names</string>
325-
</property>
326-
</widget>
327-
</item>
328-
<item>
329-
<widget class="QRadioButton" name="rbFilterDescriptions">
330-
<property name="text">
331-
<string>descriptions</string>
332-
</property>
333-
</widget>
334-
</item>
335-
<item>
336-
<widget class="QRadioButton" name="rbFilterTags">
337-
<property name="text">
338-
<string>tags</string>
339-
</property>
340-
</widget>
341-
</item>
342-
<item>
343-
<widget class="QRadioButton" name="rbFilterAuthors">
344-
<property name="text">
345-
<string>authors</string>
346-
</property>
347-
</widget>
348-
</item>
349308
</layout>
350309
</item>
351310
<item>
@@ -1026,10 +985,6 @@ p, li { white-space: pre-wrap; }
1026985
<tabstops>
1027986
<tabstop>mOptionsListWidget</tabstop>
1028987
<tabstop>leFilter</tabstop>
1029-
<tabstop>rbFilterNames</tabstop>
1030-
<tabstop>rbFilterDescriptions</tabstop>
1031-
<tabstop>rbFilterTags</tabstop>
1032-
<tabstop>rbFilterAuthors</tabstop>
1033988
<tabstop>vwPlugins</tabstop>
1034989
<tabstop>tbDetails</tabstop>
1035990
<tabstop>buttonUpgradeAll</tabstop>

0 commit comments

Comments
 (0)