Skip to content
Permalink
Browse files

Fixed some bugs, change symbols for ranges in graduated renderer, upd…

…ate of bindings.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11062 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 13, 2009
1 parent 0668a81 commit 45ae45fefe0d69d5232aa1dd50fd9e33bb1d7671
@@ -87,7 +87,7 @@ public:
virtual QList<int> usedAttributes();

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

//////////
@@ -101,7 +101,7 @@ class QgsRendererCategoryV2
public:

//! takes ownership of symbol
QgsRendererCategoryV2(QVariant value, QgsSymbolV2* symbol, QString label);
QgsRendererCategoryV2(QVariant value, QgsSymbolV2* symbol /Transfer/, QString label);

QgsRendererCategoryV2(const QgsRendererCategoryV2& cat);

@@ -111,7 +111,7 @@ public:
QgsSymbolV2* symbol();
QString label() const;

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

};
@@ -143,7 +143,7 @@ public:
//! return index of category with specified value (-1 if not found)
int categoryIndexForValue(QVariant val);

bool updateCategorySymbol(int catIndex, QgsSymbolV2* symbol);
bool updateCategorySymbol(int catIndex, QgsSymbolV2* symbol /Transfer/);
bool updateCategoryLabel(int catIndex, QString label);

bool deleteCategory(int catIndex);
@@ -159,6 +159,81 @@ protected:

//////////

