New mechanism that speeds up the selection of legend type by storing objects of renderer, renderer dialog and qpixmap in qgsvectorlayerproperties and applying it only if the ok-button or the apply button is pressed. Todo: fix various problems, clean up the code, document it propertly

git-svn-id: http://svn.osgeo.org/qgis/trunk@625 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2004-01-28 14:01:31 +00:00
parent f7c8931a43
commit 8c91ca4efb
17 changed files with 305 additions and 158 deletions

View File

@ -940,8 +940,8 @@ void QgisApp::layerProperties(QListViewItem * lvi)
//TODO Fix this area below and above
//this is a very hacky way to force the legend entry to refresh - the call above does ne happen for some reason
mapCanvas->render2();
mapLegend->update();
//mapCanvas->render2();
//mapLegend->update();
/* else if ((lyr->type()==QgsMapLayer::VECTOR) || (lyr->type()==QgsMapLayer::DATABASE))

View File

@ -128,8 +128,8 @@ void QgsContColDialog::apply()
}
QgsRenderItem* maximumitem=new QgsRenderItem(maxsymbol,QString::number(maximum,'f')," ");
//set the render items to the render of m_vectorlayer
QgsContinuousColRenderer* renderer=dynamic_cast<QgsContinuousColRenderer*>(m_vectorlayer->renderer());
//set the render items to the buffer renderer of the property dialog
QgsContinuousColRenderer* renderer=dynamic_cast<QgsContinuousColRenderer*>(m_vectorlayer->propertiesDialog()->getBufferRenderer());
if(renderer)
{
renderer->setMinimumItem(minimumitem);
@ -191,11 +191,16 @@ void QgsContColDialog::apply()
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));
m_vectorlayer->triggerRepaint();
if(m_vectorlayer->legendItem())
{
m_vectorlayer->legendItem()->setPixmap(0,(*pix));
}
m_vectorlayer->setRenderer(renderer);
m_vectorlayer->setRendererDialog(this);
m_vectorlayer->propertiesDialog()->unsetRendererDirty();
m_vectorlayer->triggerRepaint();
}
void QgsContColDialog::selectMinimumColor()

View File

@ -52,8 +52,14 @@ void QgsContinuousColRenderer::setMaximumItem(QgsRenderItem* it)
m_maximumItem=it;
}
void QgsContinuousColRenderer::initializeSymbology(QgsVectorLayer* layer)
void QgsContinuousColRenderer::initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr)
{
bool toproperties=false;//if false: rendererDialog is associated with the vector layer and image is rendered, true: rendererDialog is associated with buffer dialog of vector layer properties and no image is rendered
if(pr)
{
toproperties=true;
}
setClassificationField(0);//the classification field does not matter
if(layer)
@ -73,7 +79,15 @@ void QgsContinuousColRenderer::initializeSymbology(QgsVectorLayer* layer)
QFont f( "times", 12, QFont::Normal );
QFontMetrics fm(f);
QPixmap* pixmap=layer->legendPixmap();
QPixmap* pixmap;
if(toproperties)
{
pixmap=pr->getBufferPixmap();
}
else
{
pixmap=layer->legendPixmap();
}
QString name=layer->name();
int width=40+fm.width(layer->name());
int height=(fm.height()+10>35) ? fm.height()+10 : 35;
@ -117,12 +131,19 @@ void QgsContinuousColRenderer::initializeSymbology(QgsVectorLayer* layer)
setMaximumItem(QgsRenderItem2);
QgsContColDialog* dialog=new QgsContColDialog(layer);
layer->setRendererDialog(dialog);
QgsLegendItem* item;
if(item=layer->legendItem())
if(toproperties)
{
item->setPixmap(0,(*pixmap));
pr->setBufferDialog(dialog);
}
else
{
layer->setRendererDialog(dialog);
QgsLegendItem* item;
if(item=layer->legendItem())
{
item->setPixmap(0,(*pixmap));
}
}
}
else

View File

@ -25,6 +25,7 @@
#include "qgspoint.h"
#include "qgsfeature.h"
#include <iostream>
#include "qgsvectorlayerproperties.h"
/**Renderer class which interpolates rgb values linear between the minimum and maximum value of the classification field*/
@ -35,7 +36,7 @@ class QgsContinuousColRenderer: public QgsRenderer
~QgsContinuousColRenderer();
/**Sets the initial symbology configuration for a layer. An instance of the corresponding renderer dialog is created and associated with the layer. Finally, a pixmap for the legend is drawn
@param layer the vector layer associated with the renderer*/
void initializeSymbology(QgsVectorLayer* layer);
void initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr=0);
/**Renders the feature using the minimum and maximum value of the classification field*/
void renderFeature(QPainter* p, QgsFeature* f, QgsCoordinateTransform* t);
/**Returns the number of the classification field*/

