Skip to content
Permalink
Browse files

[FEATURE] Add diagram system that uses the same pal instance as label…

…ing-ng

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15503 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Mar 15, 2011
1 parent f2d40a7 commit 15d3812fa147ec3c0a6a3de5eef07a7703291a22
Showing with 2,371 additions and 77 deletions.
  1. +160 −0 python/core/qgsdiagramrendererv2.sip
  2. +1 −0 src/analysis/interpolation/qgsinterpolator.cpp
  3. +5 −2 src/app/qgisapp.cpp
  4. +1 −0 src/app/qgslabelpropertydialog.cpp
  5. +33 −2 src/app/qgsmaptoollabel.cpp
  6. +7 −2 src/app/qgsmaptoollabel.h
  7. +2 −2 src/app/qgsmaptoolmovelabel.cpp
  8. +372 −0 src/app/qgsvectorlayerproperties.cpp
  9. +15 −0 src/app/qgsvectorlayerproperties.h
  10. +2 −0 src/core/CMakeLists.txt
  11. +283 −0 src/core/qgsdiagram.cpp
  12. +74 −0 src/core/qgsdiagram.h
  13. +342 −0 src/core/qgsdiagramrendererv2.cpp
  14. +219 −0 src/core/qgsdiagramrendererv2.h
  15. +2 −2 src/core/qgslabelsearchtree.cpp
  16. +1 −1 src/core/qgslabelsearchtree.h
  17. +10 −3 src/core/qgsmaprenderer.h
  18. +157 −10 src/core/qgspallabeling.cpp
  19. +10 −1 src/core/qgspallabeling.h
  20. +1 −0 src/core/qgsrendercontext.h
  21. +6 −1 src/core/qgsvectordataprovider.h
  22. +118 −40 src/core/qgsvectorlayer.cpp
  23. +21 −1 src/core/qgsvectorlayer.h
  24. +1 −0 src/gui/qgsmaptip.cpp
  25. +2 −2 src/plugins/CMakeLists.txt
  26. +1 −0 src/plugins/grass/qgsgrassedittools.cpp
  27. +0 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  28. +1 −0 src/providers/delimitedtext/qgsdelimitedtextprovider.h
  29. +1 −0 src/providers/grass/qgsgrassprovider.h
  30. +1 −0 src/providers/memory/qgsmemoryprovider.h
  31. +1 −0 src/providers/osm/osmprovider.cpp
  32. +1 −0 src/providers/osm/osmprovider.h
  33. +1 −0 src/providers/postgres/qgspostgresprovider.cpp
  34. +1 −0 src/providers/sqlanywhere/qgssqlanywhereprovider.h
  35. +518 −7 src/ui/qgsvectorlayerpropertiesbase.ui
@@ -0,0 +1,160 @@
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)

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

//diagram settings for rendering
struct QgsDiagramSettings
{
%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;
};

/**Returns diagram settings for a feature*/
class QgsDiagramRendererV2
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
%End
public:

QgsDiagramRendererV2();
virtual ~QgsDiagramRendererV2();

/**Returns size of the diagram for feature f in map units. Returns an invalid QSizeF in case of error*/
virtual QSizeF sizeMapUnits( const QgsAttributeMap& attributes, const QgsRenderContext& c );

virtual QString rendererName() const = 0;

/**Returns attribute indices needed for diagram rendering*/
virtual QList<int> diagramAttributes() const = 0;

void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QPointF& pos );

void setDiagram( QgsDiagram* d );
const QgsDiagram* diagram() const;

/**Returns list with all diagram settings in the renderer*/
virtual QList<QgsDiagramSettings> diagramSettings() const = 0;

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

/**Renders the diagrams for all features with the same settings*/
class QgsSingleCategoryDiagramRenderer: QgsDiagramRendererV2
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
%End
public:
QgsSingleCategoryDiagramRenderer();
~QgsSingleCategoryDiagramRenderer();

QString rendererName() const;

QList<int> diagramAttributes() const;

void setDiagramSettings( const QgsDiagramSettings& s );

QList<QgsDiagramSettings> diagramSettings() const;

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

class QgsLinearlyInterpolatedDiagramRenderer: QgsDiagramRendererV2
{
%TypeHeaderCode
#include <qgsdiagramrendererv2.h>
%End
public:
QgsLinearlyInterpolatedDiagramRenderer();
~QgsLinearlyInterpolatedDiagramRenderer();

/**Returns list with all diagram settings in the renderer*/
QList<QgsDiagramSettings> diagramSettings() const;

void setDiagramSettings( const QgsDiagramSettings& s );

QList<int> diagramAttributes() const;

QString rendererName() const;

void setLowerValue( double val );
double lowerValue() const;

void setUpperValue( double val );
double upperValue() const;

void setLowerSize( QSizeF s );
QSizeF lowerSize() const;

void setUpperSize( QSizeF s );
QSizeF upperSize() const;

int classificationAttribute() const;
void setClassificationAttribute( int index );

void readXML( const QDomElement& elem );
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
};
@@ -17,6 +17,7 @@

