2014-08-22 12:22:12 +07:00
|
|
|
|
|
|
|
/** \ingroup MapComposer
|
|
|
|
* Item model implementation based on layer tree model for composer legend.
|
|
|
|
* Overrides some functionality of QgsLayerTreeModel to better fit the needs of composer legend.
|
|
|
|
*
|
|
|
|
* @note added in 2.6
|
|
|
|
*/
|
|
|
|
class QgsLegendModelV2 : QgsLayerTreeModel
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgscomposerlegend.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
QgsLegendModelV2( QgsLayerTreeGroup* rootNode, QObject *parent /TransferThis/ = 0 );
|
|
|
|
|
|
|
|
QVariant data( const QModelIndex& index, int role ) const;
|
|
|
|
|
|
|
|
Qt::ItemFlags flags( const QModelIndex &index ) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-27 13:57:26 +00:00
|
|
|
/** \ingroup MapComposer
|
|
|
|
* A legend that can be placed onto a map composition
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
class QgsComposerLegend : QgsComposerItem
|
2009-02-27 13:57:26 +00:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgscomposerlegend.h>
|
2013-03-26 20:03:59 +01:00
|
|
|
#include <qgscomposerlegendstyle.h>
|
2009-02-27 13:57:26 +00:00
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2009-02-28 14:35:45 +00:00
|
|
|
QgsComposerLegend( QgsComposition* composition /TransferThis/);
|
2009-02-27 13:57:26 +00:00
|
|
|
~QgsComposerLegend();
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Return correct graphics item type. Added in v1.7 */
|
2010-11-25 21:45:52 +00:00
|
|
|
virtual int type() const;
|
|
|
|
|
2009-02-27 13:57:26 +00:00
|
|
|
/** \brief Reimplementation of QCanvasItem::paint*/
|
|
|
|
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Paints the legend and calculates its size. If painter is 0, only size is calculated*/
|
2009-02-27 13:57:26 +00:00
|
|
|
QSizeF paintAndDetermineSize( QPainter* painter );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets item box to the whole content*/
|
2009-02-27 13:57:26 +00:00
|
|
|
void adjustBoxSize();
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns pointer to the legend model*/
|
2014-08-22 12:22:12 +07:00
|
|
|
//! @note deprecated in 2.6 - use modelV2()
|
|
|
|
QgsLegendModel* model() /Deprecated/;
|
|
|
|
|
|
|
|
//! @note added in 2.6
|
|
|
|
QgsLegendModelV2* modelV2();
|
|
|
|
|
|
|
|
//! @note added in 2.6
|
|
|
|
void setAutoUpdateModel( bool autoUpdate );
|
|
|
|
//! @note added in 2.6
|
|
|
|
bool autoUpdateModel() const;
|
2009-02-27 13:57:26 +00:00
|
|
|
|
2014-09-25 12:00:45 +02:00
|
|
|
//! Set whether legend items should be filtered to show just the ones visible in the associated map
|
|
|
|
//! @note added in 2.6
|
|
|
|
void setLegendFilterByMapEnabled( bool enabled );
|
|
|
|
//! Find out whether legend items are filtered to show just the ones visible in the associated map
|
|
|
|
//! @note added in 2.6
|
|
|
|
bool legendFilterByMapEnabled() const;
|
|
|
|
|
2015-06-26 10:12:58 +02:00
|
|
|
//! When set to true, during an atlas rendering, it will filter out legend elements
|
|
|
|
//! where features are outside the current atlas feature.
|
|
|
|
//! @note added in 2.14
|
|
|
|
void setLegendFilterOutAtlas( bool doFilter );
|
|
|
|
|
|
|
|
//! Whether to filter out legend elements outside of the current atlas feature
|
|
|
|
//! @see setLegendFilterOutAtlas()
|
|
|
|
//! @note added in 2.14
|
|
|
|
bool legendFilterOutAtlas() const;
|
|
|
|
|
2009-02-27 13:57:26 +00:00
|
|
|
//setters and getters
|
|
|
|
void setTitle( const QString& t );
|
|
|
|
QString title() const;
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the alignment of the legend title
|
2014-04-07 13:55:44 +02:00
|
|
|
* @returns Qt::AlignmentFlag for the legend title
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setTitleAlignment
|
|
|
|
*/
|
|
|
|
Qt::AlignmentFlag titleAlignment() const;
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets the alignment of the legend title
|
2014-04-07 13:55:44 +02:00
|
|
|
* @param alignment Text alignment for drawing the legend title
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see titleAlignment
|
|
|
|
*/
|
|
|
|
void setTitleAlignment( Qt::AlignmentFlag alignment );
|
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
/** Returns reference to modifiable style */
|
|
|
|
QgsComposerLegendStyle & rstyle( QgsComposerLegendStyle::Style s );
|
|
|
|
/** Returns style */
|
|
|
|
QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const;
|
2015-10-07 11:55:34 +11:00
|
|
|
void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle& style );
|
2013-06-23 16:00:16 +02:00
|
|
|
|
2013-03-26 20:03:59 +01:00
|
|
|
QFont styleFont( QgsComposerLegendStyle::Style s ) const;
|
2013-06-23 16:00:16 +02:00
|
|
|
/** Set style font */
|
2013-03-26 20:03:59 +01:00
|
|
|
void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );
|
2013-06-23 16:00:16 +02:00
|
|
|
|
|
|
|
/** Set style margin*/
|
2013-03-26 20:03:59 +01:00
|
|
|
void setStyleMargin( QgsComposerLegendStyle::Style s, double margin );
|
|
|
|
void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin );
|
2009-02-27 13:57:26 +00:00
|
|
|
|
|
|
|
double boxSpace() const;
|
|
|
|
void setBoxSpace( double s );
|
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
double columnSpace() const;
|
|
|
|
void setColumnSpace( double s );
|
|
|
|
|
|
|
|
QColor fontColor() const;
|
|
|
|
void setFontColor( const QColor& c );
|
|
|
|
|
2009-02-27 13:57:26 +00:00
|
|
|
double symbolWidth() const;
|
|
|
|
void setSymbolWidth( double w );
|
|
|
|
|
|
|
|
double symbolHeight() const;
|
|
|
|
void setSymbolHeight( double h );
|
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
double wmsLegendWidth() const;
|
|
|
|
void setWmsLegendWidth( double w );
|
|
|
|
|
|
|
|
double wmsLegendHeight() const;
|
|
|
|
void setWmsLegendHeight( double h );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
void setWrapChar( const QString& t );
|
|
|
|
QString wrapChar() const;
|
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
int columnCount() const;
|
|
|
|
void setColumnCount( int c );
|
|
|
|
|
|
|
|
int splitLayer() const;
|
|
|
|
void setSplitLayer( bool s );
|
|
|
|
|
|
|
|
int equalColumnWidth() const;
|
|
|
|
void setEqualColumnWidth( bool s );
|
|
|
|
|
2015-10-08 23:14:18 +11:00
|
|
|
/** Returns whether a border will be drawn around raster symbol items.
|
|
|
|
* @see setDrawRasterBorder()
|
|
|
|
* @see rasterBorderColor()
|
|
|
|
* @see rasterBorderWidth()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
bool drawRasterBorder() const;
|
|
|
|
|
|
|
|
/** Sets whether a border will be drawn around raster symbol items.
|
|
|
|
* @param enabled set to true to draw borders
|
|
|
|
* @see drawRasterBorder()
|
|
|
|
* @see setRasterBorderColor()
|
|
|
|
* @see setRasterBorderWidth()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setDrawRasterBorder( bool enabled );
|
|
|
|
|
|
|
|
/** Returns the border color for the border drawn around raster symbol items. The border is
|
|
|
|
* only drawn if drawRasterBorder() is true.
|
|
|
|
* @see setRasterBorderColor()
|
|
|
|
* @see drawRasterBorder()
|
|
|
|
* @see rasterBorderWidth()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QColor rasterBorderColor() const;
|
|
|
|
|
|
|
|
/** Sets the border color for the border drawn around raster symbol items. The border is
|
|
|
|
* only drawn if drawRasterBorder() is true.
|
|
|
|
* @param color border color
|
|
|
|
* @see rasterBorderColor()
|
|
|
|
* @see setDrawRasterBorder()
|
|
|
|
* @see setRasterBorderWidth()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setRasterBorderColor( const QColor& color );
|
|
|
|
|
|
|
|
/** Returns the border width (in millimeters) for the border drawn around raster symbol items. The border is
|
|
|
|
* only drawn if drawRasterBorder() is true.
|
|
|
|
* @see setRasterBorderWidth()
|
|
|
|
* @see drawRasterBorder()
|
|
|
|
* @see rasterBorderColor()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
double rasterBorderWidth() const;
|
|
|
|
|
|
|
|
/** Sets the border width for the border drawn around raster symbol items. The border is
|
|
|
|
* only drawn if drawRasterBorder() is true.
|
|
|
|
* @param width border width in millimeters
|
|
|
|
* @see rasterBorderWidth()
|
|
|
|
* @see setDrawRasterBorder()
|
|
|
|
* @see setRasterBorderColor()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setRasterBorderWidth( double width );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
void setComposerMap( const QgsComposerMap* map );
|
|
|
|
const QgsComposerMap* composerMap() const;
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Updates the model and all legend entries*/
|
2009-02-27 13:57:26 +00:00
|
|
|
void updateLegend();
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Stores state in Dom node
|
2009-02-27 13:57:26 +00:00
|
|
|
* @param elem is Dom element corresponding to 'Composer' tag
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param doc Dom document
|
2009-02-27 13:57:26 +00:00
|
|
|
*/
|
|
|
|
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets state from Dom document
|
2009-02-27 13:57:26 +00:00
|
|
|
* @param itemElem is Dom node corresponding to item tag
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param doc is Dom document
|
2009-02-27 13:57:26 +00:00
|
|
|
*/
|
|
|
|
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
|
|
|
|
|
|
|
|
public slots:
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Data changed*/
|
2009-02-27 13:57:26 +00:00
|
|
|
void synchronizeWithModel();
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets mCompositionMap to 0 if the map is deleted*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void invalidateCurrentMap();
|
2009-02-28 14:35:45 +00:00
|
|
|
};
|