[Plugin Manager] Simplify the filter behaviour: always search in names + descriptions + authors + tags. Additionally, a tag: prefix to search in tags only

This commit is contained in:
Borys Jurgiel 2013-09-15 13:32:37 +00:00
parent 07efdbefaf
commit e049f8486d
5 changed files with 39 additions and 104 deletions

View File

@ -93,7 +93,6 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
// Preset widgets
leFilter->setFocus( Qt::MouseFocusReason );
rbFilterNames->setChecked( true );
// Don't restore the last used tab from QSettings
mOptionsListWidget->setCurrentRow( 0 );
@ -107,8 +106,6 @@ QgsPluginManager::QgsPluginManager( QWidget * parent, bool pluginsAreEnabled, Qt
setCurrentTab( 0 );
// Hide widgets only suitable with Python support enabled (they will be uncovered back in setPythonUtils)
rbFilterTags->hide();
rbFilterAuthors->hide();
buttonUpgradeAll->hide();
buttonInstall->hide();
buttonUninstall->hide();
@ -134,8 +131,6 @@ void QgsPluginManager::setPythonUtils( QgsPythonUtils* pythonUtils )
// Now enable Python support:
// Show and preset widgets only suitable when Python support active
rbFilterTags->show();
rbFilterAuthors->show();
buttonUpgradeAll->show();
buttonInstall->show();
buttonUninstall->show();
@ -1075,7 +1070,18 @@ void QgsPluginManager::on_vwPlugins_doubleClicked( const QModelIndex & theIndex
void QgsPluginManager::on_leFilter_textChanged( QString theText )
{
QgsDebugMsg( "PluginManager filter changed to :" + theText );
if ( theText.startsWith( "tag:", Qt::CaseInsensitive ) )
{
theText = theText.remove( "tag:" );
mModelProxy->setFilterRole( PLUGIN_TAGS_ROLE );
QgsDebugMsg( "PluginManager TAG filter changed to :" + theText );
}
else
{
mModelProxy->setFilterRole( 0 );
QgsDebugMsg( "PluginManager filter changed to :" + theText );
}
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
QRegExp myRegExp( theText, myCaseSensitivity, mySyntax );
@ -1084,46 +1090,6 @@ void QgsPluginManager::on_leFilter_textChanged( QString theText )
void QgsPluginManager::on_rbFilterNames_toggled( bool checked )
{
if ( checked )
{
mModelProxy->setFilterRole( Qt::DisplayRole );
}
}
void QgsPluginManager::on_rbFilterDescriptions_toggled( bool checked )
{
if ( checked )
{
mModelProxy->setFilterRole( PLUGIN_DESCRIPTION_ROLE );
}
}
void QgsPluginManager::on_rbFilterTags_toggled( bool checked )
{
if ( checked )
{
mModelProxy->setFilterRole( PLUGIN_TAGS_ROLE );
}
}
void QgsPluginManager::on_rbFilterAuthors_toggled( bool checked )
{
if ( checked )
{
mModelProxy->setFilterRole( PLUGIN_AUTHOR_ROLE );
}
}
void QgsPluginManager::on_buttonUpgradeAll_clicked( )
{
QgsPythonRunner::run( "pyplugin_installer.instance().upgradeAllUpgradeable()" );

View File

@ -118,18 +118,6 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Update the filter when user changes the filter expression
void on_leFilter_textChanged( QString theText );
//! Set filter mode to filter by name
void on_rbFilterNames_toggled( bool checked );
//! Set filter mode to filter by description
void on_rbFilterDescriptions_toggled( bool checked );
//! Set filter mode to filter by tags
void on_rbFilterTags_toggled( bool checked );
//! Set filter mode to filter by autor
void on_rbFilterAuthors_toggled( bool checked );
//! Upgrade all upgradeable plugins
void on_buttonUpgradeAll_clicked( );

View File

@ -35,7 +35,7 @@ bool QgsPluginSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QMode
return ( filterByStatus( inx ) && mAcceptedStatuses.count() > 2 && sourceModel()->data( inx, SPACER_ROLE ).toString() == mAcceptedSpacers );
}
return ( filterByStatus( inx ) && sourceModel()->data( inx, filterRole() ).toString().contains( filterRegExp() ) );
return ( filterByStatus( inx ) && filterByPhrase( inx ) );
}
@ -81,6 +81,29 @@ bool QgsPluginSortFilterProxyModel::filterByStatus( QModelIndex &index ) const
bool QgsPluginSortFilterProxyModel::filterByPhrase( QModelIndex &index ) const
{
switch ( filterRole() )
{
case PLUGIN_TAGS_ROLE:
// search in tags only
return sourceModel()->data( index, PLUGIN_TAGS_ROLE ).toString().contains( filterRegExp() );
break;
case 0:
// full search: name + description + tags + author
return sourceModel()->data( index, PLUGIN_DESCRIPTION_ROLE ).toString().contains( filterRegExp() )
|| sourceModel()->data( index, PLUGIN_AUTHOR_ROLE ).toString().contains( filterRegExp() )
|| sourceModel()->data( index, Qt::DisplayRole ).toString().contains( filterRegExp() )
|| sourceModel()->data( index, PLUGIN_TAGS_ROLE ).toString().contains( filterRegExp() );
break;
default:
// unknown filter mode, return nothing
return false;
}
}
int QgsPluginSortFilterProxyModel::countWithCurrentStatus( )
{
int result = 0;

View File

@ -63,6 +63,9 @@ class QgsPluginSortFilterProxyModel : public QSortFilterProxyModel
//! Filter by status: this method is used in both filterAcceptsRow and countWithCurrentStatus.
bool filterByStatus( QModelIndex &index ) const;
//! Filter by phrase: this method is used in filterAcceptsRow.
bool filterByPhrase( QModelIndex &index ) const;
//! The main filter method
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;

View File

@ -305,47 +305,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblIn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>in:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbFilterNames">
<property name="text">
<string>names</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbFilterDescriptions">
<property name="text">
<string>descriptions</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbFilterTags">
<property name="text">
<string>tags</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbFilterAuthors">
<property name="text">
<string>authors</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -1026,10 +985,6 @@ p, li { white-space: pre-wrap; }
<tabstops>
<tabstop>mOptionsListWidget</tabstop>
<tabstop>leFilter</tabstop>
<tabstop>rbFilterNames</tabstop>
<tabstop>rbFilterDescriptions</tabstop>
<tabstop>rbFilterTags</tabstop>
<tabstop>rbFilterAuthors</tabstop>
<tabstop>vwPlugins</tabstop>
<tabstop>tbDetails</tabstop>
<tabstop>buttonUpgradeAll</tabstop>