Skip to content

Commit

Permalink
more legend icon size related fixes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5303 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 18, 2006
1 parent 7369eea commit 564e82d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ void QgsLegend::removeAll()
{
mStateOfCheckBoxes.clear();
clear();
mPixmapWidthValues.clear();
mPixmapHeightValues.clear();
updateMapCanvasLayerSet();
setIconSize(mMinimumIconSize);
}

void QgsLegend::removeLayer(QString layer_key)
Expand All @@ -131,6 +134,7 @@ void QgsLegend::removeLayer(QString layer_key)
//remove the map entry for the checkbox
mStateOfCheckBoxes.erase(llf);
removeItem(llf);
delete llf;
break;
}
}
Expand All @@ -139,6 +143,7 @@ void QgsLegend::removeLayer(QString layer_key)
}

updateMapCanvasLayerSet();
adjustIconSize();
}

void QgsLegend::mousePressEvent(QMouseEvent * e)
Expand Down Expand Up @@ -548,6 +553,7 @@ void QgsLegend::legendGroupRemove()
child = lg->child(0);
}
delete lg;
adjustIconSize();
}
}

Expand Down Expand Up @@ -584,6 +590,8 @@ void QgsLegend::legendLayerRemove()
mMapCanvas->refresh();
}
removeItem(ll);
delete ll;
adjustIconSize();
}

void QgsLegend::legendLayerAddToOverview()
Expand Down Expand Up @@ -1284,8 +1292,6 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
theSymbologyItem = dynamic_cast<QgsLegendSymbologyItem*>((theLegendLayer)->child(i));
if(theSymbologyItem)
{
removePixmapWidthValue(theSymbologyItem->pixmapWidth());
removePixmapHeightValue(theSymbologyItem->pixmapHeight());
delete (theLegendLayer->takeChild(i));
}
}
Expand All @@ -1297,12 +1303,10 @@ void QgsLegend::changeSymbologySettings(const QString& key, const std::list< std
for(std::list< std::pair<QString, QPixmap> >::const_iterator it= newSymbologyItems->begin(); it != newSymbologyItems->end(); ++it)
{
QgsLegendSymbologyItem* theItem = new QgsLegendSymbologyItem(it->second.width(), it->second.height());
theItem->setLegend(this);
theItem->setText(0, it->first);
theItem->setIcon(0, QIcon(it->second));
theLegendLayer->insertChild(childposition, theItem);
//add the width and height values to the multisets
addPixmapWidthValue(theItem->pixmapWidth());
addPixmapHeightValue(theItem->pixmapHeight());
++childposition;
}
}
Expand Down
21 changes: 18 additions & 3 deletions src/legend/qgslegendsymbologyitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "qgslegend.h"

#include "qgslegendsymbologyitem.h"

QgsLegendSymbologyItem::QgsLegendSymbologyItem(QTreeWidgetItem * theItem,QString theString, int pixmapWidth, int pixmapHeight)
: QgsLegendItem(theItem, theString), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight)
: QgsLegendItem(theItem, theString), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight), mLegend(0)
{
mType = LEGEND_SYMBOL_ITEM;
}

QgsLegendSymbologyItem::QgsLegendSymbologyItem(int pixmapWidth, int pixmapHeight): QgsLegendItem(), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight)
QgsLegendSymbologyItem::QgsLegendSymbologyItem(int pixmapWidth, int pixmapHeight): QgsLegendItem(), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight), mLegend(0)
{
mType = LEGEND_SYMBOL_ITEM;
}

QgsLegendSymbologyItem::~QgsLegendSymbologyItem()
{
if(mLegend)
{
mLegend->removePixmapWidthValue(mPixmapWidth);
mLegend->removePixmapHeightValue(mPixmapHeight);
}
}

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

void QgsLegendSymbologyItem::setLegend(QgsLegend* theLegend)
{
mLegend = theLegend;
if(mLegend)
{
mLegend->addPixmapWidthValue(mPixmapWidth);
mLegend->addPixmapHeightValue(mPixmapHeight);
}
}

6 changes: 6 additions & 0 deletions src/legend/qgslegendsymbologyitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef QGSLEGENDSYMBOLOGYITEM_H
#define QGSLEGENDSYMBOLOGYITEM_H

#include "qgslegend.h"
#include <qgslegenditem.h>

/**
Expand All @@ -36,9 +37,14 @@ class QgsLegendSymbologyItem : public QgsLegendItem
QgsLegendItem::DRAG_ACTION accept(const QgsLegendItem* li) const;
int pixmapWidth() const {return mPixmapWidth;}
int pixmapHeight() const {return mPixmapHeight;}
void setLegend(QgsLegend* theLegend);
QgsLegend* legend() const {return mLegend;}
protected:
int mPixmapWidth;
int mPixmapHeight;
/**This pointer is needed to remove the width/height values of this item
in the legend even if this item is not in the legend anymore*/
QgsLegend* mLegend;
};

#endif
2 changes: 1 addition & 1 deletion src/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5060,7 +5060,7 @@ void QgsRasterLayer::refreshLegend()
if(mLegend)
{
std::list< std::pair<QString, QPixmap> > itemList;
QPixmap legendpixmap = getLegendQPixmap(true).scaled(20, 20);
QPixmap legendpixmap = getLegendQPixmap(true).scaled(20, 20, Qt::KeepAspectRatio);
itemList.push_back(std::make_pair("", legendpixmap));
mLegend->changeSymbologySettings(getLayerID(), &itemList);
}
Expand Down

0 comments on commit 564e82d

Please sign in to comment.