Skip to content
Permalink
Browse files

Slightly reworked the internal working of symbol levels. Fixes some p…

…roblems with symbol levels handling.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11151 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 23, 2009
1 parent 1e8cd68 commit da2894a6215cc92cfd8f42f5e2642516fe3a5f8c
@@ -61,8 +61,8 @@ public:

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

QgsSymbolV2LevelOrder& symbolLevels();
void setSymbolLevels(const QgsSymbolV2LevelOrder& levelOrder);
bool usingSymbolLevels() const;
void setUsingSymbolLevels(bool usingSymbolLevels);

protected:
QgsFeatureRendererV2(RendererType type);
@@ -296,7 +296,11 @@ public:

void setLocked(bool locked);
bool isLocked() const;


// used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
void setRenderingPass(int renderingPass);
int renderingPass() const;

protected:
QgsSymbolLayerV2(QgsSymbolV2::SymbolType type, bool locked = false);

@@ -73,6 +73,8 @@
#include "qgsmaplayerregistry.h"

#include "qgsrendererv2.h"
#include "qgssymbolv2.h"
#include "qgssymbollayerv2.h"

#ifdef Q_WS_X11
#include "qgsclipper.h"
@@ -706,8 +708,23 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
mLabelingRegisterFeatureHook(fet, mLabelingLayerContext);
}

// find out the order
QgsSymbolV2LevelOrder levels;
QgsSymbolV2List symbols = mRendererV2->symbols();
for (int i = 0; i < symbols.count(); i++)
{
QgsSymbolV2* sym = symbols[i];
for (int j = 0; j < sym->symbolLayerCount(); j++)
{
int level = sym->symbolLayer(j)->renderingPass();
QgsSymbolV2LevelItem item(sym,j);
while (level >= levels.count()) // append new empty levels
levels.append( QgsSymbolV2Level() );
levels[level].append(item);
}
}

// 2. draw features in correct order
QgsSymbolV2LevelOrder& levels = mRendererV2->symbolLevels();
for (int l = 0; l < levels.count(); l++)
{
QgsSymbolV2Level& level = levels[l];
@@ -762,10 +779,10 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )

select( attributes, rendererContext.extent() );

if (mRendererV2->symbolLevels().isEmpty())
drawRendererV2(rendererContext, labeling);
else
if (mRendererV2->usingSymbolLevels())
drawRendererV2Levels(rendererContext, labeling);
else
drawRendererV2(rendererContext, labeling);

return TRUE;
}
@@ -111,7 +111,7 @@ static unsigned char* _getPolygon(QPolygonF& pts, QList<QPolygonF>& holes, const


QgsFeatureRendererV2::QgsFeatureRendererV2(RendererType type)
: mType(type)
: mType(type), mUsingSymbolLevels(false)
{
}

@@ -294,7 +294,7 @@ QString QgsSingleSymbolRendererV2::dump()
QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone()
{
QgsSingleSymbolRendererV2* r = new QgsSingleSymbolRendererV2( mSymbol->clone() );
r->setSymbolLevels( symbolLevels() );
r->setUsingSymbolLevels( usingSymbolLevels() );
return r;
}

@@ -496,7 +496,7 @@ QString QgsCategorizedSymbolRendererV2::dump()
QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone()
{
QgsCategorizedSymbolRendererV2* r = new QgsCategorizedSymbolRendererV2( mAttrNum, mCategories );
r->setSymbolLevels( symbolLevels() );
r->setUsingSymbolLevels( usingSymbolLevels() );
return r;
}

@@ -654,7 +654,7 @@ QString QgsGraduatedSymbolRendererV2::dump()
QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone()
{
QgsGraduatedSymbolRendererV2* r = new QgsGraduatedSymbolRendererV2( mAttrNum, mRanges );
r->setSymbolLevels( symbolLevels() );
r->setUsingSymbolLevels( usingSymbolLevels() );
return r;
}

@@ -73,15 +73,15 @@ class QgsFeatureRendererV2
//! for symbol levels
virtual QgsSymbolV2List symbols()=0;

QgsSymbolV2LevelOrder& symbolLevels() { return mLevelOrder; }
void setSymbolLevels(const QgsSymbolV2LevelOrder& levelOrder) { mLevelOrder = levelOrder; }
bool usingSymbolLevels() const { return mUsingSymbolLevels; }
void setUsingSymbolLevels(bool usingSymbolLevels) { mUsingSymbolLevels = usingSymbolLevels; }

protected:
QgsFeatureRendererV2(RendererType type);

RendererType mType;

QgsSymbolV2LevelOrder mLevelOrder;
bool mUsingSymbolLevels;
};

class QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
@@ -49,13 +49,19 @@ class QgsSymbolLayerV2

void setLocked(bool locked) { mLocked = locked; }
bool isLocked() const { return mLocked; }

// used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
void setRenderingPass(int renderingPass) { mRenderingPass = renderingPass; }
int renderingPass() const { return mRenderingPass; }

protected:
QgsSymbolLayerV2(QgsSymbolV2::SymbolType type, bool locked = false) : mType(type), mLocked(locked) {}
QgsSymbolLayerV2(QgsSymbolV2::SymbolType type, bool locked = false)
: mType(type), mLocked(locked), mRenderingPass(0) {}

QgsSymbolV2::SymbolType mType;
bool mLocked;
QColor mColor;
int mRenderingPass;
};

//////////////////////
@@ -216,6 +216,7 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const
{
QgsSymbolLayerV2* layer = (*it)->clone();
layer->setLocked( (*it)->isLocked() );
layer->setRenderingPass( (*it)->renderingPass() );
lst.append( layer );
}
return lst;
@@ -550,9 +550,9 @@ void QgsRendererV2PropertiesDialog::symbolLevels()
{
QgsSymbolV2List symbols = mRenderer->symbols();

QgsSymbolLevelsV2Dialog dlg(symbols, mRenderer->symbolLevels(), this);
QgsSymbolLevelsV2Dialog dlg(symbols, mRenderer->usingSymbolLevels(), this);
if (dlg.exec())
{
mRenderer->setSymbolLevels( dlg.levels() );
mRenderer->setUsingSymbolLevels( dlg.usingLevels() );
}
}
@@ -2,16 +2,17 @@
#include "qgssymbollevelsv2dialog.h"

#include "qgssymbollayerv2utils.h"
#include "qgssymbollayerv2.h"
#include "qgssymbolv2.h"

#include <QTableWidgetItem>

QgsSymbolLevelsV2Dialog::QgsSymbolLevelsV2Dialog(QgsSymbolV2List symbols, QgsSymbolV2LevelOrder levels, QWidget* parent)
: QDialog(parent), mSymbols(symbols), mLevels(levels)
QgsSymbolLevelsV2Dialog::QgsSymbolLevelsV2Dialog(QgsSymbolV2List symbols, bool usingSymbolLevels, QWidget* parent)
: QDialog(parent), mSymbols(symbols)
{
setupUi(this);

chkEnable->setChecked( !levels.isEmpty() );
chkEnable->setChecked( usingSymbolLevels );

connect(chkEnable, SIGNAL(clicked()), this, SLOT(updateUi()));

@@ -42,17 +43,14 @@ QgsSymbolLevelsV2Dialog::QgsSymbolLevelsV2Dialog(QgsSymbolV2List symbols, QgsSym

updateUi();

connect(tableLevels, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(updateLevels(QTableWidgetItem*)));
if (!usingSymbolLevels)
setDefaultLevels();

populateTable();
}

void QgsSymbolLevelsV2Dialog::populateTable()
{
if (mLevels.isEmpty())
return;

disconnect(tableLevels, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(updateLevels(QTableWidgetItem*)));

for (int row = 0; row < mSymbols.count(); row++)
{
QgsSymbolV2* sym = mSymbols[row];
@@ -66,81 +64,33 @@ void QgsSymbolLevelsV2Dialog::populateTable()
}
else
{
item = new QTableWidgetItem( QString::number(levelForSymbolLayer(sym, layer)) );
item = new QTableWidgetItem( QString::number( sym->symbolLayer(layer)->renderingPass() ) );
}
tableLevels->setItem(row, layer, item);
}
}

