190 changes: 132 additions & 58 deletions python/core/qgsdiagramrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,108 @@ struct QgsDiagramLayerSettings
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
%End
//avoid inclusion of QgsPalLabeling
enum Placement
{
AroundPoint, // Point / Polygon
OverPoint, // Point / Polygon
Line, // Line / Polygon
Curved, // Line
Horizontal, // Polygon
Free // Polygon
};

enum LinePlacementFlags
{
OnLine = 1,
AboveLine = 2,
BelowLine = 4,
MapOrientation = 8
};

QgsDiagramLayerSettings();

//pal placement properties
Placement placement;
LinePlacementFlags placementFlags;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
double dist; // distance from the feature (in mm)
QgsDiagramRendererV2* renderer;
int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)

//avoid inclusion of QgsPalLabeling
enum Placement
{
AroundPoint, // Point / Polygon
OverPoint, // Point / Polygon
Line, // Line / Polygon
Curved, // Line
Horizontal, // Polygon
Free // Polygon
};

enum LinePlacementFlags
{
OnLine = 1,
AboveLine = 2,
BelowLine = 4,
MapOrientation = 8
};

QgsDiagramLayerSettings();

//pal placement properties
Placement placement;
LinePlacementFlags placementFlags;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
double dist; // distance from the feature (in mm)
QgsDiagramRendererV2* renderer;
int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)

void readXML( const QDomElement& elem );
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
void readXML( const QDomElement& elem );
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
};

//diagram settings for rendering
struct QgsDiagramSettings
class QgsDiagramSettings
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
%End
public:
enum SizeType
{
MM,
MapUnits
};

enum LabelPlacementMethod
{
Height,
XHeight
};

//! Orientation of histogram
enum DiagramOrientation
{
Up,
Down,
Left,
Right
};

QgsDiagramSettings();
QFont font;
QList< QColor > categoryColors;
QList< int > categoryIndices;
QSizeF size; //size
SizeType sizeType; //mm or map units
QColor backgroundColor;
QColor penColor;
double penWidth;
LabelPlacementMethod labelPlacementMethod;
DiagramOrientation diagramOrientation;
double barWidth;
int transparency; // 0 - 100
bool scaleByArea;

//scale range (-1 if no lower / upper bound )
double minScaleDenominator;
double maxScaleDenominator;

//! Scale diagrams smaller than mMinimumSize to mMinimumSize
double minimumSize;

void readXML( const QDomElement& elem );
void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
};

//additional diagram settings for interpolated size rendering
class QgsDiagramInterpolationSettings
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
%End
enum SizeType
{
MM,
MapUnits
};

QgsDiagramSettings();
QFont font;
QList< QColor > categoryColors;
QList< int > categoryIndices;
QSizeF size; //size
SizeType sizeType; //mm or map units
QColor backgroundColor;
QColor penColor;
double penWidth;

//scale range (-1 if no lower / upper bound )
double minScaleDenominator;
double maxScaleDenominator;

void readXML( const QDomElement& elem );
void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
public:
QSizeF lowerSize;
QSizeF upperSize;
double lowerValue;
double upperValue;
/**Index of the classification attribute*/
int classificationAttribute;
};

/**Returns diagram settings for a feature*/
Expand Down Expand Up @@ -98,10 +136,36 @@ class QgsDiagramRendererV2

virtual void readXML( const QDomElement& elem ) = 0;
virtual void writeXML( QDomElement& layerElem, QDomDocument& doc ) const = 0;


protected:

/**Returns diagram settings for a feature (or false if the diagram for the feature is not to be rendered). Used internally within renderDiagram()
* @param att attribute map
* @param c render context
* @param s out: diagram settings for the feature
*/
virtual bool diagramSettings( const QgsAttributeMap& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;

/**Returns size of the diagram (in painter units) or an invalid size in case of error*/
virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) = 0;

/**Converts size from mm to map units*/
void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;

/**Returns the paint device dpi (or -1 in case of error*/
static int dpiPaintDevice( const QPainter* );

//read / write diagram
void _readXML( const QDomElement& elem );
void _writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;

/**Reference to the object that does the real diagram rendering*/
QgsDiagram* mDiagram;
};

/**Renders the diagrams for all features with the same settings*/
class QgsSingleCategoryDiagramRenderer: QgsDiagramRendererV2
class QgsSingleCategoryDiagramRenderer : QgsDiagramRendererV2
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
Expand All @@ -120,9 +184,14 @@ class QgsSingleCategoryDiagramRenderer: QgsDiagramRendererV2

void readXML( const QDomElement& elem );
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;

protected:
bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );

QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
};

class QgsLinearlyInterpolatedDiagramRenderer: QgsDiagramRendererV2
class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRendererV2
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
Expand Down Expand Up @@ -157,4 +226,9 @@ class QgsLinearlyInterpolatedDiagramRenderer: QgsDiagramRendererV2

void readXML( const QDomElement& elem );
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;

protected:
bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );

QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
};
75 changes: 38 additions & 37 deletions src/app/legend/qgsapplegendinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ void QgsAppLegendInterface::updateIndex( QModelIndex oldIndex, QModelIndex newIn

void QgsAppLegendInterface::setGroupExpanded( int groupIndex, bool expand )
{
QTreeWidgetItem * item = getItem (groupIndex);
if ( !item )
{
return;
}
QTreeWidgetItem * item = getItem( groupIndex );
if ( !item )
{
return;
}

item->setExpanded(expand);
item->setExpanded( expand );
}

void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
Expand All @@ -82,29 +82,30 @@ void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
return;
}

Qt::CheckState state = visible ? Qt::Checked : Qt::Unchecked;
getItem (groupIndex)->setCheckState( 0, state );
Qt::CheckState state = visible ? Qt::Checked : Qt::Unchecked;
getItem( groupIndex )->setCheckState( 0, state );
}

QTreeWidgetItem *QgsAppLegendInterface::getItem(int itemIndex)
QTreeWidgetItem *QgsAppLegendInterface::getItem( int itemIndex )
{
int itemCount = 0;
for (QTreeWidgetItem* theItem = mLegend->firstItem(); theItem; theItem = mLegend->nextItem( theItem ) )
{
QgsLegendItem* legendItem = dynamic_cast<QgsLegendItem *>( theItem );
if (legendItem->type() == QgsLegendItem::LEGEND_GROUP) {
if (itemCount == itemIndex)
{
return theItem;
}
else
{
itemCount = itemCount + 1;
}
}
}
int itemCount = 0;
for ( QTreeWidgetItem* theItem = mLegend->firstItem(); theItem; theItem = mLegend->nextItem( theItem ) )
{
QgsLegendItem* legendItem = dynamic_cast<QgsLegendItem *>( theItem );
if ( legendItem->type() == QgsLegendItem::LEGEND_GROUP )
{
if ( itemCount == itemIndex )
{
return theItem;
}
else
{
itemCount = itemCount + 1;
}
}
}

return NULL;
return NULL;
}

void QgsAppLegendInterface::setLayerVisible( QgsMapLayer * ml, bool visible )
Expand All @@ -128,24 +129,24 @@ QList< GroupLayerInfo > QgsAppLegendInterface::groupLayerRelationship()

bool QgsAppLegendInterface::groupExists( int groupIndex )
{
QTreeWidgetItem * item = getItem (groupIndex);
QgsLegendItem* legendItem = dynamic_cast<QgsLegendItem *>( item );
QTreeWidgetItem * item = getItem( groupIndex );
QgsLegendItem* legendItem = dynamic_cast<QgsLegendItem *>( item );

if ( !legendItem )
{
return false;
}
if ( !legendItem )
{
return false;
}

return legendItem->type() == QgsLegendItem::LEGEND_GROUP;
return legendItem->type() == QgsLegendItem::LEGEND_GROUP;
}

bool QgsAppLegendInterface::isGroupExpanded( int groupIndex )
{
QTreeWidgetItem * item = getItem (groupIndex);
if ( !item )
{
return false;
}
QTreeWidgetItem * item = getItem( groupIndex );
if ( !item )
{
return false;
}

return item->isExpanded();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgsapplegendinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class QgsAppLegendInterface : public QgsLegendInterface

//! Pointer to QgsLegend object
QgsLegend *mLegend;
QTreeWidgetItem *getItem(int itemIndex);
QTreeWidgetItem *getItem( int itemIndex );
};

#endif //QGSLEGENDAPPIFACE_H
9 changes: 7 additions & 2 deletions src/core/qgscoordinatereferencesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ typedef struct sqlite3 sqlite3;
//qgis includes
#include "qgis.h"

#ifdef DEBUG
typedef struct OGRSpatialReferenceHS *OGRSpatialReferenceH;
#else
typedef void *OGRSpatialReferenceH;
#endif

class QgsCoordinateReferenceSystem;
typedef void ( *CUSTOM_CRS_VALIDATION )( QgsCoordinateReferenceSystem* );


/** \ingroup core
* Class for storing a coordinate reference system (CRS)
*/
Expand Down Expand Up @@ -472,7 +477,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
//! Helper for sql-safe value quoting
static QString quotedValue( QString value );

void *mCRS;
OGRSpatialReferenceH mCRS;

bool loadFromDb( QString db, QString expression, QString value );

Expand Down
Loading