29 #include <QApplication>    30 #include <QDomDocument>    31 #include <QDomElement>    34 #include <QMessageBox>    68       addGroupFromLayerTree( nodeGroup, groupItem );
    73       if ( nodeLayer->
layer() )
    91     QString infoKey = infoIt->first;
    98       currentGroupItem = 
addGroup( infoKey, i );
   102       for ( ; currentItem && ( groupLayerIt != layerList.
constEnd() ); ++groupLayerIt )
   111         if ( layerList.
contains( layerID ) )
   140     addLayer( currentLayer, scaleDenominator, rule );
   147     text = 
tr( 
"Group" );
   155   if ( position == -1 )
   161   parentItem->
insertRow( position, itemsList );
   171   if ( !layerItem || !lItem || !vlayer )
   193   for ( ; symbolIt != lst.
constEnd(); ++symbolIt )
   206       currentSymbolItem->
setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
   207       if ( symbolIt->second )
   213         currentSymbolItem->
setSymbolV2( symbolIt->second->clone() );
   215       layerItem->
setChild( row, 0, currentSymbolItem );
   218       updateSymbolV2ItemText( currentSymbolItem );
   227       currentSymbolItem->
setSymbolV2( symbolIt->second->clone() );
   228       layerItem->
setChild( row, 0, currentSymbolItem );
   229       currentSymbolItem->
setText( symbolIt->first );
   239     for ( 
int i = layerItem->
rowCount() - 1; i >= row; --i )
   250   if ( !layerItem || !rlayer )
   272     if ( !legendGraphic.
isNull() )
   282       currentSymbolItem->
setText( 
tr( 
"No Legend Available" ) );
   295     for ( ; itemIt != rasterItemList.
constEnd(); ++itemIt )
   309         itemPixmap.
fill( itemIt->second );
   314       QColor itemColor = itemIt->second;
   319       if ( rasterRenderer )
   321         opacity = rasterRenderer->
opacity() * 255.0;
   325       currentSymbolItem->
setColor( itemColor );
   327       int currentRowCount = layerItem->
rowCount();
   328       layerItem->
setChild( currentRowCount, 0, currentSymbolItem );
   333     for ( 
int i = layerItem->
rowCount() - 1; i >= row; --i )
   342 void QgsLegendModel::updateSymbolV2ItemText( 
QStandardItem* symbolItem )
   345   if ( !sv2Item ) 
return;
   348   if ( !lItem ) 
return;
   351   if ( !mapLayer ) 
return;
   354   if ( !vLayer ) 
return;
   357   if ( !renderer ) 
return;
   367   if ( renderer->
type() == 
"singleSymbol" )
   379       label = vLayer->
title();
   383       label = vLayer->
name();
   399 void QgsLegendModel::updateRasterSymbolItemText( 
QStandardItem* symbolItem )
   402   if ( !rItem ) 
return;
   405   if ( !lItem ) 
return;
   408   if ( !mapLayer ) 
return;
   411   if ( !rLayer ) 
return;
   458     updateLayerItemText( lItem );
   465     updateSymbolV2ItemText( sv2Item );
   472     updateRasterSymbolItemText( rItem );
   489       updateLayerItemText( lItem );
   494         addVectorLayerItemsV2( lItem, vLayer );
   500         addRasterLayerItems( lItem, rLayer );
   506 void QgsLegendModel::updateLayerItemText( 
QStandardItem* layerItem )
   509   if ( !lItem ) 
return;
   512   if ( !mapLayer ) 
return;
   519     addVectorLayerItemsV2( lItem, vLayer );
   531   for ( 
int i = 0; i < numRootItems ; ++i )
   539     if ( layerId == lItem->
layerID() )
   567   if ( theMapLayer->
title() != 
"" )
   574   layerItem->
setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
   580   switch ( theMapLayer->
type() )
   587         addVectorLayerItemsV2( layerItem, vl, scaleDenominator, rule );
   592       addRasterLayerItems( layerItem, theMapLayer );
   610   for ( 
int i = 0, n = 
rowCount(); i < n ; ++i )
   613     if ( lItem && layerId == lItem->
layerID() )
   624   if ( composerLegendElem.
isNull() )
   635   for ( 
int i = 0; i < nTopLevelItems; ++i )
   639     if ( currentLegendItem )
   641       currentLegendItem->
writeXML( legendModelElem, doc );
   653   if ( legendModelElem.
isNull() )
   666   int nTopLevelItems =  topLevelItemList.
size();
   667   for ( 
int i = 0; i < nTopLevelItems; ++i )
   669     currentElem = topLevelItemList.
at( i ).
toElement();
   670     if ( currentElem.
isNull() )
   677     if ( currentElem.
tagName() == 
"LayerItem" )
   681     else if ( currentElem.
tagName() == 
"GroupItem" )
   702   return Qt::MoveAction;
   710     flags |= Qt::ItemIsDropEnabled;
   722       flags |= Qt::ItemIsDragEnabled;
   723       flags |= Qt::ItemIsDropEnabled;
   727       flags |= Qt::ItemIsDragEnabled;
   749         flags |= Qt::ItemIsEditable;
   765     for ( 
int i = row + count - 1; i >= row; --i )
   776     for ( 
int i = row + count - 1; i >= row; --i )
   791   QModelIndexList::const_iterator indexIt = indexes.constBegin();
   792   for ( ; indexIt != indexes.constEnd(); ++indexIt )
   800         mItem->
writeXML( xmlRootElement, xmlDoc );
   841   if ( dragDataElem.
tagName() != 
"LegendModelDragData" )
   847   int nChildNodes = nodeList.
size();
   852   for ( 
int i = 0; i < nChildNodes; ++i )
   855     if ( currentElem.
isNull() )
   859     currentTagName = currentElem.
tagName();
   860     if ( currentTagName == 
"LayerItem" )
   864     else if ( currentTagName == 
"GroupItem" )
   872     currentItem->
readXML( currentElem );
   884     dropIntoItem->
insertRow( index, itemsList );
   905       for ( 
int i = 0, n = 
rowCount(); i < n ; ++i )
   926       for ( 
int i = 0, n = 
rowCount(); i < n ; ++i )
 void removeLayer(const QString &layerId)
 
Layer tree group node serves as a container for layers and further groups. 
 
virtual void readXML(const QDomElement &itemElem, bool xServerAvailable=true)=0
Read item content from xml. 
 
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
 
bool showFeatureCount() const
 
Base class for all map layer types. 
 
QByteArray data(const QString &mimeType) const
 
void setIcon(const QIcon &icon)
 
void setLayerID(const QString &id)
 
void updateItemText(QStandardItem *item)
Update single item text using item userText and other properties like showFeatureCount. 
 
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Implements the drop operation. 
 
QStringList mimeTypes() const override
 
virtual QVariant data(const QModelIndex &index, int role) const
 
QDomNode appendChild(const QDomNode &newChild)
 
QStandardItem * invisibleRootItem() const
 
void fill(const QColor &color)
 
QList< QStandardItem * > takeRow(int row)
 
QString attribute(const QString &name, const QString &defValue) const
 
bool mHasTopLevelWindow
True if this application has toplevel windows (normally true). 
 
This class provides qgis with the ability to render raster datasets onto the mapcanvas. 
 
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID. 
 
bool removeRow(int row, const QModelIndex &parent)
 
QStandardItem * addGroup(QString text=QString::null, int position=-1, QStandardItem *parentItem=nullptr)
Adds a group. 
 
bool writeXML(QDomElement &composerLegendElem, QDomDocument &doc) const
 
