Quantum GIS API Documentation  1.8
Public Types | Public Slots | Signals | Public Member Functions | Protected Attributes | Private Member Functions
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)

Signals

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.
void setAutoUpdate (bool autoUpdate)
bool autoUpdate ()

Protected Attributes

QStringList mLayerIds
bool mHasTopLevelWindow
 True if this application has toplevel windows (normally true).
bool mAutoUpdate
 True if the legend is auto updated when layers are added or removed from the map canvas.

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 addRasterLayerItems (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

Enumerator:
GroupItem 
LayerItem 
ClassificationItem 

Definition at line 46 of file qgslegendmodel.h.


Constructor & Destructor Documentation

Definition at line 50 of file qgslegendmodel.cpp.


Member Function Documentation

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 120 of file qgslegendmodel.cpp.

Referenced by setLayerSetAndGroups().

void QgsLegendModel::addLayer ( QgsMapLayer theMapLayer) [slot]
int QgsLegendModel::addRasterLayerItems ( QStandardItem *  layerItem,
QgsMapLayer rlayer 
) [private]

Adds item of raster layer.

Returns:
0 in case of success

Definition at line 226 of file qgslegendmodel.cpp.

References QgsMapLayer::id(), QgsRasterLayer::legendSymbologyItems(), mHasTopLevelWindow, QgsComposerRasterSymbolItem::setColor(), and QgsComposerRasterSymbolItem::setLayerID().

Referenced by addLayer(), and updateLayer().

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 134 of file qgslegendmodel.cpp.

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

Referenced by addLayer(), and updateLayer().

bool QgsLegendModel::autoUpdate ( ) [inline]

Definition at line 91 of file qgslegendmodel.h.

Referenced by setAutoUpdate().

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

Implements the drop operation.

Definition at line 620 of file qgslegendmodel.cpp.

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

Qt::ItemFlags QgsLegendModel::flags ( const QModelIndex &  index) const
QStandardItem * QgsLegendModel::itemFromSymbol ( QgsSymbol s,
int  opacity,
const QString &  layerID 
) [private]
void QgsLegendModel::layersChanged ( ) [signal]

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

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

For the drag operation.

Definition at line 588 of file qgslegendmodel.cpp.

References QgsComposerLegendItem::writeXML().

QStringList QgsLegendModel::mimeTypes ( ) const

Definition at line 613 of file qgslegendmodel.cpp.

bool QgsLegendModel::readXML ( const QDomElement &  legendModelElem,
const QDomDocument &  doc 
)
void QgsLegendModel::removeLayer ( const QString &  layerId) [slot]

Definition at line 320 of file qgslegendmodel.cpp.

References QgsComposerLayerItem::layerID(), and layersChanged().

Referenced by QgsLegendModel(), and setAutoUpdate().

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

Implemented to support drag operations.

Definition at line 560 of file qgslegendmodel.cpp.

void QgsLegendModel::setAutoUpdate ( bool  autoUpdate)

Definition at line 691 of file qgslegendmodel.cpp.

References addLayer(), autoUpdate(), QgsMapLayerRegistry::instance(), mAutoUpdate, and removeLayer().

Referenced by readXML().

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

Sets layer set and groups.

Definition at line 54 of file qgslegendmodel.cpp.

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

Qt::DropActions QgsLegendModel::supportedDropActions ( ) const

Definition at line 527 of file qgslegendmodel.cpp.

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 259 of file qgslegendmodel.cpp.

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

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

Definition at line 71 of file qgslegendmodel.h.

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 69 of file qgslegendmodel.h.

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

Definition at line 459 of file qgslegendmodel.cpp.

References mAutoUpdate, and QgsComposerLegendItem::writeXML().

Referenced by QgsComposerLegend::writeXML().


Member Data Documentation

bool QgsLegendModel::mAutoUpdate [protected]

True if the legend is auto updated when layers are added or removed from the map canvas.

Definition at line 122 of file qgslegendmodel.h.

Referenced by setAutoUpdate(), and writeXML().

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 119 of file qgslegendmodel.h.

Referenced by addRasterLayerItems(), addVectorLayerItemsV2(), itemFromSymbol(), QgsLegendModel(), and readXML().

QStringList QgsLegendModel::mLayerIds [protected]

Definition at line 116 of file qgslegendmodel.h.

Referenced by setLayerSet().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines