33 #include <QDomDocument>    34 #include <QDomElement>    39     , mCustomLayerTree( nullptr )
    40     , mComposerMap( nullptr )
    41     , mLegendFilterByMap( false )
    42     , mFilterOutAtlas( false )
    43     , mFilterAskedForUpdate( false )
    62     , mLegendModel2( 
nullptr )
    63     , mCustomLayerTree( 
nullptr )
    64     , mComposerMap( 
nullptr )
    65     , mLegendFilterByMap( 
false )
    66     , mLegendFilterByExpression( 
false )
    67     , mFilterOutAtlas( 
false )
    68     , mFilterAskedForUpdate( 
false )
    77   delete mCustomLayerTree;
    82   Q_UNUSED( itemStyle );
    93   if ( mFilterAskedForUpdate )
    95     mFilterAskedForUpdate = 
false;
    96     doUpdateFilterByMap();
   100   double dotsPerMM = dpi / 25.4;
   157   if ( mFilterAskedForUpdate )
   159     mFilterAskedForUpdate = 
false;
   160     doUpdateFilterByMap();
   189   delete mCustomLayerTree;
   190   mCustomLayerTree = rootGroup;
   216   return !mCustomLayerTree;
   221   mLegendFilterByMap = enabled;
   351   composerLegendElem.
appendChild( composerLegendStyles );
   359   if ( mCustomLayerTree )
   362     mCustomLayerTree->
writeXML( composerLegendElem );
   365   if ( mLegendFilterByMap )
   367     composerLegendElem.
setAttribute( 
"legendFilterByMap", 
"1" );
   370   return _writeXML( composerLegendElem, doc );
   377   while ( !itemElem.
isNull() )
   380     if ( itemElem.
tagName() == 
"LayerItem" )
   393         if ( showFeatureCount.
toInt() )
   399     else if ( itemElem.
tagName() == 
"GroupItem" )
   427   if ( colCount < 1 ) colCount = 1;
   433   if ( !stylesNodeList.
isEmpty() )
   440       style.
readXML( styleElem, doc );
   472   mLegendFilterByMap = itemElem.
attribute( 
"legendFilterByMap", 
"0" ).
toInt();
   479   if ( !oldLegendModelElem.
isNull() )
   484     setCustomLayerTree( nodeRoot );
   495   if ( !composerItemList.
isEmpty() )
   504   if ( !titleFontString.
isEmpty() )
   510   if ( !groupFontString.
isEmpty() )
   517   if ( !layerFontString.
isEmpty() )
   523   if ( !itemFontString.
isEmpty() )
   549   if ( !
id().isEmpty() )
   558     return tr( 
"<legend>" );
   576     disconnect( mComposerMap, SIGNAL( extentChanged() ), 
this, SLOT( updateFilterByMap() ) );
   577     disconnect( mComposerMap, SIGNAL( layerStyleOverridesChanged() ), 
this, SLOT( mapLayerStyleOverridesChanged() ) );
   586     QObject::connect( map, SIGNAL( extentChanged() ), 
this, SLOT( updateFilterByMap() ) );
   587     QObject::connect( map, SIGNAL( layerStyleOverridesChanged() ), 
this, SLOT( mapLayerStyleOverridesChanged() ) );
   598 void QgsComposerLegend::mapLayerStyleOverridesChanged()
   604   if ( mLegendFilterByMap )
   622 void QgsComposerLegend::updateFilterByMap()
   629   mFilterAskedForUpdate = 
true;
   632 void QgsComposerLegend::doUpdateFilterByMap()
   642   if ( mComposerMap && ( mLegendFilterByMap || filterByExpression || mInAtlas ) )
   659     mLegendModel2->
