Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Support for icons of plugins in the plugin manager dialog.
Both C++ and Python plugins now can implement icon() metadata function which returns path to the icon file name.
The icon file is passed to QPixmap() constructor. For C++ it's preferred to use an icon from the resource file
(e.g. ":/plugins/foo/foo_icon.png") because plugin's resource file gets loaded automatically when the plugin is loaded.
Python plugins can use either relative path to the icon ("images/plugin-icon.png") or icon from the resource file
(starting with a colon). The relative path is preferred, since it doesn't require the plugin to load its resource file
and plugin repository will not have a trouble to fetch the icon automatically.

Updated C++ plugins and Python plugins to include icon where applicable.

Default plugin icon is (c) Anna Shlyapnikova, licensed under Creative Commons (Attribution 3.0 Unported).


git-svn-id: http://svn.osgeo.org/qgis/trunk@14897 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Dec 12, 2010
1 parent 936a67e commit 3a18bdd
Show file tree
Hide file tree
Showing 33 changed files with 193 additions and 7 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -247,6 +247,7 @@
<file>themes/default/mIconUnknownLayerType.png</file>
<file>themes/default/mIconWaitingForLayerType.png</file>
<file>themes/default/mMapserverExport.png</file>
<file>themes/default/plugin.png</file>
<file>themes/default/rendererCategorizedSymbol.png</file>
<file>themes/default/rendererGraduatedSymbol.png</file>
<file>themes/default/rendererSingleSymbol.png</file>
Expand Down
Binary file added images/themes/default/plugin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions python/plugins/GdalTools/__init__.py
Expand Up @@ -25,6 +25,8 @@ def version():
return "Version 1.2.18"
def qgisMinimumVersion():
return "1.0"
def icon():
return "icons/raster-info.png"
def classFactory(iface):
# load GdalTools class from file GdalTools
from GdalTools import GdalTools
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/fTools/__init__.py
Expand Up @@ -25,6 +25,9 @@ def version():

def qgisMinimumVersion():
return "1.0"

def icon():
return "icons/logo_small.png"

def authorName():
return "Carson J. Q. Farmer"
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/fTools/icons/CMakeLists.txt
Expand Up @@ -5,6 +5,6 @@ gis-0.1.svg
logo.svg
menu_icons.svg
)
INSTALL(FILES ${VECTOR_GRAPHICS_FILES} DESTINATION ${QGIS_DATA_DIR}/python/plugins/fTools/icons)
INSTALL(FILES ${VECTOR_GRAPHICS_FILES} logo_small.png DESTINATION ${QGIS_DATA_DIR}/python/plugins/fTools/icons)

SUBDIRS(default gis)
Binary file added python/plugins/fTools/icons/logo_small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions python/plugins/mapserver_export/__init__.py
Expand Up @@ -27,6 +27,8 @@ def version():
return "Version 0.4.3"
def qgisMinimumVersion():
return "1.0"
def icon():
return "mapserver_export.png"
def authorName():
return "Gary E. Sherman"
def classFactory(iface):
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/osm/__init__.py
Expand Up @@ -51,6 +51,10 @@ def qgisMinimumVersion():

return "1.0.0"

def icon():
import resources_rc
return ":/plugins/osm_plugin/images/osm_load.png"


