QgsLegendModel Class Reference

A model that provides group, layer and classification items. More...

#include <qgslegendmodel.h>

List of all members.

Public Types

enum  ItemType { GroupItem = 0, LayerItem, ClassificationItem }

Public Slots

void removeLayer (const QString &layerId)
void addLayer (QgsMapLayer *theMapLayer)


void layersChanged ()

Public Member Functions

 QgsLegendModel ()
 ~QgsLegendModel ()
void setLayerSetAndGroups (const QStringList &layerIds, const QList< GroupLayerInfo > &groupInfo)
 Sets layer set and groups.
void setLayerSet (const QStringList &layerIds)
QStandardItem * addGroup (QString text=tr("Group"), int position=-1)
 Adds a group to a toplevel position (or -1 if it should be placed at the end of the legend).
void updateItem (QStandardItem *item)
 Tries to automatically update a model entry (e.g.
void updateLayer (QStandardItem *layerItem)
 Updates the whole symbology of a layer.
void updateVectorClassificationItem (QStandardItem *classificationItem, QgsSymbol *symbol, QString itemText)
 Tries to update a single classification item.
void updateVectorV2ClassificationItem (QStandardItem *classificationItem, QgsSymbolV2 *symbol, QString itemText)
void updateRasterClassificationItem (QStandardItem *classificationItem)
bool writeXML (QDomElement &composerLegendElem, QDomDocument &doc) const
bool readXML (const QDomElement &legendModelElem, const QDomDocument &doc)
Qt::DropActions supportedDropActions () const
Qt::ItemFlags flags (const QModelIndex &index) const
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Implemented to support drag operations.
QMimeData * mimeData (const QModelIndexList &indexes) const
 For the drag operation.
QStringList mimeTypes () const
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Implements the drop operation.

Protected Attributes

QStringList mLayerIds
bool mHasTopLevelWindow
 True if this application has toplevel windows (normally true).

Private Member Functions

int addVectorLayerItems (QStandardItem *layerItem, QgsVectorLayer *vlayer)
 Adds classification items of vector layers.
int addVectorLayerItemsV2 (QStandardItem *layerItem, QgsVectorLayer *vlayer)
 Adds classification items of vector layers using new symbology.
int addRasterLayerItem (QStandardItem *layerItem, QgsMapLayer *rlayer)
 Adds item of raster layer.
QStandardItem * itemFromSymbol (QgsSymbol *s, int opacity, const QString &layerID)
 Creates a model item for a vector symbol.

Detailed Description

A model that provides group, layer and classification items.

Definition at line 40 of file qgslegendmodel.h.

Member Enumeration Documentation


Definition at line 46 of file qgslegendmodel.h.

Constructor & Destructor Documentation

QgsLegendModel::QgsLegendModel (  ) 

QgsLegendModel::~QgsLegendModel (  ) 

Definition at line 49 of file qgslegendmodel.cpp.

Member Function Documentation

void QgsLegendModel::setLayerSetAndGroups ( const QStringList &  layerIds,
const QList< GroupLayerInfo > &  groupInfo 

Sets layer set and groups.

Definition at line 53 of file qgslegendmodel.cpp.

References addGroup(), QgsComposerLayerItem::layerID(), and setLayerSet().

void QgsLegendModel::setLayerSet ( const QStringList &  layerIds  ) 

QStandardItem * QgsLegendModel::addGroup ( QString  text = tr( "Group" ),
int  position = -1 

Adds a group to a toplevel position (or -1 if it should be placed at the end of the legend).

Returns a pointer to the added group

Definition at line 119 of file qgslegendmodel.cpp.

Referenced by setLayerSetAndGroups().

void QgsLegendModel::updateItem ( QStandardItem *  item  ) 

Tries to automatically update a model entry (e.g.

a whole layer or only a single item)

Definition at line 251 of file qgslegendmodel.cpp.

References QgsComposerLegendItem::itemType(), QgsComposerLegendItem::LayerItem, and updateLayer().

void QgsLegendModel::updateLayer ( QStandardItem *  layerItem  ) 

void QgsLegendModel::updateVectorClassificationItem ( QStandardItem *  classificationItem,
QgsSymbol symbol,
QString  itemText 
) [inline]

Tries to update a single classification item.

Definition at line 67 of file qgslegendmodel.h.

void QgsLegendModel::updateVectorV2ClassificationItem ( QStandardItem *  classificationItem,
QgsSymbolV2 symbol,
QString  itemText 
) [inline]

Definition at line 68 of file qgslegendmodel.h.

void QgsLegendModel::updateRasterClassificationItem ( QStandardItem *  classificationItem  )  [inline]

Definition at line 69 of file qgslegendmodel.h.

bool QgsLegendModel::writeXML ( QDomElement &  composerLegendElem,
QDomDocument &  doc 
) const

Definition at line 454 of file qgslegendmodel.cpp.

References QgsComposerLegendItem::writeXML().

Referenced by QgsComposerLegend::writeXML().

bool QgsLegendModel::readXML ( const QDomElement &  legendModelElem,
const QDomDocument &  doc 

Definition at line 480 of file qgslegendmodel.cpp.

References QgsComposerLegendItem::readXML().

Referenced by QgsComposerLegend::readXML().

Qt::DropActions QgsLegendModel::supportedDropActions (  )  const

Definition at line 517 of file qgslegendmodel.cpp.

Qt::ItemFlags QgsLegendModel::flags ( const QModelIndex &  index  )  const

bool QgsLegendModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
) [virtual]

Implemented to support drag operations.

Definition at line 550 of file qgslegendmodel.cpp.

QMimeData * QgsLegendModel::mimeData ( const QModelIndexList &  indexes  )  const

For the drag operation.

Definition at line 578 of file qgslegendmodel.cpp.

References QgsComposerLegendItem::writeXML().

QStringList QgsLegendModel::mimeTypes (  )  const

Definition at line 603 of file qgslegendmodel.cpp.

bool QgsLegendModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 

Implements the drop operation.

Definition at line 610 of file qgslegendmodel.cpp.

References layersChanged(), and QgsComposerLegendItem::readXML().

void QgsLegendModel::removeLayer ( const QString &  layerId  )  [slot]

Definition at line 312 of file qgslegendmodel.cpp.

References layersChanged().

Referenced by QgsLegendModel().

void QgsLegendModel::addLayer ( QgsMapLayer theMapLayer  )  [slot]

void QgsLegendModel::layersChanged (  )  [signal]

Referenced by addLayer(), dropMimeData(), and removeLayer().

int QgsLegendModel::addVectorLayerItems ( QStandardItem *  layerItem,
QgsVectorLayer vlayer 
) [private]

int QgsLegendModel::addVectorLayerItemsV2 ( QStandardItem *  layerItem,
QgsVectorLayer vlayer 
) [private]

Adds classification items of vector layers using new symbology.

Definition at line 133 of file qgslegendmodel.cpp.

References QgsFeatureRendererV2::legendSymbolItems(), mHasTopLevelWindow, QgsVectorLayer::rendererV2(), QgsComposerSymbolV2Item::setSymbolV2(), and QgsSymbolLayerV2Utils::symbolPreviewIcon().

Referenced by addLayer(), and updateLayer().

int QgsLegendModel::addRasterLayerItem ( QStandardItem *  layerItem,
QgsMapLayer rlayer 
) [private]

Adds item of raster layer.

0 in case of success

Definition at line 225 of file qgslegendmodel.cpp.

References QgsMapLayer::getLayerID(), QgsRasterLayer::legendAsPixmap(), mHasTopLevelWindow, and QgsComposerRasterSymbolItem::setLayerID().

Referenced by addLayer(), and updateLayer().

QStandardItem * QgsLegendModel::itemFromSymbol ( QgsSymbol s,
int  opacity,
const QString &  layerID 
) [private]

Member Data Documentation

QStringList QgsLegendModel::mLayerIds [protected]

Definition at line 111 of file qgslegendmodel.h.

Referenced by setLayerSet().

True if this application has toplevel windows (normally true).

If this is false, this means that the application might not have a running x-server on unix systems and so QPixmap and QIcon cannot be used

Definition at line 114 of file qgslegendmodel.h.

Referenced by addRasterLayerItem(), addVectorLayerItemsV2(), itemFromSymbol(), and QgsLegendModel().

The documentation for this class was generated from the following files:

Generated on Sat Feb 4 19:17:36 2012 for Quantum GIS API Documentation by  doxygen 1.5.6