setLegendFilter( &ms,  mInAtlas || mLegendFilterByMap, filterPolygon,  
true );
   667   mFilterOutAtlas = doFilter;
   672   return mFilterOutAtlas;
   675 void QgsComposerLegend::onAtlasFeature( 
QgsFeature* feat )
   679   mInAtlas = mFilterOutAtlas;
   683 void QgsComposerLegend::onAtlasEnded()
   705     if ( 
QgsLayerTree::isLayer( node ) && ( role == Qt::DisplayRole || role == Qt::EditRole ) && !node->customProperty( 
"legend/title-label" ).isNull() )
   708       QString name = node->customProperty( 
"legend/title-label" ).toString();
   709       if ( nodeLayer->
customProperty( 
"showFeatureCount", 0 ).
toInt() && role == Qt::DisplayRole )
 
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title. 
 
void setWrapChar(const QString &t)
 
Layer tree group node serves as a container for layers and further groups. 
 
QDomNodeList elementsByTagName(const QString &tagname) const
 
void setLegendSize(QSizeF s)
Set the preferred resulting legend size. 
 
QgsComposerLegend(QgsComposition *composition)
 
A rectangle specified with double values. 
 
Base class for all map layer types. 
 
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const 
Returns style. 
 
bool legendFilterOutAtlas() const 
Whether to filter out legend elements outside of the current atlas feature. 
 
void setEqualColumnWidth(bool s)
 
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name. Newly created node is owned by this group. 
 
void setBoxSpace(double s)
 
void setMmPerMapUnit(double mmPerMapUnit)
 
double scale() const 
Return the calculated scale of the map. 
 
void readXML(const QDomElement &elem, const QDomDocument &doc)
 
void setRenderHint(RenderHint hint, bool on)
 
void setDrawRasterBorder(bool enabled)
Sets whether a border will be drawn around raster symbol items. 
 
QgsLayerTreeGroup * rootGroup() const 
Return pointer to the root node of the layer tree. Always a non-null pointer. 
 
QDomNode appendChild(const QDomNode &newChild)
 
double mapUnitsToMM() const 
Returns the conversion factor map units -> mm. 
 
void writeXML(const QString &name, QDomElement &elem, QDomDocument &doc) const 
 
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style. 
 
void setMargin(Side side, double margin)
 
Item model implementation based on layer tree model for composer legend. 
 
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const 
Read a custom property from layer. 
 
QString attribute(const QString &name, const QString &defValue) const
 
static QgsLayerTreeGroup * readXML(QDomElement &element)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on ...
 
QgsMapLayer * layer() const 
 
void setSplitLayer(bool s)
 
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint. 
 
QgsComposerModel * itemsModel()
Returns the items model attached to the composition. 
 
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels. 
 
void itemChanged()
Emitted when the item changes. 
 
void requestedExtent(QgsRectangle &extent) const 
Calculates the extent to request and the yShift of the top-left point in case of rotation. 
 
static QString encodeColor(const QColor &color)
 
const QgsMapSettings & mapSettings() const 
Return setting of QGIS map canvas. 
 
void setSymbolSize(QSizeF s)
 
void drawLegend(QPainter *painter)
Draw the legend with given painter. 
 
void setColumnSpace(double s)
 
A item that forms part of a map composition. 
 
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
 
QDomElement nextSiblingElement(const QString &tagName) const
 
double columnSpace() const 
 
double columnSpace() const 
 
Flags flags() const 
Return OR-ed combination of model flags. 
 
QMap< QString, QString > layerStyleOverrides() const 
Getter for stored overrides of styles for layers. 
 
A geometry is the spatial representation of a feature. 
 
QVariant data(const QModelIndex &index, int role) const override
 
double wmsLegendWidth() const 
 
virtual void drawFrame(QPainter *p)
Draw black frame around item. 
 
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const 
Returns style. 
 
void setTitle(const QString &t)
 
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
 
QColor rasterBorderColor() const 
Returns the border color for the border drawn around raster symbol items. 
 
void setNamedColor(const QString &name)
 
double toDouble(bool *ok) const
 
void updateLegend()
Updates the model and all legend entries. 
 
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
QDomNodeList childNodes() const
 
QString tr(const char *sourceText, const char *disambiguation, int n)
 
bool equalColumnWidth() const 
 
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified. 
 
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
 
void setWmsLegendHeight(double h)
 
Allow check boxes for legend nodes (if supported by layer's legend) 
 
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle &style)
 
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style. 
 
