27 : QAbstractItemModel( parent )
28 , mLayersChecked( QMap<QString, Qt::CheckState>() )
29 , mItemCheckable( false )
36 : QAbstractItemModel( parent )
37 , mLayersChecked( QMap<QString, Qt::CheckState>() )
38 , mItemCheckable( false )
61 QList<QgsMapLayer *> layers;
66 layers.append( layer );
74 int r =
mLayers.indexOf( layer );
80 foreach (
const QString layerId, layerIds )
82 QModelIndex startIndex =
index( 0, 0 );
83 QModelIndexList list = match( startIndex,
LayerIdRole, layerId, 1 );
86 QModelIndex
index = list[0];
87 beginRemoveRows( QModelIndex(), index.row(), index.row() );
89 mLayers.removeAt( index.row() );
97 beginInsertRows( QModelIndex(),
mLayers.count(),
mLayers.count() + layers.count() - 1 );
108 if ( hasIndex( row, column, parent ) )
110 return createIndex( row, column,
mLayers[row] );
113 return QModelIndex();
120 return QModelIndex();
126 return parent.isValid() ? 0 :
mLayers.length();
137 if ( !index.isValid() || !index.internalPointer() )
140 if ( role == Qt::DisplayRole )
143 return layer->
name();
158 if ( role == Qt::DecorationRole )
162 if ( role == Qt::DecorationRole )
217 if ( !index.isValid() )
222 Qt::ItemFlags
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
225 flags |= Qt::ItemIsUserCheckable;
233 if ( role == Qt::CheckStateRole )
237 emit dataChanged( index, index );
Base class for all map layer types.
QgsMapLayer::LayerType type() const
Get the type of the layer.
QList< QgsMapLayer * > mLayers
bool setData(const QModelIndex &index, const QVariant &value, int role)
void checkAll(Qt::CheckState checkState)
checkAll changes the checkstate for all the layers
int rowCount(const QModelIndex &parent) const
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
void setItemsCheckable(bool checkable)
setItemsCheckable defines if layers should be selectable in the widget
void addLayers(QList< QgsMapLayer * > layers)
QgsMapLayerModel(QObject *parent=0)
QgsMapLayerModel creates a model to display layers in widgets.
const QString & name() const
Get the display name of the layer.
LayerType
Layers enum defining the types of layers that can be added to a map.
QVariant data(const QModelIndex &index, int role) const
QMap< QString, Qt::CheckState > mLayersChecked
Qt::ItemFlags flags(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
int columnCount(const QModelIndex &parent) const
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QModelIndex parent(const QModelIndex &child) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
static const int LayerIdRole
QModelIndex indexFromLayer(QgsMapLayer *layer)
indexFromLayer returns the model index for a given layer
void removeLayers(const QStringList layerIds)
Represents a vector layer which manages a vector based data sets.
QList< QgsMapLayer * > layersChecked(Qt::CheckState checkState=Qt::Checked)
layersChecked returns the list of layers which are checked (or unchecked)