Skip to content
Permalink
Browse files

QgsRendererV2 metadata: for renderer icon use QIcon instead of icon f…

…ile name.

git-svn-id: http://svn.osgeo.org/qgis/trunk@12852 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jan 29, 2010
1 parent d2af21c commit a70f812d1ee402f5abbd015c0b2abc0372e5d255
@@ -809,11 +809,13 @@ class QgsRendererV2AbstractMetadata
%End

public:
QgsRendererV2AbstractMetadata( QString name, QString visibleName, QString iconName = QString() );
QgsRendererV2AbstractMetadata( QString name, QString visibleName, QIcon icon = QIcon() );

QString name() const;
QString visibleName() const;
QString iconName() const;

QIcon icon() const;
void setIcon(const QIcon& icon);

/** Return new instance of the renderer given the DOM element. Returns NULL on error.
* Pure virtual function: must be implemented in derived classes. */
@@ -13,16 +13,13 @@ QgsRendererV2Registry::QgsRendererV2Registry()
// add default renderers
addRenderer( new QgsRendererV2Metadata( "singleSymbol",
QObject::tr( "Single Symbol" ),
QgsSingleSymbolRendererV2::create,
"rendererSingleSymbol.png" ) );
QgsSingleSymbolRendererV2::create ) );
addRenderer( new QgsRendererV2Metadata( "categorizedSymbol",
QObject::tr( "Categorized" ),
QgsCategorizedSymbolRendererV2::create,
"rendererCategorizedSymbol.png" ) );
QgsCategorizedSymbolRendererV2::create ) );
addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
QObject::tr( "Graduated" ),
QgsGraduatedSymbolRendererV2::create,
"rendererGraduatedSymbol.png" ) );
QgsGraduatedSymbolRendererV2::create ) );
}

QgsRendererV2Registry::~QgsRendererV2Registry()
@@ -1,6 +1,7 @@
#ifndef QGSRENDERERV2REGISTRY_H
#define QGSRENDERERV2REGISTRY_H

#include <QIcon>
#include <QMap>
#include <QStringList>

@@ -19,12 +20,14 @@ class QgsRendererV2Widget;
class CORE_EXPORT QgsRendererV2AbstractMetadata
{
public:
QgsRendererV2AbstractMetadata( QString name, QString visibleName, QString iconName = QString() )
: mName( name ), mVisibleName( visibleName ), mIconName( iconName ) {}
QgsRendererV2AbstractMetadata( QString name, QString visibleName, QIcon icon = QIcon() )
: mName( name ), mVisibleName( visibleName ), mIcon( icon ) {}

QString name() const { return mName; }
QString visibleName() const { return mVisibleName; }
QString iconName() const { return mIconName; }

QIcon icon() const { return mIcon; }
void setIcon(const QIcon& icon) { mIcon = icon; }

/** Return new instance of the renderer given the DOM element. Returns NULL on error.
* Pure virtual function: must be implemented in derived classes. */
@@ -39,7 +42,7 @@ class CORE_EXPORT QgsRendererV2AbstractMetadata
//! name visible for users (translatable)
QString mVisibleName;
//! icon to be shown in the renderer properties dialog
QString mIconName;
QIcon mIcon;
};


@@ -57,9 +60,9 @@ class CORE_EXPORT QgsRendererV2Metadata : public QgsRendererV2AbstractMetadata
QgsRendererV2Metadata( QString name,
QString visibleName,
QgsRendererV2CreateFunc pfCreate,
QString iconName = QString(),
QIcon icon = QIcon(),
QgsRendererV2WidgetFunc pfWidget = NULL )
: QgsRendererV2AbstractMetadata( name, visibleName, iconName ), mCreateFunc( pfCreate ), mWidgetFunc( pfWidget ) {}
: QgsRendererV2AbstractMetadata( name, visibleName, icon ), mCreateFunc( pfCreate ), mWidgetFunc( pfWidget ) {}

virtual QgsFeatureRendererV2* createRenderer( QDomElement& elem ) { return mCreateFunc ? mCreateFunc(elem):NULL; }
virtual QgsRendererV2Widget* createRendererWidget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
@@ -18,7 +18,7 @@
#include <QKeyEvent>
#include <QMessageBox>

static bool _initRendererWidgetFunction(QString name, QgsRendererV2WidgetFunc f )
static bool _initRenderer(QString name, QgsRendererV2WidgetFunc f, QString iconName )
{
QgsRendererV2Registry* reg = QgsRendererV2Registry::instance();
QgsRendererV2AbstractMetadata* am = reg->rendererMetadata( name );
@@ -29,6 +29,12 @@ static bool _initRendererWidgetFunction(QString name, QgsRendererV2WidgetFunc f
return false;

m->setWidgetFunction(f);

QString iconPath = QgsApplication::defaultThemePath() + iconName;
QPixmap pix;
if ( pix.load( iconPath, "png" ) )
m->setIcon(pix);

QgsDebugMsg("Set for "+name);
return true;
}
@@ -39,9 +45,9 @@ static void _initRendererWidgetFunctions()
if (initialized)
return;

_initRendererWidgetFunction( "singleSymbol", QgsSingleSymbolRendererV2Widget::create );
_initRendererWidgetFunction( "categorizedSymbol", QgsCategorizedSymbolRendererV2Widget::create );
_initRendererWidgetFunction( "graduatedSymbol", QgsGraduatedSymbolRendererV2Widget::create );
_initRenderer( "singleSymbol", QgsSingleSymbolRendererV2Widget::create, "rendererSingleSymbol.png" );
_initRenderer( "categorizedSymbol", QgsCategorizedSymbolRendererV2Widget::create, "rendererCategorizedSymbol.png" );
_initRenderer( "graduatedSymbol", QgsGraduatedSymbolRendererV2Widget::create, "rendererGraduatedSymbol.png" );
initialized = true;
}

@@ -70,12 +76,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
foreach( QString name, renderers )
{
QgsRendererV2AbstractMetadata* m = reg->rendererMetadata( name );

QString iconPath = QgsApplication::defaultThemePath() + m->iconName();
if ( !pix.load( iconPath, "png" ) )
pix = QPixmap();

cboRenderers->addItem( QIcon( pix ), m->visibleName(), name );
cboRenderers->addItem( m->icon(), m->visibleName(), name );
}

cboRenderers->setCurrentIndex( -1 ); // set no current renderer

0 comments on commit a70f812

Please sign in to comment.
You can’t perform that action at this time.