def classFactory(iface):
"""Function returns OSM Plugin instance.
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/plugin_installer/__init__.py
Expand Up @@ -23,6 +23,10 @@ def description():
def qgisMinimumVersion():
return "1.0"

def icon():
import resources_rc
return ":/plugins/installer/plugin_installer.png"

def authorName():
return "Matthew Perry, Borys Jurgiel"

Expand Down
4 changes: 4 additions & 0 deletions python/utils.py
Expand Up @@ -266,6 +266,10 @@ def showPluginHelp(packageName=None,filename="index",section=""):
iface.openURL(url,False)


def pluginDirectory(packageName):
""" return directory where the plugin resides. Plugin must be loaded already """
return os.path.dirname(sys.modules[packageName].__file__)

#######################
# IMPORT wrapper

Expand Down
28 changes: 26 additions & 2 deletions src/app/qgspluginmanager.cpp
Expand Up @@ -44,7 +44,7 @@
#include "qgslogger.h"

// Do we need this?
// #define TESTLIB
// #define TESTLIB
#ifdef TESTLIB
// This doesn't work on WIN32 and causes problems with plugins
// on OS X (the code doesn't cause a problem but including dlfcn.h
Expand Down Expand Up @@ -174,8 +174,9 @@ void QgsPluginManager::getPythonPluginDescriptions()
QString pluginName = mPythonUtils->getPluginMetadata( packageName, "name" );
QString description = mPythonUtils->getPluginMetadata( packageName, "description" );
QString version = mPythonUtils->getPluginMetadata( packageName, "version" );
QString iconName = mPythonUtils->getPluginMetadata( packageName, "icon" );

if ( pluginName == "???" || description == "???" || version == "???" ) continue;
if ( pluginName == "__error__" || description == "__error__" || version == "__error__" ) continue;

bool isCompatible = QgsPluginRegistry::instance()->isPythonPluginCompatible( packageName );
QString compatibleString; // empty by default
Expand All @@ -200,6 +201,19 @@ void QgsPluginManager::getPythonPluginDescriptions()
myData.setCheckable( true );
myData.setRenderAsWidget( false );
myData.setChecked( false ); //start off assuming false
if ( iconName == "__error__" )
myData.setIcon( QPixmap( QgsApplication::defaultThemePath() + "/plugin.png" ) );
else
{
bool relative = QFileInfo( iconName ).isRelative();
if ( relative )
{
QString pluginDir;
mPythonUtils->evalString( QString( "qgis.utils.pluginDirectory('%1')" ).arg( packageName ), pluginDir );
iconName = pluginDir + "/" + iconName;
}
myData.setIcon( QPixmap( iconName ) );
}

// check to see if the plugin is loaded and set the checkbox accordingly
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
Expand Down Expand Up @@ -296,6 +310,7 @@ void QgsPluginManager::getPluginDescriptions()
name_t *pName = ( name_t * ) cast_to_fptr( myLib->resolve( "name" ) );
description_t *pDesc = ( description_t * ) cast_to_fptr( myLib->resolve( "description" ) );
version_t *pVersion = ( version_t * ) cast_to_fptr( myLib->resolve( "version" ) );
icon_t* pIcon = ( icon_t * ) cast_to_fptr( myLib->resolve( "icon" ) );

// show the values (or lack of) for each function
if ( pName )
Expand All @@ -322,6 +337,10 @@ void QgsPluginManager::getPluginDescriptions()
{
QgsDebugMsg( "Plugin version not returned when queried" );
}
if ( pIcon )
{
QgsDebugMsg( "Plugin icon: " + pIcon() );
}

if ( !pName || !pDesc || !pVersion )
{
Expand All @@ -333,6 +352,7 @@ void QgsPluginManager::getPluginDescriptions()
QString pluginName = pName();
QString pluginDesc = pDesc();
QString pluginVersion = pVersion();
QString pluginIconFileName = ( pIcon ? pIcon() : QString() );
QString baseName = QFileInfo( lib ).baseName();

QString myLibraryName = pluginDir[i];
Expand All @@ -347,6 +367,10 @@ void QgsPluginManager::getPluginDescriptions()
myData.setRenderAsWidget( false );
myData.setCheckable( true );
myData.setChecked( false ); //start unchecked - we will check it later if needed
if ( pluginIconFileName.isEmpty() )
myData.setIcon( QPixmap( QgsApplication::defaultThemePath() + "/plugin.png" ) );
else
myData.setIcon( QPixmap( pluginIconFileName ) );

QgsDebugMsg( "Getting an instance of the QgsPluginRegistry" );

Expand Down
26 changes: 22 additions & 4 deletions src/gui/qgsdetaileditemdelegate.cpp
Expand Up @@ -147,10 +147,28 @@ void QgsDetailedItemDelegate::paintManually( QPainter * thepPainter,
QPixmap myDecoPixmap = theData.icon();
if ( !myDecoPixmap.isNull() )
{
thepPainter->drawPixmap( myTextStartX,
myTextStartY + ( myDecoPixmap.height() / 2 ),
myDecoPixmap );
myTextStartX += myDecoPixmap.width() + horizontalSpacing();
int iconWidth = 32, iconHeight = 32;

if ( myDecoPixmap.width() <= iconWidth && myDecoPixmap.height() <= iconHeight )
{
// the pixmap has reasonable size
int offsetX = 0, offsetY = 0;
if ( myDecoPixmap.width() < iconWidth )
offsetX = ( iconWidth - myDecoPixmap.width() ) / 2;
if ( myDecoPixmap.height() < iconHeight )
offsetY = ( iconHeight - myDecoPixmap.height() ) / 2;

thepPainter->drawPixmap( myTextStartX + offsetX,
myTextStartY + offsetY,
myDecoPixmap );
}
else
{
// shrink the pixmap, it's too big
thepPainter->drawPixmap( myTextStartX, myTextStartY, iconWidth, iconHeight, myDecoPixmap );
}

myTextStartX += iconWidth + horizontalSpacing();
}
//
// Draw the title
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
Expand Up @@ -53,6 +53,7 @@ static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z ti
static const QString sName = QObject::tr( "Coordinate Capture" );
static const QString sDescription = QObject::tr( "Capture mouse coordinates in different CRS" );
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
static const QString sPluginIcon = ":/coordinate_capture/coordinate_capture.png";
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -343,6 +344,11 @@ QGISEXTERN QString version()
return sPluginVersion;
}

QGISEXTERN QString icon()
{
return sPluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/copyright_label/plugin.cpp
Expand Up @@ -51,6 +51,7 @@ static const char * const ident_ = "$Id$";
static const QString name_ = QObject::tr( "CopyrightLabel" );
static const QString description_ = QObject::tr( "Draws copyright information" );
static const QString version_ = QObject::tr( "Version 0.1" );
static const QString icon_ = ":/copyright_label.png";
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;


Expand Down Expand Up @@ -318,6 +319,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/delimited_text/qgsdelimitedtextplugin.cpp
Expand Up @@ -43,6 +43,8 @@

static const QString pluginVersion = QObject::tr( "Version 0.2" );
static const QString description_ = QObject::tr( "Loads and displays delimited text files containing x,y coordinates" );
static const QString icon_ = ":/delimited_text.png";

/**
* Constructor for the plugin. The plugin is passed a pointer to the main app
* and an interface object that provides access to exposed functions in QGIS.
Expand Down Expand Up @@ -206,6 +208,11 @@ QGISEXTERN QString version()
return pluginVersion;
}

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * theQgsDelimitedTextPluginPointer )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/dxf2shp_converter/dxf2shpconverter.cpp
Expand Up @@ -40,6 +40,7 @@ static const QString sName = QObject::tr( "Dxf2Shp Converter" );
static const QString sDescription = QObject::tr( "Converts from dxf to shp file format" );
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
static const QString sPluginIcon = ":/dxf2shp_converter.png";

//////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -194,6 +195,11 @@ QGISEXTERN QString version()
return sPluginVersion;
}

QGISEXTERN QString icon()
{
return sPluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin *thePluginPointer )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/geoprocessing/qgspggeoprocessing.cpp
Expand Up @@ -46,6 +46,7 @@ static const QString name_ = QObject::tr( "PostgreSQL Geoprocessing" );
static const QString description_ = QObject::tr( "Geoprocessing functions for working with PostgreSQL/PostGIS layers" );
static const QString version_ = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
static const QString icon_ = ":/geoprocessing.png";


/**
Expand Down Expand Up @@ -478,6 +479,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * p )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/georeferencer/qgsgeorefplugin.cpp
Expand Up @@ -66,6 +66,7 @@ static const QString sName = QObject::tr( "Georeferencer GDAL" );
static const QString sDescription = QObject::tr( "Georeferencing rasters using GDAL" );
static const QString sPluginVersion = QObject::tr( "Version 3.1.9" );
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
static const QString sPluginIcon = ":/icons/mGeorefRun.png";

//////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -236,6 +237,11 @@ QGISEXTERN QString version()
return sPluginVersion;
}

QGISEXTERN QString icon()
{
return sPluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/gps_importer/qgsgpsplugin.cpp
Expand Up @@ -54,6 +54,7 @@ static const QString name_ = QObject::tr( "GPS Tools" );
static const QString description_ = QObject::tr( "Tools for loading and importing GPS data" );
static const QString version_ = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
static const QString icon_ = ":/gps_importer.png";


/**
Expand Down Expand Up @@ -733,6 +734,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/grass/qgsgrassplugin.cpp
Expand Up @@ -50,6 +50,7 @@ extern "C"
}

static const QString pluginVersion = QObject::tr( "Version 0.1" );
static const QString pluginIcon = ":/images/themes/default/grass/grass_tools.png";

/**
* Constructor for the plugin. The plugin is passed a pointer to the main app
Expand Down Expand Up @@ -909,6 +910,11 @@ QGISEXTERN QString version()
return pluginVersion;
}

QGISEXTERN QString icon()
{
return pluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/interpolation/qgsinterpolationplugin.cpp
Expand Up @@ -25,6 +25,7 @@
static const QString name_ = QObject::tr( "Interpolation plugin" );
static const QString description_ = QObject::tr( "A plugin for interpolation based on vertices of a vector layer" );
static const QString version_ = QObject::tr( "Version 0.001" );
static const QString icon_ = ":/interpolation.png";

QgsInterpolationPlugin::QgsInterpolationPlugin( QgisInterface* iface ): mIface( iface ), mInterpolationAction( 0 )
{
Expand Down Expand Up @@ -107,6 +108,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

QGISEXTERN int type()
{
return QgisPlugin::UI;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/north_arrow/plugin.cpp
Expand Up @@ -60,6 +60,7 @@ static const QString name_ = QObject::tr( "NorthArrow" );
static const QString description_ = QObject::tr( "Displays a north arrow overlayed onto the map" );
static const QString version_ = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
static const QString icon_ = ":/north_arrow.png";

const double QgsNorthArrowPlugin::PI = 3.14159265358979323846;
// const double QgsNorthArrowPlugin::DEG2RAD = 0.0174532925199433;
Expand Down Expand Up @@ -455,6 +456,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
Expand Down

0 comments on commit 3a18bdd

Please sign in to comment.