Skip to content
Permalink
Browse files

Corrected renderer assignment in the renderer properties dialog.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11066 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 14, 2009
1 parent 06f5de8 commit 0676d26d168295f0bb0399d384c710194005ede5
@@ -53,7 +53,8 @@ public:

virtual QString dump();


virtual QgsFeatureRendererV2* clone()=0 /Factory/;

void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1);

QgsSymbolV2LevelOrder& symbolLevels();
@@ -88,6 +89,10 @@ public:

QgsSymbolV2* symbol() const;
void setSymbol(QgsSymbolV2* s /Transfer/);

virtual QString dump();

virtual QgsFeatureRendererV2* clone() /Factory/;
};

//////////
@@ -114,6 +119,7 @@ public:
void setSymbol(QgsSymbolV2* s /Transfer/);
void setLabel(QString label);

QString dump();
};

typedef QList<QgsRendererCategoryV2> QgsCategoryList;
@@ -138,6 +144,10 @@ public:

virtual QList<int> usedAttributes();

virtual QString dump();

virtual QgsFeatureRendererV2* clone() /Factory/;

const QgsCategoryList& categories();

//! return index of category with specified value (-1 if not found)
@@ -179,6 +189,8 @@ public:

void setSymbol(QgsSymbolV2* s /Transfer/);
void setLabel(QString label);

QString dump();
};

typedef QList<QgsRendererRangeV2> QgsRangeList;
@@ -202,6 +214,10 @@ public:

virtual QList<int> usedAttributes();

virtual QString dump();

virtual QgsFeatureRendererV2* clone() /Factory/;

int attributeIndex() const;
void setAttributeIndex(int attr);

@@ -241,7 +241,6 @@ QString QgsFeatureRendererV2::dump()
return "UNKNOWN RENDERER\n";
}


///////////////////

QgsSingleSymbolRendererV2::QgsSingleSymbolRendererV2(QgsSymbolV2* symbol)
@@ -291,6 +290,12 @@ QString QgsSingleSymbolRendererV2::dump()
return QString("SINGLE: %1").arg(mSymbol->dump());
}

QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone()
{
QgsSingleSymbolRendererV2* r = new QgsSingleSymbolRendererV2( mSymbol->clone() );
r->setSymbolLevels( symbolLevels() );
return r;
}

///////////////////

@@ -480,6 +485,13 @@ QString QgsCategorizedSymbolRendererV2::dump()
return s;
}

QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone()
{
QgsCategorizedSymbolRendererV2* r = new QgsCategorizedSymbolRendererV2( mAttrNum, mCategories );
r->setSymbolLevels( symbolLevels() );
return r;
}


/////////////////////////
// graduated
@@ -534,6 +546,10 @@ void QgsRendererRangeV2::setLabel(QString label)
mLabel = label;
}

QString QgsRendererRangeV2::dump()
{
return QString("%1 - %2::%3::%4\n").arg(mLowerValue).arg(mUpperValue).arg(mLabel).arg(mSymbol->dump());
}

///////////

@@ -612,6 +628,21 @@ bool QgsGraduatedSymbolRendererV2::updateRangeLabel(int rangeIndex, QString labe
return true;
}

QString QgsGraduatedSymbolRendererV2::dump()
{
QString s = QString("GRADUATED: idx %1\n").arg(mAttrNum);
for (int i=0; i<mRanges.count();i++)
s += mRanges[i].dump();
return s;
}

QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone()
{
QgsGraduatedSymbolRendererV2* r = new QgsGraduatedSymbolRendererV2( mAttrNum, mRanges );
r->setSymbolLevels( symbolLevels() );
return r;
}


static QList<double> _calcEqualIntervalBreaks(double minimum, double maximum, int classes)
{
@@ -61,6 +61,8 @@ class QgsFeatureRendererV2
virtual QList<int> usedAttributes()=0;

virtual ~QgsFeatureRendererV2() {}

virtual QgsFeatureRendererV2* clone()=0;

void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1);

@@ -101,6 +103,8 @@ class QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2

virtual QString dump();

virtual QgsFeatureRendererV2* clone();

protected:
QgsSymbolV2* mSymbol;
};
@@ -154,6 +158,8 @@ class QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QString dump();

virtual QgsFeatureRendererV2* clone();

const QgsCategoryList& categories() { return mCategories; }

//! return index of category with specified value (-1 if not found)
@@ -200,6 +206,9 @@ class QgsRendererRangeV2
void setSymbol(QgsSymbolV2* s);
void setLabel(QString label);

// debugging
QString dump();

protected:
double mLowerValue, mUpperValue;
QgsSymbolV2* mSymbol;
@@ -225,7 +234,11 @@ class QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
virtual void stopRender(QgsRenderContext& context);

virtual QList<int> usedAttributes();


virtual QString dump();

virtual QgsFeatureRendererV2* clone();

int attributeIndex() const { return mAttrNum; }
void setAttributeIndex(int attr) { mAttrNum = attr; }

@@ -28,9 +28,13 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay
mLayer->setRendererV2(new QgsSingleSymbolRendererV2( createDefaultSymbol() ));
mLayer->setUsingRendererV2(true);
}

mRenderer = mLayer->rendererV2()->clone();

setupUi(this);

connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()));

connect(btnSymbolLevels, SIGNAL(clicked()), this, SLOT(symbolLevels()));

connect(radSingleSymbol, SIGNAL(clicked()), this, SLOT(updateRenderer()));
@@ -83,28 +87,34 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay

QgsRendererV2PropertiesDialog::~QgsRendererV2PropertiesDialog()
{
//delete mGraduatedSymbol;
// delete the temporary renderer (if exists)
delete mRenderer;
}

