Skip to content

Commit e3433a0

Browse files
author
mhugent
committedApr 18, 2006
more legend icon size related fixes
git-svn-id: http://svn.osgeo.org/qgis/trunk@5303 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5f9793c commit e3433a0

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed
 

‎src/legend/qgslegend.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ void QgsLegend::removeAll()
109109
{
110110
mStateOfCheckBoxes.clear();
111111
clear();
112+
mPixmapWidthValues.clear();
113+
mPixmapHeightValues.clear();
112114
updateMapCanvasLayerSet();
115+
setIconSize(mMinimumIconSize);
113116
}
114117

115118
void QgsLegend::removeLayer(QString layer_key)
@@ -131,6 +134,7 @@ void QgsLegend::removeLayer(QString layer_key)
131134
//remove the map entry for the checkbox
132135
mStateOfCheckBoxes.erase(llf);
133136
removeItem(llf);
137+
delete llf;
134138
break;
135139
}
136140
}
@@ -139,6 +143,7 @@ void QgsLegend::removeLayer(QString layer_key)
139143
}
140144

141145
updateMapCanvasLayerSet();
146+
adjustIconSize();
142147
}
143148

144149
void QgsLegend::mousePressEvent(QMouseEvent * e)
@@ -548,6 +553,7 @@ void QgsLegend::legendGroupRemove()
548553
child = lg->child(0);
549554
}
550555
delete lg;
556+
adjustIconSize();
551557
}
552558
}
553559

@@ -584,6 +590,8 @@ void QgsLegend::legendLayerRemove()
584590
mMapCanvas->refresh();
585591
}
586592
removeItem(ll);
593+
delete ll;
594+
adjustIconSize();
587595
}
588596

589597
void QgsLegend::legendLayerAddToOverview()
@@ -1284,8 +1292,6 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
12841292
theSymbologyItem = dynamic_cast<QgsLegendSymbologyItem*>((theLegendLayer)->child(i));
12851293
if(theSymbologyItem)
12861294
{
1287-
removePixmapWidthValue(theSymbologyItem->pixmapWidth());
1288-
removePixmapHeightValue(theSymbologyItem->pixmapHeight());
12891295
delete (theLegendLayer->takeChild(i));
12901296
}
12911297
}
@@ -1297,12 +1303,10 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
12971303
for(std::list< std::pair<QString, QPixmap> >::const_iterator it= newSymbologyItems->begin(); it != newSymbologyItems->end(); ++it)
12981304
{
12991305
QgsLegendSymbologyItem* theItem = new QgsLegendSymbologyItem(it->second.width(), it->second.height());
1306+
theItem->setLegend(this);
13001307
theItem->setText(0, it->first);
13011308
theItem->setIcon(0, QIcon(it->second));
13021309
theLegendLayer->insertChild(childposition, theItem);
1303-
//add the width and height values to the multisets
1304-
addPixmapWidthValue(theItem->pixmapWidth());
1305-
addPixmapHeightValue(theItem->pixmapHeight());
13061310
++childposition;
13071311
}
13081312
}

‎src/legend/qgslegendsymbologyitem.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
* Free Software Foundation, Inc., *
1818
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
1919
***************************************************************************/
20-
#include "qgslegend.h"
20+
2121
#include "qgslegendsymbologyitem.h"
2222

2323
QgsLegendSymbologyItem::QgsLegendSymbologyItem(QTreeWidgetItem * theItem,QString theString, int pixmapWidth, int pixmapHeight)
24-
: QgsLegendItem(theItem, theString), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight)
24+
: QgsLegendItem(theItem, theString), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight), mLegend(0)
2525
{
2626
mType = LEGEND_SYMBOL_ITEM;
2727
}
2828

29-
QgsLegendSymbologyItem::QgsLegendSymbologyItem(int pixmapWidth, int pixmapHeight): QgsLegendItem(), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight)
29+
QgsLegendSymbologyItem::QgsLegendSymbologyItem(int pixmapWidth, int pixmapHeight): QgsLegendItem(), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight), mLegend(0)
3030
{
3131
mType = LEGEND_SYMBOL_ITEM;
3232
}
3333

3434
QgsLegendSymbologyItem::~QgsLegendSymbologyItem()
3535
{
36+
if(mLegend)
37+
{
38+
mLegend->removePixmapWidthValue(mPixmapWidth);
39+
mLegend->removePixmapHeightValue(mPixmapHeight);
40+
}
3641
}
3742

3843
QgsLegendItem::DRAG_ACTION QgsLegendSymbologyItem::accept(LEGEND_ITEM_TYPE type)
@@ -45,3 +50,13 @@ QgsLegendItem::DRAG_ACTION QgsLegendSymbologyItem::accept(const QgsLegendItem* l
4550
return NO_ACTION;
4651
}
4752

53+
void QgsLegendSymbologyItem::setLegend(QgsLegend* theLegend)
54+
{
55+
mLegend = theLegend;
56+
if(mLegend)
57+
{
58+
mLegend->addPixmapWidthValue(mPixmapWidth);
59+
mLegend->addPixmapHeightValue(mPixmapHeight);
60+
}
61+
}
62+

‎src/legend/qgslegendsymbologyitem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef QGSLEGENDSYMBOLOGYITEM_H
2121
#define QGSLEGENDSYMBOLOGYITEM_H
2222

23+
#include "qgslegend.h"
2324
#include <qgslegenditem.h>
2425

2526
/**
@@ -36,9 +37,14 @@ class QgsLegendSymbologyItem : public QgsLegendItem
3637
QgsLegendItem::DRAG_ACTION accept(const QgsLegendItem* li) const;
3738
int pixmapWidth() const {return mPixmapWidth;}
3839
int pixmapHeight() const {return mPixmapHeight;}
40+
void setLegend(QgsLegend* theLegend);
41+
QgsLegend* legend() const {return mLegend;}
3942
protected:
4043
int mPixmapWidth;
4144
int mPixmapHeight;
45+
/**This pointer is needed to remove the width/height values of this item
46+
in the legend even if this item is not in the legend anymore*/
47+
QgsLegend* mLegend;
4248
};
4349

4450
#endif

‎src/raster/qgsrasterlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5060,7 +5060,7 @@ void QgsRasterLayer::refreshLegend()
50605060
if(mLegend)
50615061
{
50625062
std::list< std::pair<QString, QPixmap> > itemList;
5063-
QPixmap legendpixmap = getLegendQPixmap(true).scaled(20, 20);
5063+
QPixmap legendpixmap = getLegendQPixmap(true).scaled(20, 20, Qt::KeepAspectRatio);
50645064
itemList.push_back(std::make_pair("", legendpixmap));
50655065
mLegend->changeSymbologySettings(getLayerID(), &itemList);
50665066
}

0 commit comments

Comments
 (0)
Please sign in to comment.