[QGIS Commit] r10772 - in branches/symbology-ng-branch/src/gui: . symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue May 12 05:44:10 EDT 2009


Author: wonder
Date: 2009-05-12 05:44:09 -0400 (Tue, 12 May 2009)
New Revision: 10772

Added:
   branches/symbology-ng-branch/src/gui/symbology-ng/
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.h
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp
   branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.h
Modified:
   branches/symbology-ng-branch/src/gui/CMakeLists.txt
Log:
Added a bunch of widgets and dialogs for new symbology.


Modified: branches/symbology-ng-branch/src/gui/CMakeLists.txt
===================================================================
--- branches/symbology-ng-branch/src/gui/CMakeLists.txt	2009-05-12 09:37:34 UTC (rev 10771)
+++ branches/symbology-ng-branch/src/gui/CMakeLists.txt	2009-05-12 09:44:09 UTC (rev 10772)
@@ -1,5 +1,15 @@
 
 SET(QGIS_GUI_SRCS
+
+symbology-ng/qgsbrushstylecombobox.cpp
+symbology-ng/qgspenstylecombobox.cpp
+symbology-ng/qgssymbollayerv2widget.cpp
+symbology-ng/qgssymbolv2propertiesdialog.cpp
+symbology-ng/qgsrendererv2propertiesdialog.cpp
+symbology-ng/qgsstylev2managerdialog.cpp
+symbology-ng/qgssymbolv2selectordialog.cpp
+symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp
+
 qgisgui.cpp
 qgisinterface.cpp
 qgscolorbutton.cpp
@@ -29,6 +39,14 @@
 )
 
 SET(QGIS_GUI_MOC_HDRS
+
+symbology-ng/qgssymbollayerv2widget.h
+symbology-ng/qgssymbolv2propertiesdialog.h
+symbology-ng/qgsrendererv2propertiesdialog.h
+symbology-ng/qgsstylev2managerdialog.h
+symbology-ng/qgssymbolv2selectordialog.h
+symbology-ng/qgsvectorgradientcolorrampv2dialog.h
+
 qgscomposerview.h
 qgsdetaileditemdelegate.h
 qgsdetaileditemwidget.h
@@ -45,8 +63,8 @@
 
 QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
 
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ../core
-     ../core/composer ../core/raster ../core/renderer ../core/symbology
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/symbology-ng ../core
+     ../core/composer ../core/raster ../core/renderer ../core/symbology ../core/symbology-ng
      ${CMAKE_CURRENT_BINARY_DIR}
      ${CMAKE_CURRENT_BINARY_DIR}/../ui
      ${GEOS_INCLUDE_DIR}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,71 @@
+
+#include "qgsbrushstylecombobox.h"
+
+#include <QList>
+#include <QPair>
+
+#include <QBrush>
+#include <QPainter>
+#include <QPen>
+
+QgsBrushStyleComboBox::QgsBrushStyleComboBox(QWidget* parent)
+  : QComboBox(parent)
+{
+  QList < QPair<Qt::BrushStyle, QString> > styles;
+  styles << qMakePair(Qt::SolidPattern, QString("Solid"))
+      << qMakePair(Qt::HorPattern, QString("Horizontal"))
+      << qMakePair(Qt::VerPattern, QString("Vertical"))
+      << qMakePair(Qt::CrossPattern, QString("Cross"))
+      << qMakePair(Qt::BDiagPattern, QString("BDiagonal"))
+      << qMakePair(Qt::FDiagPattern, QString("FDiagonal"))
+      << qMakePair(Qt::DiagCrossPattern, QString("Diagonal X"))
+      << qMakePair(Qt::Dense1Pattern, QString("Dense 1"))
+      << qMakePair(Qt::Dense2Pattern, QString("Dense 2"))
+      << qMakePair(Qt::Dense3Pattern, QString("Dense 3"))
+      << qMakePair(Qt::Dense4Pattern, QString("Dense 4"))
+      << qMakePair(Qt::Dense5Pattern, QString("Dense 5"))
+      << qMakePair(Qt::Dense6Pattern, QString("Dense 6"))
+      << qMakePair(Qt::Dense7Pattern, QString("Dense 7"))
+      << qMakePair(Qt::NoBrush, QString("No Brush"));
+  
+  setIconSize(QSize(32,16));
+  
+  for (int i = 0; i < styles.count(); i++)
+  {
+    Qt::BrushStyle style = styles.at(i).first;
+    QString name = styles.at(i).second;
+    addItem(iconForBrush(style), name, QVariant(style));
+  }  
+  
+ setCurrentIndex(1);
+
+}
+
+
+Qt::BrushStyle QgsBrushStyleComboBox::brushStyle() const
+{
+  return (Qt::BrushStyle) itemData(currentIndex()).toInt();
+}
+  
+void QgsBrushStyleComboBox::setBrushStyle(Qt::BrushStyle style)
+{
+  int idx = findData(QVariant(style));
+  setCurrentIndex( idx == -1 ? 0 : idx );
+}
+
+QIcon QgsBrushStyleComboBox::iconForBrush(Qt::BrushStyle style)
+{
+  QPixmap pix(iconSize());
+  QPainter p;
+  pix.fill(Qt::transparent);
+  
+  p.begin(&pix);
+  QBrush brush(QColor(100,100,100), style);
+  p.setBrush(brush);
+  QPen pen(Qt::NoPen);
+  p.setPen(pen);
+  p.drawRect(QRect(QPoint(0,0),iconSize()));
+  p.end();
+  
+  return QIcon(pix);
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsbrushstylecombobox.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,21 @@
+
+#ifndef QGSBRUSHSTYLECOMBOBOX_H
+#define QGSBRUSHSTYLECOMBOBOX_H
+
+#include <QComboBox>
+
+class QgsBrushStyleComboBox : public QComboBox
+{
+  public:
+    QgsBrushStyleComboBox(QWidget* parent = NULL);
+  
+    Qt::BrushStyle brushStyle() const;
+  
+    void setBrushStyle(Qt::BrushStyle style);
+  
+  protected:
+    QIcon iconForBrush(Qt::BrushStyle style);
+    
+};
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,56 @@
+
+#include "qgspenstylecombobox.h"
+
+#include <QList>
+#include <QPair>
+
+#include <QPainter>
+#include <QPen>
+
+QgsPenStyleComboBox::QgsPenStyleComboBox(QWidget* parent)
+  : QComboBox(parent)
+{
+  QList < QPair<Qt::PenStyle, QString> > styles;
+  styles << qMakePair(Qt::SolidLine, QString("Solid Line"))
+      << qMakePair(Qt::DashLine, QString("Dash Line"))
+      << qMakePair(Qt::DotLine, QString("Dot Line"))
+      << qMakePair(Qt::DashDotLine, QString("Dash Dot Line"))
+      << qMakePair(Qt::DashDotDotLine, QString("Dash Dot Dot Line"));
+  
+  setIconSize(QSize(32,12));
+  
+  for (int i = 0; i < styles.count(); i++)
+  {
+    Qt::PenStyle style = styles.at(i).first;
+    QString name = styles.at(i).second;
+    addItem(iconForPen(style), name, QVariant(style));
+  }
+}
+  
+Qt::PenStyle QgsPenStyleComboBox::penStyle() const
+{
+  return (Qt::PenStyle) itemData(currentIndex()).toInt();
+}
+  
+void QgsPenStyleComboBox::setPenStyle(Qt::PenStyle style)
+{
+  int idx = findData(QVariant(style));
+  setCurrentIndex( idx == -1 ? 0 : idx );
+}
+
+QIcon QgsPenStyleComboBox::iconForPen(Qt::PenStyle style)
+{
+  QPixmap pix(iconSize());
+  QPainter p;
+  pix.fill(Qt::transparent);
+  
+  p.begin(&pix);
+  QPen pen(style);
+  pen.setWidth(2);
+  p.setPen(pen);
+  double mid = iconSize().height() / 2.0;
+  p.drawLine(0,mid,iconSize().width(),mid);
+  p.end();
+  
+  return QIcon(pix);
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgspenstylecombobox.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,21 @@
+
+#ifndef QGSPENSTYLECOMBOBOX_H
+#define QGSPENSTYLECOMBOBOX_H
+
+#include <QComboBox>
+
+class QgsPenStyleComboBox : public QComboBox
+{
+public:
+  QgsPenStyleComboBox(QWidget* parent = NULL);
+  
+  Qt::PenStyle penStyle() const;
+  
+  void setPenStyle(Qt::PenStyle style);
+  
+protected:
+  QIcon iconForPen(Qt::PenStyle style);
+    
+};
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,476 @@
+
+#include "qgsrendererv2propertiesdialog.h"
+
+#include "qgssymbollayerv2utils.h"
+#include "qgsrendererv2.h"
+#include "qgssymbolv2.h"
+#include "qgsvectorcolorrampv2.h"
+#include "qgsstylev2.h"
+
+#include "qgssymbolv2selectordialog.h"
+
+#include "qgslogger.h"
+#include "qgsvectorlayer.h"
+#include "qgsvectordataprovider.h"
+
+#include <QStandardItemModel>
+#include <QStandardItem>
+
+QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent)
+  : QDialog(parent), mStyle(style)
+{
+  mLayer = layer;
+  
+  // if the layer doesn't use renderer V2, let's start using it!
+  if (!mLayer->isUsingRendererV2())
+  {
+    mLayer->setRendererV2(new QgsSingleSymbolRendererV2( createDefaultSymbol() ));
+    mLayer->setUsingRendererV2(true);
+  }
+  
+  setupUi(this);
+
+  connect(radSingleSymbol, SIGNAL(clicked()), this, SLOT(updateRenderer()));
+  connect(radCategorized, SIGNAL(clicked()), this, SLOT(updateRenderer()));
+  connect(radGraduated, SIGNAL(clicked()), this, SLOT(updateRenderer()));
+  
+  //connect(btnSymbolLevels, SIGNAL(clicked()), this, SLOT(setSymbolLevels()));
+  
+  // simple symbol page
+  connect(btnChangeSingleSymbol, SIGNAL(clicked()), this, SLOT(changeSingleSymbol()));
+
+  // categorized symbol page
+  
+  populateColumns(); // together with graduated
+  QStandardItemModel* m = new QStandardItemModel(this);
+  QStringList labels;
+  labels << "Value" << "Label";
+  m->setHorizontalHeaderLabels(labels);
+  viewCategories->setModel(m);
+  
+  connect(cboCategorizedColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColumnChanged()));
+  
+  connect(viewCategories, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(categoriesDoubleClicked(const QModelIndex &)));
+  
+  connect(btnAddCategories, SIGNAL(clicked()), this, SLOT(addCategories()));
+  connect(btnDeleteCategory, SIGNAL(clicked()), this, SLOT(deleteCategory()));
+  connect(btnDeleteAllCategories, SIGNAL(clicked()), this, SLOT(deleteAllCategories()));
+  
+  // graduated symbol page
+  populateColorRamps();
+  QStandardItemModel* mg = new QStandardItemModel(this);
+  QStringList labelsG;
+  labels << "Range" << "Label";
+  mg->setHorizontalHeaderLabels(labels);
+  viewGraduated->setModel(mg);
+  
+  mGraduatedSymbol = createDefaultSymbol();
+  
+  connect(btnGraduatedClassify, SIGNAL(clicked()), this, SLOT(classifyGraduated()));
+  connect(btnChangeGraduatedSymbol, SIGNAL(clicked()), this, SLOT(changeGraduatedSymbol()));
+
+  // initialize from previously set renderer
+  updateUiFromRenderer();
+}
+
+QgsRendererV2PropertiesDialog::~QgsRendererV2PropertiesDialog()
+{
+  //delete mGraduatedSymbol;
+}
+
+QgsSingleSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererSingle()
+{
+  QgsFeatureRendererV2* r = mLayer->rendererV2();
+  Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererSingleSymbol);
+  return static_cast<QgsSingleSymbolRendererV2*>(r);
+}
+
+QgsCategorizedSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererCategorized()
+{
+  QgsFeatureRendererV2* r = mLayer->rendererV2();
+  Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererCategorizedSymbol);
+  return static_cast<QgsCategorizedSymbolRendererV2*>(r);
+}
+
+QgsGraduatedSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererGraduated()
+{
+  QgsFeatureRendererV2* r = mLayer->rendererV2();
+  Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererGraduatedSymbol);
+  return static_cast<QgsGraduatedSymbolRendererV2*>(r);
+}
+
+void QgsRendererV2PropertiesDialog::changeSingleSymbol()
+{
+
+  QgsSymbolV2SelectorDialog dlg(rendererSingle()->symbol(), mStyle, this);
+  if (!dlg.exec())
+    return;
+  
+  updateSingleSymbolIcon();
+}
+
+void QgsRendererV2PropertiesDialog::updateSingleSymbolIcon()
+{
+  QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(rendererSingle()->symbol(), btnChangeSingleSymbol->iconSize());
+  btnChangeSingleSymbol->setIcon(icon);
+}
+
+void QgsRendererV2PropertiesDialog::updateRenderer()
+{
+  if (radSingleSymbol->isChecked())
+    mLayer->setRendererV2( new QgsSingleSymbolRendererV2( createDefaultSymbol() ) );
+  else if (radCategorized->isChecked())
+    mLayer->setRendererV2( new QgsCategorizedSymbolRendererV2(-1, QgsCategoryList()) );
+  else if (radGraduated->isChecked())
+    mLayer->setRendererV2( new QgsGraduatedSymbolRendererV2(-1, QgsRangeList()) );
+  else
+    Q_ASSERT(false);
+    
+  updateUiFromRenderer();
+}
+
+void QgsRendererV2PropertiesDialog::updateUiFromRenderer()
+{
+  switch (mLayer->rendererV2()->type())
+  {
+    case QgsFeatureRendererV2::RendererSingleSymbol:
+      radSingleSymbol->setChecked(true);
+    
+      stackedWidget->setCurrentWidget(pageSingleSymbol);
+      updateSingleSymbolIcon();
+      break;
+      
+    case QgsFeatureRendererV2::RendererCategorizedSymbol:
+      radCategorized->setChecked(true);
+    
+      stackedWidget->setCurrentWidget(pageCategorized);
+      
+      {
+        int idx = rendererCategorized()->attributeIndex();
+        cboCategorizedColumn->setCurrentIndex(idx >= 0 ? idx : 0);
+      }
+      disconnect(cboCategorizedColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColumnChanged()));
+      connect(cboCategorizedColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColumnChanged()));
+      populateCategories();
+      break;
+  
+    case QgsFeatureRendererV2::RendererGraduatedSymbol:
+      radGraduated->setChecked(true);
+      
+      stackedWidget->setCurrentWidget(pageGraduated);
+      updateGraduatedSymbolIcon();
+      populateRanges();
+      
+      {
+        // update UI from the graduated renderer (update combo boxes, view)
+        QgsGraduatedSymbolRendererV2* r = rendererGraduated();
+        if (r->mode() < cboGraduatedMode->count())
+          cboGraduatedMode->setCurrentIndex( r->mode() );
+        if (r->ranges().count())
+          spinGraduatedClasses->setValue( r->ranges().count() );
+        
+        // set column
+        int attrNum = r->attributeIndex();
+        const QgsFieldMap& flds = mLayer->dataProvider()->fields();
+        if (flds.contains(attrNum))
+        {
+          QString fldName = flds[ attrNum ].name();
+          for (int i=0; i < cboGraduatedColumn->count(); i++)
+          {
+            if (cboGraduatedColumn->itemText(i) == fldName)
+              cboGraduatedColumn->setCurrentIndex(i);
+          }
+        }
+      }
+      break;
+      
+    default: // custom renderer
+      break;
+  }
+}
+
+ 
+QgsSymbolV2* QgsRendererV2PropertiesDialog::createDefaultSymbol()
+{
+  switch (mLayer->geometryType())
+  {
+    case QGis::Point: return new QgsMarkerSymbolV2();
+    case QGis::Line:  return new QgsLineSymbolV2();
+    case QGis::Polygon: return new QgsFillSymbolV2();
+    default: QgsDebugMsg("unknown layer's geometry type"); return NULL;
+  }
+}
+
+void QgsRendererV2PropertiesDialog::populateCategories()
+{
+  QStandardItemModel* m = qobject_cast<QStandardItemModel*>(viewCategories->model());
+  m->clear();
+  
+  QStringList labels;
+  labels << "Value" << "Label";
+  m->setHorizontalHeaderLabels(labels);
+  
+  QSize iconSize(16,16);
+  
+  QgsCategorizedSymbolRendererV2* r = rendererCategorized();
+  int i, count = r->categories().count();
+  
+  // TODO: sort?? utils.sortVariantList(keys);
+  
+  for (i = 0; i < count; i++)
+  {
+    const QgsRendererCategoryV2& cat = r->categories()[i];
+    QVariant k = cat.value();
+    
+    QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(cat.symbol(), iconSize);
+    QStandardItem* item = new QStandardItem(icon, k.toString());
+    item->setData(k); // set attribute value as user role
+    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+    
+    QList<QStandardItem *> list;
+    list << item << new QStandardItem(cat.label());
+    m->appendRow( list );
+  }
+}
+
+void QgsRendererV2PropertiesDialog::populateColumns()
+{
+  cboCategorizedColumn->clear();
+  const QgsFieldMap& flds = mLayer->dataProvider()->fields();
+  QgsFieldMap::ConstIterator it = flds.begin();
+  for ( ; it != flds.end(); ++it)
+  {
+    cboCategorizedColumn->addItem(it->name());
+    
+    if (it->type() == QVariant::Double || it->type() == QVariant::Int)
+      cboGraduatedColumn->addItem(it->name());
+  }
+}
+
+
+void QgsRendererV2PropertiesDialog::categoryColumnChanged()
+{
+  deleteAllCategories();
+}
+
+void QgsRendererV2PropertiesDialog::categoriesDoubleClicked(const QModelIndex & idx)
+{
+  if (idx.isValid() && idx.column() == 0)
+    changeCategorySymbol();
+}
+
+void QgsRendererV2PropertiesDialog::changeCategorySymbol()
+{
+  QVariant k = currentCategory();
+  if (!k.isValid())
+    return;
+  
+  QgsCategorizedSymbolRendererV2* r = rendererCategorized();
+  int catIdx = r->categoryIndexForValue(k);
+  QgsSymbolV2* newSymbol = r->categories()[catIdx].symbol()->clone();
+  
+  QgsSymbolV2SelectorDialog dlg(newSymbol, mStyle, this);
+  if (!dlg.exec())
+  {
+    delete newSymbol;
+    return;
+  }
+  
+  r->updateCategorySymbol(catIdx, newSymbol);
+  
+  populateCategories();
+}
+
+void createCategories(QgsCategoryList& cats, QList<QVariant>& values, QgsSymbolV2* symbol, QgsVectorColorRampV2* ramp)
+{
+  // sort the categories first
+  // TODO: sortVariantList(values);
+  
+  int num = values.count();
+  
+  for (int i = 0; i < num; i++)
+  {
+    QVariant value = values[i];
+    double x = i / (double) num;
+    QgsSymbolV2* newSymbol = symbol->clone();
+    newSymbol->setColor( ramp->color(x) );
+    
+    cats.append( QgsRendererCategoryV2(value, newSymbol, value.toString()) );
+  }
+  
+}
+
+void QgsRendererV2PropertiesDialog::addCategories()
+{
+  int idx = mLayer->dataProvider()->fieldNameIndex(cboCategorizedColumn->currentText());
+  QList<QVariant> unique_vals;
+  mLayer->dataProvider()->uniqueValues(idx, unique_vals);
+  
+  //DlgAddCategories dlg(mStyle, createDefaultSymbol(), unique_vals, this);
+  //if (!dlg.exec())
+  //  return;
+  
+  QgsSymbolV2* newSymbol = createDefaultSymbol();
+  QgsSymbolV2SelectorDialog dlg(newSymbol, mStyle, this);
+  if (!dlg.exec())
+  {
+    delete newSymbol;
+    return;
+  }
+  
+  QgsCategoryList cats;
+  ::createCategories(cats, unique_vals, newSymbol, new QgsVectorGradientColorRampV2()); // dlg.activeRamp());
+  
+  // TODO: if not all categories are desired, delete some!
+  /*
+  if (not dlg.radAllCats.isChecked())
+  {
+    cats2 = {}
+    for item in dlg.listCategories.selectedItems():
+      for k,c in cats.iteritems():
+        if item.text() == k.toString():
+          break
+      cats2[k] = c
+    cats = cats2
+  }
+  */
+      
+  // recreate renderer
+  mLayer->setRendererV2(new QgsCategorizedSymbolRendererV2(idx, cats));
+  
+  populateCategories();
+}
+
+int QgsRendererV2PropertiesDialog::currentCategoryRow()
+{
+  QModelIndex idx = viewCategories->selectionModel()->currentIndex();
+  if (!idx.isValid())
+    return -1;
+  return idx.row();
+}
+
+QVariant QgsRendererV2PropertiesDialog::currentCategory()
+{
+  int row = currentCategoryRow();
+  if (row == -1)
+    return QVariant();
+  QStandardItemModel* m = qobject_cast<QStandardItemModel*>(viewCategories->model());
+  return m->item(row)->data();
+}
+
+void QgsRendererV2PropertiesDialog::deleteCategory()
+{
+  QVariant k = currentCategory();
+  if (!k.isValid())
+    return;
+  
+  QgsCategorizedSymbolRendererV2* r = rendererCategorized();
+  const QgsCategoryList& cats = r->categories();
+  QgsCategoryList::ConstIterator it = cats.begin();
+  
+  for ( ; it != cats.end(); ++it)
+  {
+    if (k.toString() == it->value().toString())
+    {
+      int idx = r->categoryIndexForValue(k);
+      r->deleteCategory(idx);
+    }
+  }
+  
+  populateCategories();
+}
+
+void QgsRendererV2PropertiesDialog::deleteAllCategories()
+{
+  rendererCategorized()->deleteAllCategories();
+  populateCategories();
+}
+
+//////
+
+
+void QgsRendererV2PropertiesDialog::populateColorRamps()
+{
+  QSize rampIconSize(50,16);
+  cboGraduatedColorRamp->setIconSize(rampIconSize);
+  QStringList rampNames = mStyle->colorRampNames();
+  for (QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it)
+  {
+    QgsVectorColorRampV2* ramp = mStyle->colorRamp(*it);
+    cboGraduatedColorRamp->addItem( QgsSymbolLayerV2Utils::colorRampPreviewIcon(ramp, rampIconSize), *it);
+    delete ramp;
+  }
+}
+
+void QgsRendererV2PropertiesDialog::classifyGraduated()
+{
+  int idx = mLayer->dataProvider()->fieldNameIndex(cboGraduatedColumn->currentText());
+  
+  int classes = spinGraduatedClasses->value();
+  
+  QgsVectorColorRampV2* ramp = mStyle->colorRamp( cboGraduatedColorRamp->currentText() );
+  
+  QgsGraduatedSymbolRendererV2::Mode mode;
+  if (cboGraduatedMode->currentIndex() == 0)
+    mode = QgsGraduatedSymbolRendererV2::EqualInterval;
+  else
+    mode = QgsGraduatedSymbolRendererV2::Quantile;
+  
+  // create and set new renderer
+  QgsGraduatedSymbolRendererV2* r = QgsGraduatedSymbolRendererV2::createRenderer(
+      mLayer, idx, classes, mode, mGraduatedSymbol, ramp);
+  r->setMode(mode);
+  
+  mLayer->setRendererV2(r);
+  
+  populateRanges();
+}
+
+void QgsRendererV2PropertiesDialog::changeGraduatedSymbol()
+{
+  QgsSymbolV2SelectorDialog dlg(mGraduatedSymbol, mStyle, this);
+  if (!dlg.exec())
+    return;
+  
+  updateGraduatedSymbolIcon();
+}
+
+void QgsRendererV2PropertiesDialog::updateGraduatedSymbolIcon()
+{
+  QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(mGraduatedSymbol, btnChangeGraduatedSymbol->iconSize());
+  btnChangeGraduatedSymbol->setIcon(icon);
+}
+
+void QgsRendererV2PropertiesDialog::populateRanges()
+{
+
+  QStandardItemModel* m = qobject_cast<QStandardItemModel*>(viewGraduated->model());
+  m->clear();
+  
+  QStringList labels;
+  labels << "Range" << "Label";
+  m->setHorizontalHeaderLabels(labels);
+  
+  QSize iconSize(16,16);
+  
+  QgsGraduatedSymbolRendererV2* r = rendererGraduated();
+  int i, count = r->ranges().count();
+  
+  for (i = 0; i < count; i++)
+  {
+    const QgsRendererRangeV2& range = r->ranges()[i];
+    QString rangeStr = QString::number(range.lowerValue(),'f',4) + " - " + QString::number(range.upperValue(),'f',4);
+    
+    QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(range.symbol(), iconSize);
+    QStandardItem* item = new QStandardItem(icon, rangeStr);
+    //item->setData(k); // set attribute value as user role
+    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+    
+    QList<QStandardItem *> list;
+    list << item << new QStandardItem(range.label());
+    m->appendRow( list );
+  }
+
+  // make sure that the "range" column has visible context
+  viewGraduated->resizeColumnToContents(0);
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsrendererv2propertiesdialog.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,76 @@
+
+#ifndef QGSRENDERERV2PROPERTIESDIALOG_H
+#define QGSRENDERERV2PROPERTIESDIALOG_H
+
+#include "ui_qgsrendererv2propsdialogbase.h"
+
+class QgsVectorLayer;
+class QgsStyleV2;
+class QgsSymbolV2;
+class QgsSingleSymbolRendererV2;
+class QgsCategorizedSymbolRendererV2;
+class QgsGraduatedSymbolRendererV2;
+
+class QgsRendererV2PropertiesDialog : public QDialog, private Ui::QgsRendererV2PropsDialogBase
+{
+  Q_OBJECT
+
+public:
+  QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL);
+  ~QgsRendererV2PropertiesDialog();
+  
+public slots:
+  void changeSingleSymbol();
+  void updateRenderer();
+  
+  void categoryColumnChanged();
+  void categoriesDoubleClicked(const QModelIndex & idx);
+  void addCategories();
+  void deleteCategory();
+  void deleteAllCategories();
+
+  void changeGraduatedSymbol();
+  void classifyGraduated();
+
+protected:
+  
+  //! update UI to reflect changes in renderer
+  void updateUiFromRenderer();
+  
+  void updateSingleSymbolIcon();
+  void updateGraduatedSymbolIcon();
+ 
+  //! create default symbol for the layer's geometry type (point/line/polygon)
+  QgsSymbolV2* createDefaultSymbol();
+  
+  //! populate categories view
+  void populateCategories();
+  
+  //! populate column combos in categorized and graduated page
+  void populateColumns();
+  
+  //! populate ranges of graduated symbol renderer
+  void populateRanges();
+  
+  void populateColorRamps();
+
+  //! return row index for the currently selected category (-1 if on no selection)
+  int currentCategoryRow();
+  
+  //! return key for the currently selected category
+  QVariant currentCategory();
+  
+  void changeCategorySymbol();
+  
+  QgsSingleSymbolRendererV2* rendererSingle();
+  QgsCategorizedSymbolRendererV2* rendererCategorized();
+  QgsGraduatedSymbolRendererV2* rendererGraduated();
+  
+  QgsVectorLayer* mLayer;
+  
+  QgsStyleV2* mStyle;
+  
+  QgsSymbolV2* mGraduatedSymbol;
+};
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,364 @@
+
+#include "qgsstylev2managerdialog.h"
+
+#include "qgsstylev2.h"
+#include "qgssymbolv2.h"
+#include "qgssymbollayerv2utils.h"
+#include "qgsvectorcolorrampv2.h"
+
+#include "qgssymbolv2propertiesdialog.h"
+#include "qgsvectorgradientcolorrampv2dialog.h"
+
+#include <QFile>
+#include <QInputDialog>
+#include <QStandardItemModel>
+
+#include "qgsapplication.h"
+
+
+static QString iconPath(QString iconFile)
+{
+  // try active theme
+  QString path = QgsApplication::activeThemePath();
+  if ( QFile::exists( path + iconFile ) )
+    return path + iconFile;
+
+  // use default theme
+  return QgsApplication::defaultThemePath() + iconFile;
+}
+
+///////
+
+QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog(QgsStyleV2* style, QWidget* parent)
+  : QDialog(parent), mStyle(style)
+{
+
+  setupUi(this);
+
+  // setup icons
+  btnAddItem->setIcon( QIcon( iconPath( "symbologyAdd.png" ) ) );
+  btnEditItem->setIcon( QIcon( iconPath( "symbologyEdit.png" ) ) );
+  btnRemoveItem->setIcon( QIcon( iconPath( "symbologyRemove.png" ) ) );
+
+  connect(this, SIGNAL(finished(int)), this, SLOT(onFinished()));
+  
+  connect(listItems, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(editItem()));
+  
+  connect(btnAddItem, SIGNAL(clicked()), this, SLOT(addItem()));
+  connect(btnEditItem, SIGNAL(clicked()), this, SLOT(editItem()));
+  connect(btnRemoveItem, SIGNAL(clicked()), this, SLOT(removeItem()));
+
+  QStandardItemModel* model = new QStandardItemModel(listItems);
+  listItems->setModel(model);
+  
+  populateTypes();
+  
+  connect(cboItemType, SIGNAL(currentIndexChanged(int)), this, SLOT(populateList()));
+  
+  populateList();
+
+}
+
+void QgsStyleV2ManagerDialog::onFinished()
+{
+  // TODO: if modified, save the changes
+}
+
+void QgsStyleV2ManagerDialog::populateTypes()
+{
+  // save current selection index in types combo
+  int current = (cboItemType->count() > 0 ? cboItemType->currentIndex() : 0);
+
+  int markerCount = 0, lineCount = 0, fillCount = 0;
+  
+  QStringList symbolNames = mStyle->symbolNames();
+  for (int i = 0; i < symbolNames.count(); ++i)
+  {
+    switch (mStyle->symbolRef(symbolNames[i])->type())
+    {
+      case QgsSymbolV2::Marker: markerCount++; break;
+      case QgsSymbolV2::Line: lineCount++; break;
+      case QgsSymbolV2::Fill: fillCount++; break;
+      default: Q_ASSERT(0 && "unknown symbol type"); break;
+    }
+  }
+    
+  cboItemType->clear();
+  cboItemType->addItem(QString("Marker symbol (%1)").arg(markerCount), QVariant(QgsSymbolV2::Marker));
+  cboItemType->addItem(QString("Line symbol (%1)").arg(lineCount), QVariant(QgsSymbolV2::Line));
+  cboItemType->addItem(QString("Fill symbol (%1)").arg(fillCount), QVariant(QgsSymbolV2::Fill));
+    
+  cboItemType->addItem(QString("Color ramp (%1)").arg(mStyle->colorRampCount()), QVariant(3));
+  
+  // update current index to previous selection
+  cboItemType->setCurrentIndex(current);
+
+}
+
+void QgsStyleV2ManagerDialog::populateList()
+{
+  // get current symbol type
+  int itemType = currentItemType();
+  
+  if (itemType < 3)
+    populateSymbols(itemType);
+  else
+    populateColorRamps();
+}
+
+void QgsStyleV2ManagerDialog::populateSymbols(int type)
+{
+  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(listItems->model());
+  model->clear();
+  
+  QStringList symbolNames = mStyle->symbolNames();
+  
+  for (int i = 0; i < symbolNames.count(); ++i)
+  {
+    QString name = symbolNames[i];
+    QgsSymbolV2* symbol = mStyle->symbol(name);
+    if (symbol->type() == type)
+    {
+      QStandardItem* item = new QStandardItem(name);
+      QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(symbol, listItems->iconSize());
+      item->setIcon(icon);
+      // add to model
+      model->appendRow(item);
+    }
+    delete symbol;
+  }
+
+}
+
+void QgsStyleV2ManagerDialog::populateColorRamps()
+{
+  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(listItems->model());
+  model->clear();
+  
+  QStringList colorRamps = mStyle->colorRampNames();
+  
+  for (int i = 0; i < colorRamps.count(); ++i)
+  {
+    QString name = colorRamps[i];
+    QgsVectorColorRampV2* ramp = mStyle->colorRamp(name);
+    
+    QStandardItem* item = new QStandardItem(name);
+    QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon(ramp, listItems->iconSize());
+    item->setIcon(icon);
+    model->appendRow(item);
+    delete ramp;
+  }
+}
+
+int QgsStyleV2ManagerDialog::currentItemType()
+{
+  int idx = cboItemType->currentIndex();
+  return cboItemType->itemData(idx).toInt();
+}
+
+QString QgsStyleV2ManagerDialog::currentItemName()
+{
+  QModelIndex index = listItems->selectionModel()->currentIndex();
+  if (!index.isValid())
+    return QString();
+  return index.model()->data(index, 0).toString();
+}
+
+void QgsStyleV2ManagerDialog::addItem()
+{
+  if (currentItemType() < 3)
+    addSymbol();
+  else if (currentItemType() == 3)
+    addColorRamp();
+  else
+    Q_ASSERT(0 && "not implemented");
+  
+  populateList();
+  populateTypes();
+}
+
+bool QgsStyleV2ManagerDialog::addSymbol()
+{
+  // create new symbol with current type
+  QgsSymbolV2* symbol;
+  switch (currentItemType())
+  {
+    case QgsSymbolV2::Marker: symbol = new QgsMarkerSymbolV2(); break;
+    case QgsSymbolV2::Line:   symbol = new QgsLineSymbolV2(); break;
+    case QgsSymbolV2::Fill:   symbol = new QgsFillSymbolV2(); break;
+    default: Q_ASSERT(0 && "unknown symbol type"); break;
+  }
+  
+  // get symbol design
+  QgsSymbolV2PropertiesDialog dlg(symbol, this);
+  if (dlg.exec() == 0)
+  {
+    delete symbol;
+    return false;
+  }
+  
+  // get name
+  bool ok;
+  QString name = QInputDialog::getText(this, "Symbol name",
+          "Please enter name for new symbol:", QLineEdit::Normal, "new symbol", &ok);
+  if (!ok || name.isEmpty())
+  {
+    delete symbol;
+    return false;
+  }
+  
+  // add new symbol to style and re-populate the list
+  mStyle->addSymbol(name, symbol);
+  return true;
+}
+
+bool QgsStyleV2ManagerDialog::addColorRamp()
+{
+  // TODO: random color ramp
+/*
+  QStringList rampTypes;
+  rampTypes << "Gradient" << "Random";
+  bool ok;
+  QString rampType = QInputDialog.getItem(this, "Color ramp type",
+        "Please select color ramp type:", rampTypes, 0, false, &ok);
+  if (!ok || rampType.isEmpty())
+    return false;
+*/
+  QString rampType = "Gradient";
+  
+  QgsVectorColorRampV2* ramp;
+  if (rampType == "Gradient")
+  {
+    QgsVectorGradientColorRampV2* gradRamp = new QgsVectorGradientColorRampV2();
+    QgsVectorGradientColorRampV2Dialog dlg(gradRamp, this);
+    if (!dlg.exec())
+    {
+      delete gradRamp;
+      return false;
+    }
+    ramp = gradRamp;
+  }
+  else
+  {
+    /*
+    QgsVectorRandomColorRampV2* randRamp = new QgsVectorRandomColorRampV2();
+    DlgRandomColorRamp dlg(randRamp, this);
+    if (!dlg.exec())
+    {
+      delete randRamp;
+      return false;
+    }
+    ramp = randRamp;
+    */
+  }
+  
+  // get name
+  bool ok;
+  QString name = QInputDialog::getText(this, "Color ramp name",
+       "Please enter name for new color ramp:", QLineEdit::Normal, "new color ramp", &ok);
+  if (!ok || name.isEmpty())
+  {
+    delete ramp;
+    return false;
+  }
+  
+  // add new symbol to style and re-populate the list
+  mStyle->addColorRamp(name, ramp);
+  return true;
+}
+
+
+void QgsStyleV2ManagerDialog::editItem()
+{
+  if (currentItemType() < 3)
+    editSymbol();
+  else if (currentItemType() == 3)
+    editColorRamp();
+  else
+    Q_ASSERT(0 && "not implemented");
+  
+  populateList();
+}
+
+bool QgsStyleV2ManagerDialog::editSymbol()
+{
+  QString symbolName = currentItemName();
+  if (symbolName.isEmpty())
+    return false;
+  
+  QgsSymbolV2* symbol = mStyle->symbol(symbolName);
+  
+  // let the user edit the symbol and update list when done
+  QgsSymbolV2PropertiesDialog dlg(symbol, this);
+  if (dlg.exec() == 0)
+  {
+    delete symbol;
+    return false;
+  }
+  
+  // by adding symbol to style with the same name the old effectively gets overwritten
+  mStyle->addSymbol(symbolName, symbol);
+  return true;
+}
+
+bool QgsStyleV2ManagerDialog::editColorRamp()
+{
+  QString name = currentItemName();
+  if (name.isEmpty())
+    return false;
+  
+  QgsVectorColorRampV2* ramp = mStyle->colorRamp(name);
+  
+  if (ramp->type() == "gradient")
+  {
+    QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>(ramp);
+    QgsVectorGradientColorRampV2Dialog dlg(gradRamp, this);
+    if (!dlg.exec())
+    {
+      delete ramp;
+      return false;
+    }
+  }
+  else
+  {
+    // TODO: random color ramp
+    //dlg = DlgRandomColorRamp(ramp, self)
+  }
+  
+  mStyle->addColorRamp(name, ramp);
+  return true;
+}
+
+
+void QgsStyleV2ManagerDialog::removeItem()
+{
+  if (currentItemType() < 3)
+    removeSymbol();
+  else if (currentItemType() == 3)
+    removeColorRamp();
+  else
+    Q_ASSERT(0 && "not implemented");
+  
+  populateList();
+  populateTypes();
+}
+
+bool QgsStyleV2ManagerDialog::removeSymbol()
+{
+  QString symbolName = currentItemName();
+  if (symbolName.isEmpty())
+    return false;
+  
+  // delete from style and update list
+  mStyle->removeSymbol(symbolName);
+  return true;
+}
+
+bool QgsStyleV2ManagerDialog::removeColorRamp()
+{
+  QString rampName = currentItemName();
+  if (rampName.isEmpty())
+    return false;
+  
+  mStyle->removeColorRamp(rampName);
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsstylev2managerdialog.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,56 @@
+
+#ifndef QGSSTYLEV2MANAGERDIALOG_H
+#define QGSSTYLEV2MANAGERDIALOG_H
+
+#include <QDialog>
+
+#include "ui_qgsstylev2managerdialogbase.h"
+
+class QgsStyleV2;
+
+class QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV2ManagerDialogBase
+{
+  Q_OBJECT
+  
+public:
+  QgsStyleV2ManagerDialog(QgsStyleV2* style, QWidget* parent = NULL);
+  
+public slots:
+  void addItem();
+  void editItem();
+  void removeItem();
+  //! adds symbols of some type to list
+  void populateList();
+  
+  //! called when the dialog is going to be closed
+  void onFinished();
+
+protected:
+  
+  //! populate combo box with known style items (symbols, color ramps)
+  void populateTypes();
+  
+  //! populate list view with symbols of specified type
+  void populateSymbols(int type);
+  //! populate list view with color ramps
+  void populateColorRamps();
+  
+  int currentItemType();
+  QString currentItemName();
+  
+  //! add a new symbol to style
+  bool addSymbol();
+  //! add a new color ramp to style
+  bool addColorRamp();
+  
+  bool editSymbol();
+  bool editColorRamp();
+  
+  bool removeSymbol();
+  bool removeColorRamp();
+  
+  QgsStyleV2* mStyle;
+
+};
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,445 @@
+
+#include "qgssymbollayerv2widget.h"
+
+#include "qgslinesymbollayerv2.h"
+#include "qgsmarkersymbollayerv2.h"
+#include "qgsfillsymbollayerv2.h"
+
+#include "qgssymbolv2propertiesdialog.h"
+
+#include "qgsapplication.h"
+
+#include <QAbstractButton>
+#include <QColorDialog>
+#include <QDir>
+#include <QPainter>
+#include <QStandardItemModel>
+#include <QSvgRenderer>
+
+static void updateColorButton(QAbstractButton* button, QColor color)
+{
+	QPixmap p(20,20);
+	p.fill(color);
+	button->setIcon(QIcon(p));
+}
+
+//////////
+
+QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget(QWidget* parent)
+  : QgsSymbolLayerV2Widget(parent)
+{
+  mLayer = NULL;
+  
+  setupUi(this);
+  
+  connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(penWidthChanged()));
+  connect(btnChangeColor, SIGNAL(clicked()), this, SLOT(colorChanged()));
+  connect(cboPenStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(penStyleChanged()));
+}
+
+void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
+{
+  if (layer->layerType() != "SimpleLine")
+    return;
+  
+  // layer type is correct, we can do the cast
+  mLayer = static_cast<QgsSimpleLineSymbolLayerV2*>(layer);
+
+  // set values
+  spinWidth->setValue(mLayer->width());
+  updateColorButton(btnChangeColor, mLayer->color());
+  cboPenStyle->setPenStyle(mLayer->penStyle());
+}
+
+QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2Widget::symbolLayer()
+{
+  return mLayer;
+}
+
+void QgsSimpleLineSymbolLayerV2Widget::penWidthChanged()
+{
+  mLayer->setWidth(spinWidth->value());
+  emit changed();
+}
+
+void QgsSimpleLineSymbolLayerV2Widget::colorChanged()
+{
+  QColor color = QColorDialog::getColor(mLayer->color(), this);
+  if (!color.isValid())
+    return;
+  mLayer->setColor(color);
+  updateColorButton(btnChangeColor, mLayer->color());
+  emit changed();
+}
+
+void QgsSimpleLineSymbolLayerV2Widget::penStyleChanged()
+{
+  mLayer->setPenStyle(cboPenStyle->penStyle());
+  emit changed();
+}
+
+
+///////////
+
+
+QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget(QWidget* parent)
+  : QgsSymbolLayerV2Widget(parent)
+{
+  mLayer = NULL;
+  
+  setupUi(this);
+  
+  QSize size = lstNames->iconSize();
+  QStringList names;
+  names << "circle" << "rectangle" << "diamond" << "pentagon" << "cross" << "cross2" << "triangle"
+        << "equilateral_triangle" << "star" << "regular_star" << "arrow";
+  double markerSize = size.width()-1; // keep some space around
+  for (int i = 0; i < names.count(); ++i)
+  {
+    QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2(names[i], QColor(200,200,200), QColor(0,0,0), markerSize);
+    QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon(lyr, size);
+    QListWidgetItem* item = new QListWidgetItem(icon, QString(), lstNames);
+    item->setData(Qt::UserRole, names[i]);
+    delete lyr;
+  }
+
+  connect(lstNames, SIGNAL(currentRowChanged(int)), this, SLOT(setName()));
+  connect(btnChangeColorBorder, SIGNAL(clicked()), this, SLOT(setColorBorder()));
+  connect(btnChangeColorFill, SIGNAL(clicked()), this, SLOT(setColorFill()));
+  connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setSize()));
+  connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setAngle()));
+}
+
+void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
+{
+  if (layer->layerType() != "SimpleMarker")
+    return;
+  
+  // layer type is correct, we can do the cast
+  mLayer = static_cast<QgsSimpleMarkerSymbolLayerV2*>(layer);
+  
+  // set values
+  QString name = mLayer->name();
+  for (int i = 0; i < lstNames->count(); ++i)
+  {
+    if (lstNames->item(i)->data(Qt::UserRole).toString() == name)
+    {
+      lstNames->setCurrentRow(i);
+      break;
+    }
+  }
+  updateColorButton(btnChangeColorBorder, mLayer->borderColor());
+  updateColorButton(btnChangeColorFill, mLayer->color());
+  spinSize->setValue(mLayer->size());
+  spinAngle->setValue(mLayer->angle());
+}
+
+QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2Widget::symbolLayer()
+{
+  return mLayer;
+}
+
+void QgsSimpleMarkerSymbolLayerV2Widget::setName()
+{
+  mLayer->setName(lstNames->currentItem()->data(Qt::UserRole).toString());
+  emit changed();
+}
+
+void QgsSimpleMarkerSymbolLayerV2Widget::setColorBorder()
+{
+  QColor borderColor = QColorDialog::getColor(mLayer->borderColor(), this);
+  if (!borderColor.isValid())
+    return;
+  mLayer->setBorderColor(borderColor);
+  updateColorButton(btnChangeColorBorder, mLayer->borderColor());
+  emit changed();
+}
+
+void QgsSimpleMarkerSymbolLayerV2Widget::setColorFill()
+{
+  QColor color = QColorDialog::getColor(mLayer->color(), this);
+  if (!color.isValid())
+    return;
+  mLayer->setColor(color);
+  updateColorButton(btnChangeColorFill, mLayer->color());
+  emit changed();
+}
+
+void QgsSimpleMarkerSymbolLayerV2Widget::setSize()
+{
+  mLayer->setSize(spinSize->value());
+  emit changed();
+}
+  
+void QgsSimpleMarkerSymbolLayerV2Widget::setAngle()
+{
+  mLayer->setAngle(spinAngle->value());
+  emit changed();
+}
+
+
+///////////
+
+QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget(QWidget* parent)
+  : QgsSymbolLayerV2Widget(parent)
+{
+  mLayer = NULL;
+  
+  setupUi(this);
+  
+  connect(btnChangeColor, SIGNAL(clicked()), this, SLOT(setColor()));
+  connect(btnChangeBorderColor, SIGNAL(clicked()), this, SLOT(setBorderColor()));
+  connect(cboFillStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(setBrushStyle()));
+}
+
+void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
+{
+  if (layer->layerType() != "SimpleFill")
+    return;
+  
+  // layer type is correct, we can do the cast
+  mLayer = static_cast<QgsSimpleFillSymbolLayerV2*>(layer);
+  
+  // set values
+  updateColorButton(btnChangeColor, mLayer->color());
+  updateColorButton(btnChangeBorderColor, mLayer->borderColor());
+  cboFillStyle->setBrushStyle(mLayer->brushStyle());
+}
+
+QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2Widget::symbolLayer()
+{
+  return mLayer;
+}
+
+void QgsSimpleFillSymbolLayerV2Widget::setColor()
+{
+  QColor color = QColorDialog::getColor(mLayer->color(), this);
+  if (!color.isValid())
+    return;
+  mLayer->setColor(color);
+  updateColorButton(btnChangeColor, mLayer->color());
+  emit changed();
+}
+
+void QgsSimpleFillSymbolLayerV2Widget::setBorderColor()
+{
+  QColor color = QColorDialog::getColor(mLayer->borderColor(), this);
+  if (!color.isValid())
+    return;
+  mLayer->setBorderColor(color);
+  updateColorButton(btnChangeBorderColor, mLayer->borderColor());
+  emit changed();
+}
+
+void QgsSimpleFillSymbolLayerV2Widget::setBrushStyle()
+{
+  mLayer->setBrushStyle(cboFillStyle->brushStyle());
+  emit changed();
+}
+
+///////////
+
+QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget(QWidget* parent)
+  : QgsSymbolLayerV2Widget(parent)
+{
+  mLayer = NULL;
+  
+  setupUi(this);
+  
+  connect(spinInterval, SIGNAL(valueChanged(int)), this, SLOT(setInterval(int)));
+  connect(btnChangeMarker, SIGNAL(clicked()), this, SLOT(setMarker()));
+  connect(chkRotateMarker, SIGNAL(clicked()), this, SLOT(setRotate()));
+}
+
+void QgsMarkerLineSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
+{
+  if (layer->layerType() != "MarkerLine")
+    return;
+  
+  // layer type is correct, we can do the cast
+  mLayer = static_cast<QgsMarkerLineSymbolLayerV2*>(layer);
+  
+  // set values
+  spinInterval->setValue( (int) mLayer->interval());
+  chkRotateMarker->setChecked(mLayer->rotateMarker());
+  updateMarker();
+}
+
+QgsSymbolLayerV2* QgsMarkerLineSymbolLayerV2Widget::symbolLayer()
+{
+  return mLayer;
+}
+
+void QgsMarkerLineSymbolLayerV2Widget::setInterval(int val)
+{
+  mLayer->setInterval(val);
+  emit changed();
+}
+
+void QgsMarkerLineSymbolLayerV2Widget::setMarker()
+{
+  QgsSymbolV2PropertiesDialog dlg(mLayer->subSymbol(), this);
+  if (dlg.exec() == 0)
+    return;
+  updateMarker();
+
+  emit changed();
+}
+
+void QgsMarkerLineSymbolLayerV2Widget::setRotate()
+{
+  mLayer->setRotateMarker(chkRotateMarker->isChecked());
+  emit changed();
+}
+
+void QgsMarkerLineSymbolLayerV2Widget::updateMarker()
+{
+  QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(mLayer->subSymbol(), btnChangeMarker->iconSize());
+  btnChangeMarker->setIcon(icon);
+}
+
+
+///////////
+
+
+QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget(QWidget* parent)
+  : QgsSymbolLayerV2Widget(parent)
+{
+  mLayer = NULL;
+  
+  setupUi(this);
+  
+  populateList();
+  
+  connect(viewImages->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(setName(const QModelIndex&)));
+  connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setSize()));
+  connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setAngle()));
+}
+
+void QgsSvgMarkerSymbolLayerV2Widget::populateList()
+{
+  QStandardItemModel* m = new QStandardItemModel(viewImages);
+  viewImages->setModel(m);
+  
+  QString svgPath = QgsApplication::svgPath();
+  QSvgRenderer renderer;
+  QPainter painter;
+  
+  QDir dir( svgPath );
+
+  QStringList dl = dir.entryList( QDir::Dirs );
+
+  for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it )
+  {
+    if ( *it == "." || *it == ".." ) continue;
+
+    QDir dir2( svgPath + *it );
+
+    QStringList dl2 = dir2.entryList( QStringList( "*.svg" ), QDir::Files );
+
+    for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 )
+    {
+      // TODO test if it is correct SVG
+      QString entry = *it2;
+    
+      // render SVG file
+      renderer.load( dir2.filePath( *it2 ) );
+      QPixmap pixmap(renderer.defaultSize());
+      pixmap.fill();
+      painter.begin(&pixmap);
+      renderer.render(&painter);
+      painter.end();
+    
+      // add item
+      QStandardItem* item = new QStandardItem(QIcon(pixmap), *it + "/" + entry);
+      m->appendRow(item);
+    }
+  }
+  
+}
+
+void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
+{
+  if (layer->layerType() != "SvgMarker")
+    return;
+  
+  // layer type is correct, we can do the cast
+  mLayer = static_cast<QgsSvgMarkerSymbolLayerV2*>(layer);
+  
+  // set values
+  
+  QStandardItemModel* m = static_cast<QStandardItemModel*>(viewImages->model());
+  QList<QStandardItem*> items = m->findItems(mLayer->name());
+  if (items.count() > 0)
+  {
+    QModelIndex idx = items[0]->index();
+    viewImages->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent);
+  }
+  
+  spinSize->setValue(mLayer->size());
+  spinAngle->setValue(mLayer->angle());
+}
+
+QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2Widget::symbolLayer()
+{
+  return mLayer;
+}
+
+void QgsSvgMarkerSymbolLayerV2Widget::setName(const QModelIndex& idx)
+{
+  mLayer->setName(idx.data().toString());
+
+  //mLayer->setName(lstNames->currentItem()->data(Qt::UserRole).toString());
+  emit changed();
+}
+
+void QgsSvgMarkerSymbolLayerV2Widget::setSize()
+{
+  mLayer->setSize(spinSize->value());
+  emit changed();
+}
+  
+void QgsSvgMarkerSymbolLayerV2Widget::setAngle()
+{
+  mLayer->setAngle(spinAngle->value());
+  emit changed();
+}
+
+///////////////
+
+QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget(QWidget* parent)
+  : QgsSymbolLayerV2Widget(parent)
+{
+  mLayer = NULL;
+  
+  setupUi(this);
+  
+  connect(btnChangeColor, SIGNAL(clicked()), this, SLOT(colorChanged()));
+}
+
+void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
+{
+  if (layer->layerType() != "LineDecoration")
+    return;
+  
+  // layer type is correct, we can do the cast
+  mLayer = static_cast<QgsLineDecorationSymbolLayerV2*>(layer);
+
+  // set values
+  updateColorButton(btnChangeColor, mLayer->color());
+}
+
+QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer()
+{
+  return mLayer;
+}
+
+void QgsLineDecorationSymbolLayerV2Widget::colorChanged()
+{
+  QColor color = QColorDialog::getColor(mLayer->color(), this);
+  if (!color.isValid())
+    return;
+  mLayer->setColor(color);
+  updateColorButton(btnChangeColor, mLayer->color());
+  emit changed();
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbollayerv2widget.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,203 @@
+
+#ifndef QGSSYMBOLLAYERV2WIDGET_H
+#define QGSSYMBOLLAYERV2WIDGET_H
+
+#include <QWidget>
+
+class QgsSymbolLayerV2;
+
+
+class QgsSymbolLayerV2Widget : public QWidget
+{
+  Q_OBJECT
+  
+  public:
+    QgsSymbolLayerV2Widget(QWidget* parent) : QWidget(parent) {}
+    
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer) = 0;
+    virtual QgsSymbolLayerV2* symbolLayer() = 0;
+    
+  signals:
+    void changed();
+};
+
+///////////
+
+#include "ui_widget_simpleline.h"
+
+class QgsSimpleLineSymbolLayerV2;
+
+class QgsSimpleLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSimpleLine
+{
+  Q_OBJECT
+  
+  public:
+    QgsSimpleLineSymbolLayerV2Widget(QWidget* parent = NULL);
+    
+    static QgsSymbolLayerV2Widget* create() { return new QgsSimpleLineSymbolLayerV2Widget(); }
+    
+    // from base class
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
+    virtual QgsSymbolLayerV2* symbolLayer();
+  
+  public slots:
+    void penWidthChanged();
+    void colorChanged();
+    void penStyleChanged();
+    
+  protected:
+    QgsSimpleLineSymbolLayerV2* mLayer;
+};
+
+///////////
+
+#include "ui_widget_simplemarker.h"
+
+class QgsSimpleMarkerSymbolLayerV2;
+
+class QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSimpleMarker
+{
+  Q_OBJECT
+  
+  public:
+    QgsSimpleMarkerSymbolLayerV2Widget(QWidget* parent = NULL);
+    
+    static QgsSymbolLayerV2Widget* create() { return new QgsSimpleMarkerSymbolLayerV2Widget(); }
+    
+    // from base class
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
+    virtual QgsSymbolLayerV2* symbolLayer();
+    
+  public slots:
+    void setName();
+    void setColorBorder();
+    void setColorFill();
+    void setSize();
+    void setAngle();
+    
+  protected:
+    QgsSimpleMarkerSymbolLayerV2* mLayer;
+};
+
+///////////
+
+#include "ui_widget_simplefill.h"
+
+class QgsSimpleFillSymbolLayerV2;
+
+class QgsSimpleFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSimpleFill
+{
+  Q_OBJECT
+  
+  public:
+    QgsSimpleFillSymbolLayerV2Widget(QWidget* parent = NULL);
+    
+    static QgsSymbolLayerV2Widget* create() { return new QgsSimpleFillSymbolLayerV2Widget(); }
+    
+    // from base class
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
+    virtual QgsSymbolLayerV2* symbolLayer();
+    
+  public slots:
+    void setColor();
+    void setBorderColor();
+    void setBrushStyle();
+    
+  protected:
+    QgsSimpleFillSymbolLayerV2* mLayer;
+};
+
+
+///////////
+
+#include "ui_widget_markerline.h"
+
+class QgsMarkerLineSymbolLayerV2;
+
+class QgsMarkerLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetMarkerLine
+{
+  Q_OBJECT
+  
+  public:
+    QgsMarkerLineSymbolLayerV2Widget(QWidget* parent = NULL);
+    
+    static QgsSymbolLayerV2Widget* create() { return new QgsMarkerLineSymbolLayerV2Widget(); }
+    
+    // from base class
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
+    virtual QgsSymbolLayerV2* symbolLayer();
+    
+  public slots:
+    
+    void setInterval(int val);
+    void setMarker();
+    void setRotate();
+    
+  protected:
+    
+    void updateMarker();
+    
+    QgsMarkerLineSymbolLayerV2* mLayer;
+};
+
+
+///////////
+
+#include "ui_widget_svgmarker.h"
+
+class QgsSvgMarkerSymbolLayerV2;
+
+class QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSvgMarker
+{
+  Q_OBJECT
+  
+  public:
+    QgsSvgMarkerSymbolLayerV2Widget(QWidget* parent = NULL);
+    
+    static QgsSymbolLayerV2Widget* create() { return new QgsSvgMarkerSymbolLayerV2Widget(); }
+    
+    // from base class
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
+    virtual QgsSymbolLayerV2* symbolLayer();
+    
+  public slots:
+    void setName(const QModelIndex& idx);
+    void setSize();
+    void setAngle();
+    
+  protected:
+    
+    void populateList();
+    
+    QgsSvgMarkerSymbolLayerV2* mLayer;
+};
+
+
+///////////
+
+#include "ui_widget_linedecoration.h"
+
+class QgsLineDecorationSymbolLayerV2;
+
+class QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetLineDecoration
+{
+  Q_OBJECT
+  
+  public:
+    QgsLineDecorationSymbolLayerV2Widget(QWidget* parent = NULL);
+    
+    static QgsSymbolLayerV2Widget* create() { return new QgsLineDecorationSymbolLayerV2Widget(); }
+    
+    // from base class
+    virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
+    virtual QgsSymbolLayerV2* symbolLayer();
+    
+  public slots:
+    void colorChanged();
+    
+  protected:
+    QgsLineDecorationSymbolLayerV2* mLayer;
+};
+
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,363 @@
+
+#include "qgssymbolv2propertiesdialog.h"
+
+#include <QFile>
+#include <QStandardItem>
+
+#include "qgssymbollayerv2.h"
+#include "qgssymbolv2.h"
+#include "qgssymbollayerv2registry.h"
+
+#include "qgsapplication.h"
+
+#include "qgssymbollayerv2widget.h"
+
+static const int SymbolLayerItemType = QStandardItem::UserType + 1;
+
+class SymbolLayerItem : public QStandardItem
+{
+public:
+  SymbolLayerItem(QgsSymbolLayerV2* layer)
+  {
+    setLayer(layer);
+  }
+  
+  void setLayer(QgsSymbolLayerV2* layer)
+  {
+    mLayer = layer;
+    updatePreview();
+  }
+    
+  void updatePreview()
+  {
+    QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon(mLayer, QSize(16,16));
+    setIcon(icon);
+  }
+  
+  int type() const { return SymbolLayerItemType; }
+    
+  QVariant data(int role) const
+  {
+    if (role == Qt::DisplayRole)
+      return QVariant(mLayer->layerType());
+    if (role == Qt::SizeHintRole)
+      return QVariant(QSize(32,32));
+    if (role == Qt::CheckStateRole)
+      return QVariant(); // could be true/false
+    return QStandardItem::data(role);
+  }
+  
+protected:
+  QgsSymbolLayerV2* mLayer;
+};
+
+//////////
+
+static QString iconPath(QString iconFile)
+{
+  // try active theme
+  QString path = QgsApplication::activeThemePath();
+  if ( QFile::exists( path + iconFile ) )
+    return path + iconFile;
+
+  // use default theme
+  return QgsApplication::defaultThemePath() + iconFile;
+}
+
+//////////
+
+QgsSymbolV2PropertiesDialog::QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent)
+  : QDialog(parent), mSymbol(symbol)
+{
+  setupUi(this);
+
+  // setup icons
+  btnAddLayer->setIcon( QIcon( iconPath( "symbologyAdd.png" ) ) );
+  btnRemoveLayer->setIcon( QIcon( iconPath( "symbologyRemove.png" ) ) );
+  btnLock->setIcon( QIcon( iconPath( "symbologyLock.png" ) ) );
+  btnUp->setIcon( QIcon( iconPath( "symbologyUp.png" ) ) );
+  btnDown->setIcon( QIcon( iconPath( "symbologyDown.png" ) ) );
+
+  // set widget functions
+  // (should be probably moved somewhere else)
+  QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SimpleLine", QgsSimpleLineSymbolLayerV2Widget::create);
+  QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("MarkerLine", QgsMarkerLineSymbolLayerV2Widget::create);
+  QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("LineDecoration", QgsLineDecorationSymbolLayerV2Widget::create);
+  
+  QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SimpleMarker", QgsSimpleMarkerSymbolLayerV2Widget::create);
+  QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create);
+  
+  QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create);
+  
+  loadSymbol();
+  
+  connect(btnUp, SIGNAL(clicked()), this, SLOT(moveLayerUp()));
+  connect(btnDown, SIGNAL(clicked()), this, SLOT(moveLayerDown()));
+  connect(btnAddLayer, SIGNAL(clicked()), this, SLOT(addLayer()));
+  connect(btnRemoveLayer, SIGNAL(clicked()), this, SLOT(removeLayer()));
+  connect(btnLock, SIGNAL(clicked()), this, SLOT(lockLayer()));
+  
+  populateLayerTypes();
+  connect(cboLayerType, SIGNAL(currentIndexChanged(int)), this, SLOT(layerTypeChanged()));
+  
+  loadPropertyWidgets();
+  
+  updateUi();
+  
+  // set first layer as active
+  QModelIndex newIndex = listLayers->model()->index(0,0);
+  listLayers->setCurrentIndex(newIndex);
+}
+
+
+void QgsSymbolV2PropertiesDialog::loadSymbol()
+{
+  QStandardItemModel* model = new QStandardItemModel(this);
+  listLayers->setModel(model);
+  
+  QItemSelectionModel* selModel = listLayers->selectionModel();
+  connect(selModel, SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(layerChanged()));
+  
+  int count = mSymbol->symbolLayerCount();
+  for (int i = 0; i < count; i++)
+  {
+    model->appendRow(new SymbolLayerItem( mSymbol->symbolLayer(i) ));
+  }
+    
+  updatePreview();
+}
+
+
+void QgsSymbolV2PropertiesDialog::populateLayerTypes()
+{
+  QStringList types = QgsSymbolLayerV2Registry::instance()->symbolLayersForType(mSymbol->type());
+
+  cboLayerType->clear();
+  for (int i = 0; i < types.count(); i++)
+    cboLayerType->addItem(types[i]);
+}
+
+
+void QgsSymbolV2PropertiesDialog::updateUi()
+{
+  int row = currentLayerIndex();
+  btnUp->setEnabled( row > 0 );
+  btnDown->setEnabled( row < listLayers->model()->rowCount()-1 && row != -1 );
+  btnRemoveLayer->setEnabled( row != -1 );
+}
+
+void QgsSymbolV2PropertiesDialog::updatePreview()
+{
+  QImage preview = mSymbol->bigSymbolPreviewImage();
+  lblPreview->setPixmap(QPixmap::fromImage(preview));
+}
+
+void QgsSymbolV2PropertiesDialog::updateLayerPreview()
+{
+  // get current layer item and update its icon
+  SymbolLayerItem* item = currentLayerItem();
+  if (item)
+    item->updatePreview();
+  
+  // update also preview of the whole symbol
+  updatePreview();
+}
+
+void QgsSymbolV2PropertiesDialog::updateSymbolLayerWidget(QgsSymbolLayerV2* layer)
+{
+  QString layerType = layer->layerType();
+  
+  // stop updating from the original widget
+  if (stackedWidget->currentWidget() != pageDummy)
+    disconnect(stackedWidget->currentWidget(), SIGNAL(changed()), this, SLOT(updateLayerPreview()));
+  
+  // update active properties widget
+  if (mWidgets.contains(layerType))
+  {
+    stackedWidget->setCurrentWidget(mWidgets[layerType]);
+    mWidgets[layerType]->setSymbolLayer(layer);
+    
+    // start recieving updates from widget
+    connect(mWidgets[layerType], SIGNAL(changed()), this, SLOT(updateLayerPreview()));
+  }
+  else
+  {
+    // use dummy widget instead
+    stackedWidget->setCurrentWidget(pageDummy);
+  }
+}
+
+void QgsSymbolV2PropertiesDialog::loadPropertyWidgets()
+{
+  QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance();
+  
+  QStringList layerTypes = pReg->symbolLayersForType(mSymbol->type());
+  
+  for (int i = 0; i < layerTypes.count(); i++)
+  {
+    QString layerType = layerTypes[i];
+    QgsSymbolLayerV2WidgetFunc f = pReg->symbolLayerMetadata(layerType).widgetFunction();
+    if (f == NULL) // check whether the function is assigned
+      continue;
+    
+    QgsSymbolLayerV2Widget* w = f();
+    if (w == NULL) // check whether the function returns correct widget
+      continue;
+    
+    mWidgets[layerType] = w;
+    stackedWidget->addWidget(w);
+  }
+}
+
+int QgsSymbolV2PropertiesDialog::currentLayerIndex()
+{
+  QModelIndex idx = listLayers->selectionModel()->currentIndex();
+  if (!idx.isValid())
+    return -1;
+  return idx.row();
+}
+
+SymbolLayerItem* QgsSymbolV2PropertiesDialog::currentLayerItem()
+{
+  int index = currentLayerIndex();
+  if (index < 0)
+    return NULL;
+  
+  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(listLayers->model());
+  if (model == NULL)
+    return NULL;
+  QStandardItem* item = model->item(index);
+  if (item->type() != SymbolLayerItemType)
+    return NULL;
+  return static_cast<SymbolLayerItem*>(item);
+}
+
+QgsSymbolLayerV2* QgsSymbolV2PropertiesDialog::currentLayer()
+{
+  int idx = currentLayerIndex();
+  if (idx < 0)
+    return NULL;
+  
+  return mSymbol->symbolLayer(idx);
+}
+
+
+void QgsSymbolV2PropertiesDialog::layerChanged()
+{
+  updateUi();
+  
+  // get layer info
+  QgsSymbolLayerV2* layer = currentLayer();
+  if (layer == NULL)
+    return;
+  
+  // update layer type combo box
+  int idx = cboLayerType->findText(layer->layerType());
+  cboLayerType->setCurrentIndex(idx);
+  
+  updateSymbolLayerWidget(layer);
+  
+  updateLockButton();
+}
+
+
+void QgsSymbolV2PropertiesDialog::updateLockButton()
+{
+  QgsSymbolLayerV2* layer = currentLayer();
+  if (layer == NULL) return;
+  
+  btnLock->setChecked(layer->isLocked());
+}
+
+
+void QgsSymbolV2PropertiesDialog::layerTypeChanged()
+{
+  QgsSymbolLayerV2* layer = currentLayer();
+  if (layer == NULL) return;
+  
+  QString newLayerType = cboLayerType->currentText();
+  if (layer->layerType() == newLayerType)
+    return;
+  
+  // get creation function for new layer from registry
+  QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance();
+  QgsSymbolLayerV2CreateFunc f = pReg->symbolLayerMetadata(newLayerType).createFunction();
+  if (f == NULL) // check whether the function is assigned
+    return;
+  
+  // change layer to a new (with different type)
+  QgsSymbolLayerV2* newLayer = f(QgsStringMap());
+  mSymbol->changeSymbolLayer(currentLayerIndex(), newLayer);
+  
+  updateSymbolLayerWidget(newLayer);
+  
+  // update symbol layer item
+  SymbolLayerItem* item = currentLayerItem();
+  item->setLayer(newLayer);
+  item->updatePreview();
+  
+  updatePreview();
+}
+
+
+void QgsSymbolV2PropertiesDialog::addLayer()
+{
+  QgsSymbolLayerV2* newLayer = QgsSymbolLayerV2Registry::instance()->defaultSymbolLayer(mSymbol->type());
+  
+  mSymbol->appendSymbolLayer(newLayer);
+  
+  loadSymbol();
+  
+  QModelIndex newIndex = listLayers->model()->index(0,0);
+  listLayers->setCurrentIndex(newIndex);
+  
+  updateUi();
+}
+
+
+void QgsSymbolV2PropertiesDialog::removeLayer()
+{
+  int idx = currentLayerIndex();
+  if (idx < 0) return;
+  mSymbol->deleteSymbolLayer(idx);
+  
+  loadSymbol();
+  
+  updateUi();
+}
+
+
+void QgsSymbolV2PropertiesDialog::moveLayerDown()
+{
+  moveLayerByOffset(+1);
+}
+
+void QgsSymbolV2PropertiesDialog::moveLayerUp()
+{
+  moveLayerByOffset(-1);
+}
+
+void QgsSymbolV2PropertiesDialog::moveLayerByOffset(int offset)
+{
+  int idx = currentLayerIndex();
+  
+  // switch layers
+  QgsSymbolLayerV2* tmpLayer = mSymbol->takeSymbolLayer(idx);
+  mSymbol->insertSymbolLayer(idx + offset, tmpLayer);
+  
+  loadSymbol();
+  
+  QModelIndex newIndex = listLayers->model()->index(idx + offset,0);
+  listLayers->setCurrentIndex(newIndex);
+  
+  updateUi();
+}
+
+
+void QgsSymbolV2PropertiesDialog::lockLayer()
+{
+  QgsSymbolLayerV2* layer = currentLayer();
+  if (layer == NULL) return;
+  
+  layer->setLocked( btnLock->isChecked() );
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,65 @@
+
+#ifndef QGSSYMBOLV2PROPERTIESDIALOG_H
+#define QGSSYMBOLV2PROPERTIESDIALOG_H
+
+#include "ui_qgssymbolv2propertiesdialogbase.h"
+
+class QgsSymbolV2;
+class QgsSymbolLayerV2;
+class QgsSymbolLayerV2Widget;
+
+class SymbolLayerItem;
+
+#include <QMap>
+
+
+class QgsSymbolV2PropertiesDialog : public QDialog, private Ui::DlgSymbolV2Properties
+{
+  Q_OBJECT
+  
+public:
+  QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent = NULL);
+  
+  
+public slots:
+  void moveLayerDown();
+  void moveLayerUp();
+
+  void addLayer();
+  void removeLayer();
+
+  void lockLayer();
+
+  void layerTypeChanged();
+  
+  void layerChanged();
+
+  void updateLayerPreview();
+  void updatePreview();
+  
+protected:
+  
+  void loadSymbol();
+  
+  void populateLayerTypes();
+  
+  void updateUi();
+  
+  void loadPropertyWidgets();
+  
+  void updateSymbolLayerWidget(QgsSymbolLayerV2* layer);
+  void updateLockButton();
+  
+  int currentLayerIndex();
+  SymbolLayerItem* currentLayerItem();
+  QgsSymbolLayerV2* currentLayer();
+  
+  void moveLayerByOffset(int offset);
+  
+protected: // data
+  QgsSymbolV2* mSymbol;
+  
+  QMap<QString, QgsSymbolLayerV2Widget*> mWidgets;
+};
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,173 @@
+
+#include "qgssymbolv2selectordialog.h"
+
+#include "qgssymbolv2propertiesdialog.h"
+
+#include "qgssymbolv2.h"
+#include "qgssymbollayerv2utils.h"
+#include "qgsstylev2.h"
+
+#include <QColorDialog>
+#include <QPainter>
+#include <QStandardItemModel>
+
+QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent)
+  : QDialog(parent)
+{
+  mStyle = style;
+  mSymbol = symbol;
+  
+  setupUi(this);
+  
+  connect(btnSymbolProperties, SIGNAL(clicked()), this, SLOT(changeSymbolProperties()));
+
+
+  QStandardItemModel* model = new QStandardItemModel(viewSymbols);
+  viewSymbols->setModel(model);
+  connect(viewSymbols, SIGNAL(clicked(const QModelIndex &)), this, SLOT(setSymbolFromStyle(const QModelIndex &)));
+
+  populateSymbolView();
+  updateSymbolPreview();
+  updateSymbolInfo();
+  
+  // select correct page in stacked widget
+  // there's a correspondence between symbol type number and page numbering => exploit it!
+  stackedWidget->setCurrentIndex(symbol->type());
+  
+  connect(btnSetColor, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
+  connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setMarkerAngle(double)));
+  connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setMarkerSize(int)));
+  connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(setLineWidth(int)));
+
+}
+
+void QgsSymbolV2SelectorDialog::populateSymbolView()
+{	
+  QSize previewSize = viewSymbols->iconSize();
+  QPixmap p(previewSize);
+  QPainter painter;
+
+  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(viewSymbols->model());
+  if (!model)
+    return;
+  model->clear();
+
+  QStringList names = mStyle->symbolNames();
+  for (int i = 0; i < names.count(); i++)
+  {
+    QgsSymbolV2* s = mStyle->symbol(names[i]);
+    if (s->type() != mSymbol->type())
+    {
+      delete s;
+      continue;
+    }
+    QStandardItem* item = new QStandardItem(names[i]);
+    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+    // create preview icon
+    QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(s, previewSize);
+    item->setIcon(icon);
+    // add to model
+    model->appendRow(item);
+    delete s;
+  }
+}
+
+void QgsSymbolV2SelectorDialog::setSymbolFromStyle(const QModelIndex & index)
+{
+  QString symbolName = index.data().toString();
+  // get new instance of symbol from style
+  QgsSymbolV2* s = mStyle->symbol(symbolName);
+  // remove all symbol layers from original symbol
+  while (mSymbol->symbolLayerCount())
+    mSymbol->deleteSymbolLayer(0);
+  // move all symbol layers to our symbol
+  while (s->symbolLayerCount())
+  {
+    QgsSymbolLayerV2* sl = s->takeSymbolLayer(0);
+    mSymbol->appendSymbolLayer(sl);
+  }
+  // delete the temporary symbol
+  delete s;
+  
+  updateSymbolPreview();
+  updateSymbolInfo();
+}
+
+void QgsSymbolV2SelectorDialog::updateSymbolPreview()
+{
+  QImage preview = mSymbol->bigSymbolPreviewImage();
+  lblPreview->setPixmap(QPixmap::fromImage(preview));
+}
+
+void QgsSymbolV2SelectorDialog::updateSymbolColor()
+{
+  QPixmap p(20,20);
+  p.fill(mSymbol->color());
+  btnSetColor->setIcon(QIcon(p));
+}
+
+void QgsSymbolV2SelectorDialog::updateSymbolInfo()
+{
+  updateSymbolColor();
+  
+  if (mSymbol->type() == QgsSymbolV2::Marker)
+  {
+    QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
+    spinSize->setValue(markerSymbol->size());
+    spinAngle->setValue(markerSymbol->angle());
+  }
+  else if (mSymbol->type() == QgsSymbolV2::Line)
+  {
+    QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>(mSymbol);
+    spinWidth->setValue(lineSymbol->width());
+  }
+}
+
+void QgsSymbolV2SelectorDialog::changeSymbolProperties()
+{
+  QgsSymbolV2PropertiesDialog dlg(mSymbol, this);
+  if (!dlg.exec())
+    return;
+  
+  updateSymbolPreview();
+  updateSymbolInfo();
+}
+
+
+void QgsSymbolV2SelectorDialog::setSymbolColor()
+{
+  QColor color = QColorDialog::getColor(mSymbol->color(), this);
+  if (!color.isValid())
+    return;
+  
+  mSymbol->setColor(color);
+  updateSymbolColor();
+  updateSymbolPreview();
+}
+ 
+void QgsSymbolV2SelectorDialog::setMarkerAngle(double angle)
+{
+  QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
+  if (markerSymbol->angle() == angle)
+    return;
+  markerSymbol->setAngle(angle);
+  updateSymbolPreview();
+}
+
+void QgsSymbolV2SelectorDialog::setMarkerSize(int size)
+{
+  QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
+  if (markerSymbol->size() == size)
+    return;
+  markerSymbol->setSize(size);
+  updateSymbolPreview();
+}
+
+void QgsSymbolV2SelectorDialog::setLineWidth(int width)
+{
+  QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>(mSymbol);
+  if (lineSymbol->width() == width)
+    return;
+  lineSymbol->setWidth(width);
+  updateSymbolPreview();
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgssymbolv2selectordialog.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,39 @@
+
+#ifndef QGSSYMBOLV2SELECTORDIALOG_H
+#define QGSSYMBOLV2SELECTORDIALOG_H
+
+#include <QDialog>
+
+#include "ui_qgssymbolv2selectordialogbase.h"
+
+class QgsStyleV2;
+class QgsSymbolV2;
+
+class QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymbolV2SelectorDialogBase
+{
+  Q_OBJECT
+
+public:
+  QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent = NULL);
+  
+protected:
+  void populateSymbolView();
+  void updateSymbolPreview();
+  void updateSymbolColor();
+  void updateSymbolInfo();
+  
+
+public slots:
+  void changeSymbolProperties();
+  void setSymbolFromStyle(const QModelIndex & index);
+  void setSymbolColor();
+  void setMarkerAngle(double angle);
+  void setMarkerSize(int size);
+  void setLineWidth(int width);
+
+protected:
+  QgsStyleV2* mStyle;
+  QgsSymbolV2* mSymbol;
+};
+
+#endif

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,55 @@
+
+#include "qgsvectorgradientcolorrampv2dialog.h"
+
+#include "qgsvectorcolorrampv2.h"
+
+#include <QColorDialog>
+
+static void updateColorButton(QAbstractButton* button, QColor color)
+{
+  QPixmap p(20,20);
+  p.fill(color);
+  button->setIcon(QIcon(p));
+}
+
+/////////
+
+
+QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2* ramp, QWidget* parent)
+  : QDialog(parent), mRamp(ramp)
+{
+
+  setupUi(this);
+  
+  connect(btnColor1, SIGNAL(clicked()), this, SLOT(setColor1()));
+  connect(btnColor2, SIGNAL(clicked()), this, SLOT(setColor2()));
+  
+  updatePreview();
+}
+
+void QgsVectorGradientColorRampV2Dialog::updatePreview()
+{
+  QSize size(300,40);
+  lblPreview->setPixmap(QgsSymbolLayerV2Utils::colorRampPreviewPixmap(mRamp, size));
+  
+  updateColorButton(btnColor1, mRamp->color1());
+  updateColorButton(btnColor2, mRamp->color2());
+}
+
+void QgsVectorGradientColorRampV2Dialog::setColor1()
+{
+  QColor color = QColorDialog::getColor(mRamp->color1(), this);
+  if (!color.isValid())
+    return;
+  mRamp->setColor1(color);
+  updatePreview();
+}
+
+void QgsVectorGradientColorRampV2Dialog::setColor2()
+{
+  QColor color = QColorDialog::getColor(mRamp->color2(), this);
+  if (!color.isValid())
+    return;
+  mRamp->setColor2(color);
+  updatePreview();
+}

Added: branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.h
===================================================================
--- branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.h	                        (rev 0)
+++ branches/symbology-ng-branch/src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.h	2009-05-12 09:44:09 UTC (rev 10772)
@@ -0,0 +1,29 @@
+
+#ifndef QGSVECTORGRADIENTCOLORRAMPV2DIALOG_H
+#define QGSVECTORGRADIENTCOLORRAMPV2DIALOG_H
+
+#include <QDialog>
+
+#include "ui_qgsvectorgradientcolorrampv2dialogbase.h"
+
+class QgsVectorGradientColorRampV2;
+
+class QgsVectorGradientColorRampV2Dialog : public QDialog, private Ui::QgsVectorGradientColorRampV2DialogBase
+{
+  Q_OBJECT
+      
+public:
+  QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2* ramp, QWidget* parent = NULL);
+  
+public slots:
+  void setColor1();
+  void setColor2();
+  
+protected:
+  
+  void updatePreview();
+  
+  QgsVectorGradientColorRampV2* mRamp;
+};
+
+#endif



More information about the QGIS-commit mailing list