Skip to content
Permalink
Browse files
[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/qgis@14897 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Dec 12, 2010
1 parent e82639f commit 317e0f3cc70f303efb1d874f72479b193ca2f809
Showing with 193 additions and 7 deletions.
  1. +1 −0 images/images.qrc
  2. BIN images/themes/default/plugin.png
  3. +2 −0 python/plugins/GdalTools/__init__.py
  4. +3 −0 python/plugins/fTools/__init__.py
  5. +1 −1 python/plugins/fTools/icons/CMakeLists.txt
  6. BIN python/plugins/fTools/icons/logo_small.png
  7. +2 −0 python/plugins/mapserver_export/__init__.py
  8. +4 −0 python/plugins/osm/__init__.py
  9. +4 −0 python/plugins/plugin_installer/__init__.py
  10. +4 −0 python/utils.py
  11. +26 −2 src/app/qgspluginmanager.cpp
  12. +22 −4 src/gui/qgsdetaileditemdelegate.cpp
  13. +6 −0 src/plugins/coordinate_capture/coordinatecapture.cpp
  14. +6 −0 src/plugins/copyright_label/plugin.cpp
  15. +7 −0 src/plugins/delimited_text/qgsdelimitedtextplugin.cpp
  16. +6 −0 src/plugins/dxf2shp_converter/dxf2shpconverter.cpp
  17. +6 −0 src/plugins/geoprocessing/qgspggeoprocessing.cpp
  18. +6 −0 src/plugins/georeferencer/qgsgeorefplugin.cpp
  19. +6 −0 src/plugins/gps_importer/qgsgpsplugin.cpp
  20. +6 −0 src/plugins/grass/qgsgrassplugin.cpp
  21. +6 −0 src/plugins/interpolation/qgsinterpolationplugin.cpp
  22. +6 −0 src/plugins/north_arrow/plugin.cpp
  23. +6 −0 src/plugins/offline_editing/offline_editing_plugin.cpp
  24. +6 −0 src/plugins/ogr_converter/plugin.cpp
  25. +6 −0 src/plugins/oracle_raster/qgsoracle_plugin.cpp
  26. +6 −0 src/plugins/plugin_template/plugin.cpp
  27. +3 −0 src/plugins/qgisplugin.h
  28. +6 −0 src/plugins/quick_print/quickprintplugin.cpp
  29. +6 −0 src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp
  30. +6 −0 src/plugins/scale_bar/plugin.cpp
  31. +6 −0 src/plugins/spatialquery/qgsspatialqueryplugin.cpp
  32. +6 −0 src/plugins/spit/qgsspitplugin.cpp
  33. +6 −0 src/plugins/wfs/qgswfsplugin.cpp
@@ -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>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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
@@ -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"
@@ -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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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):
@@ -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.
@@ -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"

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

@@ -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
@@ -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
@@ -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();
@@ -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 )
@@ -322,6 +337,10 @@ void QgsPluginManager::getPluginDescriptions()
{
QgsDebugMsg( "Plugin version not returned when queried" );
}
if ( pIcon )
{
QgsDebugMsg( "Plugin icon: " + pIcon() );
}

if ( !pName || !pDesc || !pVersion )
{
@@ -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];
@@ -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" );

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

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

QGISEXTERN QString icon()
{
return sPluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
@@ -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;


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

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
@@ -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.
@@ -206,6 +208,11 @@ QGISEXTERN QString version()
return pluginVersion;
}

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * theQgsDelimitedTextPluginPointer )
{
@@ -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";

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

QGISEXTERN QString icon()
{
return sPluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin *thePluginPointer )
{
@@ -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";


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

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * p )
{
@@ -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";

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

QGISEXTERN QString icon()
{
return sPluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
@@ -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";


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

QGISEXTERN QString icon()
{
return icon_;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
@@ -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
@@ -909,6 +910,11 @@ QGISEXTERN QString version()
return pluginVersion;
}

QGISEXTERN QString icon()
{
return pluginIcon;
}

// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
@@ -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 )
{
@@ -107,6 +108,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

QGISEXTERN int type()
{
return QgisPlugin::UI;
@@ -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;
@@ -455,6 +456,11 @@ QGISEXTERN QString version()
return version_;
}

QGISEXTERN QString icon()
{
return icon_;
}

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

0 comments on commit 317e0f3

Please sign in to comment.