View File

@ -227,8 +227,14 @@ void QgsGraduatedSymRenderer::renderFeature(QPainter* p, QgsFeature* f, QgsCoord
delete[]feature;
}
void QgsGraduatedSymRenderer::initializeSymbology(QgsVectorLayer* layer)
void QgsGraduatedSymRenderer::initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr)
{
bool toproperties=false;//if false: rendererDialog is associated with the vector layer and image is rendered, true: rendererDialog is associated with buffer dialog of vector layer properties and no image is rendered
if(pr)
{
toproperties=true;
}
setClassificationField(0);//the classification field does not matter
if(layer)
@ -248,7 +254,15 @@ void QgsGraduatedSymRenderer::initializeSymbology(QgsVectorLayer* layer)
QFont f( "times", 12, QFont::Normal );
QFontMetrics fm(f);
QPixmap* pixmap=layer->legendPixmap();
QPixmap* pixmap;
if(toproperties)
{
pixmap=pr->getBufferPixmap();
}
else
{
pixmap=layer->legendPixmap();
}
QString name=layer->name();
int width=40+fm.width(layer->name());
int height=(fm.height()+10>35) ? fm.height()+10 : 35;
@ -289,11 +303,19 @@ void QgsGraduatedSymRenderer::initializeSymbology(QgsVectorLayer* layer)
addItem(ri);
QgsGraSyDialog* dialog=new QgsGraSyDialog(layer);
layer->setRendererDialog(dialog);
QgsLegendItem* item;
if(item=layer->legendItem())
if(toproperties)
{
item->setPixmap(0,(*pixmap));
pr->setBufferDialog(dialog);
}
else
{
layer->setRendererDialog(dialog);
QgsLegendItem* item;
if(item=layer->legendItem())
{
item->setPixmap(0,(*pixmap));
}
}
}
else

View File

@ -27,6 +27,7 @@
#include "qgscoordinatetransform.h"
#include "qgsfeature.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerproperties.h"
/**This class contains the information for graduate symbol rendering*/
class QgsGraduatedSymRenderer: public QgsRenderer
@ -49,7 +50,7 @@ class QgsGraduatedSymRenderer: public QgsRenderer
/**Sets the number of the classicifation field
\param field the number of the field to classify*/
void setClassificationField(int field);
void initializeSymbology(QgsVectorLayer* layer);
void initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr=0);
/**Returns the list with the render items*/
std::list<QgsRangeRenderItem*>& items();
/** Returns true*/

View File

