Skip to content
Permalink
Browse files
Renderer properties dialog completely refactored into several classes…
… and made generic to be able to handle any custom renderer.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@12116 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 15, 2009
1 parent f5b6073 commit 4cf3ae1be2b06332597870a4978ae29ac1a9711a
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -26,27 +26,30 @@ public slots:
};



class QgsRendererV2PropertiesDialog : QDialog //, private Ui::QgsRendererV2PropsDialogBase
{
%TypeHeaderCode
#include <qgsrendererv2propertiesdialog.h>
%End

public:
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL, bool embedded = false);
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, bool embedded = false);

public slots:
void changeSingleSymbol();
void updateRenderer();

void categoryColumnChanged();
void categoriesDoubleClicked(const QModelIndex & idx);
void addCategories();
void deleteCategory();
void deleteAllCategories();
};
//! called when user changes renderer type
void rendererChanged();

void apply();
void onOK();

void showSymbolLevels();

protected:

//! Reimplements dialog keyPress event so we can ignore it
void keyPressEvent( QKeyEvent * event );

};


class QgsStyleV2ManagerDialog : QDialog //, private Ui::QgsStyleV2ManagerDialogBase
@@ -475,7 +475,7 @@ void QgsVectorLayerProperties::reset( void )

if (layer->isUsingRendererV2())
{
mRendererDialog = new QgsRendererV2PropertiesDialog(layer, QgsStyleV2::defaultStyle(), NULL, true);
mRendererDialog = new QgsRendererV2PropertiesDialog(layer, QgsStyleV2::defaultStyle(), true);

// hide unused widgets
legendtypecombobox->hide();
@@ -266,7 +266,7 @@ QgsFeatureRendererV2* QgsFeatureRendererV2::load(QDomElement& element)
// load renderer
QString rendererType = element.attribute("type");

QgsRendererV2CreateFunc pfCreate = QgsRendererV2Registry::instance()->rendererCreateFunction(rendererType);
QgsRendererV2CreateFunc pfCreate = QgsRendererV2Registry::instance()->rendererMetadata(rendererType).createFunction();

// unknown renderer type?
if (pfCreate == NULL)
@@ -11,9 +11,18 @@ QgsRendererV2Registry* QgsRendererV2Registry::mInstance = NULL;
QgsRendererV2Registry::QgsRendererV2Registry()
{
// add default renderers
addRenderer("singleSymbol", QgsSingleSymbolRendererV2::create);
addRenderer("categorizedSymbol", QgsCategorizedSymbolRendererV2::create);
addRenderer("graduatedSymbol", QgsGraduatedSymbolRendererV2::create);
addRenderer(QgsRendererV2Metadata("singleSymbol",
QObject::tr("Single Symbol"),
QgsSingleSymbolRendererV2::create,
"rendererSingleSymbol.png"));
addRenderer(QgsRendererV2Metadata("categorizedSymbol",
QObject::tr("Categorized"),
QgsCategorizedSymbolRendererV2::create,
"rendererCategorizedSymbol.png"));
addRenderer(QgsRendererV2Metadata("graduatedSymbol",
QObject::tr("Graduated"),
QgsGraduatedSymbolRendererV2::create,
"rendererGraduatedSymbol.png"));
}

QgsRendererV2Registry* QgsRendererV2Registry::instance()
@@ -25,23 +34,35 @@ QgsRendererV2Registry* QgsRendererV2Registry::instance()
}


bool QgsRendererV2Registry::addRenderer(QString rendererName, QgsRendererV2CreateFunc pfCreate)
void QgsRendererV2Registry::addRenderer(const QgsRendererV2Metadata& metadata)
{
if (mRenderers.contains(rendererName))
return false;
mRenderers.insert(rendererName, pfCreate);
return true;
mRenderers[metadata.name()] = metadata;
mRenderersOrder << metadata.name();
}

bool QgsRendererV2Registry::removeRenderer(QString rendererName)
{
if (!mRenderers.contains(rendererName))
return false;
mRenderers.remove(rendererName);
mRenderersOrder.removeAll(rendererName);
return true;
}

QgsRendererV2Metadata QgsRendererV2Registry::rendererMetadata(QString rendererName)
{
return mRenderers.value(rendererName);
}

bool QgsRendererV2Registry::setRendererWidgetFunction(QString name, QgsRendererV2WidgetFunc f)
{
if (!mRenderers.contains(name))
return false;
mRenderers[name].setWidgetFunction(f);
return true;
}

