mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
code cleanup
git-svn-id: http://svn.osgeo.org/qgis/trunk@1033 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
d7bb9f1a63
commit
1b7ad1ae91
@ -32,236 +32,242 @@
|
||||
#include "qgsfield.h"
|
||||
#include <qspinbox.h>
|
||||
|
||||
QgsContColDialog::QgsContColDialog(QgsVectorLayer * layer):QgsContColDialogBase(), m_vectorlayer(layer)
|
||||
QgsContColDialog::QgsContColDialog(QgsVectorLayer * layer):QgsContColDialogBase(), mVectorLayer(layer)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("constructor QgsContColDialog");
|
||||
qWarning("constructor QgsContColDialog");
|
||||
#endif
|
||||
|
||||
QObject::connect(mincolorbutton, SIGNAL(clicked()), this, SLOT(selectMinimumColor()));
|
||||
QObject::connect(maxcolorbutton, SIGNAL(clicked()), this, SLOT(selectMaximumColor()));
|
||||
QObject::connect(mincolorbutton, SIGNAL(clicked()), this, SLOT(selectMinimumColor()));
|
||||
QObject::connect(maxcolorbutton, SIGNAL(clicked()), this, SLOT(selectMaximumColor()));
|
||||
|
||||
//find out the numerical fields of m_vectorlayer
|
||||
QgsDataProvider *provider;
|
||||
if (provider = m_vectorlayer->getDataProvider())
|
||||
//find out the numerical fields of mVectorLayer
|
||||
QgsDataProvider *provider;
|
||||
if (provider = mVectorLayer->getDataProvider())
|
||||
{
|
||||
std::vector < QgsField > &fields = provider->fields();
|
||||
int fieldnumber = 0;
|
||||
QString str;
|
||||
std::vector < QgsField > &fields = provider->fields();
|
||||
int fieldnumber = 0;
|
||||
QString str;
|
||||
|
||||
for (std::vector < QgsField >::iterator it = fields.begin(); it != fields.end(); ++it)
|
||||
for (std::vector < QgsField >::iterator it = fields.begin(); it != fields.end(); ++it)
|
||||
{
|
||||
QString type = (*it).type();
|
||||
if (type != "String" && type != "varchar" && type != "geometry")
|
||||
QString type = (*it).type();
|
||||
if (type != "String" && type != "varchar" && type != "geometry")
|
||||
{
|
||||
str = (*it).name();
|
||||
str = str.left(1).upper() + str.right(str.length() - 1); //make the first letter uppercase
|
||||
classificationComboBox->insertItem(str);
|
||||
m_fieldmap.insert(std::make_pair(str, fieldnumber));
|
||||
str = (*it).name();
|
||||
str = str.left(1).upper() + str.right(str.length() - 1); //make the first letter uppercase
|
||||
classificationComboBox->insertItem(str);
|
||||
mFieldMap.insert(std::make_pair(str, fieldnumber));
|
||||
}
|
||||
fieldnumber++;
|
||||
fieldnumber++;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Warning, data provider is null in QgsContColDialog::QgsContColDialog(...)");
|
||||
return;
|
||||
qWarning("Warning, data provider is null in QgsContColDialog::QgsContColDialog(...)");
|
||||
return;
|
||||
}
|
||||
|
||||
//restore the correct colors for minimum and maximum values
|
||||
|
||||
QgsContinuousColRenderer *renderer;
|
||||
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
|
||||
//restore the correct colors for minimum and maximum values
|
||||
|
||||
QgsContinuousColRenderer *renderer;
|
||||
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(layer->propertiesDialog()->getBufferRenderer());
|
||||
} else
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(layer->propertiesDialog()->getBufferRenderer());
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(layer->renderer());
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(layer->renderer());
|
||||
}
|
||||
|
||||
if (renderer)
|
||||
|
||||
if (renderer)
|
||||
{
|
||||
QgsRenderItem *minitem = renderer->minimumItem();
|
||||
QgsRenderItem *maxitem = renderer->maximumItem();
|
||||
if (m_vectorlayer->vectorType() == QGis::Line)
|
||||
QgsRenderItem *minitem = renderer->minimumItem();
|
||||
QgsRenderItem *maxitem = renderer->maximumItem();
|
||||
if (mVectorLayer->vectorType() == QGis::Line)
|
||||
{
|
||||
mincolorbutton->setPaletteBackgroundColor(minitem->getSymbol()->pen().color());
|
||||
maxcolorbutton->setPaletteBackgroundColor(maxitem->getSymbol()->pen().color());
|
||||
} else
|
||||
mincolorbutton->setPaletteBackgroundColor(minitem->getSymbol()->pen().color());
|
||||
maxcolorbutton->setPaletteBackgroundColor(maxitem->getSymbol()->pen().color());
|
||||
}
|
||||
else
|
||||
{
|
||||
mincolorbutton->setPaletteBackgroundColor(minitem->getSymbol()->brush().color());
|
||||
maxcolorbutton->setPaletteBackgroundColor(maxitem->getSymbol()->brush().color());
|
||||
mincolorbutton->setPaletteBackgroundColor(minitem->getSymbol()->brush().color());
|
||||
maxcolorbutton->setPaletteBackgroundColor(maxitem->getSymbol()->brush().color());
|
||||
}
|
||||
outlinewidthspinbox->setValue(minitem->getSymbol()->pen().width());
|
||||
outlinewidthspinbox->setMinValue(1);
|
||||
outlinewidthspinbox->setValue(minitem->getSymbol()->pen().width());
|
||||
outlinewidthspinbox->setMinValue(1);
|
||||
}
|
||||
}
|
||||
|
||||
QgsContColDialog::QgsContColDialog()
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("constructor QgsContColDialog");
|
||||
qWarning("constructor QgsContColDialog");
|
||||
#endif
|
||||
}
|
||||
|
||||
QgsContColDialog::~QgsContColDialog()
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("destructor QgsContColDialog");
|
||||
qWarning("destructor QgsContColDialog");
|
||||
#endif
|
||||
}
|
||||
|
||||
void QgsContColDialog::apply()
|
||||
{
|
||||
QString fieldstring = classificationComboBox->currentText();
|
||||
if (fieldstring.isEmpty()) //don't do anything, it there is no classification field
|
||||
QString fieldstring = classificationComboBox->currentText();
|
||||
if (fieldstring.isEmpty()) //don't do anything, it there is no classification field
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
std::map < QString, int >::iterator iter = m_fieldmap.find(fieldstring);
|
||||
int classfield = iter->second;
|
||||
|
||||
//find the minimum and maximum for the classification variable
|
||||
double minimum, maximum;
|
||||
QgsDataProvider *provider = m_vectorlayer->getDataProvider();
|
||||
if (provider)
|
||||
std::map < QString, int >::iterator iter = mFieldMap.find(fieldstring);
|
||||
int classfield = iter->second;
|
||||
|
||||
//find the minimum and maximum for the classification variable
|
||||
double minimum, maximum;
|
||||
QgsDataProvider *provider = mVectorLayer->getDataProvider();
|
||||
if (provider)
|
||||
{
|
||||
minimum = provider->minValue(classfield).toDouble();
|
||||
maximum = provider->maxValue(classfield).toDouble();
|
||||
} else
|
||||
{
|
||||
qWarning("Warning, provider is null in QgsGraSyExtensionWidget::QgsGraSyExtensionWidget(...)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//create the render items for minimum and maximum value
|
||||
QgsSymbol minsymbol;
|
||||
if (m_vectorlayer->vectorType() == QGis::Line)
|
||||
{
|
||||
minsymbol.setPen(QPen(mincolorbutton->paletteBackgroundColor(),outlinewidthspinbox->value()));
|
||||
minimum = provider->minValue(classfield).toDouble();
|
||||
maximum = provider->maxValue(classfield).toDouble();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
minsymbol.setBrush(QBrush(mincolorbutton->paletteBackgroundColor()));
|
||||
minsymbol.setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value()));
|
||||
qWarning("Warning, provider is null in QgsGraSyExtensionWidget::QgsGraSyExtensionWidget(...)");
|
||||
return;
|
||||
}
|
||||
QgsRenderItem *minimumitem = new QgsRenderItem(minsymbol, QString::number(minimum, 'f'), " ");
|
||||
|
||||
|
||||
QgsSymbol maxsymbol;
|
||||
if (m_vectorlayer->vectorType() == QGis::Line)
|
||||
//create the render items for minimum and maximum value
|
||||
QgsSymbol minsymbol;
|
||||
if (mVectorLayer->vectorType() == QGis::Line)
|
||||
{
|
||||
maxsymbol.setPen(QPen(maxcolorbutton->paletteBackgroundColor(),outlinewidthspinbox->value()));
|
||||
minsymbol.setPen(QPen(mincolorbutton->paletteBackgroundColor(),outlinewidthspinbox->value()));
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
maxsymbol.setBrush(QBrush(maxcolorbutton->paletteBackgroundColor()));
|
||||
maxsymbol.setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value()));
|
||||
minsymbol.setBrush(QBrush(mincolorbutton->paletteBackgroundColor()));
|
||||
minsymbol.setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value()));
|
||||
}
|
||||
QgsRenderItem *maximumitem = new QgsRenderItem(maxsymbol, QString::number(maximum, 'f'), " ");
|
||||
|
||||
//set the render items to the buffer renderer of the property dialog (if there is one)
|
||||
QgsContinuousColRenderer *renderer;
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
QgsRenderItem *minimumitem = new QgsRenderItem(minsymbol, QString::number(minimum, 'f'), " ");
|
||||
|
||||
|
||||
QgsSymbol maxsymbol;
|
||||
if (mVectorLayer->vectorType() == QGis::Line)
|
||||
{
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(m_vectorlayer->propertiesDialog()->getBufferRenderer());
|
||||
} else
|
||||
maxsymbol.setPen(QPen(maxcolorbutton->paletteBackgroundColor(),outlinewidthspinbox->value()));
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(m_vectorlayer->renderer());
|
||||
maxsymbol.setBrush(QBrush(maxcolorbutton->paletteBackgroundColor()));
|
||||
maxsymbol.setPen(QPen(QColor(0, 0, 0), outlinewidthspinbox->value()));
|
||||
}
|
||||
|
||||
if (renderer)
|
||||
QgsRenderItem *maximumitem = new QgsRenderItem(maxsymbol, QString::number(maximum, 'f'), " ");
|
||||
|
||||
//set the render items to the buffer renderer of the property dialog (if there is one)
|
||||
QgsContinuousColRenderer *renderer;
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
renderer->setMinimumItem(minimumitem);
|
||||
renderer->setMaximumItem(maximumitem);
|
||||
renderer->setClassificationField(classfield);
|
||||
} else
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(mVectorLayer->propertiesDialog()->getBufferRenderer());
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Warning, typecast failed in QgsContColDialog::apply()");
|
||||
return;
|
||||
renderer = dynamic_cast < QgsContinuousColRenderer * >(mVectorLayer->renderer());
|
||||
}
|
||||
|
||||
//add a pixmap to the legend item
|
||||
|
||||
//font tor the legend text
|
||||
//TODO Make the font a user option
|
||||
QFont f("times", 12, QFont::Normal);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
//spaces in pixel
|
||||
int topspace = 5; //space between top of pixmap and first row
|
||||
int leftspace = 10; //space between left side and text/graphics
|
||||
int rightspace = 5; //space betwee text/graphics and right side
|
||||
int bottomspace = 5; //space between last row and bottom of the pixmap
|
||||
int gradientwidth = 40; //widht of the gradient
|
||||
int gradientheight = 100; //height of the gradient
|
||||
int wordspace = 10; //space between graphics/word
|
||||
|
||||
//add a pixmap to the QgsLegendItem
|
||||
QPixmap *pix = m_vectorlayer->legendPixmap();
|
||||
//use the name and the maximum value to estimate the necessary width of the pixmap
|
||||
QString name;
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
|
||||
if (renderer)
|
||||
{
|
||||
name = m_vectorlayer->propertiesDialog()->displayName();
|
||||
} else
|
||||
renderer->setMinimumItem(minimumitem);
|
||||
renderer->setMaximumItem(maximumitem);
|
||||
renderer->setClassificationField(classfield);
|
||||
}
|
||||
else
|
||||
{
|
||||
name = "";
|
||||
qWarning("Warning, typecast failed in QgsContColDialog::apply()");
|
||||
return;
|
||||
}
|
||||
int namewidth = fm.width(name);
|
||||
int numberlength = gradientwidth + wordspace + fm.width(QString::number(maximum, 'f', 2));
|
||||
int pixwidth = (numberlength > namewidth) ? numberlength : namewidth;
|
||||
pix->resize(leftspace + pixwidth + rightspace, topspace + 2 * fm.height() + gradientheight + bottomspace);
|
||||
pix->fill();
|
||||
QPainter p(pix);
|
||||
|
||||
p.setPen(QPen(QColor(0, 0, 0), 1));
|
||||
p.setFont(f);
|
||||
//draw the layer name and the name of the classification field into the pixmap
|
||||
p.drawText(leftspace, topspace + fm.height(), name);
|
||||
p.drawText(leftspace, topspace + fm.height() * 2, classificationComboBox->currentText());
|
||||
|
||||
int rangeoffset = topspace + fm.height() * 2;
|
||||
|
||||
//draw the color range line by line
|
||||
for (int i = 0; i < gradientheight; i++)
|
||||
|
||||
//add a pixmap to the legend item
|
||||
|
||||
//font tor the legend text
|
||||
QFont f("times", 12, QFont::Normal);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
//spaces in pixel
|
||||
int topspace = 5; //space between top of pixmap and first row
|
||||
int leftspace = 10; //space between left side and text/graphics
|
||||
int rightspace = 5; //space betwee text/graphics and right side
|
||||
int bottomspace = 5; //space between last row and bottom of the pixmap
|
||||
int gradientwidth = 40; //widht of the gradient
|
||||
int gradientheight = 100; //height of the gradient
|
||||
int wordspace = 10; //space between graphics/word
|
||||
|
||||
//add a pixmap to the QgsLegendItem
|
||||
QPixmap *pix = mVectorLayer->legendPixmap();
|
||||
//use the name and the maximum value to estimate the necessary width of the pixmap
|
||||
QString name;
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
p.setPen(QColor(mincolorbutton->paletteBackgroundColor().red() + (maxcolorbutton->paletteBackgroundColor().red() - mincolorbutton->paletteBackgroundColor().red()) / gradientheight * i, mincolorbutton->paletteBackgroundColor().green() + (maxcolorbutton->paletteBackgroundColor().green() - mincolorbutton->paletteBackgroundColor().green()) / gradientheight * i, mincolorbutton->paletteBackgroundColor().blue() + (maxcolorbutton->paletteBackgroundColor().blue() - mincolorbutton->paletteBackgroundColor().blue()) / gradientheight * i)); //use the appropriate color
|
||||
p.drawLine(leftspace, rangeoffset + i, leftspace + gradientwidth, rangeoffset + i);
|
||||
}
|
||||
|
||||
//draw the minimum and maximum values beside the color range
|
||||
p.setPen(QPen(QColor(0, 0, 0)));
|
||||
p.setFont(f);
|
||||
p.drawText(leftspace + gradientwidth + wordspace, rangeoffset + fm.height(), QString::number(minimum, 'f', 2));
|
||||
p.drawText(leftspace + gradientwidth + wordspace, rangeoffset + gradientheight, QString::number(maximum, 'f', 2));
|
||||
|
||||
if (m_vectorlayer->legendItem())
|
||||
name = mVectorLayer->propertiesDialog()->displayName();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vectorlayer->legendItem()->setPixmap(0, (*pix));
|
||||
name = "";
|
||||
}
|
||||
|
||||
m_vectorlayer->setRenderer(renderer);
|
||||
m_vectorlayer->setRendererDialog(this);
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
int namewidth = fm.width(name);
|
||||
int numberlength = gradientwidth + wordspace + fm.width(QString::number(maximum, 'f', 2));
|
||||
int pixwidth = (numberlength > namewidth) ? numberlength : namewidth;
|
||||
pix->resize(leftspace + pixwidth + rightspace, topspace + 2 * fm.height() + gradientheight + bottomspace);
|
||||
pix->fill();
|
||||
QPainter p(pix);
|
||||
|
||||
p.setPen(QPen(QColor(0, 0, 0), 1));
|
||||
p.setFont(f);
|
||||
//draw the layer name and the name of the classification field into the pixmap
|
||||
p.drawText(leftspace, topspace + fm.height(), name);
|
||||
p.drawText(leftspace, topspace + fm.height() * 2, classificationComboBox->currentText());
|
||||
|
||||
int rangeoffset = topspace + fm.height() * 2;
|
||||
|
||||
//draw the color range line by line
|
||||
for (int i = 0; i < gradientheight; i++)
|
||||
{
|
||||
m_vectorlayer->propertiesDialog()->setRendererDirty(false);
|
||||
p.setPen(QColor(mincolorbutton->paletteBackgroundColor().red() + (maxcolorbutton->paletteBackgroundColor().red() - mincolorbutton->paletteBackgroundColor().red()) / gradientheight * i, mincolorbutton->paletteBackgroundColor().green() + (maxcolorbutton->paletteBackgroundColor().green() - mincolorbutton->paletteBackgroundColor().green()) / gradientheight * i, mincolorbutton->paletteBackgroundColor().blue() + (maxcolorbutton->paletteBackgroundColor().blue() - mincolorbutton->paletteBackgroundColor().blue()) / gradientheight * i)); //use the appropriate color
|
||||
p.drawLine(leftspace, rangeoffset + i, leftspace + gradientwidth, rangeoffset + i);
|
||||
}
|
||||
|
||||
m_vectorlayer->triggerRepaint();
|
||||
|
||||
//draw the minimum and maximum values beside the color range
|
||||
p.setPen(QPen(QColor(0, 0, 0)));
|
||||
p.setFont(f);
|
||||
p.drawText(leftspace + gradientwidth + wordspace, rangeoffset + fm.height(), QString::number(minimum, 'f', 2));
|
||||
p.drawText(leftspace + gradientwidth + wordspace, rangeoffset + gradientheight, QString::number(maximum, 'f', 2));
|
||||
|
||||
if (mVectorLayer->legendItem())
|
||||
{
|
||||
mVectorLayer->legendItem()->setPixmap(0, (*pix));
|
||||
}
|
||||
|
||||
mVectorLayer->setRenderer(renderer);
|
||||
mVectorLayer->setRendererDialog(this);
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
mVectorLayer->propertiesDialog()->setRendererDirty(false);
|
||||
}
|
||||
|
||||
mVectorLayer->triggerRepaint();
|
||||
}
|
||||
|
||||
void QgsContColDialog::selectMinimumColor()
|
||||
{
|
||||
mincolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
m_vectorlayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
mincolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
mVectorLayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
void QgsContColDialog::selectMaximumColor()
|
||||
{
|
||||
maxcolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
m_vectorlayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
maxcolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
mVectorLayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ class QgsContColDialog: public QgsContColDialogBase
|
||||
void selectMinimumColor();
|
||||
void selectMaximumColor();
|
||||
protected:
|
||||
QgsVectorLayer* m_vectorlayer;
|
||||
QgsVectorLayer* mVectorLayer;
|
||||
/**Stores the names and numbers of the fields with numeric values*/
|
||||
std::map<QString,int> m_fieldmap;
|
||||
std::map<QString,int> mFieldMap;
|
||||
private:
|
||||
QgsContColDialog();
|
||||
};
|
||||
|
@ -32,343 +32,345 @@
|
||||
#include "qscrollview.h"
|
||||
#include <qlayout.h>
|
||||
|
||||
QgsGraSyDialog::QgsGraSyDialog(QgsVectorLayer * layer):QgsGraSyDialogBase(), ext(0), m_vectorlayer(layer)
|
||||
QgsGraSyDialog::QgsGraSyDialog(QgsVectorLayer * layer):QgsGraSyDialogBase(), ext(0), mVectorLayer(layer)
|
||||
{
|
||||
|
||||
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("constructor QgsGraSyDialog");
|
||||
qWarning("constructor QgsGraSyDialog");
|
||||
#endif
|
||||
|
||||
setOrientation(Qt::Vertical);
|
||||
setSizeGripEnabled(true);
|
||||
setOrientation(Qt::Vertical);
|
||||
setSizeGripEnabled(true);
|
||||
|
||||
//find out the numerical fields of m_vectorlayer
|
||||
QgsDataProvider *provider;
|
||||
if (provider = m_vectorlayer->getDataProvider())
|
||||
//find out the numerical fields of mVectorLayer
|
||||
QgsDataProvider *provider;
|
||||
if (provider = mVectorLayer->getDataProvider())
|
||||
{
|
||||
std::vector < QgsField > &fields = provider->fields();
|
||||
int fieldnumber = 0;
|
||||
QString str;
|
||||
|
||||
for (std::vector < QgsField >::iterator it = fields.begin(); it != fields.end(); ++it)
|
||||
std::vector < QgsField > &fields = provider->fields();
|
||||
int fieldnumber = 0;
|
||||
QString str;
|
||||
|
||||
for (std::vector < QgsField >::iterator it = fields.begin(); it != fields.end(); ++it)
|
||||
{
|
||||
QString type = (*it).type();
|
||||
if (type != "String" && type != "varchar" && type != "geometry")
|
||||
QString type = (*it).type();
|
||||
if (type != "String" && type != "varchar" && type != "geometry")
|
||||
{
|
||||
str = (*it).name();
|
||||
str = str.left(1).upper() + str.right(str.length() - 1); //make the first letter uppercase
|
||||
classificationComboBox->insertItem(str);
|
||||
m_fieldmap.insert(std::make_pair(str, fieldnumber));
|
||||
str = (*it).name();
|
||||
str = str.left(1).upper() + str.right(str.length() - 1); //make the first letter uppercase
|
||||
classificationComboBox->insertItem(str);
|
||||
mFieldMap.insert(std::make_pair(str, fieldnumber));
|
||||
}
|
||||
fieldnumber++;
|
||||
fieldnumber++;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Warning, data provider is null in QgsGraSyDialog::QgsGraSyDialog(...)");
|
||||
return;
|
||||
qWarning("Warning, data provider is null in QgsGraSyDialog::QgsGraSyDialog(...)");
|
||||
return;
|
||||
}
|
||||
|
||||
modeComboBox->insertItem("Empty");
|
||||
modeComboBox->insertItem("Equal Interval");
|
||||
|
||||
//restore the correct settings
|
||||
QgsGraduatedSymRenderer *renderer;
|
||||
|
||||
//initial settings, use the buffer of the propertiesDialog if possible. If this is not possible, use the renderer of the vectorlayer directly
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
modeComboBox->insertItem("Empty");
|
||||
modeComboBox->insertItem("Equal Interval");
|
||||
|
||||
//restore the correct settings
|
||||
QgsGraduatedSymRenderer *renderer;
|
||||
|
||||
//initial settings, use the buffer of the propertiesDialog if possible. If this is not possible, use the renderer of the vectorlayer directly
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
renderer = dynamic_cast < QgsGraduatedSymRenderer * >(layer->propertiesDialog()->getBufferRenderer());
|
||||
} else
|
||||
renderer = dynamic_cast < QgsGraduatedSymRenderer * >(layer->propertiesDialog()->getBufferRenderer());
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = dynamic_cast < QgsGraduatedSymRenderer * >(layer->renderer());
|
||||
renderer = dynamic_cast < QgsGraduatedSymRenderer * >(layer->renderer());
|
||||
}
|
||||
|
||||
|
||||
if (renderer)
|
||||
if (renderer)
|
||||
{
|
||||
std::list < QgsRangeRenderItem * >list = renderer->items();
|
||||
std::list < QgsRangeRenderItem * >list = renderer->items();
|
||||
|
||||
ext = new QgsGraSyExtensionWidget(this, renderer->classificationField(), QgsGraSyDialog::EMPTY, list.size(), mVectorLayer);
|
||||
|
||||
classificationComboBox->setCurrentItem(renderer->classificationField());
|
||||
|
||||
ext = new QgsGraSyExtensionWidget(this, renderer->classificationField(), QgsGraSyDialog::EMPTY, list.size(), m_vectorlayer);
|
||||
QGis::VectorType m_type = mVectorLayer->vectorType();
|
||||
|
||||
|
||||
//todo:find out the fieldname for the classification field
|
||||
classificationComboBox->setCurrentItem(renderer->classificationField());
|
||||
|
||||
QGis::VectorType m_type = m_vectorlayer->vectorType();
|
||||
|
||||
//set the right colors and texts to the widgets
|
||||
int number = 0;
|
||||
for (std::list < QgsRangeRenderItem * >::iterator it = list.begin(); it != list.end(); ++it)
|
||||
//set the right colors and texts to the widgets
|
||||
int number = 0;
|
||||
for (std::list < QgsRangeRenderItem * >::iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
((QLineEdit *) (ext->getWidget(0, number)))->setText((*it)->value());
|
||||
((QLineEdit *) ext->getWidget(1, number))->setText((*it)->upper_value());
|
||||
((QLineEdit *) ext->getWidget(2, number))->setText((*it)->label());
|
||||
if(m_type != QGis::Polygon || number < 1)
|
||||
{
|
||||
((QPushButton *) ext->getWidget(3, number))->setPaletteBackgroundColor((*it)->getSymbol()->pen().color());
|
||||
((QPushButton *) ext->getWidget(4, number))->setPixmap(QgsSymbologyUtils::penStyle2Pixmap((*it)->getSymbol()->pen().style()));
|
||||
((QPushButton *) ext->getWidget(4, number))->setName(QgsSymbologyUtils::penStyle2Char((*it)->getSymbol()->pen().style()));
|
||||
}
|
||||
|
||||
((QSpinBox *) ext->getWidget(5, number))->setValue((*it)->getSymbol()->pen().width());
|
||||
if(m_type!=QGis::Line)
|
||||
{
|
||||
((QPushButton *) ext->getWidget(6, number))->setPaletteBackgroundColor((*it)->getSymbol()->brush().color());
|
||||
((QPushButton *) ext->getWidget(7, number))->setName(QgsSymbologyUtils::brushStyle2Char((*it)->getSymbol()->brush().style()));
|
||||
((QPushButton *) ext->getWidget(7, number))->setPixmap(QgsSymbologyUtils::brushStyle2Pixmap((*it)->getSymbol()->brush().style()));
|
||||
}
|
||||
number++;
|
||||
((QLineEdit *) (ext->getWidget(0, number)))->setText((*it)->value());
|
||||
((QLineEdit *) ext->getWidget(1, number))->setText((*it)->upper_value());
|
||||
((QLineEdit *) ext->getWidget(2, number))->setText((*it)->label());
|
||||
if(m_type != QGis::Polygon || number < 1)
|
||||
{
|
||||
((QPushButton *) ext->getWidget(3, number))->setPaletteBackgroundColor((*it)->getSymbol()->pen().color());
|
||||
((QPushButton *) ext->getWidget(4, number))->setPixmap(QgsSymbologyUtils::penStyle2Pixmap((*it)->getSymbol()->pen().style()));
|
||||
((QPushButton *) ext->getWidget(4, number))->setName(QgsSymbologyUtils::penStyle2Char((*it)->getSymbol()->pen().style()));
|
||||
}
|
||||
|
||||
((QSpinBox *) ext->getWidget(5, number))->setValue((*it)->getSymbol()->pen().width());
|
||||
if(m_type!=QGis::Line)
|
||||
{
|
||||
((QPushButton *) ext->getWidget(6, number))->setPaletteBackgroundColor((*it)->getSymbol()->brush().color());
|
||||
((QPushButton *) ext->getWidget(7, number))->setName(QgsSymbologyUtils::brushStyle2Char((*it)->getSymbol()->brush().style()));
|
||||
((QPushButton *) ext->getWidget(7, number))->setPixmap(QgsSymbologyUtils::brushStyle2Pixmap((*it)->getSymbol()->brush().style()));
|
||||
}
|
||||
number++;
|
||||
}
|
||||
|
||||
numberofclassesspinbox->setValue(list.size());
|
||||
|
||||
if (numberofclassesspinbox->value() == 0)
|
||||
|
||||
numberofclassesspinbox->setValue(list.size());
|
||||
|
||||
if (numberofclassesspinbox->value() == 0)
|
||||
{
|
||||
ext = 0;
|
||||
return;
|
||||
ext = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
numberofclassesspinbox->setValue(list.size());
|
||||
QgsGraSyDialogBaseLayout->addMultiCellWidget(ext, 5, 5, 0, 3);
|
||||
ext->show();
|
||||
|
||||
|
||||
numberofclassesspinbox->setValue(list.size());
|
||||
QgsGraSyDialogBaseLayout->addMultiCellWidget(ext, 5, 5, 0, 3);
|
||||
ext->show();
|
||||
|
||||
}
|
||||
|
||||
//do the necessary signal/slot connections
|
||||
QObject::connect(numberofclassesspinbox, SIGNAL(valueChanged(int)), this, SLOT(adjustNumberOfClasses()));
|
||||
QObject::connect(classificationComboBox, SIGNAL(activated(int)), this, SLOT(adjustNumberOfClasses()));
|
||||
QObject::connect(modeComboBox, SIGNAL(activated(int)), this, SLOT(adjustNumberOfClasses()));
|
||||
|
||||
//do the necessary signal/slot connections
|
||||
QObject::connect(numberofclassesspinbox, SIGNAL(valueChanged(int)), this, SLOT(adjustNumberOfClasses()));
|
||||
QObject::connect(classificationComboBox, SIGNAL(activated(int)), this, SLOT(adjustNumberOfClasses()));
|
||||
QObject::connect(modeComboBox, SIGNAL(activated(int)), this, SLOT(adjustNumberOfClasses()));
|
||||
}
|
||||
|
||||
QgsGraSyDialog::QgsGraSyDialog()
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("constructor QgsGraSyDialog");
|
||||
qWarning("constructor QgsGraSyDialog");
|
||||
#endif
|
||||
}
|
||||
|
||||
QgsGraSyDialog::~QgsGraSyDialog()
|
||||
{
|
||||
if (ext)
|
||||
if (ext)
|
||||
{
|
||||
ext->hide();
|
||||
delete ext;
|
||||
ext->hide();
|
||||
delete ext;
|
||||
}
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("destructor QgsGraSyDialog");
|
||||
qWarning("destructor QgsGraSyDialog");
|
||||
#endif
|
||||
}
|
||||
|
||||
void QgsGraSyDialog::adjustNumberOfClasses()
|
||||
{
|
||||
//find out the number of the classification field
|
||||
QString fieldstring = classificationComboBox->currentText();
|
||||
|
||||
if (fieldstring.isEmpty()) //don't do anything, it there is no classification field
|
||||
//find out the number of the classification field
|
||||
QString fieldstring = classificationComboBox->currentText();
|
||||
|
||||
if (fieldstring.isEmpty()) //don't do anything, it there is no classification field
|
||||
{
|
||||
show();
|
||||
return;
|
||||
show();
|
||||
return;
|
||||
}
|
||||
|
||||
std::map < QString, int >::iterator iter = m_fieldmap.find(fieldstring);
|
||||
int field = iter->second;
|
||||
|
||||
if(ext)
|
||||
{
|
||||
QgsGraSyDialogBaseLayout->remove(ext);
|
||||
delete ext;
|
||||
}
|
||||
|
||||
//create a new extension dialog
|
||||
if (modeComboBox->currentText() == "Empty")
|
||||
|
||||
std::map < QString, int >::iterator iter = mFieldMap.find(fieldstring);
|
||||
int field = iter->second;
|
||||
|
||||
if(ext)
|
||||
{
|
||||
ext = new QgsGraSyExtensionWidget(this, field, QgsGraSyDialog::EMPTY, numberofclassesspinbox->value(), m_vectorlayer);
|
||||
} else if (modeComboBox->currentText() == "Equal Interval")
|
||||
{
|
||||
ext = new QgsGraSyExtensionWidget(this, field, QgsGraSyDialog::EQUAL_INTERVAL, numberofclassesspinbox->value(), m_vectorlayer);
|
||||
QgsGraSyDialogBaseLayout->remove(ext);
|
||||
delete ext;
|
||||
}
|
||||
|
||||
if (numberofclassesspinbox->value() == 0)
|
||||
{
|
||||
ext = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
QgsGraSyDialogBaseLayout->addMultiCellWidget(ext, 5, 5, 0, 3);
|
||||
ext->show();
|
||||
|
||||
|
||||
//create a new extension dialog
|
||||
if (modeComboBox->currentText() == "Empty")
|
||||
{
|
||||
ext = new QgsGraSyExtensionWidget(this, field, QgsGraSyDialog::EMPTY, numberofclassesspinbox->value(), mVectorLayer);
|
||||
}
|
||||
else if (modeComboBox->currentText() == "Equal Interval")
|
||||
{
|
||||
ext = new QgsGraSyExtensionWidget(this, field, QgsGraSyDialog::EQUAL_INTERVAL, numberofclassesspinbox->value(), mVectorLayer);
|
||||
}
|
||||
|
||||
if (numberofclassesspinbox->value() == 0)
|
||||
{
|
||||
ext = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
QgsGraSyDialogBaseLayout->addMultiCellWidget(ext, 5, 5, 0, 3);
|
||||
ext->show();
|
||||
|
||||
}
|
||||
|
||||
void QgsGraSyDialog::apply()
|
||||
{
|
||||
if (ext)
|
||||
if (ext)
|
||||
{
|
||||
if (classificationComboBox->currentText().isEmpty()) //don't do anything, it there is no classification field
|
||||
if (classificationComboBox->currentText().isEmpty()) //don't do anything, it there is no classification field
|
||||
{
|
||||
return;
|
||||
}
|
||||
//font tor the legend text
|
||||
//TODO Make the font a user option
|
||||
QFont f("times", 12, QFont::Normal);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
//spaces
|
||||
int topspace = 5;
|
||||
int bottomspace = 5;
|
||||
int leftspace = 10; //space between left side of the pixmap and the text/graphics
|
||||
int rightspace = 5; //space between text/graphics and right side of the pixmap
|
||||
int wordspace = 5; //space between graphics/word
|
||||
int symbolheight = 15; //height of an area where a symbol is painted
|
||||
int symbolwidth = 15; //width of an area where a symbol is painted
|
||||
int rowspace = 5; //spaces between rows of symbols
|
||||
int rowheight = (fm.height() > symbolheight) ? fm.height() : symbolheight; //height of a row in the symbology part
|
||||
//find out the width of the widest label
|
||||
QString widestlabel = "";
|
||||
for (int i = 0; i < numberofclassesspinbox->value(); i++)
|
||||
{
|
||||
QString string = ((QLineEdit *) (ext->getWidget(2, i)))->text();
|
||||
if (string.length() > widestlabel.length())
|
||||
{
|
||||
widestlabel = string;
|
||||
}
|
||||
}
|
||||
int labelwidth = fm.width(widestlabel);
|
||||
//create the pixmap for the render item
|
||||
QPixmap *pix = m_vectorlayer->legendPixmap();
|
||||
QString name;
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
{
|
||||
name = m_vectorlayer->propertiesDialog()->displayName();
|
||||
} else
|
||||
{
|
||||
name = "";
|
||||
}
|
||||
//query the name and the maximum upper value to estimate the necessary width of the pixmap (12 pixel width per letter seems to be appropriate)
|
||||
int pixwidth = leftspace + rightspace + symbolwidth + 2 * wordspace + labelwidth + fm.width(((QLineEdit *) (ext->getWidget(1, numberofclassesspinbox->value() - 1)))->text() + " - " + ((QLineEdit *) (ext->getWidget(0, numberofclassesspinbox->value() - 1)))->text()); //width of the pixmap with symbol and values
|
||||
//consider 240 pixel for labels
|
||||
int namewidth = leftspace + fm.width(name) + rightspace;
|
||||
int width = (pixwidth > namewidth) ? pixwidth : namewidth;
|
||||
pix->resize(width, topspace + 2 * fm.height() + bottomspace + (rowheight + rowspace) * numberofclassesspinbox->value());
|
||||
pix->fill();
|
||||
QPainter p(pix);
|
||||
p.setFont(f);
|
||||
//draw the layer name and the name of the classification field into the pixmap
|
||||
p.drawText(leftspace, topspace + fm.height(), name);
|
||||
p.drawText(leftspace, topspace + 2 * fm.height(), classificationComboBox->currentText());
|
||||
|
||||
|
||||
QgsGraduatedSymRenderer *renderer = dynamic_cast < QgsGraduatedSymRenderer * >(m_vectorlayer->renderer());
|
||||
|
||||
if (!renderer)
|
||||
{
|
||||
qWarning("Warning, typecast failed in QgsGraSyDialog::apply()");
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
renderer->removeItems();
|
||||
|
||||
int offset = topspace + 2 * fm.height();
|
||||
int rowincrement = rowheight + rowspace;
|
||||
for (int i = 0; i < numberofclassesspinbox->value(); i++)
|
||||
//font tor the legend text
|
||||
QFont f("times", 12, QFont::Normal);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
//spaces
|
||||
int topspace = 5;
|
||||
int bottomspace = 5;
|
||||
int leftspace = 10; //space between left side of the pixmap and the text/graphics
|
||||
int rightspace = 5; //space between text/graphics and right side of the pixmap
|
||||
int wordspace = 5; //space between graphics/word
|
||||
int symbolheight = 15; //height of an area where a symbol is painted
|
||||
int symbolwidth = 15; //width of an area where a symbol is painted
|
||||
int rowspace = 5; //spaces between rows of symbols
|
||||
int rowheight = (fm.height() > symbolheight) ? fm.height() : symbolheight; //height of a row in the symbology part
|
||||
//find out the width of the widest label
|
||||
QString widestlabel = "";
|
||||
for (int i = 0; i < numberofclassesspinbox->value(); i++)
|
||||
{
|
||||
QgsSymbol sy(QColor(255, 0, 0));
|
||||
|
||||
if (m_vectorlayer->vectorType() == QGis::Polygon)
|
||||
QString string = ((QLineEdit *) (ext->getWidget(2, i)))->text();
|
||||
if (string.length() > widestlabel.length())
|
||||
{
|
||||
sy.pen().setColor(((QPushButton *) (ext->getWidget(3, 0)))->paletteBackgroundColor());
|
||||
//sy.pen().setStyle(QgsSymbologyUtils::qString2PenStyle((((QPushButton*)(ext->getWidget(4,0)))->text())));
|
||||
sy.pen().setStyle(QgsSymbologyUtils::char2PenStyle((((QPushButton *) (ext->getWidget(4, 0)))->name())));
|
||||
sy.pen().setWidth(((QSpinBox *) (ext->getWidget(5, 0)))->value());
|
||||
} else
|
||||
{
|
||||
sy.pen().setColor(((QPushButton *) (ext->getWidget(3, i)))->paletteBackgroundColor());
|
||||
//sy.pen().setStyle(QgsSymbologyUtils::qString2PenStyle((((QPushButton*)(ext->getWidget(4,i)))->text())));
|
||||
sy.pen().setStyle(QgsSymbologyUtils::char2PenStyle((((QPushButton *) (ext->getWidget(4, i)))->name())));
|
||||
sy.pen().setWidth(((QSpinBox *) (ext->getWidget(5, i)))->value());
|
||||
widestlabel = string;
|
||||
}
|
||||
|
||||
if (m_vectorlayer->vectorType() != QGis::Line)
|
||||
}
|
||||
int labelwidth = fm.width(widestlabel);
|
||||
//create the pixmap for the render item
|
||||
QPixmap *pix = mVectorLayer->legendPixmap();
|
||||
QString name;
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
name = mVectorLayer->propertiesDialog()->displayName();
|
||||
}
|
||||
else
|
||||
{
|
||||
name = "";
|
||||
}
|
||||
//query the name and the maximum upper value to estimate the necessary width of the pixmap (12 pixel width per letter seems to be appropriate)
|
||||
int pixwidth = leftspace + rightspace + symbolwidth + 2 * wordspace + labelwidth + fm.width(((QLineEdit *) (ext->getWidget(1, numberofclassesspinbox->value() - 1)))->text() + " - " + ((QLineEdit *) (ext->getWidget(0, numberofclassesspinbox->value() - 1)))->text()); //width of the pixmap with symbol and values
|
||||
//consider 240 pixel for labels
|
||||
int namewidth = leftspace + fm.width(name) + rightspace;
|
||||
int width = (pixwidth > namewidth) ? pixwidth : namewidth;
|
||||
pix->resize(width, topspace + 2 * fm.height() + bottomspace + (rowheight + rowspace) * numberofclassesspinbox->value());
|
||||
pix->fill();
|
||||
QPainter p(pix);
|
||||
p.setFont(f);
|
||||
//draw the layer name and the name of the classification field into the pixmap
|
||||
p.drawText(leftspace, topspace + fm.height(), name);
|
||||
p.drawText(leftspace, topspace + 2 * fm.height(), classificationComboBox->currentText());
|
||||
|
||||
|
||||
QgsGraduatedSymRenderer *renderer = dynamic_cast < QgsGraduatedSymRenderer * >(mVectorLayer->renderer());
|
||||
|
||||
if (!renderer)
|
||||
{
|
||||
qWarning("Warning, typecast failed in QgsGraSyDialog::apply()");
|
||||
return;
|
||||
}
|
||||
|
||||
renderer->removeItems();
|
||||
|
||||
int offset = topspace + 2 * fm.height();
|
||||
int rowincrement = rowheight + rowspace;
|
||||
for (int i = 0; i < numberofclassesspinbox->value(); i++)
|
||||
{
|
||||
QgsSymbol sy(QColor(255, 0, 0));
|
||||
|
||||
if (mVectorLayer->vectorType() == QGis::Polygon)
|
||||
{
|
||||
sy.brush().setColor(((QPushButton *) (ext->getWidget(6, i)))->paletteBackgroundColor());
|
||||
sy.pen().setColor(((QPushButton *) (ext->getWidget(3, 0)))->paletteBackgroundColor());
|
||||
sy.pen().setStyle(QgsSymbologyUtils::char2PenStyle((((QPushButton *) (ext->getWidget(4, 0)))->name())));
|
||||
sy.pen().setWidth(((QSpinBox *) (ext->getWidget(5, 0)))->value());
|
||||
}
|
||||
else
|
||||
{
|
||||
sy.pen().setColor(((QPushButton *) (ext->getWidget(3, i)))->paletteBackgroundColor());
|
||||
sy.pen().setStyle(QgsSymbologyUtils::char2PenStyle((((QPushButton *) (ext->getWidget(4, i)))->name())));
|
||||
sy.pen().setWidth(((QSpinBox *) (ext->getWidget(5, i)))->value());
|
||||
}
|
||||
|
||||
if (m_vectorlayer->vectorType() == QGis::Polygon)
|
||||
|
||||
if (mVectorLayer->vectorType() != QGis::Line)
|
||||
{
|
||||
//sy.brush().setStyle(QgsSymbologyUtils::qString2BrushStyle((((QPushButton*)(ext->getWidget(7,i)))->text())));
|
||||
sy.brush().setStyle(QgsSymbologyUtils::char2BrushStyle((((QPushButton *) (ext->getWidget(7, i)))->name())));
|
||||
} else if (m_vectorlayer->vectorType() == QGis::Point)
|
||||
{
|
||||
sy.brush().setStyle(Qt::SolidPattern);
|
||||
sy.brush().setColor(((QPushButton *) (ext->getWidget(6, i)))->paletteBackgroundColor());
|
||||
}
|
||||
QString lower_bound = ((QLineEdit *) (ext->getWidget(0, i)))->text();
|
||||
QString upper_bound = ((QLineEdit *) (ext->getWidget(1, i)))->text();
|
||||
QString label = ((QLineEdit *) (ext->getWidget(2, i)))->text();
|
||||
|
||||
//test, if lower_bound is numeric or not (making a subclass of QString would be the proper solution)
|
||||
bool lbcontainsletter = false;
|
||||
for (uint j = 0; j < lower_bound.length(); j++)
|
||||
|
||||
if (mVectorLayer->vectorType() == QGis::Polygon)
|
||||
{
|
||||
if (lower_bound.ref(j).isLetter())
|
||||
sy.brush().setStyle(QgsSymbologyUtils::char2BrushStyle((((QPushButton *) (ext->getWidget(7, i)))->name())));
|
||||
}
|
||||
else if (mVectorLayer->vectorType() == QGis::Point)
|
||||
{
|
||||
sy.brush().setStyle(Qt::SolidPattern);
|
||||
}
|
||||
QString lower_bound = ((QLineEdit *) (ext->getWidget(0, i)))->text();
|
||||
QString upper_bound = ((QLineEdit *) (ext->getWidget(1, i)))->text();
|
||||
QString label = ((QLineEdit *) (ext->getWidget(2, i)))->text();
|
||||
|
||||
//test, if lower_bound is numeric or not (making a subclass of QString would be the proper solution)
|
||||
bool lbcontainsletter = false;
|
||||
for (uint j = 0; j < lower_bound.length(); j++)
|
||||
{
|
||||
if (lower_bound.ref(j).isLetter())
|
||||
{
|
||||
lbcontainsletter = true;
|
||||
lbcontainsletter = true;
|
||||
}
|
||||
}
|
||||
|
||||
//test, if upper_bound is numeric or not (making a subclass of QString would be the proper solution)
|
||||
bool ubcontainsletter = false;
|
||||
for (uint j = 0; j < upper_bound.length(); j++)
|
||||
|
||||
//test, if upper_bound is numeric or not (making a subclass of QString would be the proper solution)
|
||||
bool ubcontainsletter = false;
|
||||
for (uint j = 0; j < upper_bound.length(); j++)
|
||||
{
|
||||
if (upper_bound.ref(j).isLetter())
|
||||
if (upper_bound.ref(j).isLetter())
|
||||
{
|
||||
ubcontainsletter = true;
|
||||
ubcontainsletter = true;
|
||||
}
|
||||
}
|
||||
if (lbcontainsletter == false && ubcontainsletter == false && lower_bound.length() > 0 && upper_bound.length() > 0) //only add the item if the value bounds do not contain letters and are not null strings
|
||||
if (lbcontainsletter == false && ubcontainsletter == false && lower_bound.length() > 0 && upper_bound.length() > 0) //only add the item if the value bounds do not contain letters and are not null strings
|
||||
{
|
||||
QgsRangeRenderItem *item =
|
||||
new QgsRangeRenderItem(sy, lower_bound, upper_bound, ((QLineEdit *) (ext->getWidget(2, i)))->text());
|
||||
QgsRangeRenderItem *item = new QgsRangeRenderItem(sy, lower_bound, upper_bound, ((QLineEdit *) (ext->getWidget(2, i)))->text());
|
||||
|
||||
renderer->addItem(item);
|
||||
//add the symbol to the picture
|
||||
|
||||
renderer->addItem(item);
|
||||
//add the symbol to the picture
|
||||
|
||||
QString legendstring = lower_bound + " - " + upper_bound;
|
||||
p.setPen(sy.pen());
|
||||
p.setBrush(sy.brush());
|
||||
if (m_vectorlayer->vectorType() == QGis::Polygon)
|
||||
QString legendstring = lower_bound + " - " + upper_bound;
|
||||
p.setPen(sy.pen());
|
||||
p.setBrush(sy.brush());
|
||||
if (mVectorLayer->vectorType() == QGis::Polygon)
|
||||
{
|
||||
p.drawRect(leftspace, offset + rowincrement * i + (rowheight - symbolheight), symbolwidth, symbolheight); //implement different painting for lines and points here
|
||||
} else if (m_vectorlayer->vectorType() == QGis::Line)
|
||||
p.drawRect(leftspace, offset + rowincrement * i + (rowheight - symbolheight), symbolwidth, symbolheight); //implement different painting for lines and points here
|
||||
}
|
||||
else if (mVectorLayer->vectorType() == QGis::Line)
|
||||
{
|
||||
p.drawLine(leftspace, offset + rowincrement * i + (rowheight - symbolheight), leftspace + symbolwidth,
|
||||
p.drawLine(leftspace, offset + rowincrement * i + (rowheight - symbolheight), leftspace + symbolwidth,
|
||||
offset + rowincrement * i + rowheight);
|
||||
} else if (m_vectorlayer->vectorType() == QGis::Point)
|
||||
}
|
||||
else if (mVectorLayer->vectorType() == QGis::Point)
|
||||
{
|
||||
p.drawRect(leftspace + symbolwidth / 2, offset + (int) (rowincrement * (i + 0.5)), 5, 5);
|
||||
p.drawRect(leftspace + symbolwidth / 2, offset + (int) (rowincrement * (i + 0.5)), 5, 5);
|
||||
}
|
||||
p.setPen(Qt::black);
|
||||
p.drawText(leftspace + symbolwidth + wordspace, offset + rowincrement * i + rowheight, legendstring);
|
||||
p.drawText(pixwidth - labelwidth - rightspace, offset + rowincrement * i + rowheight, label);
|
||||
p.setPen(Qt::black);
|
||||
p.drawText(leftspace + symbolwidth + wordspace, offset + rowincrement * i + rowheight, legendstring);
|
||||
p.drawText(pixwidth - labelwidth - rightspace, offset + rowincrement * i + rowheight, label);
|
||||
}
|
||||
}
|
||||
renderer->setClassificationField(ext->classfield());
|
||||
|
||||
if (m_vectorlayer->legendItem())
|
||||
renderer->setClassificationField(ext->classfield());
|
||||
|
||||
if (mVectorLayer->legendItem())
|
||||
{
|
||||
m_vectorlayer->legendItem()->setPixmap(0, (*pix));
|
||||
mVectorLayer->legendItem()->setPixmap(0, (*pix));
|
||||
}
|
||||
m_vectorlayer->setRenderer(renderer);
|
||||
m_vectorlayer->setRendererDialog(this);
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
mVectorLayer->setRenderer(renderer);
|
||||
mVectorLayer->setRendererDialog(this);
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
m_vectorlayer->propertiesDialog()->setRendererDirty(false);
|
||||
mVectorLayer->propertiesDialog()->setRendererDirty(false);
|
||||
}
|
||||
m_vectorlayer->triggerRepaint();
|
||||
mVectorLayer->triggerRepaint();
|
||||
}
|
||||
|
||||
else //number of classes is 0
|
||||
|
||||
else //number of classes is 0
|
||||
{
|
||||
std::cout << "warning, number of classes is zero" << std::endl << std::flush;
|
||||
std::cout << "warning, number of classes is zero" << std::endl << std::flush;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ class QgsGraSyDialog: public QgsGraSyDialogBase
|
||||
protected:
|
||||
/**Pointer to the curret extension widget*/
|
||||
QgsGraSyExtensionWidget* ext;
|
||||
QgsVectorLayer* m_vectorlayer;
|
||||
QgsVectorLayer* mVectorLayer;
|
||||
/**Stores the names and numbers of the fields with numeric values*/
|
||||
std::map<QString,int> m_fieldmap;
|
||||
std::map<QString,int> mFieldMap;
|
||||
private:
|
||||
/**Default constructor is privat to not use is*/
|
||||
QgsGraSyDialog();
|
||||
|
@ -31,186 +31,187 @@
|
||||
#include "qgsvectorlayerproperties.h"
|
||||
#include <qlineedit.h>
|
||||
|
||||
QgsSiSyDialog::QgsSiSyDialog():QgsSiSyDialogBase(), m_vectorlayer(0)
|
||||
QgsSiSyDialog::QgsSiSyDialog():QgsSiSyDialogBase(), mVectorLayer(0)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("constructor QgsSiSyDialog");
|
||||
qWarning("constructor QgsSiSyDialog");
|
||||
#endif
|
||||
}
|
||||
|
||||
QgsSiSyDialog::QgsSiSyDialog(QgsVectorLayer * layer):QgsSiSyDialogBase(), m_vectorlayer(layer)
|
||||
QgsSiSyDialog::QgsSiSyDialog(QgsVectorLayer * layer):QgsSiSyDialogBase(), mVectorLayer(layer)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("constructor QgsSiSyDialog");
|
||||
qWarning("constructor QgsSiSyDialog");
|
||||
#endif
|
||||
|
||||
if (layer)
|
||||
|
||||
if (layer)
|
||||
{
|
||||
QgsSingleSymRenderer *renderer;
|
||||
|
||||
//initial settings, use the buffer of the propertiesDialog if possible. If this is not possible, use the renderer of the vectorlayer directly
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
QgsSingleSymRenderer *renderer;
|
||||
|
||||
//initial settings, use the buffer of the propertiesDialog if possible. If this is not possible, use the renderer of the vectorlayer directly
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
renderer = dynamic_cast < QgsSingleSymRenderer * >(layer->propertiesDialog()->getBufferRenderer());
|
||||
} else
|
||||
renderer = dynamic_cast < QgsSingleSymRenderer * >(layer->propertiesDialog()->getBufferRenderer());
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = dynamic_cast < QgsSingleSymRenderer * >(layer->renderer());
|
||||
renderer = dynamic_cast < QgsSingleSymRenderer * >(layer->renderer());
|
||||
}
|
||||
|
||||
if (renderer)
|
||||
if (renderer)
|
||||
{
|
||||
outlinewidthspinbox->setValue(renderer->item()->getSymbol()->pen().width());
|
||||
outlinewidthspinbox->setMinValue(1);//set line width 1 as minimum to avoid confusion between line width 0 and no pen line style
|
||||
fillcolorbutton->setPaletteBackgroundColor(renderer->item()->getSymbol()->brush().color());
|
||||
patternbutton->setName(QgsSymbologyUtils::brushStyle2Char(renderer->item()->getSymbol()->brush().style()));
|
||||
patternbutton->setPixmap(QgsSymbologyUtils::char2PatternPixmap(patternbutton->name()));
|
||||
stylebutton->setName(QgsSymbologyUtils::penStyle2Char(renderer->item()->getSymbol()->pen().style()));
|
||||
stylebutton->setPixmap(QgsSymbologyUtils::char2LinePixmap(stylebutton->name()));
|
||||
outlinecolorbutton->setPaletteBackgroundColor(renderer->item()->getSymbol()->pen().color());
|
||||
outlinewidthspinbox->setValue(renderer->item()->getSymbol()->pen().width());
|
||||
outlinewidthspinbox->setMinValue(1);//set line width 1 as minimum to avoid confusion between line width 0 and no pen line style
|
||||
fillcolorbutton->setPaletteBackgroundColor(renderer->item()->getSymbol()->brush().color());
|
||||
patternbutton->setName(QgsSymbologyUtils::brushStyle2Char(renderer->item()->getSymbol()->brush().style()));
|
||||
patternbutton->setPixmap(QgsSymbologyUtils::char2PatternPixmap(patternbutton->name()));
|
||||
stylebutton->setName(QgsSymbologyUtils::penStyle2Char(renderer->item()->getSymbol()->pen().style()));
|
||||
stylebutton->setPixmap(QgsSymbologyUtils::char2LinePixmap(stylebutton->name()));
|
||||
outlinecolorbutton->setPaletteBackgroundColor(renderer->item()->getSymbol()->pen().color());
|
||||
}
|
||||
|
||||
if (m_vectorlayer && m_vectorlayer->vectorType() == QGis::Line)
|
||||
if (mVectorLayer && mVectorLayer->vectorType() == QGis::Line)
|
||||
{
|
||||
fillcolorbutton->unsetPalette();
|
||||
fillcolorbutton->setEnabled(false);
|
||||
patternbutton->setText("");
|
||||
patternbutton->setEnabled(false);
|
||||
fillcolorbutton->unsetPalette();
|
||||
fillcolorbutton->setEnabled(false);
|
||||
patternbutton->setText("");
|
||||
patternbutton->setEnabled(false);
|
||||
}
|
||||
//do the signal/slot connections
|
||||
QObject::connect(outlinecolorbutton, SIGNAL(clicked()), this, SLOT(selectOutlineColor()));
|
||||
QObject::connect(stylebutton, SIGNAL(clicked()), this, SLOT(selectOutlineStyle()));
|
||||
QObject::connect(fillcolorbutton, SIGNAL(clicked()), this, SLOT(selectFillColor()));
|
||||
QObject::connect(patternbutton, SIGNAL(clicked()), this, SLOT(selectFillPattern()));
|
||||
} else
|
||||
//do the signal/slot connections
|
||||
QObject::connect(outlinecolorbutton, SIGNAL(clicked()), this, SLOT(selectOutlineColor()));
|
||||
QObject::connect(stylebutton, SIGNAL(clicked()), this, SLOT(selectOutlineStyle()));
|
||||
QObject::connect(fillcolorbutton, SIGNAL(clicked()), this, SLOT(selectFillColor()));
|
||||
QObject::connect(patternbutton, SIGNAL(clicked()), this, SLOT(selectFillPattern()));
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Warning, layer is a null pointer in QgsSiSyDialog::QgsSiSyDialog(QgsVectorLayer)");
|
||||
qWarning("Warning, layer is a null pointer in QgsSiSyDialog::QgsSiSyDialog(QgsVectorLayer)");
|
||||
}
|
||||
}
|
||||
|
||||
QgsSiSyDialog::~QgsSiSyDialog()
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("destructor QgsSiSyDialog");
|
||||
qWarning("destructor QgsSiSyDialog");
|
||||
#endif
|
||||
}
|
||||
|
||||
void QgsSiSyDialog::selectOutlineColor()
|
||||
{
|
||||
outlinecolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
m_vectorlayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
outlinecolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
mVectorLayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
void QgsSiSyDialog::selectOutlineStyle()
|
||||
{
|
||||
QgsLineStyleDialog linestyledialog;
|
||||
if (linestyledialog.exec() == QDialog::Accepted)
|
||||
QgsLineStyleDialog linestyledialog;
|
||||
if (linestyledialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
stylebutton->setName(QgsSymbologyUtils::penStyle2QString(linestyledialog.style()).ascii());
|
||||
stylebutton->setPixmap(QgsSymbologyUtils::qString2LinePixmap(QString::fromAscii(stylebutton->name())));
|
||||
stylebutton->setName(QgsSymbologyUtils::penStyle2QString(linestyledialog.style()).ascii());
|
||||
stylebutton->setPixmap(QgsSymbologyUtils::qString2LinePixmap(QString::fromAscii(stylebutton->name())));
|
||||
}
|
||||
m_vectorlayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
mVectorLayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
void QgsSiSyDialog::selectFillColor()
|
||||
{
|
||||
fillcolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
m_vectorlayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
fillcolorbutton->setPaletteBackgroundColor(QColorDialog::getColor());
|
||||
mVectorLayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
void QgsSiSyDialog::selectFillPattern()
|
||||
{
|
||||
QgsPatternDialog patterndialog;
|
||||
if (patterndialog.exec() == QDialog::Accepted)
|
||||
QgsPatternDialog patterndialog;
|
||||
if (patterndialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
patternbutton->setName(QgsSymbologyUtils::brushStyle2Char(patterndialog.pattern()));
|
||||
patternbutton->setPixmap(QgsSymbologyUtils::brushStyle2Pixmap(patterndialog.pattern()));
|
||||
patternbutton->setName(QgsSymbologyUtils::brushStyle2Char(patterndialog.pattern()));
|
||||
patternbutton->setPixmap(QgsSymbologyUtils::brushStyle2Pixmap(patterndialog.pattern()));
|
||||
}
|
||||
m_vectorlayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
mVectorLayer->propertiesDialog()->raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
void QgsSiSyDialog::apply()
|
||||
{
|
||||
//query the values of the widgets and set the symbology of the vector layer
|
||||
QgsSymbol sy(QColor(255, 0, 0));
|
||||
sy.brush().setColor(fillcolorbutton->paletteBackgroundColor());
|
||||
sy.brush().setStyle(QgsSymbologyUtils::char2BrushStyle(patternbutton->name()));
|
||||
sy.pen().setStyle(QgsSymbologyUtils::char2PenStyle(stylebutton->name()));
|
||||
sy.pen().setWidth(outlinewidthspinbox->value());
|
||||
sy.pen().setColor(outlinecolorbutton->paletteBackgroundColor());
|
||||
QgsRenderItem ri(sy, "blabla", "blabla");
|
||||
|
||||
QgsSingleSymRenderer *renderer = dynamic_cast < QgsSingleSymRenderer * >(m_vectorlayer->renderer());
|
||||
|
||||
if (renderer)
|
||||
//query the values of the widgets and set the symbology of the vector layer
|
||||
QgsSymbol sy(QColor(255, 0, 0));
|
||||
sy.brush().setColor(fillcolorbutton->paletteBackgroundColor());
|
||||
sy.brush().setStyle(QgsSymbologyUtils::char2BrushStyle(patternbutton->name()));
|
||||
sy.pen().setStyle(QgsSymbologyUtils::char2PenStyle(stylebutton->name()));
|
||||
sy.pen().setWidth(outlinewidthspinbox->value());
|
||||
sy.pen().setColor(outlinecolorbutton->paletteBackgroundColor());
|
||||
QgsRenderItem ri(sy, "blabla", "blabla");
|
||||
|
||||
QgsSingleSymRenderer *renderer = dynamic_cast < QgsSingleSymRenderer * >(mVectorLayer->renderer());
|
||||
|
||||
if (renderer)
|
||||
{
|
||||
renderer->addItem(ri);
|
||||
} else
|
||||
renderer->addItem(ri);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("typecast failed in QgsSiSyDialog::apply()");
|
||||
return;
|
||||
qWarning("typecast failed in QgsSiSyDialog::apply()");
|
||||
return;
|
||||
}
|
||||
|
||||
//add a pixmap to the legend item
|
||||
|
||||
//font tor the legend text
|
||||
QFont f("times", 12, QFont::Normal);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
QPixmap *pix = mVectorLayer->legendPixmap();
|
||||
|
||||
QString name;
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
name = mVectorLayer->propertiesDialog()->displayName();
|
||||
}
|
||||
else
|
||||
{
|
||||
name = "";
|
||||
}
|
||||
|
||||
//add a pixmap to the legend item
|
||||
int width = 40 + fm.width(name); //problem, how do we determine the width of the displaynamefield now?
|
||||
int height = (fm.height() + 10 > 35) ? fm.height() + 10 : 35;
|
||||
pix->resize(width, height);
|
||||
pix->fill();
|
||||
|
||||
//font tor the legend text
|
||||
//TODO Make the font a user option
|
||||
QFont f("times", 12, QFont::Normal);
|
||||
QFontMetrics fm(f);
|
||||
|
||||
|
||||
QPixmap *pix = m_vectorlayer->legendPixmap();
|
||||
|
||||
|
||||
QString name;
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
QPainter p(pix);
|
||||
p.setPen(sy.pen());
|
||||
p.setBrush(sy.brush());
|
||||
//paint differently in case of point, lines, polygones
|
||||
switch (mVectorLayer->vectorType())
|
||||
{
|
||||
name = m_vectorlayer->propertiesDialog()->displayName();
|
||||
} else
|
||||
{
|
||||
name = "";
|
||||
case QGis::Polygon:
|
||||
p.drawRect(10, pix->height() - 25, 20, 15);
|
||||
break;
|
||||
case QGis::Line:
|
||||
p.drawLine(10, pix->height() - 25, 25, pix->height() - 10);
|
||||
break;
|
||||
case QGis::Point:
|
||||
p.drawRect(20, pix->height() - 17, 5, 5);
|
||||
}
|
||||
|
||||
int width = 40 + fm.width(name); //problem, how do we determine the width of the displaynamefield now?
|
||||
int height = (fm.height() + 10 > 35) ? fm.height() + 10 : 35;
|
||||
pix->resize(width, height);
|
||||
pix->fill();
|
||||
p.setPen(Qt::black);
|
||||
p.setFont(f);
|
||||
p.drawText(35, pix->height() - 10, name); //the problem again
|
||||
|
||||
QPainter p(pix);
|
||||
p.setPen(sy.pen());
|
||||
p.setBrush(sy.brush());
|
||||
//paint differently in case of point, lines, polygones
|
||||
switch (m_vectorlayer->vectorType())
|
||||
if (mVectorLayer->legendItem())
|
||||
{
|
||||
case QGis::Polygon:
|
||||
p.drawRect(10, pix->height() - 25, 20, 15);
|
||||
break;
|
||||
case QGis::Line:
|
||||
p.drawLine(10, pix->height() - 25, 25, pix->height() - 10);
|
||||
break;
|
||||
case QGis::Point:
|
||||
p.drawRect(20, pix->height() - 17, 5, 5);
|
||||
mVectorLayer->legendItem()->setPixmap(0, (*pix));
|
||||
}
|
||||
|
||||
p.setPen(Qt::black);
|
||||
p.setFont(f);
|
||||
p.drawText(35, pix->height() - 10, name); //the problem again
|
||||
|
||||
if (m_vectorlayer->legendItem())
|
||||
|
||||
mVectorLayer->setRenderer(renderer);
|
||||
mVectorLayer->setRendererDialog(this);
|
||||
|
||||
if (mVectorLayer->propertiesDialog())
|
||||
{
|
||||
m_vectorlayer->legendItem()->setPixmap(0, (*pix));
|
||||
mVectorLayer->propertiesDialog()->setRendererDirty(false);
|
||||
}
|
||||
|
||||
m_vectorlayer->setRenderer(renderer);
|
||||
m_vectorlayer->setRendererDialog(this);
|
||||
|
||||
if (m_vectorlayer->propertiesDialog())
|
||||
{
|
||||
m_vectorlayer->propertiesDialog()->setRendererDirty(false);
|
||||
}
|
||||
//repaint the map canvas
|
||||
m_vectorlayer->triggerRepaint();
|
||||
//repaint the map canvas
|
||||
mVectorLayer->triggerRepaint();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class QgsSiSyDialog: public QgsSiSyDialogBase
|
||||
QgsSiSyDialog(QgsVectorLayer* layer);
|
||||
~QgsSiSyDialog();
|
||||
protected:
|
||||
QgsVectorLayer* m_vectorlayer;
|
||||
QgsVectorLayer* mVectorLayer;
|
||||
public slots:
|
||||
/**applies the changes to the vector layer*/
|
||||
void apply();
|
||||
|
Loading…
x
Reference in New Issue
Block a user