490 changes: 86 additions & 404 deletions src/app/pluginmanager/qgspluginmanager.cpp

Large diffs are not rendered by default.

84 changes: 42 additions & 42 deletions src/app/pluginmanager/qgspluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/***************************************************************************
* *
// * This program is free software; you can redistribute it and/or modify *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
Expand All @@ -30,10 +30,8 @@
#include "qgspythonutils.h"
#include "qgspluginsortfilterproxymodel.h"



/*!
* \brief Plugin manager for loading/unloading plugins
* \brief Plugin manager for browsing, (un)installing and (un)loading plugins
@author Gary Sherman
*/
class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManagerBase
Expand All @@ -42,96 +40,108 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
public:
//! Constructor
QgsPluginManager( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );

//! Destructor
~QgsPluginManager();

//! Save pointer for python utils - necessary for unloading Python plugins
//! Save pointer to python utils
void setPythonUtils( QgsPythonUtils* pythonUtils );

//! Load selected plugin
void loadPlugin( QString id );

//! Unload unselected plugin
void unloadPlugin( QString id );
//! Get description of C++ plugins (name, etc)

//! Get metadata of C++ plugins
void getCppPluginDescriptions();

//! Repopulate the plugin list model
void reloadModelData();
//! Populate the html browser widget with plugin details

//! Fill the html browser widget with plugin details
void showPluginDetails( QStandardItem * item );

//! Remove python plugins from the metadata registry (c++ plugins stay)
void clearPythonPluginMetadata();

//! Add a single plugin to the map of plugin metadata
void addPluginMetadata( QString key, QMap<QString,QString> metadata );
//! Add a single plugin to the metadata registry
void addPluginMetadata( QString key, QMap<QString, QString> metadata );

//! Get metadata of given plugin
QMap<QString,QString> * pluginMetadata( QString key );
//! Return metadata of given plugin
QMap<QString, QString> * pluginMetadata( QString key );

//! Switch to one of vertical tabs by API
//! Select one of the vertical tabs programatically
void selectTabItem( int idx );

//! Clear the repository listWidget
void clearRepositoryList();

//! Add repository to the repository listWidget
void addToRepositoryList( QMap<QString,QString> repository );

// // //! Set vwPlugins table GUI
// // void setTable();
// // //! Get description of Pythin plugins (does nothing when python is disabled)
// // void getPythonPluginDescriptions();
// // //! Resize columns to contents
// // void resizeColumnsToContents();
// // //! Sort model by column ascending
// // void sortModel( int );
// // //! Check whether plugin installer is available (and tries to load it if it's disabled)
// // bool checkForPluginInstaller();
void addToRepositoryList( QMap<QString, QString> repository );

public slots:
//! Load selected plugins and close the dialog (called when the "Close" button clicked)
//! Close the dialog window (called when the "Close" button clicked)
void reject();
//! Update stacket widget (called from the vertical list item)

//! Set tab of the stacked widget (called from the vertical list item)
void setCurrentTab( int idx );
//! Updates current tab tile of according to current filters

//! Update title of the current tab according to current filters
void updateTabTitle();

//! Handle plugin selection
void currentPluginChanged( const QModelIndex & theIndex );

//! Load/unload plugin when checkbox state changed
void pluginItemChanged( QStandardItem * item );

//! Display details of inactive item too
void on_vwPlugins_clicked( const QModelIndex & );
//! Disable/enable plugin after double click

//! Load/unload plugin by double click
void on_vwPlugins_doubleClicked( const QModelIndex & index );

//! 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( );

//! Install selected plugin
void on_buttonInstall_clicked( );

//! Uninstall selected plugin
void on_buttonUninstall_clicked( );

//! Enable/disable buttons according to selected repository
void on_treeRepositories_itemSelectionChanged( );

//! Edit selected repository
void on_treeRepositories_doubleClicked( QModelIndex );

//! Define new repository connection
void on_buttonAddRep_clicked( );

//! Edit selected repository connection
void on_buttonEditRep_clicked( );

//! Delete selected repository connection
void on_buttonDeleteRep_clicked( );
//! Refresh all repositories

//! Reload all repositories
void on_buttonRefreshRepos_clicked( );

//! Reload plugin metadata registry after allowing/disallowing experimental plugins
Expand All @@ -140,21 +150,10 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
//! Open help browser
void on_buttonBox_helpRequested( ) { QgsContextHelp::run( metaObject()->className() ); }

// // // //! Select all plugins by setting their checkbox on
// // // void selectAll();
// // // //! Clear all selections by clearing the plugins checkbox
// // // void clearAll();
// // // //! Show the plugin installer
// // // void showPluginInstaller();

