Skip to content

Commit 772d047

Browse files
author
mhugent
committedJan 31, 2006
Reordering of the legend and possibility to show/ hide layer files in the legend with the right click menu
git-svn-id: http://svn.osgeo.org/qgis/trunk@4782 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e90e9d0 commit 772d047

15 files changed

+246
-159
lines changed
 

‎src/core/qgsrenderer.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,16 @@ QgsRenderer::QgsRenderer()
1313

1414
}
1515

16-
void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
16+
void QgsRenderer::refreshLegend(std::list< std::pair<QString, QIcon*> >* symbologyList) const
1717
{
18-
if(legendparent)
18+
if(symbologyList)
1919
{
20-
21-
//first remove the existing childs
22-
//legendparent->takeChildren();
23-
dynamic_cast<QgsLegendItem*>(legendparent)->removeAllChildren();
24-
2520
//add the new items
2621
QString lw, uv, label;
2722
const std::list<QgsSymbol*> sym = symbols();
2823

2924
for(std::list<QgsSymbol*>::const_iterator it=sym.begin(); it!=sym.end(); ++it)
3025
{
31-
QgsLegendVectorSymbologyItem* item = new QgsLegendVectorSymbologyItem(legendparent, "");
32-
item->addSymbol(*it);
33-
3426
QPixmap pix;
3527
if((*it)->type() == QGis::Point)
3628
{
@@ -45,8 +37,8 @@ void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
4537
pix = (*it)->getPolygonSymbolAsPixmap();
4638
}
4739

48-
QIcon theIcon(pix);
49-
item->setIcon(0, theIcon);
40+
QIcon* theIcon = new QIcon(pix);
41+
5042
QString values;
5143
lw = (*it)->lowerValue();
5244
if(!lw.isEmpty())
@@ -65,7 +57,7 @@ void QgsRenderer::refreshLegend(QTreeWidgetItem* legendparent) const
6557
values += " ";
6658
values += label;
6759
}
68-
item->setText(0, values);
60+
symbologyList->push_back(std::make_pair(values, theIcon));
6961
}
7062
}
7163
}

‎src/core/qgsrenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class QgsRenderer
7575
virtual const std::list<QgsSymbol*> symbols() const=0;
7676
/**Deletes the child items of the legendparent and add new ones according to the
7777
QgsSymbols contained in this renderer*/
78-
virtual void refreshLegend(QTreeWidgetItem* legendparent) const;
78+
virtual void refreshLegend(std::list< std::pair<QString, QIcon*> >* symbologyList) const;
7979
/**Returns a copy of the renderer (a deep copy on the heap)*/
8080
virtual QgsRenderer* clone() const=0;
8181
/**Color to draw selected features - static so we can change it in proj props and automatically

‎src/gui/qgsmapcanvas.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,10 +2340,9 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
23402340
#ifdef QGISDEBUG
23412341
std::cout << "QgsMapCanvas::mouseReleaseEvent: Completed vlayer->insertVertexBefore." << std::endl;
23422342
#endif
2343+
refresh();
23432344
}
2344-
}
2345-
2346-
// TODO: Redraw?
2345+
}
23472346
break;
23482347
}
23492348

@@ -2396,8 +2395,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
23962395
point.x(), point.y(),
23972396
mCanvasProperties->snappedAtFeatureId,
23982397
mCanvasProperties->snappedAtVertex);
2399-
render();
2400-
update();
2398+
refresh();
24012399

24022400
#ifdef QGISDEBUG
24032401
std::cout << "QgsMapCanvas::mouseReleaseEvent: Completed vlayer->moveVertexAt." << std::endl;
@@ -2458,10 +2456,9 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
24582456
#ifdef QGISDEBUG
24592457
std::cout << "QgsMapCanvas::mouseReleaseEvent: Completed vlayer->deleteVertexAt." << std::endl;
24602458
#endif
2459+
refresh();
24612460
}
2462-
}
2463-
// TODO: Redraw?
2464-
2461+
}
24652462
break;
24662463
}
24672464

‎src/gui/qgsmaplayer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "qgssymbol.h"
3838
#include "qgsmaplayer.h"
3939
#include "qgslegendlayerfile.h"
40-
#include "qgslegendsymbologygroup.h"
4140

4241

4342

@@ -52,7 +51,7 @@ QgsMapLayer::QgsMapLayer(int type,
5251
mShowInOverviewAction(0),
5352
mShowInOverview(false),
5453
mCoordinateTransform(0),
55-
mLegendSymbologyGroupParent(0),
54+
mLegend(0),
5655
mLegendLayerFile(0),
5756
ID(""),
5857
layerType(type),

‎src/gui/qgsmaplayer.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class QAction;
3434
class QgisApp;
3535
class QgsMapToPixel;
3636
class QgsFeature;
37+
class QgsLegend;
3738
class QgsLegendLayerFile;
38-
class QgsLegendSymbologyGroup;
3939
class QDomNode;
4040
class QDomDocument;
4141
class QKeyEvent;
@@ -268,8 +268,8 @@ class QgsMapLayer : public QObject
268268
/**Returns the path to an icon which characterises the type of layer*/
269269
virtual QString layerTypeIconPath() = 0;
270270