void updateItem(QStandardItem *item)
Tries to automatically update a model entry (e.g. 
 
void setLayerSetAndGroups(QgsLayerTreeGroup *rootGroup)
Set layers and groups from a layer tree. 
 
Qt::ItemFlags flags(const QModelIndex &index) const override
 
virtual QImage getLegendGraphic(double scale=0, bool forceRefresh=false, const QgsRectangle *visibleExtent=nullptr)
Returns the legend rendered as pixmap. 
 
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
 
virtual bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic. 
 
QDomElement documentElement() const
 
QgsRasterRenderer * renderer() const
 
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
QDomNodeList childNodes() const
 
QgsMapLayer::LayerType type() const
Get the type of the layer. 
 
QString tr(const char *sourceText, const char *disambiguation, int n)
 
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Implemented to support drag operations. 
 
void setLayerID(const QString &id)
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference) 
 
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
 
QDomElement toElement() const
 
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol. 
 
QgsFeatureRendererV2 * rendererV2()
Return renderer V2. 
 
QString number(int n, int base)
 
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
 
void setColumnCount(int columns)
 
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry. 
 
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, const QString &rule="")
return a list of item text / symbol 
 
void setAttribute(const QString &name, const QString &value)
 
QString providerType() const
[ data provider interface ] Which provider is being used for this Raster Layer? 
 
void appendRow(const QList< QStandardItem * > &items)
 
int toInt(bool *ok, int base) const
 
void setFlags(QFlags< Qt::ItemFlag > flags)
 
void setAutoUpdate(bool autoUpdate)
 
QStandardItem * parent() const
 
virtual QString userText() const
 
virtual void writeXML(QDomElement &elem, QDomDocument &doc) const =0
 
This class is a base class for nodes in a layer tree. 
 
Qt::DropActions supportedDropActions() const override
 
void removeRows(int row, int count)
 
void setChild(int row, int column, QStandardItem *item)
 
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent. 
 
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node. 
 
void setSymbolV2(QgsSymbolV2 *s)
Set symbol (takes ownership) 
 
QStandardItem * child(int row, int column) const
 
bool mAutoUpdate
True if the legend is auto updated when layers are added or removed from the map canvas. 
 
Abstract base class for the legend item types. 
 
QStandardItem * item(int row, int column) const
 
QString title() const
Get the title of the layer used by QGIS Server in GetCapabilities request. 
 
bool readXML(const QDomElement &legendModelElem, const QDomDocument &doc)
 
bool contains(const T &value) const
 
bool countSymbolFeatures(bool showProgress=true)
Count features for symbols. 
 
QList< QStandardItem * > takeRow(int row)
 
QgsMapLayer * layer() const
 
void setText(const QString &text)
 
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call. 
 
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
 
QStandardItem * itemFromIndex(const QModelIndex &index) const
 
void addLayer(QgsMapLayer *theMapLayer, double scaleDenominator=-1, const QString &rule="", QStandardItem *parentItem=nullptr)
 
virtual ItemType itemType() const =0
 
virtual int rowCount(const QModelIndex &parent) const
 
void setColor(const QColor &c)
 
QString name
Read property of QString layerName. 
 
void setLayerSet(const QStringList &layerIds, double scaleDenominator=-1, const QString &rule="")
 
QgsRasterDataProvider * dataProvider()
Returns the data provider. 
 
QString name() const override
Get group's name. 
 
void setData(const QString &mimeType, const QByteArray &data)
 
const_iterator constEnd() const
 
QDomElement createElement(const QString &tagName)
 
const_iterator constBegin() const
 
void updateLayer(QStandardItem *layerItem)
Updates the whole symbology of a layer. 
 
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color) 
 
Represents a vector layer which manages a vector based data sets. 
 
void setDefaultStyle(double scaleDenominator=-1, const QString &rule="")
 
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node. 
 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
 
virtual void setUserText(const QString &text)
 
void appendRow(const QList< QStandardItem * > &items)
 
Raster renderer pipe that applies colors to a raster. 
 
QMimeData * mimeData(const QModelIndexList &indexes) const override
For the drag operation. 
 
void insertRow(int row, const QList< QStandardItem * > &items)
 
QByteArray toByteArray(int indent) const
 
Layer tree node points to a map layer. 
 
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
 
QDomNode at(int index) const