void QgsRendererV2PropertiesDialog::onOK()
{
mLayer->setRendererV2(mRenderer);
mRenderer = NULL;

accept();
}

QgsSingleSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererSingle()
{
QgsFeatureRendererV2* r = mLayer->rendererV2();
Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererSingleSymbol);
return static_cast<QgsSingleSymbolRendererV2*>(r);
Q_ASSERT(mRenderer != NULL && mRenderer->type() == QgsFeatureRendererV2::RendererSingleSymbol);
return static_cast<QgsSingleSymbolRendererV2*>(mRenderer);
}

QgsCategorizedSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererCategorized()
{
QgsFeatureRendererV2* r = mLayer->rendererV2();
Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererCategorizedSymbol);
return static_cast<QgsCategorizedSymbolRendererV2*>(r);
Q_ASSERT(mRenderer != NULL && mRenderer->type() == QgsFeatureRendererV2::RendererCategorizedSymbol);
return static_cast<QgsCategorizedSymbolRendererV2*>(mRenderer);
}

QgsGraduatedSymbolRendererV2* QgsRendererV2PropertiesDialog::rendererGraduated()
{
QgsFeatureRendererV2* r = mLayer->rendererV2();
Q_ASSERT(r != NULL && r->type() == QgsFeatureRendererV2::RendererGraduatedSymbol);
return static_cast<QgsGraduatedSymbolRendererV2*>(r);
Q_ASSERT(mRenderer != NULL && mRenderer->type() == QgsFeatureRendererV2::RendererGraduatedSymbol);
return static_cast<QgsGraduatedSymbolRendererV2*>(mRenderer);
}

void QgsRendererV2PropertiesDialog::changeSingleSymbol()
@@ -125,12 +135,14 @@ void QgsRendererV2PropertiesDialog::updateSingleSymbolIcon()

void QgsRendererV2PropertiesDialog::updateRenderer()
{
delete mRenderer;

if (radSingleSymbol->isChecked())
mLayer->setRendererV2( new QgsSingleSymbolRendererV2( createDefaultSymbol() ) );
mRenderer = new QgsSingleSymbolRendererV2( createDefaultSymbol() );
else if (radCategorized->isChecked())
mLayer->setRendererV2( new QgsCategorizedSymbolRendererV2(-1, QgsCategoryList()) );
mRenderer = new QgsCategorizedSymbolRendererV2(-1, QgsCategoryList());
else if (radGraduated->isChecked())
mLayer->setRendererV2( new QgsGraduatedSymbolRendererV2(-1, QgsRangeList()) );
mRenderer = new QgsGraduatedSymbolRendererV2(-1, QgsRangeList());
else
Q_ASSERT(false);

@@ -139,7 +151,7 @@ void QgsRendererV2PropertiesDialog::updateRenderer()

void QgsRendererV2PropertiesDialog::updateUiFromRenderer()
{
switch (mLayer->rendererV2()->type())
switch (mRenderer->type())
{
case QgsFeatureRendererV2::RendererSingleSymbol:
radSingleSymbol->setChecked(true);
@@ -354,7 +366,8 @@ void QgsRendererV2PropertiesDialog::addCategories()
*/

// recreate renderer
mLayer->setRendererV2(new QgsCategorizedSymbolRendererV2(idx, cats));
delete mRenderer;
mRenderer = new QgsCategorizedSymbolRendererV2(idx, cats);

populateCategories();
}
@@ -443,7 +456,8 @@ void QgsRendererV2PropertiesDialog::classifyGraduated()
mLayer, idx, classes, mode, mGraduatedSymbol, ramp);
r->setMode(mode);

mLayer->setRendererV2(r);
delete mRenderer;
mRenderer = r;

populateRanges();
}
@@ -536,7 +550,7 @@ void QgsRendererV2PropertiesDialog::symbolLevels()
{
QgsSymbolV2List symbols;

switch (mLayer->rendererV2()->type())
switch (mRenderer->type())
{
case QgsFeatureRendererV2::RendererSingleSymbol:
{
@@ -575,10 +589,9 @@ void QgsRendererV2PropertiesDialog::symbolLevels()
break;
}

// TODO: get symbol level order from layer!
QgsSymbolLevelsV2Dialog dlg(symbols, mLayer->rendererV2()->symbolLevels(), this);
QgsSymbolLevelsV2Dialog dlg(symbols, mRenderer->symbolLevels(), this);
if (dlg.exec())
{
mLayer->rendererV2()->setSymbolLevels( dlg.levels() );
mRenderer->setSymbolLevels( dlg.levels() );
}
}
@@ -7,6 +7,8 @@
class QgsVectorLayer;
class QgsStyleV2;
class QgsSymbolV2;

class QgsFeatureRendererV2;
class QgsSingleSymbolRendererV2;
class QgsCategorizedSymbolRendererV2;
class QgsGraduatedSymbolRendererV2;
@@ -36,6 +38,8 @@ public slots:

void symbolLevels();

void onOK();

protected:

//! update UI to reflect changes in renderer
@@ -73,6 +77,9 @@ public slots:
QgsCategorizedSymbolRendererV2* rendererCategorized();
QgsGraduatedSymbolRendererV2* rendererGraduated();

//! temporary renderer in current dialog
QgsFeatureRendererV2* mRenderer;

QgsVectorLayer* mLayer;

QgsStyleV2* mStyle;
@@ -463,31 +463,15 @@
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsRendererV2PropsDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsRendererV2PropsDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>325</x>
<y>388</y>
</hint>
<hint type="destinationlabel">
<x>286</x>

0 comments on commit 0676d26

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