class QgsRendererRangeV2
{
%TypeHeaderCode
#include <qgsrendererv2.h>
%End

public:
QgsRendererRangeV2(double lowerValue, double upperValue, QgsSymbolV2* symbol /Transfer/, QString label);
QgsRendererRangeV2(const QgsRendererRangeV2& range);

~QgsRendererRangeV2();

double lowerValue() const;
double upperValue() const;

QgsSymbolV2* symbol() const;
QString label() const;

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

typedef QList<QgsRendererRangeV2> QgsRangeList;

class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
{
%TypeHeaderCode
#include <qgsrendererv2.h>
%End

public:
QgsGraduatedSymbolRendererV2(int attrNum = -1, QgsRangeList ranges = QgsRangeList());

virtual ~QgsGraduatedSymbolRendererV2();

virtual QgsSymbolV2* symbolForFeature(QgsFeature& feature);

virtual void startRender(QgsRenderContext& context);

virtual void stopRender(QgsRenderContext& context);

virtual QList<int> usedAttributes();

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

const QgsRangeList& ranges();

bool updateRangeSymbol(int rangeIndex, QgsSymbolV2* symbol /Transfer/);
bool updateRangeLabel(int rangeIndex, QString label);

enum Mode
{
EqualInterval,
Quantile,
Custom
};

Mode mode() const;
void setMode(Mode mode);

static QgsGraduatedSymbolRendererV2* createRenderer(
QgsVectorLayer* vlayer,
int attrNum,
int classes,
Mode mode,
QgsSymbolV2* symbol,
QgsVectorColorRampV2* ramp);

protected:
QgsSymbolV2* symbolForValue(double value);
};

//////////

class QgsSymbolLayerV2
{
%TypeHeaderCode
@@ -294,6 +294,11 @@ QString QgsSingleSymbolRendererV2::dump()

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

QgsRendererCategoryV2::QgsRendererCategoryV2(QVariant value, QgsSymbolV2* symbol, QString label)
: mValue(value), mSymbol(symbol), mLabel(label)
{
}

QgsRendererCategoryV2::QgsRendererCategoryV2(const QgsRendererCategoryV2& cat)
: mValue(cat.mValue), mLabel(cat.mLabel)
{
@@ -306,12 +311,34 @@ QgsRendererCategoryV2::~QgsRendererCategoryV2()
delete mSymbol;
}

QVariant QgsRendererCategoryV2::value() const
{
return mValue;
}

QgsSymbolV2* QgsRendererCategoryV2::symbol() const
{
return mSymbol;
}

QString QgsRendererCategoryV2::label() const
{
return mLabel;
}

void QgsRendererCategoryV2::setSymbol(QgsSymbolV2* s)
{
if (mSymbol == s)
return;
delete mSymbol;
mSymbol = s;
}

void QgsRendererCategoryV2::setLabel(QString label)
{
mLabel = label;
}

QString QgsRendererCategoryV2::dump()
{
return QString("%1::%2::%3\n").arg(mValue.toString()).arg(mLabel).arg(mSymbol->dump());
@@ -474,6 +501,40 @@ QgsRendererRangeV2::~QgsRendererRangeV2()
delete mSymbol;
}

double QgsRendererRangeV2::lowerValue() const
{
return mLowerValue;
}

double QgsRendererRangeV2::upperValue() const
{
return mUpperValue;
}

QgsSymbolV2* QgsRendererRangeV2::symbol() const
{
return mSymbol;
}

QString QgsRendererRangeV2::label() const
{
return mLabel;
}

void QgsRendererRangeV2::setSymbol(QgsSymbolV2* s)
{
if (mSymbol == s)
return;
delete mSymbol;
mSymbol = s;
}

void QgsRendererRangeV2::setLabel(QString label)
{
mLabel = label;
}


///////////


@@ -535,6 +596,21 @@ QList<int> QgsGraduatedSymbolRendererV2::usedAttributes()
return lst;
}

bool QgsGraduatedSymbolRendererV2::updateRangeSymbol(int rangeIndex, QgsSymbolV2* symbol)
{
if (rangeIndex < 0 || rangeIndex >= mRanges.size())
return false;
mRanges[rangeIndex].setSymbol(symbol);
return true;
}

bool QgsGraduatedSymbolRendererV2::updateRangeLabel(int rangeIndex, QString label)
{
if (rangeIndex < 0 || rangeIndex >= mRanges.size())
return false;
mRanges[rangeIndex].setLabel(label);
return true;
}


static QList<double> _calcEqualIntervalBreaks(double minimum, double maximum, int classes)
@@ -111,20 +111,19 @@ class QgsRendererCategoryV2
public:

//! takes ownership of symbol
QgsRendererCategoryV2(QVariant value, QgsSymbolV2* symbol, QString label)
: mValue(value), mSymbol(symbol), mLabel(label) { }
QgsRendererCategoryV2(QVariant value, QgsSymbolV2* symbol, QString label);

//! copy constructor
QgsRendererCategoryV2(const QgsRendererCategoryV2& cat);

~QgsRendererCategoryV2();

QVariant value() const { return mValue; }
QgsSymbolV2* symbol() const { return mSymbol; }
QString label() const { return mLabel; }
QVariant value() const;
QgsSymbolV2* symbol() const;
QString label() const;

void setSymbol(QgsSymbolV2* s);
void setLabel(QString label) { mLabel = label; }
void setLabel(QString label);

// debugging
QString dump();
@@ -192,12 +191,15 @@ class QgsRendererRangeV2

~QgsRendererRangeV2();

double lowerValue() const { return mLowerValue; }
double upperValue() const { return mUpperValue; }
double lowerValue() const;
double upperValue() const;

QgsSymbolV2* symbol() const { return mSymbol; }
QString label() const { return mLabel; }
QgsSymbolV2* symbol() const;
QString label() const;

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

protected:
double mLowerValue, mUpperValue;
QgsSymbolV2* mSymbol;
@@ -229,6 +231,9 @@ class QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

const QgsRangeList& ranges() { return mRanges; }

bool updateRangeSymbol(int rangeIndex, QgsSymbolV2* symbol);
bool updateRangeLabel(int rangeIndex, QString label);

enum Mode
{
EqualInterval,
@@ -72,6 +72,8 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay

mGraduatedSymbol = createDefaultSymbol();

connect(viewGraduated, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(rangesDoubleClicked(const QModelIndex &)));

connect(btnGraduatedClassify, SIGNAL(clicked()), this, SLOT(classifyGraduated()));
connect(btnChangeGraduatedSymbol, SIGNAL(clicked()), this, SLOT(changeGraduatedSymbol()));

@@ -152,11 +154,11 @@ void QgsRendererV2PropertiesDialog::updateUiFromRenderer()
stackedWidget->setCurrentWidget(pageCategorized);
updateCategorizedSymbolIcon();

disconnect(cboCategorizedColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColumnChanged()));
{
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;
@@ -495,6 +497,41 @@ void QgsRendererV2PropertiesDialog::populateRanges()
viewGraduated->resizeColumnToContents(0);
}

/*
int QgsRendererV2PropertiesDialog::currentRangeRow()
{
QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
if (!idx.isValid())
return -1;
return idx.row();
}
*/

void QgsRendererV2PropertiesDialog::rangesDoubleClicked(const QModelIndex & idx)
{
if (idx.isValid() && idx.column() == 0)
changeRangeSymbol(idx.row());
}

void QgsRendererV2PropertiesDialog::changeRangeSymbol(int rangeIdx)
{

QgsGraduatedSymbolRendererV2* r = rendererGraduated();
QgsSymbolV2* newSymbol = r->ranges()[rangeIdx].symbol()->clone();

QgsSymbolV2SelectorDialog dlg(newSymbol, mStyle, this);
if (!dlg.exec())
{
delete newSymbol;
return;
}

r->updateRangeSymbol(rangeIdx, newSymbol);

populateRanges();
}


void QgsRendererV2PropertiesDialog::symbolLevels()
{
QgsSymbolV2List symbols;
@@ -32,6 +32,7 @@ public slots:

void changeGraduatedSymbol();
void classifyGraduated();
void rangesDoubleClicked(const QModelIndex & idx);

void symbolLevels();

@@ -65,7 +66,9 @@ public slots:
QVariant currentCategory();

void changeCategorySymbol();


void changeRangeSymbol(int rangeIdx);

QgsSingleSymbolRendererV2* rendererSingle();
QgsCategorizedSymbolRendererV2* rendererCategorized();
QgsGraduatedSymbolRendererV2* rendererGraduated();

0 comments on commit 45ae45f

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