QgsLayerTreeLayer * addLayer(QgsMapLayer *layer)
Append a new layer node for given map layer. Newly created node is owned by this group. 
 
void setHeight(qreal height)
 
void adjustBoxSize()
Sets item box to the whole content. 
 
The QgsMapSettings class contains configuration for rendering of the map. 
 
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document. 
 
QDomElement toElement() const
 
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol. 
 
The QgsLayerTreeModel class is model implementation for Qt item views framework. 
 
double rasterBorderWidth() const 
Returns the border width (in millimeters) for the border drawn around raster symbol items...
 
const char * name() const
 
QString number(int n, int base)
 
void setOutputSize(QSize size)
Set the size of the resulting map image. 
 
void setRasterBorderWidth(double width)
Sets the border width for the border drawn around raster symbol items. 
 
bool fromString(const QString &descrip)
 
int toInt(bool *ok) const
 
void setRasterBorderWidth(double width)
Sets the border width for the border drawn around raster symbol items. 
 
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses. 
 
QColor rasterBorderColor() const 
Returns the border color for the border drawn around raster symbol items. 
 
bool equalColumnWidth() const 
 
void setSymbolHeight(double h)
 
void setLegendFilterOutAtlas(bool doFilter)
When set to true, during an atlas rendering, it will filter out legend elements where features are ou...
 
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items. 
 
int printResolution() const 
 
void setPen(const QColor &color)
 
void setAttribute(const QString &name, const QString &value)
 
void setLegendFilterByMap(const QgsMapSettings *settings)
Force only display of legend nodes which are valid for given map settings. 
 
const QgsComposition * composition() const 
Returns the composition the item is attached to. 
 
int toInt(bool *ok, int base) const
 
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Return legend node for given index. 
 
QList< QgsLayerTreeLayer * > findLayers() const 
Find all layer nodes. Searches recursively the whole sub-tree. 
 
void setMapScale(double scale)
 
void setComposerMap(const QgsComposerMap *map)
 
QPaintDevice * device() const
 
void synchronizeWithModel()
Data changed. 
 
bool drawRasterBorder() const 
Returns whether a border will be drawn around raster symbol items. 
 
void setStyleFont(QgsComposerLegendStyle::Style s, const QFont &f)
Set style font. 
 
void setTitle(const QString &t)
 
Qt::AlignmentFlag titleAlignment() const 
Returns the alignment of the legend title. 
 
This class is a base class for nodes in a layer tree. 
 
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores state in Dom node. 
 
void setDrawRasterBorder(bool enabled)
Sets whether a border will be drawn around raster symbol items. 
 
bool shouldDrawItem() const 
Returns whether the item should be drawn in the current context. 
 
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document. 
 
void setFontColor(const QColor &c)
 
static bool hasLegendFilterExpression(const QgsLayerTreeGroup &group)
Test if one of the layers in a group has an expression filter. 
 
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node. 
 
void setColumnSpace(double s)
 
bool autoUpdateModel() const 
 
void setFlag(Flag f, bool on=true)
Enable or disable a model flag. 
 
virtual void writeXML(QDomElement &parentElement) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element...
 
Graphics scene for map printing. 
 
virtual void updateItem() override
Update() overloading. 
 
QSizeF minimumSize()
Run the layout algorithm and determine the size required for legend. 
 
QFont styleFont(QgsComposerLegendStyle::Style s) const 
 
void setLegendFilterByMapEnabled(bool enabled)
Set whether legend items should be filtered to show just the ones visible in the associated map...
 
Object representing map window. 
 
void setSymbolWidth(double w)
 
QSizeF paintAndDetermineSize(QPainter *painter)
Paints the legend and calculates its size. 
 
void setRasterBorderColor(const QColor &color)
Sets the border color for the border drawn around raster symbol items. 
 
void setRootGroup(QgsLayerTreeGroup *newRootGroup)
Reset the model and use a new root group node. 
 
void invalidateCurrentMap()
Sets mCompositionMap to 0 if the map is deleted. 
 
