Expand Up
@@ -19,6 +19,7 @@
#define QGSCOMPOSERLEGEND_H
#include " qgscomposeritem.h"
#include " qgscomposerlegenditem.h"
#include " qgslegendmodel.h"
class QgsSymbol ;
Expand All
@@ -35,6 +36,7 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
Q_OBJECT
public:
QgsComposerLegend ( QgsComposition* composition );
~QgsComposerLegend ();
Expand All
@@ -47,6 +49,7 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
/* *Paints the legend and calculates its size. If painter is 0, only size is calculated*/
QSizeF paintAndDetermineSize ( QPainter* painter );
/* *Sets item box to the whole content*/
void adjustBoxSize ();
Expand All
@@ -70,31 +73,34 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
void setItemFont ( const QFont& f );
double boxSpace () const {return mBoxSpace ;}
void setBoxSpace ( double s ) {mBoxSpace = s;}
void setBoxSpace ( double s ) {mBoxSpace = s; mColumns . clear (); }
double groupSpace () const {return mGroupSpace ;}
void setGroupSpace ( double s ) {mGroupSpace = s;}
void setGroupSpace ( double s ) {mGroupSpace = s;mColumns . clear (); }
double layerSpace () const {return mLayerSpace ;}
void setLayerSpace ( double s ) {mLayerSpace = s;}
void setLayerSpace ( double s ) {mLayerSpace = s;mColumns . clear (); }
double symbolSpace () const {return mSymbolSpace ;}
void setSymbolSpace ( double s ) {mSymbolSpace = s;}
void setSymbolSpace ( double s ) {mSymbolSpace = s;mColumns . clear (); }
double iconLabelSpace () const {return mIconLabelSpace ;}
void setIconLabelSpace ( double s ) {mIconLabelSpace = s;}
void setIconLabelSpace ( double s ) {mIconLabelSpace = s;mColumns . clear (); }
double symbolWidth () const {return mSymbolWidth ;}
void setSymbolWidth ( double w ) {mSymbolWidth = w;}
void setSymbolWidth ( double w ) {mSymbolWidth = w;mColumns . clear (); }
double symbolHeight () const {return mSymbolHeight ;}
void setSymbolHeight ( double h ) {mSymbolHeight = h;}
void setSymbolHeight ( double h ) {mSymbolHeight = h;mColumns . clear (); }
void setWrapChar ( const QString& t ) {mWrapChar = t;}
void setWrapChar ( const QString& t ) {mWrapChar = t;mColumns . clear (); }
QString wrapChar () const {return mWrapChar ;}
int columnCount () const { return mColumnCount ; }
void setColumnCount ( int c ) { mColumnCount = c;mColumns .clear ();}
void setComposerMap ( const QgsComposerMap* map );
const QgsComposerMap* composerMap () const { return mComposerMap ; }
const QgsComposerMap* composerMap () const { return mComposerMap ;}
/* *Updates the model and all legend entries*/
void updateLegend ();
Expand Down
Expand Up
@@ -145,28 +151,71 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
/* * Spacing between lines when wrapped */
double mlineSpacing;
/* * Number of legend columns */
int mColumnCount ;
/* * Cached division of items to columns */
QMap<QStandardItem *, int > mColumns ;
QgsLegendModel mLegendModel ;
/* *Reference to map (because symbols are sometimes in map units)*/
const QgsComposerMap* mComposerMap ;
private:
// Group or layer size
struct Size
{
QSizeF size;
// bool isLayer; // layer or group
QgsComposerLegendItem::ItemType type;
QStandardItem * item;
Size () {}
Size ( QSizeF s, QgsComposerLegendItem::ItemType t, QStandardItem * i ): size( s ), type( t ), item( i ) {}
} ;
struct LegendSize
{
QSizeF size; // legend size
QList<Size > sizes; // layer / group sizes
LegendSize () {}
LegendSize ( QSizeF s, QList<Size >ls ): size( s ), sizes( ls ) {}
};
class Position
{
public:
QSizeF titleSize; // without spaces around
QPointF point; // current position
double columnTop; // y coord where columns start (mBoxSpace + title height)
int column;
QMap<QStandardItem *, int > columns;
// widths of columns, does not include spaces before/between/after columns
QVector<double > widths;
double maxColumnHeight;
// set max width for current column
void expandWidth ( double w );
// set column and x position
void setColumn ( QStandardItem *item );
double boxSpace;
double columnSpace; // space between columns
};
QgsComposerLegend (); // forbidden
/* *Draws a group item and all subitems*/
void drawGroupItem ( QPainter* p, QgsComposerGroupItem* groupItem, double & currentYCoord, double & maxXCoord );
/* *Draws a group item and all subitems
* Returns list of sizes of layers and groups including this group.
*/
QList<Size > drawGroupItem ( QPainter* p, QgsComposerGroupItem* groupItem, Position& currentPosition );
/* *Draws a layer item and all subitems*/
void drawLayerItem ( QPainter* p, QgsComposerLayerItem* layerItem, double & currentYCoord, double & maxXCoord );
Size drawLayerItem ( QPainter* p, QgsComposerLayerItem* layerItem, Position& currentPosition );
/* *Draws child items of a layer item
@param p painter
@param layerItem parent model item (layer)
@param currentYCoord in/out: current y position of legend item
@param currentPosition in/out: current y position of legend item
@param maxXCoord in/out: maximum x-coordinate of the whole legend
@param layerOpacity opacity of the corresponding map layer
*/
void drawLayerChildItems ( QPainter* p, QStandardItem* layerItem, double & currentYCoord, double & maxXCoord , int layerOpacity = 255 );
QSizeF drawLayerChildItems ( QPainter* p, QStandardItem* layerItem, Position& currentPosition , int layerOpacity = 255 );
/* *Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points,
it is possible that it differs from mSymbolHeight*/
Expand All
@@ -176,6 +225,8 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
void drawLineSymbol ( QPainter*, QgsSymbol* s, double currentYCoord, double & currentXPosition, int opacity = 255 ) const ;
void drawPolygonSymbol ( QPainter* p, QgsSymbol* s, double currentYCoord, double & currentXPosition, int opacity = 255 ) const ;
LegendSize paintAndDetermineSize ( QPainter* painter, QMap<QStandardItem *, int > columns );
/* *Helper function that lists ids of layers contained in map canvas*/
QStringList layerIdList () const ;
Expand Down