// // // //! query the metadata registry about some frequently used state questions
// // // bool pluginState( QString key, QString question );

//! Overwrite QgsOptionsDialogBase method to prevent changing the tab list from the stacked widget
//! Reimplement QgsOptionsDialogBase method to prevent modifying the tab list by signals from the stacked widget
void optionsStackedWidget_CurrentChanged( int indx ) { Q_UNUSED( indx ) }

private:

//! Return true if given plugin is currently present in QgsPluginRegistry
bool isPluginLoaded( QString key );

Expand All @@ -168,11 +167,12 @@ class QgsPluginManager : public QgsOptionsDialogBase, private Ui::QgsPluginManag
bool hasInvalidPlugins( );

QStandardItemModel *mModelPlugins;

QgsPluginSortFilterProxyModel * mModelProxy;

QgsPythonUtils* mPythonUtils;

QMap< QString, QMap< QString,QString > > mPlugins;
QMap< QString, QMap< QString, QString > > mPlugins;

QString mCurrentlyDisplayedPlugin;

Expand Down
26 changes: 14 additions & 12 deletions src/app/pluginmanager/qgspluginsortfilterproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
#include "qgspluginsortfilterproxymodel.h"
#include "qgslogger.h"

QgsPluginSortFilterProxyModel::QgsPluginSortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
QgsPluginSortFilterProxyModel::QgsPluginSortFilterProxyModel( QObject *parent ) : QSortFilterProxyModel( parent )
{
}




bool QgsPluginSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex inx = sourceModel()->index(sourceRow, 0, sourceParent);
Expand All @@ -34,20 +32,18 @@ bool QgsPluginSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModel




void QgsPluginSortFilterProxyModel::setAcceptedStatuses( QStringList statuses)
void QgsPluginSortFilterProxyModel::setAcceptedStatuses( QStringList statuses )
{
mAcceptedStatuses = statuses;
invalidateFilter();
}




