[QGIS Commit] r8688 - in branches/advanced_printing_branch/src/app:
. composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Jun 30 06:24:12 EDT 2008
Author: mhugent
Date: 2008-06-30 06:24:11 -0400 (Mon, 30 Jun 2008)
New Revision: 8688
Added:
branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.cpp
branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.h
branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.cpp
branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.h
Modified:
branches/advanced_printing_branch/src/app/CMakeLists.txt
branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp
Log:
Added two new scale bar styles
Modified: branches/advanced_printing_branch/src/app/CMakeLists.txt
===================================================================
--- branches/advanced_printing_branch/src/app/CMakeLists.txt 2008-06-30 06:18:49 UTC (rev 8687)
+++ branches/advanced_printing_branch/src/app/CMakeLists.txt 2008-06-30 10:24:11 UTC (rev 8688)
@@ -66,6 +66,8 @@
composer/qgscomposerscalebar.cpp
composer/qgscomposerscalebarwidget.cpp
composer/qgsscalebarstyle.cpp
+ composer/qgsdoubleboxscalebarstyle.cpp
+ composer/qgsnumericscalebarstyle.cpp
composer/qgssingleboxscalebarstyle.cpp
composer/qgsticksmiddlescalebarstyle.cpp
#composer/qgscomposervectorlegend.cpp
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-06-30 06:18:49 UTC (rev 8687)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-06-30 10:24:11 UTC (rev 8688)
@@ -227,7 +227,7 @@
mCacheUpdated = u;
}
-double QgsComposerMap::scale()
+double QgsComposerMap::scale() const
{
QgsScaleCalculator calculator;
calculator.setMapUnits(mMapCanvas->mapUnits());
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-06-30 06:18:49 UTC (rev 8687)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-06-30 10:24:11 UTC (rev 8688)
@@ -81,7 +81,7 @@
void setSceneRect(const QRectF& rectangle);
/** \brief Scale */
- double scale ( void );
+ double scale ( void ) const;
/**Sets new scale and changes only mExtent*/
void setNewScale(double scaleDenominator);
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp 2008-06-30 06:18:49 UTC (rev 8687)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp 2008-06-30 10:24:11 UTC (rev 8688)
@@ -17,6 +17,8 @@
#include "qgscomposerscalebar.h"
#include "qgscomposermap.h"
#include "qgsscalebarstyle.h"
+#include "qgsdoubleboxscalebarstyle.h"
+#include "qgsnumericscalebarstyle.h"
#include "qgssingleboxscalebarstyle.h"
#include "qgsticksmiddlescalebarstyle.h"
#include "qgsrect.h"
@@ -118,6 +120,7 @@
mFont.setPointSizeF(4);
mLabelBarSpace = 3.0;
+ mBoxContentSpace = 1.0;
if(mComposerMap)
{
@@ -195,9 +198,17 @@
{
mStyle = new QgsSingleBoxScaleBarStyle(this);
}
+ else if(styleName == tr("Double Box"))
+ {
+ mStyle = new QgsDoubleBoxScaleBarStyle(this);
+ }
else if(styleName == tr("Bar Ticks Middle"))
{
mStyle = new QgsTicksMiddleScaleBarStyle(this);
+ }
+ else if(styleName == tr("Numeric"))
+ {
+ mStyle = new QgsNumericScaleBarStyle(this);
}
}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp 2008-06-30 06:18:49 UTC (rev 8687)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebarwidget.cpp 2008-06-30 10:24:11 UTC (rev 8688)
@@ -26,7 +26,9 @@
setupUi(this);
mStyleComboBox->insertItem(0, tr("Single Box"));
- mStyleComboBox->insertItem(1, tr("Bar Ticks Middle"));
+ mStyleComboBox->insertItem(1, tr("Double Box"));
+ mStyleComboBox->insertItem(2, tr("Bar Ticks Middle"));
+ mStyleComboBox->insertItem(3, tr("Numeric"));
setGuiElements(); //set the GUI elements to the state of scaleBar
}
Added: branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.cpp (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.cpp 2008-06-30 10:24:11 UTC (rev 8688)
@@ -0,0 +1,96 @@
+/***************************************************************************
+ qgsdoubleboxscalebarstyle.cpp
+ -----------------------------
+ begin : June 2008
+ copyright : (C) 2008 by Marco Hugentobler
+ email : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "qgsdoubleboxscalebarstyle.h"
+#include "qgscomposerscalebar.h"
+#include <QList>
+#include <QPainter>
+
+QgsDoubleBoxScaleBarStyle::QgsDoubleBoxScaleBarStyle(const QgsComposerScaleBar* bar): QgsScaleBarStyle(bar)
+{
+
+}
+
+QgsDoubleBoxScaleBarStyle::QgsDoubleBoxScaleBarStyle(): QgsScaleBarStyle(0)
+{
+
+}
+
+QgsDoubleBoxScaleBarStyle::~QgsDoubleBoxScaleBarStyle()
+{
+
+}
+
+QString QgsDoubleBoxScaleBarStyle::name() const
+{
+ return "Double Box";
+}
+
+void QgsDoubleBoxScaleBarStyle::draw(QPainter* p) const
+{
+ if(!mScaleBar)
+ {
+ return;
+ }
+ double barTopPosition = mScaleBar->fontHeight() + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
+ double segmentHeight = mScaleBar->height() / 2;
+
+ p->save();
+ p->setPen(p->pen());
+
+ QList<QPair<double, double> > segmentInfo;
+ mScaleBar->segmentPositions(segmentInfo);
+
+ bool useColor = true; //alternate brush color/white
+
+
+
+ QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
+ for(; segmentIt != segmentInfo.constEnd(); ++segmentIt)
+ {
+ //draw top half
+ if(useColor)
+ {
+ p->setBrush(mScaleBar->brush());
+ }
+ else //white
+ {
+ p->setBrush(QColor(255, 255, 255));
+ }
+
+ QRectF segmentRectTop(segmentIt->first, barTopPosition, segmentIt->second, segmentHeight);
+ p->drawRect(segmentRectTop);
+
+ //draw bottom half
+ if(useColor)
+ {
+ p->setBrush(QColor(255, 255, 255));
+ }
+ else //white
+ {
+ p->setBrush(mScaleBar->brush());
+ }
+
+ QRectF segmentRectBottom(segmentIt->first, barTopPosition + segmentHeight, segmentIt->second, segmentHeight);
+ p->drawRect(segmentRectBottom);
+ useColor = !useColor;
+ }
+
+ p->restore();
+
+ //draw labels using the default method
+ drawLabels(p);
+}
Added: branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.h (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsdoubleboxscalebarstyle.h 2008-06-30 10:24:11 UTC (rev 8688)
@@ -0,0 +1,37 @@
+/***************************************************************************
+ qgsdoubleboxscalebarstyle.h
+ ---------------------------
+ begin : June 2008
+ copyright : (C) 2008 by Marco Hugentobler
+ email : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QGSDOUBLEBOXSCALEBARSTYLE_H
+#define QGSDOUBLEBOXSCALEBARSTYLE_H
+
+#include "qgsscalebarstyle.h"
+
+/**Double box with alternating colors*/
+class QgsDoubleBoxScaleBarStyle: public QgsScaleBarStyle
+{
+ public:
+ QgsDoubleBoxScaleBarStyle(const QgsComposerScaleBar* bar);
+ ~QgsDoubleBoxScaleBarStyle();
+
+ QString name() const;
+
+ void draw(QPainter* p) const;
+
+ private:
+ QgsDoubleBoxScaleBarStyle(); //forbidden
+};
+
+#endif
Added: branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.cpp (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.cpp 2008-06-30 10:24:11 UTC (rev 8688)
@@ -0,0 +1,87 @@
+/***************************************************************************
+ qgsnumericscalebarstyle.cpp
+ ---------------------------
+ begin : June 2008
+ copyright : (C) 2008 by Marco Hugentobler
+ email : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "qgsnumericscalebarstyle.h"
+#include "qgscomposermap.h"
+#include "qgscomposerscalebar.h"
+#include <QList>
+#include <QPainter>
+
+QgsNumericScaleBarStyle::QgsNumericScaleBarStyle(QgsComposerScaleBar* bar): QgsScaleBarStyle(bar)
+{
+
+}
+
+QgsNumericScaleBarStyle::QgsNumericScaleBarStyle(): QgsScaleBarStyle(0)
+{
+
+}
+
+QgsNumericScaleBarStyle::~QgsNumericScaleBarStyle()
+{
+
+}
+
+QString QgsNumericScaleBarStyle::name() const
+{
+ return "Numeric";
+}
+
+void QgsNumericScaleBarStyle::draw(QPainter* p) const
+{
+ if(!p || !mScaleBar)
+ {
+ return;
+ }
+
+ p->save();
+
+ p->setFont(mScaleBar->font());
+ p->drawText(QPointF(mScaleBar->pen().widthF() + mScaleBar->boxContentSpace(), mScaleBar->boxContentSpace() \
+ + mScaleBar->fontHeight()), scaleText());
+
+ p->restore();
+}
+
+QRectF QgsNumericScaleBarStyle::calculateBoxSize() const
+{
+ QRectF rect;
+ if(!mScaleBar)
+ {
+ return rect;
+ }
+
+ QFontMetricsF fontMetrics(mScaleBar->font());
+ return QRectF(mScaleBar->transform().dx(), mScaleBar->transform().dy(), 2 * mScaleBar->boxContentSpace() \
+ + 2 * mScaleBar->pen().width() + fontMetrics.width(scaleText()), \
+ mScaleBar->fontHeight() + 2 * mScaleBar->boxContentSpace());
+}
+
+QString QgsNumericScaleBarStyle::scaleText() const
+{
+ QString scaleBarText;
+ if(mScaleBar)
+ {
+ //find out scale
+ const QgsComposerMap* composerMap = mScaleBar->composerMap();
+ if(composerMap)
+ {
+ double scaleDenominator = composerMap->scale();
+ scaleBarText = "1:" + QString::number(scaleDenominator);
+ }
+ }
+ return scaleBarText;
+}
Added: branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.h (rev 0)
+++ branches/advanced_printing_branch/src/app/composer/qgsnumericscalebarstyle.h 2008-06-30 10:24:11 UTC (rev 8688)
@@ -0,0 +1,42 @@
+/***************************************************************************
+ qgsnumericscalebarstyle.h
+ ---------------------------
+ begin : June 2008
+ copyright : (C) 2008 by Marco Hugentobler
+ email : marco.hugentobler at karto.baug.ethz.ch
+ ***************************************************************************/
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QGSNUMERICSCALEBARSTYLE_H
+#define QGSNUMERICSCALEBARSTYLE_H
+
+#include "qgsscalebarstyle.h"
+
+/**A scale bar style that draws text in the form of '1:XXXXX'*/
+class QgsNumericScaleBarStyle: public QgsScaleBarStyle
+{
+ public:
+ QgsNumericScaleBarStyle(QgsComposerScaleBar* bar);
+ ~QgsNumericScaleBarStyle();
+
+ QString name() const;
+
+ void draw(QPainter* p) const;
+
+ //calculation of box size is different compared to segment based scale bars
+ QRectF calculateBoxSize() const;
+
+ private:
+ QgsNumericScaleBarStyle(); //forbidden
+ /**Returns the text for the scale bar or an empty string in case of error*/
+ QString scaleText() const;
+};
+
+#endif
More information about the QGIS-commit
mailing list