#include "qgsinterpolator.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsgeometry.h"

QgsInterpolator::QgsInterpolator( const QList<LayerData>& layerData ): mDataIsCached( false ), mLayerData( layerData )
@@ -5663,14 +5663,17 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( it.value() );
if ( !vlayer || !vlayer->isEditable() || vlayer->customProperty( "labeling" ).toString() != QString( "pal" ) )
if ( !vlayer || !vlayer->isEditable() ||
( !vlayer->diagramRenderer() && vlayer->customProperty( "labeling" ).toString() != QString( "pal" ) ) )
continue;

int colX, colY, colAng;
enableMove =
enableMove ||
( qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel ) &&
qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel )->layerIsMoveable( vlayer, colX, colY ) );
( qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel )->labelMoveable( vlayer, colX, colY )
|| qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel )->diagramMoveable( vlayer, colX, colY ) )
);

enableRotate =
enableRotate ||
@@ -18,6 +18,7 @@
#include "qgslabelpropertydialog.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgsvectorlayer.h"
#include <QColorDialog>
#include <QFontDialog>

@@ -280,6 +280,14 @@ bool QgsMapToolLabel::rotationPoint( QgsPoint& pos )
pos = mCurrentLabelPos.cornerPoints.at( 0 );
}

//alignment always center/center and rotation 0 for diagrams
if ( mCurrentLabelPos.isDiagram )
{
pos.setX( pos.x() + mCurrentLabelPos.labelRect.width() / 2.0 );
pos.setY( pos.y() + mCurrentLabelPos.labelRect.height() / 2.0 );
return true;
}

//adapt pos depending on data defined alignment
QString haliString, valiString;
currentAlignment( haliString, valiString );
@@ -356,7 +364,14 @@ bool QgsMapToolLabel::dataDefinedPosition( QgsVectorLayer* vlayer, int featureId
return false;
}

if ( !layerIsMoveable( vlayer, xCol, yCol ) )
if ( mCurrentLabelPos.isDiagram )
{
if ( !diagramMoveable( vlayer, xCol, yCol ) )
{
return false;
}
}
else if ( !labelMoveable( vlayer, xCol, yCol ) )
{
return false;
}
@@ -374,7 +389,23 @@ bool QgsMapToolLabel::dataDefinedPosition( QgsVectorLayer* vlayer, int featureId
return true;
}

bool QgsMapToolLabel::layerIsMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const
bool QgsMapToolLabel:: diagramMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const
{
const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>( ml );
if ( vlayer && vlayer->diagramRenderer() )
{
QgsDiagramLayerSettings dls = vlayer->diagramLayerSettings();
if ( dls.xPosColumn >= 0 && dls.yPosColumn >= 0 )
{
xCol = dls.xPosColumn;
yCol = dls.yPosColumn;
return true;
}
}
return false;
}

bool QgsMapToolLabel::labelMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const
{
const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>( ml );
if ( !vlayer || !vlayer->isEditable() )
@@ -31,11 +31,16 @@ class QgsMapToolLabel: public QgsMapTool
QgsMapToolLabel( QgsMapCanvas* canvas );
~QgsMapToolLabel();

/**Returns true if layer move can be applied to a layer
/**Returns true if label move can be applied to a layer
@param xCol out: index of the attribute for data defined x coordinate
@param yCol out: index of the attribute for data defined y coordinate
@return true if labels of layer can be moved*/
bool layerIsMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const;
bool labelMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const;
/**Returns true if diagram move can be applied to a layer
@param xCol out: index of the attribute for data defined x coordinate
@param yCol out: index of the attribute for data defined y coordinate
@return true if labels of layer can be moved*/
bool diagramMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const;

protected:
QgsRubberBand* mLabelRubberBand;
@@ -40,13 +40,13 @@ void QgsMapToolMoveLabel::canvasPressEvent( QMouseEvent * e )
}

QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( mCurrentLabelPos.layerID );
if ( !layer )
if ( !layer || !layer->isEditable() )
{
return;
}

int xCol, yCol;
if ( layerIsMoveable( layer, xCol, yCol ) )
if ( labelMoveable( layer, xCol, yCol ) || diagramMoveable( layer, xCol, yCol ) )
{
mStartPointMapCoords = toMapCoordinates( e->pos() );
mClickOffsetX = mStartPointMapCoords.x() - mCurrentLabelPos.labelRect.xMinimum();

0 comments on commit 15d3812

Please sign in to comment.
You can’t perform that action at this time.