bool QgsPluginSortFilterProxyModel::filterByStatus( QModelIndex &index ) const
{
if ( mAcceptedStatuses.contains( "invalid" )
&& sourceModel()->data(index, PLUGIN_ERROR_ROLE).toString().isEmpty() )
&& sourceModel()->data( index, PLUGIN_ERROR_ROLE ).toString().isEmpty() )
{
// Don't accept if the "invalid" filter is set and the plugin is ok
return false;
Expand All @@ -67,13 +63,12 @@ bool QgsPluginSortFilterProxyModel::filterByStatus( QModelIndex &index ) const




int QgsPluginSortFilterProxyModel::countWithCurrentStatus( )
int QgsPluginSortFilterProxyModel::countWithCurrentStatus( )
{
int result = 0;
for (int i=0; i < sourceModel()->rowCount(); ++i)
for ( int i=0; i < sourceModel()->rowCount(); ++i )
{
QModelIndex idx = sourceModel()->index(i, 0);
QModelIndex idx = sourceModel()->index( i, 0 );
if ( filterByStatus( idx ) )
{
result++ ;
Expand All @@ -84,31 +79,38 @@ int QgsPluginSortFilterProxyModel::countWithCurrentStatus( )




void QgsPluginSortFilterProxyModel::sortPluginsByName( )
{
sort( 0, Qt::AscendingOrder );
setSortRole( Qt::DisplayRole );
}



void QgsPluginSortFilterProxyModel::sortPluginsByDownloads( )
{
sort( 0, Qt::DescendingOrder );
setSortRole( PLUGIN_DOWNLOADS_ROLE );
}



void QgsPluginSortFilterProxyModel::sortPluginsByVote( )
{
sort( 0, Qt::DescendingOrder );
setSortRole( PLUGIN_VOTE_ROLE );
}



void QgsPluginSortFilterProxyModel::sortPluginsByStatus( )
{
sort( 0, Qt::DescendingOrder );
setSortRole( PLUGIN_STATUS_ROLE );
}



void QgsPluginSortFilterProxyModel::sortPluginsByRepository( )
{
sort( 0, Qt::DescendingOrder );
Expand Down
15 changes: 7 additions & 8 deletions src/app/pluginmanager/qgspluginsortfilterproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

#include <QSortFilterProxyModel>
#include <QStringList>
// #include <QString>
// #include <QMap>

const int PLUGIN_BASE_NAME_ROLE = Qt::UserRole + 1;
const int PLUGIN_DESCRIPTION_ROLE = Qt::UserRole + 2; // for filtering
const int PLUGIN_AUTHOR_ROLE = Qt::UserRole + 3; // for filtering
const int PLUGIN_TAGS_ROLE = Qt::UserRole + 4; // for filtering
const int PLUGIN_ERROR_ROLE = Qt::UserRole + 6; // for filtering
const int PLUGIN_STATUS_ROLE = Qt::UserRole + 5; // for filtering and sorting
const int PLUGIN_ERROR_ROLE = Qt::UserRole + 5; // for filtering
const int PLUGIN_STATUS_ROLE = Qt::UserRole + 6; // for filtering and sorting
const int PLUGIN_DOWNLOADS_ROLE = Qt::UserRole + 7; // for sorting
const int PLUGIN_VOTE_ROLE = Qt::UserRole + 8; // for sorting
const int PLUGIN_REPOSITORY_ROLE = Qt::UserRole + 9; // for sorting
Expand All @@ -41,7 +39,7 @@ class QgsPluginSortFilterProxyModel : public QSortFilterProxyModel
Q_OBJECT

public:
QgsPluginSortFilterProxyModel(QObject *parent = 0);
QgsPluginSortFilterProxyModel( QObject *parent = 0 );

//! (Re)configire the status filter
void setAcceptedStatuses( QStringList statuses );
Expand All @@ -56,13 +54,14 @@ class QgsPluginSortFilterProxyModel : public QSortFilterProxyModel
void sortPluginsByStatus( );
void sortPluginsByRepository( );

protected:
protected:
//! Filter by status: this method is used in both filterAcceptsRow and countWithCurrentStatus.
bool filterByStatus( QModelIndex &index ) const;

//! The main filter method
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;

private:
private:
QStringList mAcceptedStatuses;
};

Expand Down
8 changes: 4 additions & 4 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// pass the python utils to plugin manager
// pass the python utils to the plugin manager
mPluginManager -> setPythonUtils( mPythonUtils );
// initialize the plugin installer to start fetching repositories in background
QgsPythonRunner::run( "import pyplugin_installer");
QgsPythonRunner::run( "pyplugin_installer.initPluginInstaller()");
QgsPythonRunner::run( "import pyplugin_installer" );
QgsPythonRunner::run( "pyplugin_installer.initPluginInstaller()" );
}

mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
Expand Down Expand Up @@ -6299,7 +6299,7 @@ void QgisApp::showPluginManager()

if ( mPythonUtils && mPythonUtils->isEnabled() )
{
// A detour to the plugin manager via the plugin installer to test if fetching repositories is over.
// Call pluginManagerInterface()->showPluginManager() as soon as the plugin installer says the remote data is fetched.
QgsPythonRunner::run( "pyplugin_installer.instance().showPluginManagerWhenReady()");
}
else
Expand Down
1 change: 0 additions & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class QAuthenticator;

class QgsBrowserDockWidget;
class QgsSnappingDialog;
class QgsPluginManager;
class QgsGPSInformationWidget;

class QgsDecorationItem;
Expand Down
23 changes: 6 additions & 17 deletions src/gui/qgspluginmanagerinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,25 @@ class GUI_EXPORT QgsPluginManagerInterface : public QObject
//! Virtual destructor
virtual ~QgsPluginManagerInterface();

//! remove metadata of all python plugins from the registry (c++ plugins stay)
//! remove python plugins from the metadata registry (c++ plugins stay)
virtual void clearPythonPluginMetadata() = 0;

//! add a single plugin to the metadata registry
virtual void addPluginMetadata( QMap<QString,QString> metadata ) = 0;
virtual void addPluginMetadata( QMap<QString, QString> metadata ) = 0;

//! refresh listView model and textView content
//! refresh plugin list model (and metadata browser content if necessary)
virtual void reloadModel() = 0;

//! get given plugin metadata
//! return given plugin metadata
virtual QMap<QString, QString> * pluginMetadata( QString key ) = 0;

//! clear the repository listWidget
virtual void clearRepositoryList() = 0;

//! add repository to the repository listWidget
virtual void addToRepositoryList( QMap<QString,QString> repository ) = 0;
virtual void addToRepositoryList( QMap<QString, QString> repository ) = 0;

signals:

//! emitted when the Python Plugin Installer should show the fetching repositories window
void fetchingStillInProgress( );

public slots:

//! show the Plugin Manager window when remote repositories are fetched.
//! Display a progress dialog when fetching.
virtual void showPluginManagerWhenReady( ) = 0;

//! promptly show the Plugin Manager window and optionally open tab tabIndex:
//! show the Plugin Manager window and optionally open tab tabIndex
virtual void showPluginManager( int tabIndex = -1 ) = 0;

};
Expand Down