[QGIS Commit] r9715 -
branches/vector_overlay_branch/src/plugins/diagram_overlay
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Nov 29 04:42:36 EST 2008
Author: mhugent
Date: 2008-11-29 04:42:35 -0500 (Sat, 29 Nov 2008)
New Revision: 9715
Modified:
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.cpp
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.h
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.h
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.cpp
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.h
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.cpp
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.h
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp
branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.h
Log:
Adapted diagram interfaces to consider output resolution
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.cpp 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.cpp 2008-11-29 09:42:35 UTC (rev 9715)
@@ -29,7 +29,7 @@
}
-QImage* QgsBarDiagramFactory::createDiagram(int size, const QgsFeature& f) const
+QImage* QgsBarDiagramFactory::createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const
{
QgsAttributeMap dataValues = f.attributeMap();
@@ -84,7 +84,7 @@
return diagramImage;
}
-int QgsBarDiagramFactory::getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const
+int QgsBarDiagramFactory::getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const
{
height = getHeightBarChart(size, f.attributeMap()) + 2 * mMaximumPenWidth;
width = mBarWidth * mCategories.size() + 2 * mMaximumPenWidth;
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.h 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsbardiagramfactory.h 2008-11-29 09:42:35 UTC (rev 9715)
@@ -28,14 +28,18 @@
~QgsBarDiagramFactory();
/**Creates a diagram for a feature and a given size (that is usually determined by QgsDiagramRenderer. The calling method takes ownership of the generated image*/
- QImage* createDiagram(int size, const QgsFeature& f) const;
+ QImage* createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const;
/**Creates items to show in the legend*/
- int createLegendContent(int size, QString value, QMap<QString, QImage*>& items) const{return 1;} //soon
+ int createLegendContent(int size, const QgsRenderContext& renderContext, QString value, QMap<QString, QImage*>& items) const{return 1;} //soon
- /**Gets the diagram width and height for a given size. Considers different width, height values and the maximum width of the drawing pen.
- */
- int getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const;
+ /**Gets the width and height (in pixels) of the diagram image. Considers different width, height values, the maximum width of the drawing pen and the conversion from mm size to pixels according to render context.
+ @param size diagram size calculated by diagram renderer (in mm)
+ @param f reference to the feature associated with the diagram
+ @param the render context (contains mm scale factor and raster scale factor)
+ @param width out: the width of the diagram image in pixels
+ @param height out: the height of the diagram image in pixels*/
+ int getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const;
/**Returns the property described by the size (e.g. diameter or height). This can be important to
know if e.g. size has to be calculated proportional to pie area*/
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramfactory.h 2008-11-29 09:42:35 UTC (rev 9715)
@@ -22,6 +22,7 @@
#include <QString>
class QgsFeature;
+class QgsRenderContext;
class QDomDocument;
class QDomNode;
class QImage;
@@ -39,27 +40,44 @@
DIAMETER,
SQUARESIDE,
};
+
+ enum SizeUnit //size in millimeters on output device or in map units on map
+ {
+ MM,
+ MapUnits
+ };
- /**Creates the diagram image for a feature in order to be placed on the map*/
- virtual QImage* createDiagram(int size, const QgsFeature& f) const = 0;
+ /**Creates the diagram image for a feature in order to be placed on the map
+ @param size diagram size (may be height, diameter, squaresize depending on diagram type
+ @param f feature that is symbolized by the diagram
+ @param renderContext rendering parameters*/
+ virtual QImage* createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const = 0;
/**Creates the text/images for the legend items. The caller takes ownership of the generated \
image objects.
@param size diagram size that should be represented in the legend
+ @param u size may be in MM on output device or in map units on map
+ @param renderContext rendering parameters
@param value diagram value that should be represented in the legend
@param items generated items
@return 0 in case of success*/
- virtual int createLegendContent(int size, QString value, QMap<QString, QImage*>& items) const = 0;
- /**Gets the width and height of the diagram image for a feature. This depends on \
- the diagram type and is not necessary equal with the size.
+ virtual int createLegendContent(int size, const QgsRenderContext& renderContext, QString value, QMap<QString, QImage*>& items) const = 0;
+ /**Gets the width and height (in pixels) of the diagram image. Considers different width, height values, the maximum width of the drawing pen and the conversion from mm size to pixels according to render context.
@param size diagram size calculated by diagram renderer
@param f reference to the feature associated with the diagram
- @param width out: the width of the diagram image
- @param height out: the height of the diagram image*/
- virtual int getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const = 0;
+ @param the render context (contains mm scale factor and raster scale factor)
+ @param width out: the width of the diagram image in pixels
+ @param height out: the height of the diagram image in pixels*/
+ virtual int getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const = 0;
virtual bool writeXML(QDomNode& overlay_node, QDomDocument& doc) const = 0;
virtual ~QgsDiagramFactory(){}
/**Default is one dimensional scaling*/
virtual QgsDiagramFactory::SizeType sizeType() const {return QgsDiagramFactory::HEIGHT;}
+
+ void setSizeUnit(SizeUnit u){mSizeUnit = u;}
+
+ protected:
+ /**Size units of diagram items*/
+ SizeUnit mSizeUnit;
};
#endif
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.cpp 2008-11-29 09:42:35 UTC (rev 9715)
@@ -80,7 +80,7 @@
while(theProvider->nextFeature(currentFeature))
{
//todo: insert more objects for multipart features
- if(mDiagramRenderer->getDiagramDimensions(width, height, currentFeature) != 0)
+ if(mDiagramRenderer->getDiagramDimensions(width, height, currentFeature, renderContext) != 0)
{
//error
}
@@ -111,7 +111,7 @@
while(theProvider->nextFeature(currentFeature))
{
//request diagram from renderer
- currentDiagramImage = mDiagramRenderer->renderDiagram(currentFeature);
+ currentDiagramImage = mDiagramRenderer->renderDiagram(currentFeature, context);
if(!currentDiagramImage)
{
qWarning("diagram image is 0");
@@ -145,9 +145,9 @@
}
}
-int QgsDiagramOverlay::getOverlayObjectSize(int& width, int& height, double value, const QgsFeature& f) const
+int QgsDiagramOverlay::getOverlayObjectSize(int& width, int& height, double value, const QgsFeature& f, const QgsRenderContext& renderContext) const
{
- return mDiagramRenderer->getDiagramDimensions(width, height, f);
+ return mDiagramRenderer->getDiagramDimensions(width, height, f, renderContext);
}
bool QgsDiagramOverlay::readXML(const QDomNode& overlayNode)
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.h 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramoverlay.h 2008-11-29 09:42:35 UTC (rev 9715)
@@ -47,7 +47,7 @@
static QString attributeNameFromIndex(int index, const QgsVectorLayer* vl);
protected:
- int getOverlayObjectSize(int& width, int& height, double value, const QgsFeature& f) const;
+ int getOverlayObjectSize(int& width, int& height, double value, const QgsFeature& f, const QgsRenderContext& renderContext) const;
private:
/**Does the classification and manages the diagram generation*/
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.cpp 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.cpp 2008-11-29 09:42:35 UTC (rev 9715)
@@ -13,11 +13,11 @@
delete mFactory;
}
-QgsDiagramRenderer::QgsDiagramRenderer()
+QgsDiagramRenderer::QgsDiagramRenderer(): mScaleFactor(1.0)
{
}
-QImage* QgsDiagramRenderer::renderDiagram(const QgsFeature& f) const
+QImage* QgsDiagramRenderer::renderDiagram(const QgsFeature& f, const QgsRenderContext& renderContext) const
{
if(!mFactory)
{
@@ -36,10 +36,10 @@
return 0;
}
- return mFactory->createDiagram(size, f);
+ return mFactory->createDiagram(size, f, renderContext);
}
-int QgsDiagramRenderer::getDiagramDimensions(int& width, int& height, const QgsFeature& f) const
+int QgsDiagramRenderer::getDiagramDimensions(int& width, int& height, const QgsFeature& f, const QgsRenderContext& renderContext) const
{
//first find out classification value
if(!mFactory || mItems.size() < 1)
@@ -53,7 +53,7 @@
return 2;
}
- if(mFactory->getDiagramDimensions(size, f, width, height) != 0)
+ if(mFactory->getDiagramDimensions(size, f, renderContext, width, height) != 0)
{
return 3;
}
@@ -189,7 +189,7 @@
return true;
}
-int QgsDiagramRenderer::createLegendContent(QMap<QString, QImage*> items) const
+int QgsDiagramRenderer::createLegendContent(const QgsRenderContext& renderContext, QMap<QString, QImage*> items) const
{
if(!mFactory || mItems.size() < 1)
{
@@ -201,7 +201,7 @@
QString value = mItems.at(element).value.toString();
int size = mItems.at(element).size;
- if(mFactory->createLegendContent(size, value, items) != 0)
+ if(mFactory->createLegendContent(size, renderContext, value, items) != 0)
{
return 2;
}
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.h 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgsdiagramrenderer.h 2008-11-29 09:42:35 UTC (rev 9715)
@@ -24,6 +24,7 @@
class QgsDiagramFactory;
class QgsFeature;
+class QgsRenderContext;
class QDomDocument;
class QDomNode;
class QImage;
@@ -31,12 +32,12 @@
//structure that describes a renderer entry
struct QgsDiagramItem
{
+
QVariant value;
int size;
};
-/**An interface class for diagram renderer. The main method is 'renderDiagram', which returns the diagram image for a GIS feature. The renderer has a set of classification attributes and a reference to a diagram factory object, which is responsible for creating the specific diagram type.
-Subclasses need to implement the method calculate diagram size.*/
+
class QgsDiagramRenderer
{
public:
@@ -46,20 +47,21 @@
{
DISCRETE, //lower item is used if item falls between lower and upper item
LINEAR, //linear interpolation between items containing the value
- ATTRIBUTE, //only attribute values are considered
+ ATTRIBUTE, //size contained in attribute value
CONSTANT //constant value is used (the size of the first item)
};
QgsDiagramRenderer(const QList<int>& classificationAttributes);
virtual ~QgsDiagramRenderer();
/**Returns a diagram image for a feature.*/
- virtual QImage* renderDiagram(const QgsFeature& f) const;
+ virtual QImage* renderDiagram(const QgsFeature& f, const QgsRenderContext& renderContext) const;
/**Returns only the size of the diagram.
- @param width the width of the diagram
- @param height the height of the diagram
+ @param width the width of the diagram in pixels
+ @param height the height of the diagram in pixels
@param f feature that is associated with the diagram
+ @param context contains information about mm scale factor and dpi
@return 0 in case of success*/
- virtual int getDiagramDimensions(int& width, int& height, const QgsFeature& f) const;
+ virtual int getDiagramDimensions(int& width, int& height, const QgsFeature& f, const QgsRenderContext& renderContext) const;
//setters and getters
QgsDiagramFactory* factory() const {return mFactory;}
/**Set a (properly configured) factory class. Takes ownership of the factory object*/
@@ -72,7 +74,7 @@
virtual bool writeXML(QDomNode& overlay_node, QDomDocument& doc) const;
/**Creates pairs of strings / images for use in the legend
@return 0 in case of success*/
- virtual int createLegendContent(QMap<QString, QImage*> items) const;
+ virtual int createLegendContent(const QgsRenderContext& renderContext, QMap<QString, QImage*> items) const;
/**Sets the items for interpolation. The values of the items must be in ascending order*/
void setDiagramItems(const QList<QgsDiagramItem>& items) {mItems = items;}
/**Returns the interpolation items*/
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.cpp 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.cpp 2008-11-29 09:42:35 UTC (rev 9715)
@@ -27,7 +27,7 @@
}
-QImage* QgsPieDiagramFactory::createDiagram(int size, const QgsFeature& f) const
+QImage* QgsPieDiagramFactory::createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const
{
QgsAttributeMap dataValues = f.attributeMap();
@@ -109,7 +109,7 @@
return diagramImage;
}
-int QgsPieDiagramFactory::getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const
+int QgsPieDiagramFactory::getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const
{
width = size + 2 * mMaximumPenWidth + 2 * mMaximumGap;
height = size + 2 * mMaximumPenWidth + 2 * mMaximumGap;
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.h 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgspiediagramfactory.h 2008-11-29 09:42:35 UTC (rev 9715)
@@ -30,15 +30,19 @@
QgsPieDiagramFactory();
~QgsPieDiagramFactory();
- /**Creates a diagram for a feature and a given size (that is usually determined by QgsDiagramRenderer. The calling method takes ownership of the generated image*/
- QImage* createDiagram(int size, const QgsFeature& f) const;
+ /**Creates a diagram for a feature and a given size. The size is usually determined by QgsDiagramRenderer. The calling method takes ownership of the generated image*/
+ QImage* createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const;
/**Creates items to show in the legend*/
- int createLegendContent(int size, QString value, QMap<QString, QImage*>& items) const{return 1;} //soon
+ int createLegendContent(int size, const QgsRenderContext& renderContext, QString value, QMap<QString, QImage*>& items) const{return 1;} //soon
- /**Gets the diagram width and height for a given size. Considers different width, height values and the maximum width of the drawing pen.
- */
- int getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const;
+ /**Gets the width and height (in pixels) of the diagram image. Considers different width, height values, the maximum width of the drawing pen and the conversion from mm size to pixels according to render context.
+ @param size diagram size calculated by diagram renderer (in mm)
+ @param f reference to the feature associated with the diagram
+ @param the render context (contains mm scale factor and raster scale factor)
+ @param width out: the width of the diagram image in pixels
+ @param height out: the height of the diagram image in pixels*/
+ int getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const;
/**Returns the property described by the size (e.g. diameter or height). This can be important to
know if e.g. size has to be calculated proportional to pie area*/
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.cpp 2008-11-29 09:42:35 UTC (rev 9715)
@@ -29,7 +29,7 @@
}
-QImage* QgsSVGDiagramFactory::createDiagram(int size, const QgsFeature& f) const
+QImage* QgsSVGDiagramFactory::createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const
{
//check default size
QSize defaultSize = mRenderer.defaultSize();
@@ -63,7 +63,7 @@
return diagramImage;
}
-int QgsSVGDiagramFactory::getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const
+int QgsSVGDiagramFactory::getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const
{
return 1; //soon...
}
Modified: branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.h
===================================================================
--- branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.h 2008-11-28 09:55:09 UTC (rev 9714)
+++ branches/vector_overlay_branch/src/plugins/diagram_overlay/qgssvgdiagramfactory.h 2008-11-29 09:42:35 UTC (rev 9715)
@@ -27,23 +27,27 @@
QgsSVGDiagramFactory();
~QgsSVGDiagramFactory();
- /**Creates the diagram image for a feature in order to be placed on the map*/
- QImage* createDiagram(int size, const QgsFeature& f) const;
+ /**Creates the diagram image for a feature in order to be placed on the map
+ @param size diagram size (may be height, diameter, squaresize depending on diagram type
+ @param f feature that is symbolized by the diagram
+ @param renderContext rendering parameters*/
+ QImage* createDiagram(int size, const QgsFeature& f, const QgsRenderContext& renderContext) const;
/**Creates the text/images for the legend items. The caller takes ownership of the generated \
- image objects.
+ image objects.
@param size diagram size that should be represented in the legend
+ @param renderContext rendering parameters
@param value diagram value that should be represented in the legend
@param items generated items
@return 0 in case of success*/
- int createLegendContent(int size, QString value, QMap<QString, QImage*>& items) const {return 1;} //later...
+ int createLegendContent(int size, const QgsRenderContext& renderContext, QString value, QMap<QString, QImage*>& items) const {return 1;} //later...
- /**Gets the width and height of the diagram image for a feature. This depends on \
- the diagram type and is not necessary equal with the size.
+ /**Gets the width and height (in pixels) of the diagram image. Considers different width, height values, the maximum width of the drawing pen and the conversion from mm size to pixels according to render context.
@param size diagram size calculated by diagram renderer
@param f reference to the feature associated with the diagram
- @param width out: the width of the diagram image
- @param height out: the height of the diagram image*/
- int getDiagramDimensions(int size, const QgsFeature& f, int& width, int& height) const;
+ @param the render context (contains mm scale factor and raster scale factor)
+ @param width out: the width of the diagram image in pixels
+ @param height out: the height of the diagram image in pixels*/
+ int getDiagramDimensions(int size, const QgsFeature& f, const QgsRenderContext& context, int& width, int& height) const;
bool writeXML(QDomNode& overlay_node, QDomDocument& doc) const {return false;} //later...
More information about the QGIS-commit
mailing list