Skip to content

Commit

Permalink
Reordering of the legend and possibility to show/ hide layer files in…
Browse files Browse the repository at this point in the history
… the legend with the right click menu

git-svn-id: http://svn.osgeo.org/qgis/trunk@4782 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 31, 2006
1 parent e90e9d0 commit 772d047
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 159 deletions.
18 changes: 5 additions & 13 deletions src/core/qgsrenderer.cpp
Expand Up @@ -13,24 +13,16 @@ QgsRenderer::QgsRenderer()

}

void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
void QgsRenderer::refreshLegend(std::list< std::pair<QString, QIcon*> >* symbologyList) const
{
if(legendparent)
if(symbologyList)
{

//first remove the existing childs
//legendparent->takeChildren();
dynamic_cast<QgsLegendItem*>(legendparent)->removeAllChildren();

//add the new items
QString lw, uv, label;
const std::list<QgsSymbol*> sym = symbols();

for(std::list<QgsSymbol*>::const_iterator it=sym.begin(); it!=sym.end(); ++it)
{
QgsLegendVectorSymbologyItem* item = new QgsLegendVectorSymbologyItem(legendparent, "");
item->addSymbol(*it);

QPixmap pix;
if((*it)->type() == QGis::Point)
{
Expand All @@ -45,8 +37,8 @@ void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
pix = (*it)->getPolygonSymbolAsPixmap();
}

QIcon theIcon(pix);
item->setIcon(0, theIcon);
QIcon* theIcon = new QIcon(pix);
QString values;
lw = (*it)->lowerValue();
if(!lw.isEmpty())
Expand All @@ -65,7 +57,7 @@ void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
values += " ";
values += label;
}
item->setText(0, values);
symbologyList->push_back(std::make_pair(values, theIcon));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrenderer.h
Expand Up @@ -75,7 +75,7 @@ class QgsRenderer
virtual const std::list<QgsSymbol*> symbols() const=0;
/**Deletes the child items of the legendparent and add new ones according to the
QgsSymbols contained in this renderer*/
virtual void refreshLegend(QTreeWidgetItem* legendparent) const;
virtual void refreshLegend(std::list< std::pair<QString, QIcon*> >* symbologyList) const;
/**Returns a copy of the renderer (a deep copy on the heap)*/
virtual QgsRenderer* clone() const=0;
/**Color to draw selected features - static so we can change it in proj props and automatically
Expand Down
13 changes: 5 additions & 8 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -2340,10 +2340,9 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
#ifdef QGISDEBUG
std::cout << "QgsMapCanvas::mouseReleaseEvent: Completed vlayer->insertVertexBefore." << std::endl;
#endif
refresh();
}
}

// TODO: Redraw?
}
break;
}

Expand Down Expand Up @@ -2396,8 +2395,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
point.x(), point.y(),
mCanvasProperties->snappedAtFeatureId,
mCanvasProperties->snappedAtVertex);
render();
update();
refresh();

#ifdef QGISDEBUG
std::cout << "QgsMapCanvas::mouseReleaseEvent: Completed vlayer->moveVertexAt." << std::endl;
Expand Down Expand Up @@ -2458,10 +2456,9 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
#ifdef QGISDEBUG
std::cout << "QgsMapCanvas::mouseReleaseEvent: Completed vlayer->deleteVertexAt." << std::endl;
#endif
refresh();
}
}
// TODO: Redraw?

}
break;
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/qgsmaplayer.cpp
Expand Up @@ -37,7 +37,6 @@
#include "qgssymbol.h"
#include "qgsmaplayer.h"
#include "qgslegendlayerfile.h"
#include "qgslegendsymbologygroup.h"



Expand All @@ -52,7 +51,7 @@ QgsMapLayer::QgsMapLayer(int type,
mShowInOverviewAction(0),
mShowInOverview(false),
mCoordinateTransform(0),
mLegendSymbologyGroupParent(0),
mLegend(0),
mLegendLayerFile(0),
ID(""),
layerType(type),
Expand Down
11 changes: 5 additions & 6 deletions src/gui/qgsmaplayer.h
Expand Up @@ -34,8 +34,8 @@ class QAction;
class QgisApp;
class QgsMapToPixel;
class QgsFeature;
class QgsLegend;
class QgsLegendLayerFile;
class QgsLegendSymbologyGroup;
class QDomNode;
class QDomDocument;
class QKeyEvent;
Expand Down Expand Up @@ -268,8 +268,8 @@ class QgsMapLayer : public QObject
/**Returns the path to an icon which characterises the type of layer*/
virtual QString layerTypeIconPath() = 0;

void setLegendSymbologyGroupParent(QgsLegendSymbologyGroup* item) {mLegendSymbologyGroupParent = item;}
const QgsLegendSymbologyGroup* legendSymbologyGroupParent() {return mLegendSymbologyGroupParent;}
void setLegend(QgsLegend* legend) {mLegend = legend;}
const QgsLegend* legend() {return mLegend;}

/**Refresh the symbology part of the legend. Specific implementations have to be provided by subclasses*/
virtual void refreshLegend() = 0;
Expand Down Expand Up @@ -438,9 +438,8 @@ public slots:
//! A QgsCoordinateTransform is used for on the fly reprojection of map layers
QgsCoordinateTransform * mCoordinateTransform;

/**Pointer to the symbology group item of the legend. This pointer is used if refreshLegend()
is called by a subclass*/
QgsLegendSymbologyGroup* mLegendSymbologyGroupParent;
/**Pointer to the legend layer item of the legend*/
QgsLegend* mLegend;

/**Pointer to the legend layer file of the legend. It is used to modify the pixmap with overview
glasses, editing or pyramid symbols*/
Expand Down
33 changes: 25 additions & 8 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -64,9 +64,7 @@
#include "qgsattributetable.h"
#include "qgsfeature.h"
#include "qgsfield.h"
#include "qgslegenditem.h"
#include "qgslegendvectorsymbologyitem.h"
#include "qgslegendsymbologygroup.h"
#include "qgslegend.h"
#include "qgsvectorlayerproperties.h"
#include "qgsrenderer.h"
#include "qgssinglesymrenderer.h"
Expand Down Expand Up @@ -2865,9 +2863,27 @@ QString QgsVectorLayer::layerTypeIconPath()

void QgsVectorLayer::refreshLegend()
{
if(mLegendSymbologyGroupParent && m_renderer)
if(mLegend && m_renderer)
{
std::list< std::pair<QString, QIcon*> > itemList;
m_renderer->refreshLegend(&itemList);
if(m_renderer->needsAttributes()) //create an item for each classification field (only one for most renderers)
{
std::list<int> classfieldlist = m_renderer->classificationAttributes();
for(std::list<int>::iterator it = classfieldlist.begin(); it!=classfieldlist.end(); ++it)
{
const QgsField theField = (dataProvider->fields())[*it];
QString classfieldname = theField.name();
itemList.push_front(std::make_pair(classfieldname, (QIcon*)0));
}
}
mLegend->changeSymbologySettings(getLayerID(), &itemList);
}

#if 0
if(mLegendLayer && m_renderer)
{
m_renderer->refreshLegend(mLegendSymbologyGroupParent);
m_renderer->refreshLegend(mLegendLayer);
}

//create an item for each classification field (currently only one for all renderers)
Expand All @@ -2882,15 +2898,16 @@ void QgsVectorLayer::refreshLegend()
QString classfieldname = theField.name();
QgsLegendSymbologyItem* item = new QgsLegendSymbologyItem();
item->setText(0, classfieldname);
mLegendSymbologyGroupParent->insertChild(0, item);
static_cast<QTreeWidgetItem*>(mLegendLayer)->insertChild(0, item);
}
}
}
if(mLegendSymbologyGroupParent)
if(mLegendLayer)
{
//copy the symbology changes for the other layers in the same symbology group
mLegendSymbologyGroupParent->updateLayerSymbologySettings(this);
mLegendLayer->updateLayerSymbologySettings(this);
}
#endif
}

bool QgsVectorLayer::copySymbologySettings(const QgsMapLayer& other)
Expand Down

0 comments on commit 772d047

Please sign in to comment.