[QGIS Commit] r8915 -
branches/advanced_printing_branch/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Jul 26 05:25:41 EDT 2008
Author: mhugent
Date: 2008-07-26 05:25:41 -0400 (Sat, 26 Jul 2008)
New Revision: 8915
Modified:
branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.h
Log:
Consider that point symbols can have varying height in composer legend
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp 2008-07-26 09:25:28 UTC (rev 8914)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.cpp 2008-07-26 09:25:41 UTC (rev 8915)
@@ -152,8 +152,10 @@
}
QFontMetricsF itemFontMetrics(mItemFont);
- double itemHeight = std::max(mSymbolHeight, itemFontMetrics.height());
+ //standerd item height
+ double itemHeight = std::max(mSymbolHeight, itemFontMetrics.ascent());
+
QStandardItem* currentItem;
int numChildren = layerItem->rowCount();
@@ -165,6 +167,10 @@
for(int i = 0; i < numChildren; ++i)
{
+ //real symbol height. Can be different from standard height in case of point symbols
+ double realSymbolHeight;
+ double realItemHeight = itemHeight; //will be adjusted if realSymbolHeight turns out to be larger
+
currentYCoord += mSymbolSpace;
double currentXCoord = mBoxSpace;
@@ -187,7 +193,8 @@
if(symbol) //item with symbol?
{
//draw symbol
- drawSymbol(p, symbol, currentYCoord + (itemHeight - mSymbolHeight) /2, currentXCoord);
+ drawSymbol(p, symbol, currentYCoord + (itemHeight - mSymbolHeight) /2, currentXCoord, realSymbolHeight);
+ realItemHeight = std::max(realSymbolHeight, itemHeight);
currentXCoord += mIconLabelSpace;
}
else //item with icon?
@@ -203,16 +210,16 @@
//finally draw text
if(p)
{
- p->drawText(QPointF(currentXCoord, currentYCoord + itemFontMetrics.ascent()), currentItem->text());
+ p->drawText(QPointF(currentXCoord, currentYCoord + itemFontMetrics.ascent() + (realItemHeight - itemFontMetrics.ascent()) / 2), currentItem->text());
}
maxXCoord = std::max(maxXCoord, currentXCoord + itemFontMetrics.width(currentItem->text()) + mBoxSpace);
- currentYCoord += itemHeight;
+ currentYCoord += realItemHeight;
}
}
-void QgsComposerLegend::drawSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition) const
+void QgsComposerLegend::drawSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight) const
{
if(!s)
{
@@ -223,18 +230,20 @@
switch(symbolType)
{
case QGis::Point:
- drawPointSymbol(p, s, currentYCoord, currentXPosition);
+ drawPointSymbol(p, s, currentYCoord, currentXPosition, symbolHeight);
break;
case QGis::Line:
drawLineSymbol(p, s, currentYCoord, currentXPosition);
+ symbolHeight = mSymbolHeight;
break;
case QGis::Polygon:
drawPolygonSymbol(p, s, currentYCoord, currentXPosition);
+ symbolHeight = mSymbolHeight;
break;
}
}
-void QgsComposerLegend::drawPointSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition) const
+void QgsComposerLegend::drawPointSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight) const
{
if(!s)
{
@@ -268,7 +277,8 @@
p->restore();
}
- currentXPosition += pointImage.width();
+ currentXPosition += pointImage.width() / rasterScaleFactor;
+ symbolHeight = pointImage.height() / rasterScaleFactor;
}
void QgsComposerLegend::drawLineSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition) const
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.h 2008-07-26 09:25:28 UTC (rev 8914)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlegend.h 2008-07-26 09:25:41 UTC (rev 8915)
@@ -106,9 +106,10 @@
*/
void drawLayerChildItems(QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord);
- /**Draws a symbol at the current y position and returns the new x position*/
- void drawSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition) const;
- void drawPointSymbol(QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition) const;
+ /**Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points,
+ it is possible that it differs from mSymbolHeight*/
+ void drawSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight) const;
+ void drawPointSymbol(QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight) const;
void drawLineSymbol(QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition) const;
void drawPolygonSymbol(QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition) const;
};
More information about the QGIS-commit
mailing list