| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /*************************************************************************** | ||
| qgsdiagramproperties.h | ||
| Properties for diagram layers | ||
| ------------------- | ||
| begin : August 2012 | ||
| copyright : (C) Matthias Kuhn | ||
| email : matthias dot kuhn at gmx dot 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 QGSDIAGRAMPROPERTIES_H | ||
| #define QGSDIAGRAMPROPERTIES_H | ||
|
|
||
| #include <QDialog> | ||
| #include <ui_qgsdiagrampropertiesbase.h> | ||
|
|
||
| class QgsVectorLayer; | ||
|
|
||
| class QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPropertiesBase | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| QgsDiagramProperties( QgsVectorLayer* layer, QWidget* parent ); | ||
|
|
||
| //void handleAttributeDoubleClicked( QTreeWidgetItem * item, int column ); | ||
|
|
||
| public slots: | ||
| void apply(); | ||
| void on_mDiagramTypeComboBox_currentIndexChanged( int index ); | ||
| void on_mTransparencySlider_valueChanged( int value ); | ||
| void on_mAddCategoryPushButton_clicked(); | ||
| void on_mBackgroundColorButton_clicked(); | ||
| void on_mFindMaximumValueButton_clicked(); | ||
| void on_mDiagramPenColorButton_clicked(); | ||
| void on_mDisplayDiagramsGroupBox_toggled( bool checked ); | ||
| void on_mRemoveCategoryPushButton_clicked(); | ||
| void on_mDiagramFontButton_clicked(); | ||
| void on_mDiagramAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column ); | ||
| void on_mEngineSettingsButton_clicked(); | ||
|
|
||
| protected: | ||
| QFont mDiagramFont; | ||
|
|
||
| QgsVectorLayer* mLayer; | ||
|
|
||
| private: | ||
| }; | ||
|
|
||
| #endif // QGSDIAGRAMPROPERTIES_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /*************************************************************************** | ||
| qgsdiagram.cpp | ||
| --------------------- | ||
| begin : March 2011 | ||
| copyright : (C) 2011 by Marco Hugentobler | ||
| email : marco dot hugentobler at sourcepole dot 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 "qgsdiagram.h" | ||
| #include "qgsdiagramrendererv2.h" | ||
| #include "qgsrendercontext.h" | ||
|
|
||
| #include <QPainter> | ||
|
|
||
| void QgsDiagram::setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsRenderContext& c ) | ||
| { | ||
| if ( s.sizeType == QgsDiagramSettings::MM ) | ||
| { | ||
| pen.setWidthF( s.penWidth * c.scaleFactor() ); | ||
| } | ||
| else | ||
| { | ||
| pen.setWidthF( s.penWidth / c.mapToPixel().mapUnitsPerPixel() ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| QSizeF QgsDiagram::sizePainterUnits( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c ) | ||
| { | ||
| if ( s.sizeType == QgsDiagramSettings::MM ) | ||
| { | ||
| return QSizeF( size.width() * c.scaleFactor() * c.rasterScaleFactor(), size.height() * c.scaleFactor() * c.rasterScaleFactor() ); | ||
| } | ||
| else | ||
| { | ||
| return QSizeF( size.width() / c.mapToPixel().mapUnitsPerPixel(), size.height() / c.mapToPixel().mapUnitsPerPixel() ); | ||
| } | ||
| } | ||
|
|
||
| float QgsDiagram::sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c ) | ||
| { | ||
| if ( s.sizeType == QgsDiagramSettings::MM ) | ||
| { | ||
| return l * c.scaleFactor(); | ||
| } | ||
| else | ||
| { | ||
| return l / c.mapToPixel().mapUnitsPerPixel(); | ||
| } | ||
| } | ||
|
|
||
| QFont QgsDiagram::scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c ) | ||
| { | ||
| QFont f = s.font; | ||
| if ( s.sizeType == QgsDiagramSettings::MM ) | ||
| { | ||
| f.setPixelSize( s.font.pointSizeF() * 0.376 * c.scaleFactor() ); | ||
| } | ||
| else | ||
| { | ||
| f.setPixelSize( s.font.pointSizeF() / c.mapToPixel().mapUnitsPerPixel() ); | ||
| } | ||
|
|
||
| return f; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /*************************************************************************** | ||
| qgsdiagram.h | ||
| --------------------- | ||
| begin : March 2011 | ||
| copyright : (C) 2011 by Marco Hugentobler | ||
| email : marco dot hugentobler at sourcepole dot 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 QGSDIAGRAM_H | ||
| #define QGSDIAGRAM_H | ||
|
|
||
| #include "qgsfeature.h" | ||
| #include <QPen> | ||
| #include <QBrush> | ||
|
|
||
| class QPainter; | ||
| class QPointF; | ||
| struct QgsDiagramSettings; | ||
| struct QgsDiagramInterpolationSettings; | ||
|
|
||
| class QgsRenderContext; | ||
|
|
||
|
|
||
|
|
||
| /**Base class for all diagram types*/ | ||
| class CORE_EXPORT QgsDiagram | ||
| { | ||
| public: | ||
| virtual ~QgsDiagram() {} | ||
| /**Draws the diagram at the given position (in pixel coordinates)*/ | ||
| virtual void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) = 0; | ||
| virtual QString diagramName() const = 0; | ||
| /**Returns the size in map units the diagram will use to render.*/ | ||
| virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ) = 0; | ||
| /**Returns the size in map units the diagram will use to render. Interpolate size*/ | ||
| virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) = 0; | ||
|
|
||
| protected: | ||
| /** Changes the pen width to match the current settings and rendering context | ||
| * @param pen The pen to modify | ||
| * @param s The settings that specify the pen width | ||
| * @param c The rendering specifying the proper scale units for pixel conversion | ||
| */ | ||
| void setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsRenderContext& c ); | ||
|
|
||
| /** Calculates a size to match the current settings and rendering context | ||
| * @param size The size to convert | ||
| * @param s The settings that specify the size type | ||
| * @param c The rendering specifying the proper scale units for pixel conversion | ||
| * | ||
| * @return The converted size for rendering | ||
| */ | ||
| QSizeF sizePainterUnits( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c ); | ||
|
|
||
| /** Calculates a length to match the current settings and rendering context | ||
| * @param l The length to convert | ||
| * @param s Unused | ||
| * @param c The rendering specifying the proper scale units for pixel conversion | ||
| * | ||
| * @return The converted length for rendering | ||
| */ | ||
| float sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c ); | ||
|
|
||
| /** Calculates a size to match the current settings and rendering context | ||
| * @param s The settings that contain the font size and size type | ||
| * @param c The rendering specifying the proper scale units for pixel conversion | ||
| * | ||
| * @return The properly scaled font for rendering | ||
| */ | ||
| QFont scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c ); | ||
| }; | ||
|
|
||
| #endif // QGSDIAGRAM_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| /*************************************************************************** | ||
| qgshistogramdiagram.cpp | ||
| --------------------- | ||
| begin : August 2012 | ||
| copyright : (C) 2012 by Matthias Kuhn | ||
| email : matthias dot kuhn at gmx dot 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 "qgshistogramdiagram.h" | ||
| #include "qgsdiagramrendererv2.h" | ||
| #include "qgsrendercontext.h" | ||
|
|
||
| #include <QPainter> | ||
|
|
||
| QgsHistogramDiagram::QgsHistogramDiagram() | ||
| { | ||
| mCategoryBrush.setStyle( Qt::SolidPattern ); | ||
| mPen.setStyle( Qt::SolidLine ); | ||
| mScaleFactor = 0; | ||
| } | ||
|
|
||
| QgsHistogramDiagram::~QgsHistogramDiagram() | ||
| { | ||
| } | ||
|
|
||
| QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) | ||
| { | ||
| Q_UNUSED( c ); | ||
| QSize size; | ||
| QgsAttributeMap::const_iterator attIt = attributes.constBegin(); | ||
| if ( attIt == attributes.constEnd() ) | ||
| { | ||
| return QSizeF(); //zero size if no attributes | ||
| } | ||
|
|
||
| double maxValue = attIt.value().toDouble(); | ||
|
|
||
| for ( ++attIt; attIt != attributes.constEnd(); ++attIt ) | ||
| { | ||
| maxValue = qMax( attIt.value().toDouble(), maxValue ); | ||
| } | ||
|
|
||
| // Scale, if extension is smaller than the specified minimum | ||
| if ( maxValue < s.minimumSize ) | ||
| { | ||
| maxValue = s.minimumSize; | ||
| } | ||
|
|
||
| switch ( s.diagramOrientation ) | ||
| { | ||
| case QgsDiagramSettings::Up: | ||
| case QgsDiagramSettings::Down: | ||
| mScaleFactor = (( is.upperSize.width() - is.lowerSize.height() ) / ( is.upperValue - is.lowerValue ) ); | ||
| size.scale( s.barWidth * attributes.size(), maxValue * mScaleFactor, Qt::IgnoreAspectRatio ); | ||
| break; | ||
|
|
||
| case QgsDiagramSettings::Right: | ||
| case QgsDiagramSettings::Left: | ||
| mScaleFactor = (( is.upperSize.width() - is.lowerSize.width() ) / ( is.upperValue - is.lowerValue ) ); | ||
| size.scale( maxValue * mScaleFactor, s.barWidth * attributes.size(), Qt::IgnoreAspectRatio ); | ||
| break; | ||
| } | ||
|
|
||
| return size; | ||
| } | ||
|
|
||
| QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ) | ||
| { | ||
| Q_UNUSED( c ); | ||
| QSizeF size; | ||
|
|
||
| QgsAttributeMap::const_iterator attIt = attributes.constBegin(); | ||
| if ( attIt == attributes.constEnd() ) | ||
| { | ||
| return QSizeF(); //zero size if no attributes | ||
| } | ||
|
|
||
| double maxValue = attIt.value().toDouble(); | ||
|
|
||
| for ( ; attIt != attributes.constEnd(); ++attIt ) | ||
| { | ||
| maxValue = qMax( attIt.value().toDouble(), maxValue ); | ||
| } | ||
|
|
||
| switch ( s.diagramOrientation ) | ||
| { | ||
| case QgsDiagramSettings::Up: | ||
| case QgsDiagramSettings::Down: | ||
| mScaleFactor = maxValue / s.size.height(); | ||
| size.scale( s.barWidth * s.categoryColors.size(), s.size.height(), Qt::IgnoreAspectRatio ); | ||
| break; | ||
|
|
||
| case QgsDiagramSettings::Right: | ||
| case QgsDiagramSettings::Left: | ||
| default: // just in case... | ||
| mScaleFactor = maxValue / s.size.width(); | ||
| size.scale( s.size.width(), s.barWidth * s.categoryColors.size(), Qt::IgnoreAspectRatio ); | ||
| break; | ||
| } | ||
|
|
||
| return size; | ||
| } | ||
|
|
||
| void QgsHistogramDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) | ||
| { | ||
| QPainter* p = c.painter(); | ||
| if ( !p ) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| QList<double> values; | ||
|
|
||
| QList<int>::const_iterator catIt = s.categoryIndices.constBegin(); | ||
| for ( ; catIt != s.categoryIndices.constEnd(); ++catIt ) | ||
| { | ||
| double currentVal = att[*catIt].toDouble(); | ||
| values.push_back( currentVal ); | ||
| } | ||
|
|
||
| double currentOffset = 0; | ||
| double scaledWidth = sizePainterUnits( s.barWidth, s, c ); | ||
|
|
||
| double baseX = position.x(); | ||
| double baseY = position.y(); | ||
|
|
||
| mPen.setColor( s.penColor ); | ||
| setPenWidth( mPen, s, c ); | ||
| p->setPen( mPen ); | ||
|
|
||
| QList<double>::const_iterator valIt = values.constBegin(); | ||
| QList< QColor >::const_iterator colIt = s.categoryColors.constBegin(); | ||
| for ( ; valIt != values.constEnd(); ++valIt, ++colIt ) | ||
| { | ||
| double length = sizePainterUnits( *valIt * mScaleFactor, s, c ); | ||
|
|
||
| mCategoryBrush.setColor( *colIt ); | ||
| p->setBrush( mCategoryBrush ); | ||
|
|
||
| switch ( s.diagramOrientation ) | ||
| { | ||
| case QgsDiagramSettings::Up: | ||
| p->drawRect( baseX + currentOffset, baseY, scaledWidth, 0 - length ); | ||
| break; | ||
|
|
||
| case QgsDiagramSettings::Down: | ||
| p->drawRect( baseX + currentOffset, baseY, scaledWidth, length ); | ||
| break; | ||
|
|
||
| case QgsDiagramSettings::Right: | ||
| p->drawRect( baseX, baseY + currentOffset, length, scaledWidth ); | ||
| break; | ||
|
|
||
| case QgsDiagramSettings::Left: | ||
| p->drawRect( baseX, baseY + currentOffset, 0 - length, scaledWidth ); | ||
| break; | ||
| } | ||
|
|
||
| currentOffset += scaledWidth; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /*************************************************************************** | ||
| qgshistogramdiagram.h | ||
| --------------------- | ||
| begin : August 2012 | ||
| copyright : (C) 2012 by Matthias Kuhn | ||
| email : matthias dot kuhn at gmx dot 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 QGSHISTOGRAMDIAGRAM_H | ||
| #define QGSHISTOGRAMDIAGRAM_H | ||
|
|
||
| #define DIAGRAM_NAME_HISTOGRAM "Histogram" | ||
|
|
||
| #include "qgsdiagram.h" | ||
| #include "qgsfeature.h" | ||
| #include <QPen> | ||
| #include <QBrush> | ||
|
|
||
| class QPainter; | ||
| class QPointF; | ||
| struct QgsDiagramSettings; | ||
| struct QgsDiagramInterpolationSettings; | ||
|
|
||
| class QgsRenderContext; | ||
|
|
||
|
|
||
| class CORE_EXPORT QgsHistogramDiagram: public QgsDiagram | ||
| { | ||
| public: | ||
| QgsHistogramDiagram(); | ||
| ~QgsHistogramDiagram(); | ||
|
|
||
| void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ); | ||
| QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ); | ||
| QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ); | ||
| QString diagramName() const { return DIAGRAM_NAME_HISTOGRAM; } | ||
|
|
||
| private: | ||
| QBrush mCategoryBrush; | ||
| QPen mPen; | ||
| double mScaleFactor; | ||
| }; | ||
|
|
||
|
|
||
| #endif // QGSHISTOGRAMDIAGRAM_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /*************************************************************************** | ||
| qgspiediagram.cpp | ||
| --------------------- | ||
| begin : March 2011 | ||
| copyright : (C) 2011 by Marco Hugentobler | ||
| email : marco dot hugentobler at sourcepole dot 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 "qgspiediagram.h" | ||
| #include "qgsdiagramrendererv2.h" | ||
| #include "qgsrendercontext.h" | ||
|
|
||
| #include <QPainter> | ||
|
|
||
|
|
||
| QgsPieDiagram::QgsPieDiagram() | ||
| { | ||
| mCategoryBrush.setStyle( Qt::SolidPattern ); | ||
| mPen.setStyle( Qt::SolidLine ); | ||
| } | ||
|
|
||
| QgsPieDiagram::~QgsPieDiagram() | ||
| { | ||
| } | ||
|
|
||
| QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) | ||
| { | ||
| QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute ); | ||
| if ( attIt == attributes.constEnd() ) | ||
| { | ||
| return QSizeF(); //zero size if attribute is missing | ||
| } | ||
|
|
||
| double scaledValue = attIt.value().toDouble(); | ||
| double scaledLowerValue = is.lowerValue; | ||
| double scaledUpperValue = is.upperValue; | ||
| double scaledLowerSizeWidth = is.lowerSize.width(); | ||
| double scaledLowerSizeHeight = is.lowerSize.height(); | ||
| double scaledUpperSizeWidth = is.upperSize.width(); | ||
| double scaledUpperSizeHeight = is.upperSize.height(); | ||
|
|
||
| // interpolate the squared value if scale by area | ||
| if ( s.scaleByArea ) | ||
| { | ||
| scaledValue = sqrt( scaledValue ); | ||
| scaledLowerValue = sqrt( scaledLowerValue ); | ||
| scaledUpperValue = sqrt( scaledUpperValue ); | ||
| scaledLowerSizeWidth = sqrt( scaledLowerSizeWidth ); | ||
| scaledLowerSizeHeight = sqrt( scaledLowerSizeHeight ); | ||
| scaledUpperSizeWidth = sqrt( scaledUpperSizeWidth ); | ||
| scaledUpperSizeHeight = sqrt( scaledUpperSizeHeight ); | ||
| } | ||
|
|
||
| //interpolate size | ||
| double scaledRatio = ( scaledValue - scaledLowerValue ) / ( scaledUpperValue - scaledLowerValue ); | ||
|
|
||
| QSizeF size = QSizeF( is.upperSize.width() * scaledRatio + is.lowerSize.width() * ( 1 - scaledRatio ), | ||
| is.upperSize.height() * scaledRatio + is.lowerSize.height() * ( 1 - scaledRatio ) ); | ||
|
|
||
| // Scale, if extension is smaller than the specified minimum | ||
| if ( size.width() <= s.minimumSize && size.height() <= s.minimumSize ) | ||
| { | ||
| size.scale( s.minimumSize, s.minimumSize, Qt::KeepAspectRatio ); | ||
| } | ||
|
|
||
| return size; | ||
| } | ||
|
|
||
| QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ) | ||
| { | ||
| return s.size; | ||
| } | ||
|
|
||
| int QgsPieDiagram::sCount = 0; | ||
|
|
||
| void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) | ||
| { | ||
| QPainter* p = c.painter(); | ||
| if ( !p ) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| //get sum of values | ||
| QList<double> values; | ||
| double currentVal = 0; | ||
| double valSum = 0; | ||
| int valCount = 0; | ||
|
|
||
| QList<int>::const_iterator catIt = s.categoryIndices.constBegin(); | ||
| for ( ; catIt != s.categoryIndices.constEnd(); ++catIt ) | ||
| { | ||
| currentVal = att[*catIt].toDouble(); | ||
| values.push_back( currentVal ); | ||
| valSum += currentVal; | ||
| if ( currentVal ) valCount++; | ||
| } | ||
|
|
||
| //draw the slices | ||
| double totalAngle = 0; | ||
| double currentAngle; | ||
|
|
||
| //convert from mm / map units to painter units | ||
| QSizeF spu = sizePainterUnits( s.size, s, c ); | ||
| double w = spu.width(); | ||
| double h = spu.height(); | ||
|
|
||
| double baseX = position.x(); | ||
| double baseY = position.y() - h; | ||
|
|
||
| mPen.setColor( s.penColor ); | ||
| setPenWidth( mPen, s, c ); | ||
| p->setPen( mPen ); | ||
|
|
||
| // there are some values > 0 available | ||
| if ( valSum > 0 ) | ||
| { | ||
| QList<double>::const_iterator valIt = values.constBegin(); | ||
| QList< QColor >::const_iterator colIt = s.categoryColors.constBegin(); | ||
| for ( ; valIt != values.constEnd(); ++valIt, ++colIt ) | ||
| { | ||
| currentAngle = *valIt / valSum * 360 * 16; | ||
| mCategoryBrush.setColor( *colIt ); | ||
| p->setBrush( mCategoryBrush ); | ||
| // if only 1 value is > 0, draw a circle | ||
| if ( valCount == 1 ) | ||
| { | ||
| p->drawEllipse( baseX, baseY, w, h ); | ||
| } | ||
| else | ||
| { | ||
| p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle ); | ||
| } | ||
| totalAngle += currentAngle; | ||
| } | ||
| } | ||
| else // valSum > 0 | ||
| { | ||
| // draw empty circle if no values are defined at all | ||
| mCategoryBrush.setColor( Qt::transparent ); | ||
| p->setBrush( mCategoryBrush ); | ||
| p->drawEllipse( baseX, baseY, w, h ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /*************************************************************************** | ||
| qgspiediagram.h | ||
| --------------------- | ||
| begin : March 2011 | ||
| copyright : (C) 2011 by Marco Hugentobler | ||
| email : marco dot hugentobler at sourcepole dot 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 QGSPIEDIAGRAM_H | ||
| #define QGSPIEDIAGRAM_H | ||
|
|
||
| #define DIAGRAM_NAME_PIE "Pie" | ||
|
|
||
| #include "qgsdiagram.h" | ||
| #include "qgsfeature.h" | ||
| #include <QPen> | ||
| #include <QBrush> | ||
|
|
||
| class QPainter; | ||
| class QPointF; | ||
| struct QgsDiagramSettings; | ||
| struct QgsDiagramInterpolationSettings; | ||
|
|
||
| class QgsRenderContext; | ||
|
|
||
| class CORE_EXPORT QgsPieDiagram: public QgsDiagram | ||
| { | ||
| public: | ||
| QgsPieDiagram(); | ||
| ~QgsPieDiagram(); | ||
|
|
||
| void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ); | ||
| QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s ); | ||
| QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ); | ||
| QString diagramName() const { return DIAGRAM_NAME_PIE; } | ||
|
|
||
| private: | ||
| QBrush mCategoryBrush; | ||
| QPen mPen; | ||
|
|
||
| static int sCount; | ||
| }; | ||
|
|
||
| #endif // QGSPIEDIAGRAM_H |