QgsRendererV2CreateFunc QgsRendererV2Registry::rendererCreateFunction(QString rendererName)
QStringList QgsRendererV2Registry::renderersList()
{
return mRenderers.value(rendererName, NULL);
return mRenderersOrder;
}
@@ -2,11 +2,52 @@
#define QGSRENDERERV2REGISTRY_H

#include <QMap>
#include <QStringList>

class QgsFeatureRendererV2;
class QDomElement;
class QgsVectorLayer;
class QgsStyleV2;
class QgsRendererV2Widget;

typedef QgsFeatureRendererV2* (*QgsRendererV2CreateFunc)(QDomElement&);
typedef QgsRendererV2Widget* (*QgsRendererV2WidgetFunc)(QgsVectorLayer*, QgsStyleV2*, QgsFeatureRendererV2*);

class QgsRendererV2Metadata
{
public:
/** construct invalid metadata */
QgsRendererV2Metadata()
: mName(), mVisibleName(), mCreateFunc(NULL), mIconName(), mWidgetFunc(NULL) {}

/** construct metadata */
QgsRendererV2Metadata(QString name,
QString visibleName,
QgsRendererV2CreateFunc pfCreate,
QString iconName = QString(),
QgsRendererV2WidgetFunc pfWidget = NULL)
: mName(name), mVisibleName(visibleName), mCreateFunc(pfCreate), mIconName(iconName), mWidgetFunc(pfWidget) {}

QString name() const { return mName; }
QString visibleName() const { return mVisibleName; }
QString iconName() const { return mIconName; }
QgsRendererV2CreateFunc createFunction() const { return mCreateFunc; }
QgsRendererV2WidgetFunc widgetFunction() const { return mWidgetFunc; }

void setWidgetFunction(QgsRendererV2WidgetFunc f) { mWidgetFunc = f; }

protected:
//! name used within QGIS for identification (the same what renderer's type() returns)
QString mName;
//! name visible for users (translatable)
QString mVisibleName;
//! pointer to function that creates an instance of the renderer when loading project / style
QgsRendererV2CreateFunc mCreateFunc;
//! icon to be shown in the renderer properties dialog
QString mIconName;
//! pointer to function that creates a widget for configuration of renderer's params
QgsRendererV2WidgetFunc mWidgetFunc;
};

/**
Registry of renderers.
@@ -19,19 +60,31 @@ class QgsRendererV2Registry

static QgsRendererV2Registry* instance();

bool addRenderer(QString rendererName, QgsRendererV2CreateFunc pfCreate);
//! add a renderer to registry
void addRenderer(const QgsRendererV2Metadata& metadata);

//! remove renderer from registry
bool removeRenderer(QString rendererName);

QgsRendererV2CreateFunc rendererCreateFunction(QString rendererName);
//! get factory method for particular renderer
QgsRendererV2Metadata rendererMetadata(QString rendererName);

//! assign a widget factory to particular renderer
bool setRendererWidgetFunction(QString name, QgsRendererV2WidgetFunc f);

//! return a list of available renderers
QStringList renderersList();

protected:
//! protected constructor
QgsRendererV2Registry();

static QgsRendererV2Registry* mInstance;

QMap<QString, QgsRendererV2CreateFunc> mRenderers;
QMap<QString, QgsRendererV2Metadata> mRenderers;

//! list to keep order in which renderers have been added
QStringList mRenderersOrder;
};

#endif // QGSRENDERERV2REGISTRY_H
@@ -5,6 +5,10 @@ symbology-ng/qgsbrushstylecombobox.cpp
symbology-ng/qgspenstylecombobox.cpp
symbology-ng/qgssymbollayerv2widget.cpp
symbology-ng/qgssymbolv2propertiesdialog.cpp
symbology-ng/qgsrendererv2widget.cpp
symbology-ng/qgssinglesymbolrendererv2widget.cpp
symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
symbology-ng/qgsrendererv2propertiesdialog.cpp
symbology-ng/qgsstylev2managerdialog.cpp
symbology-ng/qgssymbollevelsv2dialog.cpp
@@ -44,6 +48,9 @@ SET(QGIS_GUI_MOC_HDRS

symbology-ng/qgssymbollayerv2widget.h
symbology-ng/qgssymbolv2propertiesdialog.h
symbology-ng/qgssinglesymbolrendererv2widget.h
symbology-ng/qgscategorizedsymbolrendererv2widget.h
symbology-ng/qgsgraduatedsymbolrendererv2widget.h
symbology-ng/qgsrendererv2propertiesdialog.h
symbology-ng/qgsstylev2managerdialog.h
symbology-ng/qgssymbollevelsv2dialog.h
Loading

0 comments on commit 4cf3ae1

Please sign in to comment.