QgsGeometry currentGeometry(const QgsCoordinateReferenceSystem &projectedTo=QgsCoordinateReferenceSystem()) const 
Returns the current atlas geometry in the given projection system (default to the coverage layer's CR...
 
virtual QString displayName() const override
Get item display name. 
 
void refreshLayerLegend(QgsLayerTreeLayer *nodeLayer)
Force a refresh of legend nodes of a layer node. 
 
double symbolWidth() const 
 
virtual bool isRemoved() const 
Returns whether this item has been removed from the composition. 
 
void setWmsLegendWidth(double w)
 
Qt::AlignmentFlag titleAlignment() const 
Returns the alignment of the legend title. 
 
bool useAdvancedEffects() const 
Returns true if a composition should use advanced effects such as blend modes. 
 
int id() const 
Get identification number. 
 
QgsLegendModelV2(QgsLayerTreeGroup *rootNode, QObject *parent=nullptr)
 
QgsComposition * mComposition
 
Composer legend components style. 
 
void setWmsLegendSize(QSizeF s)
 
void setUseAdvancedEffects(bool use)
 
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call. 
 
bool drawRasterBorder() const 
Returns whether a border will be drawn around raster symbol items. 
 
void setAutoUpdateModel(bool autoUpdate)
 
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const 
Writes parameter that are not subclass specific in document. 
 
void setStyleMargin(QgsComposerLegendStyle::Style s, double margin)
Set style margin. 
 
double rasterBorderWidth() const 
Returns the border width (in millimeters) for the border drawn around raster symbol items...
 
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
 
void setWrapChar(const QString &t)
 
void setWidth(qreal width)
 
virtual void drawBackground(QPainter *p)
Draw background. 
 
void setColumnCount(int c)
 
double wmsLegendHeight() const 
 
static QgsProject * instance()
access to canonical QgsProject instance 
 
QDomElement firstChildElement(const QString &tagName) const
 
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered. 
 
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
 
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
 
void setEqualColumnWidth(bool s)
 
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title. 
 
QString left(int n) const
 
QStringList layers() const 
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
 
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle &style)
 
QgsAtlasComposition & atlasComposition()
 
static QColor decodeColor(const QString &str)
 
void setLayerSet(const QStringList &layerIds, double scaleDenominator=-1, const QString &rule="")
 
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
 
void setColumnCount(int c)
 
QgsComposerItem(QgsComposition *composition, bool manageZValue=true)
Constructor. 
 
QDomElement createElement(const QString &tagName)
 
QSizeF symbolSize() const 
 
QSizeF wmsLegendSize() const 
 
QgsLayerTreeNode * index2node(const QModelIndex &index) const 
Return layer tree node for given index. 
 
void setFontColor(const QColor &c)
 
const QgsComposerMap * getComposerMapById(const int id) const 
Returns the composer map with specified id. 
 
double width() const 
Width of the rectangle. 
 
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
void setLegendFilter(const QgsMapSettings *settings, bool useExtent=true, const QgsGeometry &polygon=QgsGeometry(), bool useExpressions=true)
Filter display of legend nodes for given map settings. 
 
Represents a vector layer which manages a vector based data sets. 
 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
 
const QgsRectangle * currentMapExtent() const 
Returns a pointer to the current map extent, which is either the original user specified extent or th...
 
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, int dpi) const 
Return map settings that would be used for drawing of the map. 
 
void setBoxSpace(double s)
 
Allow reordering with drag'n'drop. 
 
double symbolHeight() const 
 
void destroyed(QObject *obj)
 
static void _readOldLegendGroup(QDomElement &elem, QgsLayerTreeGroup *parentGroup)
 
void setSplitLayer(bool s)
 
void setRasterBorderColor(const QColor &color)
Sets the border color for the border drawn around raster symbol items. 
 
double height() const 
Height of the rectangle. 
 
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the node. 
 
Layer tree node points to a map layer. 
 
The QgsLegendRenderer class handles automatic layout and rendering of legend. 
 
QDomNode at(int index) const
 
void setFont(const QFont &font)
 
QString id() const 
Get item's id (which is not necessarly unique)