connect(tableLevels, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(updateLevels(QTableWidgetItem*)));

}

void QgsSymbolLevelsV2Dialog::updateUi()
{
if (chkEnable->isChecked())
{
if (mLevels.isEmpty())
setDefaultLevels();
populateTable();
}
else
mLevels.clear();

tableLevels->setEnabled(chkEnable->isChecked());
}

void QgsSymbolLevelsV2Dialog::setDefaultLevels()
{
mLevels.clear();
for (int col = 0; col < tableLevels->columnCount(); col++)
for (int i = 0; i < mSymbols.count(); i++)
{
QgsSymbolV2Level level;
for (int i = 0; i < mSymbols.count(); i++)
QgsSymbolV2* sym = mSymbols[i];
for (int layer = 0; layer < sym->symbolLayerCount(); layer++)
{
QgsSymbolV2* sym = mSymbols[i];
if (col < sym->symbolLayerCount())
level.append(QgsSymbolV2LevelItem(sym, col));
sym->symbolLayer(layer)->setRenderingPass(layer);
}
mLevels.append(level);
}
}

int QgsSymbolLevelsV2Dialog::levelForSymbolLayer(QgsSymbolV2* sym, int layer)
{
for (int l = 0; l < mLevels.count(); l++)
{
QgsSymbolV2Level& level = mLevels[l];
for (int i = 0; i < level.count(); i++)
{
QgsSymbolV2LevelItem& item = level[i];
if (item.symbol() == sym && item.layer() == layer)
return l;
}
}
return -1;
}

void QgsSymbolLevelsV2Dialog::updateLevels(QTableWidgetItem* item)
bool QgsSymbolLevelsV2Dialog::usingLevels() const
{
int num = item->text().toInt();
if (num > 100)
{
item->setText("0");
return;
}

mLevels.clear();
for (int col = 0; col < tableLevels->columnCount(); col++)
{
for (int row = 0; row < mSymbols.count(); row++)
{
QgsSymbolV2* sym = mSymbols[row];
int level = tableLevels->item(row,col)->text().toInt();
QgsSymbolV2LevelItem item(sym,col);
while (level >= mLevels.count()) // append new empty levels
mLevels.append( QgsSymbolV2Level() );
mLevels[level].append(item);
}
}
return chkEnable->isChecked();
}
@@ -13,24 +13,21 @@ class QgsSymbolLevelsV2Dialog : public QDialog, private Ui::QgsSymbolLevelsV2Dia
{
Q_OBJECT
public:
QgsSymbolLevelsV2Dialog(QgsSymbolV2List symbols, QgsSymbolV2LevelOrder levels, QWidget* parent = NULL);
QgsSymbolLevelsV2Dialog(QgsSymbolV2List symbols, bool usingSymbolLevels, QWidget* parent = NULL);

QgsSymbolV2LevelOrder& levels() { return mLevels; }
bool usingLevels() const;

public slots:
void updateUi();
void updateLevels(QTableWidgetItem* item);

protected:
void populateTable();
void setDefaultLevels();
int levelForSymbolLayer(QgsSymbolV2* sym, int layer);

protected:
//! maximal number of layers from all symbols
int mMaxLayers;
QgsSymbolV2List mSymbols;
QgsSymbolV2LevelOrder mLevels;
};

#endif // QGSSYMBOLLEVELSV2DIALOG_H

0 comments on commit da2894a

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