@ -69,52 +69,56 @@ QgsGraSyDialog::QgsGraSyDialog(QgsVectorLayer* layer): QgsGraSyDialogBase(), ext
modeComboBox->insertItem("equal interval");
setSizeGripEnabled(true);
//restore the correct settings
QgsGraduatedSymRenderer* renderer=dynamic_cast<QgsGraduatedSymRenderer*>(m_vectorlayer->renderer());
if(renderer)
if(!m_vectorlayer->propertiesDialog()->getRendererDirty())
{
std::list<QgsRangeRenderItem*> list=renderer->items();
//restore the correct settings
QgsGraduatedSymRenderer* renderer=dynamic_cast<QgsGraduatedSymRenderer*>(m_vectorlayer->renderer());
if(renderer)
{
std::list<QgsRangeRenderItem*> list=renderer->items();
ext=new QgsGraSyExtensionWidget(this,renderer->classificationField(),QgsGraSyDialog::EMPTY,list.size(),m_vectorlayer);
ext=new QgsGraSyExtensionWidget(this,renderer->classificationField(),QgsGraSyDialog::EMPTY,list.size(),m_vectorlayer);
//todo:find out the fieldname for the classification field
classificationComboBox->setCurrentItem(renderer->classificationField());
//todo:find out the fieldname for the classification field
classificationComboBox->setCurrentItem(renderer->classificationField());
//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());
((QPushButton*)ext->getWidget(3,number))->setPaletteBackgroundColor((*it)->getSymbol()->pen().color());
((QPushButton*)ext->getWidget(4,number))->setText(QgsSymbologyUtils::penStyle2QString((*it)->getSymbol()->pen().style()));
((QSpinBox*)ext->getWidget(5,number))->setValue((*it)->getSymbol()->pen().width());
((QPushButton*)ext->getWidget(6,number))->setPaletteBackgroundColor((*it)->getSymbol()->brush().color());
((QPushButton*)ext->getWidget(7,number))->setText(QgsSymbologyUtils::brushStyle2QString((*it)->getSymbol()->brush().style()));
number++;
}
//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());
((QPushButton*)ext->getWidget(3,number))->setPaletteBackgroundColor((*it)->getSymbol()->pen().color());
((QPushButton*)ext->getWidget(4,number))->setText(QgsSymbologyUtils::penStyle2QString((*it)->getSymbol()->pen().style()));
((QSpinBox*)ext->getWidget(5,number))->setValue((*it)->getSymbol()->pen().width());
((QPushButton*)ext->getWidget(6,number))->setPaletteBackgroundColor((*it)->getSymbol()->brush().color());
((QPushButton*)ext->getWidget(7,number))->setText(QgsSymbologyUtils::brushStyle2QString((*it)->getSymbol()->brush().style()));
number++;
}
if(scv)
{
QgsGraSyDialogBaseLayout->remove(scv);
delete scv;
}
if(scv)
{
QgsGraSyDialogBaseLayout->remove(scv);
delete scv;
}
numberofclassesspinbox->setValue(list.size());
numberofclassesspinbox->setValue(list.size());
if(numberofclassesspinbox->value()==0)
{
scv=0;
return;
if(numberofclassesspinbox->value()==0)
{
scv=0;
return;
}
scv=new QScrollView(this);
scv->addChild(ext);
QgsGraSyDialogBaseLayout->addMultiCellWidget(scv,5,5,0,3);
scv->show();
}
scv=new QScrollView(this);
scv->addChild(ext);
QgsGraSyDialogBaseLayout->addMultiCellWidget(scv,5,5,0,3);
scv->show();
}
//do the necessary signal/slot connections
QObject::connect(numberofclassesspinbox,SIGNAL(valueChanged(int)),this,SLOT(adjustNumberOfClasses()));
@ -122,7 +126,7 @@ QgsGraSyDialog::QgsGraSyDialog(QgsVectorLayer* layer): QgsGraSyDialogBase(), ext
QObject::connect(modeComboBox,SIGNAL(activated(int)),this,SLOT(adjustNumberOfClasses()));
QObject::connect(closebutton,SIGNAL(clicked()),this,SLOT(hide()));
QObject::connect(applybutton,SIGNAL(clicked()),this,SLOT(apply()));
}
}
QgsGraSyDialog::QgsGraSyDialog()
@ -183,8 +187,9 @@ void QgsGraSyDialog::adjustNumberOfClasses()
}
void QgsGraSyDialog::apply() const
void QgsGraSyDialog::apply()
{
qWarning("1");
if(ext)
{
if(classificationComboBox->currentText().isEmpty())//don't do anything, it there is no classification field
@ -218,7 +223,7 @@ void QgsGraSyDialog::apply() const
}
}
int labelwidth=fm.width(widestlabel);
qWarning("2");
//create the pixmap for the render item
QPixmap* pix=m_vectorlayer->legendPixmap();
QString name=displaynamefield->text();
@ -231,13 +236,13 @@ void QgsGraSyDialog::apply() const
pix->fill();
QPainter p(pix);
p.setFont(f);
qWarning("3");
//draw the layer name and the name of the classification field into the pixmap
p.drawText(leftspace,topspace+fm.height(),name);
m_vectorlayer->setLayerName(name);
p.drawText(leftspace,topspace+2*fm.height(),classificationComboBox->currentText());
QgsGraduatedSymRenderer* renderer=dynamic_cast<QgsGraduatedSymRenderer*>(m_vectorlayer->renderer());
QgsGraduatedSymRenderer* renderer=dynamic_cast<QgsGraduatedSymRenderer*>(m_vectorlayer->propertiesDialog()->getBufferRenderer());
if(!renderer)
{
qWarning("Warning, typecast failed in QgsGraSyDialog::apply()");
@ -248,7 +253,7 @@ void QgsGraSyDialog::apply() const
int offset=topspace+2*fm.height();
int rowincrement=rowheight+rowspace;
qWarning("4");
for(int i=0;i<numberofclassesspinbox->value();i++)
{
QgsSymbol sy(QColor(255,0,0));
@ -279,7 +284,7 @@ void QgsGraSyDialog::apply() const
{
sy.brush().setStyle(Qt::SolidPattern);
}
qWarning("5");
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();
@ -303,7 +308,7 @@ void QgsGraSyDialog::apply() const
ubcontainsletter=true;
}
}
qWarning("6");
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());
@ -331,14 +336,21 @@ void QgsGraSyDialog::apply() const
p.drawText(pixwidth-labelwidth-rightspace,offset+rowincrement*i+rowheight,label);
}
}
qWarning("7");
renderer->setClassificationField(ext->classfield());
m_vectorlayer->triggerRepaint();
if(m_vectorlayer->legendItem())
{
m_vectorlayer->legendItem()->setPixmap(0,(*pix));
}
qWarning("8");
m_vectorlayer->setRenderer(renderer);
qWarning("9");
m_vectorlayer->setRendererDialog(this);
m_vectorlayer->propertiesDialog()->unsetRendererDirty();
qWarning("10");
m_vectorlayer->triggerRepaint();
qWarning("11");
}
else//number of classes is 0