271-
void setLegendSymbologyGroupParent(QgsLegendSymbologyGroup* item) {mLegendSymbologyGroupParent = item;}
272-
const QgsLegendSymbologyGroup* legendSymbologyGroupParent() {return mLegendSymbologyGroupParent;}
271+
void setLegend(QgsLegend* legend) {mLegend = legend;}
272+
const QgsLegend* legend() {return mLegend;}
273273

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

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

445444
/**Pointer to the legend layer file of the legend. It is used to modify the pixmap with overview
446445
glasses, editing or pyramid symbols*/

‎src/gui/qgsvectorlayer.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@
6464
#include "qgsattributetable.h"
6565
#include "qgsfeature.h"
6666
#include "qgsfield.h"
67-
#include "qgslegenditem.h"
68-
#include "qgslegendvectorsymbologyitem.h"
69-
#include "qgslegendsymbologygroup.h"
67+
#include "qgslegend.h"
7068
#include "qgsvectorlayerproperties.h"
7169
#include "qgsrenderer.h"
7270
#include "qgssinglesymrenderer.h"
@@ -2865,9 +2863,27 @@ QString QgsVectorLayer::layerTypeIconPath()
28652863

28662864
void QgsVectorLayer::refreshLegend()
28672865
{
2868-
if(mLegendSymbologyGroupParent && m_renderer)
2866+
if(mLegend && m_renderer)
2867+
{
2868+
std::list< std::pair<QString, QIcon*> > itemList;
2869+
m_renderer->refreshLegend(&itemList);
2870+
if(m_renderer->needsAttributes()) //create an item for each classification field (only one for most renderers)
2871+
{
2872+
std::list<int> classfieldlist = m_renderer->classificationAttributes();
2873+
for(std::list<int>::iterator it = classfieldlist.begin(); it!=classfieldlist.end(); ++it)
2874+
{
2875+
const QgsField theField = (dataProvider->fields())[*it];
2876+
QString classfieldname = theField.name();
2877+
itemList.push_front(std::make_pair(classfieldname, (QIcon*)0));
2878+
}
2879+
}
2880+
mLegend->changeSymbologySettings(getLayerID(), &itemList);
2881+
}
2882+
2883+
#if 0
2884+
if(mLegendLayer && m_renderer)
28692885
{
2870-
m_renderer->refreshLegend(mLegendSymbologyGroupParent);
2886+
m_renderer->refreshLegend(mLegendLayer);
28712887
}
28722888

28732889
//create an item for each classification field (currently only one for all renderers)
@@ -2882,15 +2898,16 @@ void QgsVectorLayer::refreshLegend()
28822898
QString classfieldname = theField.name();
28832899
QgsLegendSymbologyItem* item = new QgsLegendSymbologyItem();
28842900
item->setText(0, classfieldname);
2885-
mLegendSymbologyGroupParent->insertChild(0, item);
2901+
static_cast<QTreeWidgetItem*>(mLegendLayer)->insertChild(0, item);
28862902
}
28872903
}
28882904
}
2889-
if(mLegendSymbologyGroupParent)
2905+
if(mLegendLayer)
28902906
{
28912907
//copy the symbology changes for the other layers in the same symbology group
2892-
mLegendSymbologyGroupParent->updateLayerSymbologySettings(this);
2908+
mLegendLayer->updateLayerSymbologySettings(this);
28932909
}
2910+
#endif
28942911
}
28952912

28962913
bool QgsVectorLayer::copySymbologySettings(const QgsMapLayer& other)

0 commit comments

Comments
 (0)
Please sign in to comment.