Skip to content
Permalink
Browse files
[Plugin Manager] Simplify the filter behaviour: always search in name…
…s + descriptions + authors + tags. Additionally, a tag: prefix to search in tags only
  • Loading branch information
borysiasty committed Sep 15, 2013
1 parent 07efdbe commit e049f8486d6af83b1a4eb21b3a17abbca121a5b7
@@ -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,51 +1070,22 @@ void QgsPluginManager::on_vwPlugins_doubleClicked( const QModelIndex & theIndex

void QgsPluginManager::on_leFilter_textChanged( QString theText )
{
QgsDebugMsg( "PluginManager filter changed to :" + theText );
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
QRegExp myRegExp( theText, myCaseSensitivity, mySyntax );
mModelProxy->setFilterRegExp( myRegExp );
}



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 )
if ( theText.startsWith( "tag:", Qt::CaseInsensitive ) )
{
theText = theText.remove( "tag:" );
mModelProxy->setFilterRole( PLUGIN_TAGS_ROLE );
QgsDebugMsg( "PluginManager TAG filter changed to :" + theText );
}
}



void QgsPluginManager::on_rbFilterAuthors_toggled( bool checked )
{
if ( checked )
else
{
mModelProxy->setFilterRole( PLUGIN_AUTHOR_ROLE );
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 );
mModelProxy->setFilterRegExp( myRegExp );
}


@@ -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( );

@@ -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;
@@ -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;

@@ -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>

0 comments on commit e049f84

Please sign in to comment.