Skip to content

Commit

Permalink
Corrected renderer assignment in the renderer properties dialog.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11066 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 14, 2009
1 parent 06f5de8 commit 0676d26
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 41 deletions.
18 changes: 17 additions & 1 deletion python/core/symbology-ng-core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public:

virtual QString dump();


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

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

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

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

virtual QString dump();

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

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

QString dump();
};

typedef QList<QgsRendererCategoryV2> QgsCategoryList;
Expand All @@ -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)
Expand Down Expand Up @@ -179,6 +189,8 @@ public:

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

QString dump();
};

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

virtual QList<int> usedAttributes();

virtual QString dump();

virtual QgsFeatureRendererV2* clone() /Factory/;

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

Expand Down
33 changes: 32 additions & 1 deletion src/core/symbology-ng/qgsrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ QString QgsFeatureRendererV2::dump()
return "UNKNOWN RENDERER\n";
}


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

QgsSingleSymbolRendererV2::QgsSingleSymbolRendererV2(QgsSymbolV2* symbol)
Expand Down Expand Up @@ -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;
}

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

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

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


/////////////////////////
// graduated
Expand Down Expand Up @@ -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());
}

///////////

Expand Down Expand Up @@ -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)
{
Expand Down
15 changes: 14 additions & 1 deletion src/core/symbology-ng/qgsrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

virtual QString dump();

virtual QgsFeatureRendererV2* clone();

protected:
QgsSymbolV2* mSymbol;
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -200,6 +206,9 @@ class QgsRendererRangeV2
void setSymbol(QgsSymbolV2* s);
void setLabel(QString label);

// debugging
QString dump();

protected:
double mLowerValue, mUpperValue;
QgsSymbolV2* mSymbol;
Expand All @@ -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; }

Expand Down
53 changes: 33 additions & 20 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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()
Expand All @@ -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);

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

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

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

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

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

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

switch (mLayer->rendererV2()->type())
switch (mRenderer->type())
{
case QgsFeatureRendererV2::RendererSingleSymbol:
{
Expand Down Expand Up @@ -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 changes: 7 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class QgsVectorLayer;
class QgsStyleV2;
class QgsSymbolV2;

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

void symbolLevels();

void onOK();

protected:

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

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

QgsVectorLayer* mLayer;

QgsStyleV2* mStyle;
Expand Down
20 changes: 2 additions & 18 deletions src/ui/qgsrendererv2propsdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 0676d26

Please sign in to comment.