View File

@ -34,7 +34,7 @@ class QgsGraSyDialog: public QgsGraSyDialogBase
QgsGraSyDialog(QgsVectorLayer* layer);
~QgsGraSyDialog();
public slots:
void apply() const;
void apply();
protected slots:
/**Creates a new extension widget*/
void adjustNumberOfClasses();

View File

@ -12,7 +12,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* qgsprojectio.cpp,v 1.21 2004/01/28 05:55:27 gsherman Exp */
/* qgsprojectio.cpp,v 1.22 2004/01/28 14:01:31 mhugent Exp */
#include <iostream>
#include <fstream>
#include <qfiledialog.h>
@ -139,39 +139,6 @@ bool QgsProjectIo::read(){
mne = mnl.toElement();
//QMessageBox::information(0,"Zorder", mne.text());
//process symbology
/*QgsSymbol *sym = new QgsSymbol();
if ( type != "raster" ) {
mnl = node.namedItem("symbol");
QDomNode snode = mnl.namedItem("linewidth");
QDomElement lineElement = snode.toElement();
int lineWidth = lineElement.text().toInt();
snode = mnl.namedItem("outlinecolor");
QDomElement colorElement = snode.toElement();
int olRed = colorElement.attribute("red").toInt();
int olGreen = colorElement.attribute("green").toInt();
int olBlue = colorElement.attribute("blue").toInt();
snode = mnl.namedItem("fillcolor");
colorElement = snode.toElement();
int fillRed = colorElement.attribute("red").toInt();
int fillGreen = colorElement.attribute("green").toInt();
int fillBlue = colorElement.attribute("blue").toInt();
sym->setFillColor( QColor(fillRed, fillGreen, fillBlue));
sym->setColor(QColor(olRed, olGreen, olBlue));
sym->setLineWidth(lineWidth);
// get the linewidth information
}*/
//QMessageBox::information(0,"Zorder", mne.text());
// add the layer to the maplayer
if(type == "vector")
@ -187,7 +154,6 @@ bool QgsProjectIo::read(){
provider = "ogr";
}
QgsVectorLayer *dbl = new QgsVectorLayer(dataSource, layerName, provider);
//map->addLayer(dbl);
QDomNode singlenode=node.namedItem("singlesymbol");
QDomNode graduatednode=node.namedItem("graduatedsymbol");
@ -413,8 +379,6 @@ bool QgsProjectIo::read(){
properties->setLegendType("continuous color");
}
//dbl->setSymbol(sym);
dbl->setVisible(visible == "1");
qWarning("adde den Layer");
dbl->initContextMenu(qgisApp);

View File

@ -21,6 +21,7 @@ class QgsFeature;
class QgsCoordinateTransform;
class QgsVectorLayer;
class QPainter;
class QgsVectorLayerProperties;
@ -28,9 +29,11 @@ class QPainter;
class QgsRenderer
{
public:
/**Sets the initial symbology configuration for a layer. An instance of the corresponding renderer dialog is created and associated with the layer. Finally, a pixmap for the legend is drawn
@param layer the vector layer associated with the renderer*/
virtual void initializeSymbology(QgsVectorLayer* layer)=0;
/**Sets the initial symbology configuration for a layer. An instance of the corresponding renderer dialog is created and associated with the layer. Finally, a pixmap for the legend is drawn. If pr is not 0, the renderer dialog is copied to the pointer in the layer properties instead of directly to the vector layer and no image is rendered
@param layer the vector layer associated with the renderer
@param pr the layer properties class involved
*/
virtual void initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr=0)=0;
/**Renders a feature. A vector layer passes features to a renderer object for display*/
virtual void renderFeature(QPainter* p, QgsFeature* f, QgsCoordinateTransform* t)=0;
/** Returns true, if attribute values are used by the renderer and false otherwise*/

View File

@ -41,6 +41,7 @@ void QgsSingleSymRenderer::addItem(QgsRenderItem ri)
void QgsSingleSymRenderer::renderFeature(QPainter* p, QgsFeature* f, QgsCoordinateTransform* t)
{
qWarning("rendere feature");
p->setPen(m_item.getSymbol()->pen());
p->setBrush(m_item.getSymbol()->brush());
unsigned char *feature= f->getGeometry();
@ -197,8 +198,14 @@ void QgsSingleSymRenderer::renderFeature(QPainter* p, QgsFeature* f, QgsCoordina
delete[]feature;
}
void QgsSingleSymRenderer::initializeSymbology(QgsVectorLayer* layer)
void QgsSingleSymRenderer::initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr)
{
bool toproperties=false;//if false: rendererDialog is associated with the vector layer and image is rendered, true: rendererDialog is associated with buffer dialog of vector layer properties and no image is rendered
if(pr)
{
toproperties=true;
}
if(layer)
{
QgsSymbol sy;
@ -215,7 +222,16 @@ void QgsSingleSymRenderer::initializeSymbology(QgsVectorLayer* layer)
QFont f( "times", 12, QFont::Normal );
QFontMetrics fm(f);
QPixmap* pixmap=layer->legendPixmap();
QPixmap* pixmap;
if(toproperties)
{
pixmap=pr->getBufferPixmap();
}
else
{
pixmap=layer->legendPixmap();
}
QString name=layer->name();
int width=40+fm.width(layer->name());
int height=(fm.height()+10>35) ? fm.height()+10 : 35;
@ -257,11 +273,18 @@ void QgsSingleSymRenderer::initializeSymbology(QgsVectorLayer* layer)
addItem(ri);
QgsSiSyDialog* dialog=new QgsSiSyDialog(layer);
layer->setRendererDialog(dialog);
QgsLegendItem* item;
if(item=layer->legendItem())
if(toproperties)
{
item->setPixmap(0,(*pixmap));
pr->setBufferDialog(dialog);
}
else
{
layer->setRendererDialog(dialog);
QgsLegendItem* item;
if(item=layer->legendItem())
{
item->setPixmap(0,(*pixmap));
}
}
}
else

View File

@ -23,6 +23,7 @@
#include "qgspoint.h"
#include "qpainter.h"
#include "qgscoordinatetransform.h"
#include "qgsvectorlayerproperties.h"
class QgsFeature;
/**Render class to display all the features with a single QgsSymbol*/
@ -39,7 +40,7 @@ class QgsSingleSymRenderer: public QgsRenderer
void renderFeature(QPainter* p, QgsFeature* f, QgsCoordinateTransform* t);
/**Sets the initial symbology configuration for a layer. An instance of the corresponding renderer dialog is created and associated with the layer. Finally, a pixmap for the legend is drawn
@param layer the vector layer associated with the renderer*/
virtual void initializeSymbology(QgsVectorLayer* layer);
virtual void initializeSymbology(QgsVectorLayer* layer, QgsVectorLayerProperties* pr=0);
/**Returns false, no attributes neede for single symbol*/
bool needsAttributes();
protected:

View File

@ -126,7 +126,9 @@ void QgsSiSyDialog::apply()
sy.pen().setWidth(outlinewidthspinbox->value());
sy.pen().setColor(outlinecolorbutton->paletteBackgroundColor());
QgsRenderItem ri(sy,"blabla", "blabla");
QgsSingleSymRenderer* renderer=dynamic_cast<QgsSingleSymRenderer*>(m_vectorlayer->renderer());
QgsSingleSymRenderer* renderer=dynamic_cast<QgsSingleSymRenderer*>(m_vectorlayer->propertiesDialog()->getBufferRenderer());
if(renderer)
{
renderer->addItem(ri);
@ -177,6 +179,10 @@ void QgsSiSyDialog::apply()
m_vectorlayer->legendItem()->setPixmap(0,(*pix));
}
//repaint the map canvas
m_vectorlayer->triggerRepaint();
m_vectorlayer->setRenderer(renderer);
m_vectorlayer->setRendererDialog(this);
m_vectorlayer->propertiesDialog()->unsetRendererDirty();
//repaint the map canvas
m_vectorlayer->triggerRepaint();
}

View File

@ -270,7 +270,6 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
QgsPoint pt;
QPointArray *pa;
int wkbType;
while ((fet = dataProvider->getNextFeature(attributesneeded))) {//true is necessary for graduated symbol
if (fet == 0) {
@ -680,21 +679,29 @@ QDialog* QgsVectorLayer::rendererDialog()
void QgsVectorLayer::setRenderer(QgsRenderer* r)
{
if(m_renderer)//delete any previous renderer
if(r!=m_renderer)
{
delete m_renderer;
}
if(m_renderer)//delete any previous renderer
{
delete m_renderer;
}
m_renderer=r;
m_renderer=r;
}
}
void QgsVectorLayer::setRendererDialog(QDialog* dialog)
{
if(m_rendererDialog)
if(dialog!=m_rendererDialog)
{
delete m_rendererDialog;
}
m_rendererDialog=dialog;
qWarning("in loop");
if(m_rendererDialog)
{
qWarning("deleting renderer dialog");
delete m_rendererDialog;
}
m_rendererDialog=dialog;
}
}
QGis::VectorType QgsVectorLayer::vectorType()

View File

@ -35,8 +35,11 @@
#include <cfloat>
#include "qgslegenditem.h"
#include "qgscontinuouscolrenderer.h"
#include "qgssisydialog.h"
#include "qgsgrasydialog.h"
#include "qgscontcoldialog.h"
QgsVectorLayerProperties::QgsVectorLayerProperties(QgsVectorLayer* lyr):layer(lyr)
QgsVectorLayerProperties::QgsVectorLayerProperties(QgsVectorLayer* lyr):layer(lyr), rendererDirty(false), bufferDialog(layer->rendererDialog()), bufferRenderer(layer->renderer())
{
// populate the property sheet based on the layer properties
// general info
@ -49,6 +52,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(QgsVectorLayer* lyr):layer(ly
legendtypecombobox->insertItem(tr("graduated symbol"));
legendtypecombobox->insertItem(tr("continuous color"));
QObject::connect(legendtypecombobox,SIGNAL(activated(const QString&)),this,SLOT(alterLayerDialog(const QString&)));
QObject::connect(buttonOk,SIGNAL(clicked()),this,SLOT(apply()));
QObject::connect(buttonCancel,SIGNAL(clicked()),this,SLOT(cancel()));
}
QgsVectorLayerProperties::~QgsVectorLayerProperties()
@ -63,36 +68,68 @@ QgsSymbol* QgsVectorLayerProperties::getSymbol()
void QgsVectorLayerProperties::alterLayerDialog(const QString& string)
{
if(rendererDirty)
{
delete bufferDialog;
delete bufferRenderer;
}
//create a new Dialog
if(string==tr("single symbol"))
{
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();
layer->setRenderer(renderer);
renderer->initializeSymbology(layer);
bufferRenderer=new QgsSingleSymRenderer();
bufferRenderer->initializeSymbology(layer,this);
}
else if(string==tr("graduated symbol"))
{
QgsGraduatedSymRenderer* renderer=new QgsGraduatedSymRenderer();
layer->setRenderer(renderer);
renderer->initializeSymbology(layer);
bufferRenderer=new QgsGraduatedSymRenderer();
bufferRenderer->initializeSymbology(layer,this);
}
else if(string==tr("continuous color"))
{
QgsContinuousColRenderer* renderer=new QgsContinuousColRenderer();
layer->setRenderer(renderer);
renderer->initializeSymbology(layer);
bufferRenderer=new QgsContinuousColRenderer();
bufferRenderer->initializeSymbology(layer,this);
}
layer->triggerRepaint();
rendererDirty=true;
}
void QgsVectorLayerProperties::showSymbolSettings()
{
layer->rendererDialog()->show();
layer->rendererDialog()->raise();
bufferDialog->show();
bufferDialog->raise();
}
void QgsVectorLayerProperties::setLegendType(QString type)
{
legendtypecombobox->setCurrentText(type);
}
void QgsVectorLayerProperties::apply()
{
if(rendererDirty)
{
layer->setRenderer(bufferRenderer);
layer->setRendererDialog(bufferDialog);
rendererDirty=false;
//copy the bufferPixmap to the vectorlayer and to its legend item
*(layer->legendPixmap())=bufferPixmap;
if(layer->legendItem())
{
layer->legendItem()->setPixmap(0,bufferPixmap);
}
}
accept();
layer->triggerRepaint();
}
void QgsVectorLayerProperties::cancel()
{
//todo: add code to free memory here
if(rendererDirty)
{
delete bufferDialog;
delete bufferRenderer;
}
reject();
}

View File

@ -22,6 +22,8 @@ class QgsVectorLayer;
#include "qgssymbol.h"
class QString;
#include "qgsvectorlayerpropertiesbase.h"
#include "qgsrenderer.h"
#include "qpixmap.h"
/**Property sheet for a map layer
@ -42,11 +44,67 @@ public:
QgsSymbol* getSymbol();
/**Sets the legend type to "single symbol", "graduated symbol" or "continuous color"*/
void setLegendType(QString type);
/**Sets the dirty flag to false*/
void unsetRendererDirty();
/**Returns the value of rendererDirty*/
bool getRendererDirty() const;
/**Returns a pointer to the bufferDialog*/
QDialog* getBufferDialog();
/**Sets the buffer dialog*/
void setBufferDialog(QDialog* dialog);
QgsRenderer* getBufferRenderer();
QPixmap* getBufferPixmap();
private:
QgsVectorLayer* layer;
/**Flag indicating if the render type still has to be changed (true) or not (false)*/
bool rendererDirty;
/**Renderer dialog. If the legend type has changed, it is assigned to the vectorlayer if apply or ok are pressed*/
QDialog* bufferDialog;
QgsRenderer* bufferRenderer;
QPixmap bufferPixmap;
public slots:
void alterLayerDialog(const QString& string);
/**Sets the dirty flag to true*/
void setRendererDirty();
void apply();
void cancel();
protected slots:
void showSymbolSettings();
void alterLayerDialog(const QString& string);
void showSymbolSettings();
};
inline bool QgsVectorLayerProperties::getRendererDirty() const
{
return rendererDirty;
}
inline void QgsVectorLayerProperties::setRendererDirty()
{
rendererDirty=true;
}
inline void QgsVectorLayerProperties::unsetRendererDirty()
{
rendererDirty=false;
}
inline QDialog* QgsVectorLayerProperties::getBufferDialog()
{
return bufferDialog;
}
inline void QgsVectorLayerProperties::setBufferDialog(QDialog* dialog)
{
bufferDialog=dialog;
}
inline QgsRenderer* QgsVectorLayerProperties::getBufferRenderer()
{
return bufferRenderer;
}
inline QPixmap* QgsVectorLayerProperties::getBufferPixmap()
{
return &bufferPixmap;
}
#endif

View File

@ -9,7 +9,7 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>163</height>
<height>165</height>
</rect>
</property>
<property name="minimumSize">
@ -241,20 +241,6 @@
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>buttonOk</sender>
<signal>clicked()</signal>
<receiver>QgsVectorLayerPropertiesBase</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonCancel</sender>
<signal>clicked()</signal>
<receiver>QgsVectorLayerPropertiesBase</receiver>
<slot>reject()</slot>
</connection>
</connections>
<slots>
<slot>setLineWidth( int )</slot>
<slot>selectFillColor()</slot>