QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmaplayermodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaplayermodel.cpp
3  --------------------------------------
4  Date : 01.04.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #include <QIcon>
17 
18 #include "qgsdataitem.h"
19 #include "qgsmaplayermodel.h"
20 #include "qgsproject.h"
21 #include "qgsapplication.h"
22 #include "qgsvectorlayer.h"
23 
24 QgsMapLayerModel::QgsMapLayerModel( const QList<QgsMapLayer *> &layers, QObject *parent, QgsProject *project )
25  : QAbstractItemModel( parent )
26  , mProject( project ? project : QgsProject::instance() )
27 {
28  connect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
29  addLayers( layers );
30 }
31 
32 QgsMapLayerModel::QgsMapLayerModel( QObject *parent, QgsProject *project )
33  : QAbstractItemModel( parent )
34  , mProject( project ? project : QgsProject::instance() )
35 {
37  connect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
38  addLayers( mProject->mapLayers().values() );
39 }
40 
42 {
43  mItemCheckable = checkable;
44 }
45 
47 {
48  mCanReorder = allow;
49 }
50 
52 {
53  return mCanReorder;
54 }
55 
56 void QgsMapLayerModel::checkAll( Qt::CheckState checkState )
57 {
58  QMap<QString, Qt::CheckState>::iterator i = mLayersChecked.begin();
59  for ( ; i != mLayersChecked.end(); ++i )
60  {
61  *i = checkState;
62  }
63  emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ) );
64 }
65 
66 void QgsMapLayerModel::setAllowEmptyLayer( bool allowEmpty )
67 {
68  if ( allowEmpty == mAllowEmpty )
69  return;
70 
71  if ( allowEmpty )
72  {
73  beginInsertRows( QModelIndex(), 0, 0 );
74  mAllowEmpty = true;
75  endInsertRows();
76  }
77  else
78  {
79  beginRemoveRows( QModelIndex(), 0, 0 );
80  mAllowEmpty = false;
81  endRemoveRows();
82  }
83 }
84 
85 void QgsMapLayerModel::setShowCrs( bool showCrs )
86 {
87  if ( mShowCrs == showCrs )
88  return;
89 
90  mShowCrs = showCrs;
91  emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector<int>() << Qt::DisplayRole );
92 }
93 
94 QList<QgsMapLayer *> QgsMapLayerModel::layersChecked( Qt::CheckState checkState )
95 {
96  QList<QgsMapLayer *> layers;
97  const auto constMLayers = mLayers;
98  for ( QgsMapLayer *layer : constMLayers )
99  {
100  if ( mLayersChecked[layer->id()] == checkState )
101  {
102  layers.append( layer );
103  }
104  }
105  return layers;
106 }
107 
109 {
110  int r = mLayers.indexOf( layer );
111  if ( r >= 0 && mAllowEmpty )
112  r++;
113  return index( r, 0 );
114 }
115 
116 QgsMapLayer *QgsMapLayerModel::layerFromIndex( const QModelIndex &index ) const
117 {
118  return mProject->mapLayer( index.data( LayerIdRole ).toString() );
119 }
120 
121 void QgsMapLayerModel::setAdditionalItems( const QStringList &items )
122 {
123  if ( items == mAdditionalItems )
124  return;
125 
126  int offset = 0;
127  if ( mAllowEmpty )
128  offset++;
129 
130  offset += mLayers.count();
131 
132  //remove existing
133  if ( !mAdditionalItems.isEmpty() )
134  {
135  beginRemoveRows( QModelIndex(), offset, offset + mAdditionalItems.count() - 1 );
136  mAdditionalItems.clear();
137  endRemoveRows();
138  }
139 
140  //add new
141  beginInsertRows( QModelIndex(), offset, offset + items.count() - 1 );
142  mAdditionalItems = items;
143  endInsertRows();
144 }
145 
146 void QgsMapLayerModel::removeLayers( const QStringList &layerIds )
147 {
148  int offset = 0;
149  if ( mAllowEmpty )
150  offset++;
151 
152  for ( const QString &layerId : layerIds )
153  {
154  QModelIndex startIndex = index( 0, 0 );
155  QModelIndexList list = match( startIndex, LayerIdRole, layerId, 1 );
156  if ( !list.isEmpty() )
157  {
158  QModelIndex index = list[0];
159  beginRemoveRows( QModelIndex(), index.row(), index.row() );
160  mLayersChecked.remove( layerId );
161  mLayers.removeAt( index.row() - offset );
162  endRemoveRows();
163  }
164  }
165 }
166 
167 void QgsMapLayerModel::addLayers( const QList<QgsMapLayer *> &layers )
168 {
169  if ( !layers.empty( ) )
170  {
171  int offset = 0;
172  if ( mAllowEmpty )
173  offset++;
174 
175  beginInsertRows( QModelIndex(), mLayers.count() + offset, mLayers.count() + layers.count() - 1 + offset );
176  const auto constLayers = layers;
177  for ( QgsMapLayer *layer : constLayers )
178  {
179  mLayers.append( layer );
180  mLayersChecked.insert( layer->id(), Qt::Unchecked );
181  }
182  endInsertRows();
183  }
184 }
185 
186 QModelIndex QgsMapLayerModel::index( int row, int column, const QModelIndex &parent ) const
187 {
188  int offset = 0;
189  if ( mAllowEmpty )
190  offset++;
191 
192  if ( hasIndex( row, column, parent ) )
193  {
194  QgsMapLayer *layer = nullptr;
195  if ( row - offset >= 0 && row - offset < mLayers.count() )
196  layer = mLayers.at( row - offset );
197 
198  return createIndex( row, column, layer );
199  }
200 
201  return QModelIndex();
202 
203 }
204 
205 QModelIndex QgsMapLayerModel::parent( const QModelIndex &child ) const
206 {
207  Q_UNUSED( child )
208  return QModelIndex();
209 }
210 
211 
212 int QgsMapLayerModel::rowCount( const QModelIndex &parent ) const
213 {
214  if ( parent.isValid() )
215  return 0;
216 
217  return ( mAllowEmpty ? 1 : 0 ) + mLayers.length() + mAdditionalItems.count();
218 }
219 
220 int QgsMapLayerModel::columnCount( const QModelIndex &parent ) const
221 {
222  Q_UNUSED( parent )
223  return 1;
224 }
225 
226 
227 QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
228 {
229  if ( !index.isValid() )
230  return QVariant();
231 
232  bool isEmpty = index.row() == 0 && mAllowEmpty;
233  int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
234 
235  switch ( role )
236  {
237  case Qt::DisplayRole:
238  case Qt::EditRole:
239  {
240  if ( index.row() == 0 && mAllowEmpty )
241  return QVariant();
242 
243  if ( additionalIndex >= 0 )
244  return mAdditionalItems.at( additionalIndex );
245 
246  QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
247  if ( !layer )
248  return QVariant();
249 
250  if ( !mShowCrs || !layer->isSpatial() || role == Qt::EditRole )
251  {
252  return layer->name();
253  }
254  else
255  {
256  return tr( "%1 [%2]" ).arg( layer->name(), layer->crs().authid() );
257  }
258  }
259 
260  case LayerIdRole:
261  {
262  if ( isEmpty || additionalIndex >= 0 )
263  return QVariant();
264 
265  QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
266  return layer ? layer->id() : QVariant();
267  }
268 
269  case LayerRole:
270  {
271  if ( isEmpty || additionalIndex >= 0 )
272  return QVariant();
273 
274  return QVariant::fromValue<QgsMapLayer *>( mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) ) );
275  }
276 
277  case EmptyRole:
278  return isEmpty;
279 
280  case AdditionalRole:
281  return additionalIndex >= 0;
282 
283  case Qt::CheckStateRole:
284  {
285  if ( mItemCheckable )
286  {
287  if ( isEmpty || additionalIndex >= 0 )
288  return QVariant();
289 
290  QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
291  return layer ? mLayersChecked[layer->id()] : QVariant();
292  }
293 
294  return QVariant();
295  }
296 
297  case Qt::ToolTipRole:
298  {
299  QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
300  if ( layer )
301  {
302  QStringList parts;
303  QString title = layer->title().isEmpty() ? layer->shortName() : layer->title();
304  if ( title.isEmpty() )
305  title = layer->name();
306  title = "<b>" + title + "</b>";
307  if ( layer->isSpatial() && layer->crs().isValid() )
308  {
309  if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
310  title = tr( "%1 (%2 - %3)" ).arg( title, QgsWkbTypes::displayString( vl->wkbType() ), layer->crs().authid() );
311  else
312  title = tr( "%1 (%2) " ).arg( title, layer->crs().authid() );
313  }
314  parts << title;
315 
316  if ( !layer->abstract().isEmpty() )
317  parts << "<br/>" + layer->abstract().replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
318  parts << "<i>" + layer->publicSource() + "</i>";
319  return parts.join( QStringLiteral( "<br/>" ) );
320  }
321  return QVariant();
322  }
323 
324  case Qt::DecorationRole:
325  {
326  if ( isEmpty || additionalIndex >= 0 )
327  return QVariant();
328 
329  QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
330  if ( !layer )
331  return QVariant();
332 
333  return iconForLayer( layer );
334  }
335  }
336 
337  return QVariant();
338 }
339 
340 QHash<int, QByteArray> QgsMapLayerModel::roleNames() const
341 {
342  QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
343  roles[LayerIdRole] = "layerId";
344  roles[LayerRole] = "layer";
345 
346  return roles;
347 }
348 
349 Qt::ItemFlags QgsMapLayerModel::flags( const QModelIndex &index ) const
350 {
351  if ( !index.isValid() )
352  {
353  if ( mCanReorder )
354  return Qt::ItemIsDropEnabled;
355  else
356  return nullptr;
357  }
358 
359  bool isEmpty = index.row() == 0 && mAllowEmpty;
360  int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
361 
362  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
363 
364  if ( mCanReorder && !isEmpty && additionalIndex < 0 )
365  {
366  flags |= Qt::ItemIsDragEnabled;
367  }
368 
369  if ( mItemCheckable && !isEmpty && additionalIndex < 0 )
370  {
371  flags |= Qt::ItemIsUserCheckable;
372  }
373  return flags;
374 }
375 
376 bool QgsMapLayerModel::insertRows( int row, int count, const QModelIndex &parent )
377 {
378  if ( parent.isValid() )
379  return false;
380 
381  int offset = 0;
382  if ( mAllowEmpty )
383  offset++;
384 
385  beginInsertRows( parent, row, row + count - 1 );
386  for ( int i = row; i < row + count; ++i )
387  mLayers.insert( i - offset, nullptr );
388  endInsertRows();
389 
390  return true;
391 }
392 
393 bool QgsMapLayerModel::removeRows( int row, int count, const QModelIndex &parent )
394 {
395  if ( parent.isValid() || row < 0 )
396  return false;
397 
398  int offset = 0;
399  if ( mAllowEmpty )
400  {
401  if ( row == 0 )
402  return false;
403 
404  offset++;
405  }
406 
407  if ( row - offset > mLayers.count() - 1 )
408  {
409  return false;
410  }
411 
412  beginRemoveRows( parent, row, row + count - 1 );
413  for ( int i = 0; i != count; ++i )
414  mLayers.removeAt( row - offset );
415  endRemoveRows();
416 
417  return true;
418 }
419 
420 QStringList QgsMapLayerModel::mimeTypes() const
421 {
422  QStringList types;
423  types << QStringLiteral( "application/qgis.layermodeldata" );
424  return types;
425 }
426 
427 bool QgsMapLayerModel::canDropMimeData( const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex & ) const
428 {
429  if ( !mCanReorder || action != Qt::MoveAction || !data->hasFormat( QStringLiteral( "application/qgis.layermodeldata" ) ) )
430  return false;
431  return true;
432 }
433 
434 QMimeData *QgsMapLayerModel::mimeData( const QModelIndexList &indexes ) const
435 {
436  std::unique_ptr< QMimeData > mimeData = qgis::make_unique< QMimeData >();
437 
438  QByteArray encodedData;
439  QDataStream stream( &encodedData, QIODevice::WriteOnly );
440  QSet< QString > addedLayers;
441 
442  for ( const QModelIndex &i : indexes )
443  {
444  if ( i.isValid() )
445  {
446  const QString id = data( index( i.row(), 0, i.parent() ), LayerIdRole ).toString();
447  if ( !addedLayers.contains( id ) )
448  {
449  addedLayers.insert( id );
450  stream << id;
451  }
452  }
453  }
454  mimeData->setData( QStringLiteral( "application/qgis.layermodeldata" ), encodedData );
455  return mimeData.release();
456 }
457 
458 bool QgsMapLayerModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
459 {
460  if ( !canDropMimeData( data, action, row, column, parent ) || row < 0 )
461  return false;
462 
463  if ( action == Qt::IgnoreAction )
464  return true;
465  else if ( action != Qt::MoveAction )
466  return false;
467 
468  QByteArray encodedData = data->data( QStringLiteral( "application/qgis.layermodeldata" ) );
469  QDataStream stream( &encodedData, QIODevice::ReadOnly );
470  QStringList newItems;
471  int rows = 0;
472 
473  while ( !stream.atEnd() )
474  {
475  QString text;
476  stream >> text;
477  newItems << text;
478  ++rows;
479  }
480 
481  insertRows( row, rows, QModelIndex() );
482  for ( const QString &text : qgis::as_const( newItems ) )
483  {
484  QModelIndex idx = index( row, 0, QModelIndex() );
485  setData( idx, text, LayerIdRole );
486  row++;
487  }
488 
489  return true;
490 }
491 
493 {
494  return Qt::MoveAction;
495 }
496 
498 {
499  switch ( layer->type() )
500  {
502  {
503  return QgsLayerItem::iconRaster();
504  }
505 
507  {
508  return QgsLayerItem::iconMesh();
509  }
510 
512  {
514  }
515 
517  {
518  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
519  if ( !vl )
520  {
521  return QIcon();
522  }
523  QgsWkbTypes::GeometryType geomType = vl->geometryType();
524  switch ( geomType )
525  {
527  {
528  return QgsLayerItem::iconPoint();
529  }
531  {
532  return QgsLayerItem::iconPolygon();
533  }
535  {
536  return QgsLayerItem::iconLine();
537  }
539  {
540  return QgsLayerItem::iconTable();
541  }
542  default:
543  {
544  return QIcon();
545  }
546  }
547  }
548  default:
549  {
550  return QIcon();
551  }
552  }
553 }
554 
555 
556 bool QgsMapLayerModel::setData( const QModelIndex &index, const QVariant &value, int role )
557 {
558  if ( !index.isValid() )
559  return false;
560 
561  bool isEmpty = index.row() == 0 && mAllowEmpty;
562  int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
563 
564  switch ( role )
565  {
566  case Qt::CheckStateRole:
567  {
568  if ( !isEmpty && additionalIndex < 0 )
569  {
570  QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
571  mLayersChecked[layer->id()] = ( Qt::CheckState )value.toInt();
572  emit dataChanged( index, index );
573  return true;
574  }
575  break;
576  }
577 
578  case LayerIdRole:
579  if ( !isEmpty && additionalIndex < 0 )
580  {
581  mLayers[index.row() - ( mAllowEmpty ? 1 : 0 )] = mProject->mapLayer( value.toString() );
582  emit dataChanged( index, index );
583  return true;
584  }
585  break;
586  }
587 
588  return false;
589 }
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:88
QgsMapLayerModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: qgsmaplayermodel.cpp:393
QgsLayerItem::iconLine
static QIcon iconLine()
Definition: qgsdataitem.cpp:58
QgsMapLayerModel::mLayersChecked
QMap< QString, Qt::CheckState > mLayersChecked
Definition: qgsmaplayermodel.h:198
QgsProject::layersWillBeRemoved
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
QgsMapLayerModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsmaplayermodel.cpp:349
QgsMapLayerType::MeshLayer
@ MeshLayer
Added in 3.2.
QgsMapLayerModel::addLayers
void addLayers(const QList< QgsMapLayer * > &layers)
Definition: qgsmaplayermodel.cpp:167
QgsProject::layersAdded
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:145
QgsMapLayerType::VectorLayer
@ VectorLayer
QgsProject::mapLayers
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Definition: qgsproject.cpp:3347
QgsMapLayer::shortName
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.cpp:179
QgsMapLayerModel::supportedDropActions
Qt::DropActions supportedDropActions() const override
Definition: qgsmaplayermodel.cpp:492
QgsLayerItem::iconRaster
static QIcon iconRaster()
Definition: qgsdataitem.cpp:73
qgsdataitem.h
QgsMapLayerModel::itemsCanBeReordered
bool itemsCanBeReordered() const
Returns true if items in the model can be reordered via drag and drop.
Definition: qgsmaplayermodel.cpp:51
QgsMapLayerModel::roleNames
QHash< int, QByteArray > roleNames() const override
Returns strings for all roles supported by this model.
Definition: qgsmaplayermodel.cpp:340
QgsMapLayerModel::setAdditionalItems
void setAdditionalItems(const QStringList &items)
Sets a list of additional (non map layer) items to include at the end of the model.
Definition: qgsmaplayermodel.cpp:121
QgsMapLayerModel::mLayers
QList< QgsMapLayer * > mLayers
Definition: qgsmaplayermodel.h:197
QgsMapLayer::abstract
QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:302
QgsMapLayerModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: qgsmaplayermodel.cpp:227
QgsMapLayerModel::LayerIdRole
@ LayerIdRole
Stores the map layer ID.
Definition: qgsmaplayermodel.h:50
QgsProject::mapLayer
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Definition: qgsproject.cpp:3124
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
QgsProject
Definition: qgsproject.h:92
QgsMapLayerModel::mProject
QgsProject * mProject
Definition: qgsmaplayermodel.h:202
QgsMapLayerModel::layersChecked
QList< QgsMapLayer * > layersChecked(Qt::CheckState checkState=Qt::Checked)
layersChecked returns the list of layers which are checked (or unchecked)
Definition: qgsmaplayermodel.cpp:94
QgsMapLayerModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: qgsmaplayermodel.cpp:556
qgsapplication.h
QgsMapLayerModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmaplayermodel.cpp:212
QgsMapLayerModel::indexFromLayer
QModelIndex indexFromLayer(QgsMapLayer *layer) const
indexFromLayer returns the model index for a given layer
Definition: qgsmaplayermodel.cpp:108
QgsMapLayerModel::mCanReorder
bool mCanReorder
Definition: qgsmaplayermodel.h:200
QgsMapLayerModel::insertRows
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: qgsmaplayermodel.cpp:376
QgsLayerItem::iconPoint
static QIcon iconPoint()
Definition: qgsdataitem.cpp:53
QgsMapLayerModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmaplayermodel.cpp:220
QgsLayerItem::iconVectorTile
static QIcon iconVectorTile()
Returns icon for vector tile layer.
Definition: qgsdataitem.cpp:83
QgsMapLayerType::RasterLayer
@ RasterLayer
QgsCoordinateReferenceSystem::authid
QString authid() const
Returns the authority identifier for the CRS.
Definition: qgscoordinatereferencesystem.cpp:1299
QgsMapLayerModel::EmptyRole
@ EmptyRole
True if index corresponds to the empty (not set) value.
Definition: qgsmaplayermodel.h:52
QgsMapLayerModel::iconForLayer
static QIcon iconForLayer(QgsMapLayer *layer)
Returns the icon corresponding to a specified map layer.
Definition: qgsmaplayermodel.cpp:497
QgsMapLayerModel::checkAll
void checkAll(Qt::CheckState checkState)
checkAll changes the checkstate for all the layers
Definition: qgsmaplayermodel.cpp:56
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:902
QgsMapLayerModel::mItemCheckable
bool mItemCheckable
Definition: qgsmaplayermodel.h:199
QgsMapLayer::id
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Definition: qgsmaplayer.cpp:148
QgsMapLayer::title
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:286
QgsMapLayerModel::mimeTypes
QStringList mimeTypes() const override
Definition: qgsmaplayermodel.cpp:420
QgsMapLayerModel::setItemsCanBeReordered
void setItemsCanBeReordered(bool allow)
Sets whether items in the model can be reordered via drag and drop.
Definition: qgsmaplayermodel.cpp:46
QgsLayerItem::iconTable
static QIcon iconTable()
Definition: qgsdataitem.cpp:68
QgsLayerItem::iconPolygon
static QIcon iconPolygon()
Definition: qgsdataitem.cpp:63
qgsvectorlayer.h
QgsMapLayerModel::layerFromIndex
QgsMapLayer * layerFromIndex(const QModelIndex &index) const
Returns the map layer corresponding to the specified index.
Definition: qgsmaplayermodel.cpp:116
QgsMapLayer::publicSource
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Definition: qgsmaplayer.cpp:184
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsLayerItem::iconMesh
static QIcon iconMesh()
Returns icon for mesh layer type.
Definition: qgsdataitem.cpp:78
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
qgsmaplayermodel.h
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsMapLayerModel::LayerRole
@ LayerRole
Stores pointer to the map layer itself.
Definition: qgsmaplayermodel.h:51
QgsWkbTypes::displayString
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
Definition: qgswkbtypes.cpp:145
QgsMapLayerType::VectorTileLayer
@ VectorTileLayer
Added in 3.14.
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:85
QgsMapLayerModel::QgsMapLayerModel
QgsMapLayerModel(QObject *parent=nullptr, QgsProject *project=nullptr)
QgsMapLayerModel creates a model to display layers in widgets.
Definition: qgsmaplayermodel.cpp:32
QgsMapLayerModel::canDropMimeData
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
Definition: qgsmaplayermodel.cpp:427
QgsMapLayerModel::setShowCrs
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the model's display role.
Definition: qgsmaplayermodel.cpp:85
QgsMapLayerModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const override
Definition: qgsmaplayermodel.cpp:434
QgsMapLayerModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: qgsmaplayermodel.cpp:186
QgsMapLayerModel::AdditionalRole
@ AdditionalRole
True if index corresponds to an additional (non map layer) item.
Definition: qgsmaplayermodel.h:53
QgsMapLayer::isSpatial
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Definition: qgsmaplayer.cpp:1740
QgsMapLayerModel::setAllowEmptyLayer
void setAllowEmptyLayer(bool allowEmpty)
Sets whether an optional empty layer ("not set") option is present in the model.
Definition: qgsmaplayermodel.cpp:66
QgsMapLayerModel::parent
QModelIndex parent(const QModelIndex &child) const override
Definition: qgsmaplayermodel.cpp:205
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:659
QgsMapLayerModel::removeLayers
void removeLayers(const QStringList &layerIds)
Definition: qgsmaplayermodel.cpp:146
QgsMapLayerModel::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Definition: qgsmaplayermodel.cpp:458
QgsMapLayer::type
QgsMapLayerType type() const
Returns the type of the layer.
Definition: qgsmaplayer.cpp:129
QgsMapLayerModel::setItemsCheckable
void setItemsCheckable(bool checkable)
setItemsCheckable defines if layers should be selectable in the widget
Definition: qgsmaplayermodel.cpp:41
qgsproject.h
QgsMapLayerModel::showCrs
bool showCrs
Definition: qgsmaplayermodel.h:41