QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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 : denis.rouzaud@gmail.com
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 "qgsmaplayermodel.h"
19#include "moc_qgsmaplayermodel.cpp"
20#include "qgsproject.h"
21#include "qgsvectorlayer.h"
22#include "qgsiconutils.h"
24#include <QMimeData>
25
26QgsMapLayerModel::QgsMapLayerModel( const QList<QgsMapLayer *> &layers, QObject *parent, QgsProject *project )
27 : QAbstractItemModel( parent )
28 , mProject( project ? project : QgsProject::instance() ) // skip-keyword-check
29{
30 connect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
31 addLayers( layers );
32}
33
35 : QAbstractItemModel( parent )
36 , mProject( project ? project : QgsProject::instance() ) // skip-keyword-check
37{
39 connect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
40 addLayers( mProject->mapLayers().values() );
41}
42
44{
45
46 // remove layers from previous project
47 if ( mProject )
48 {
49 removeLayers( mProject->mapLayers().keys() );
51 disconnect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
52 }
53
54 mProject = project ? project : QgsProject::instance(); // skip-keyword-check
55
57 connect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
58 addLayers( mProject->mapLayers().values() );
59}
60
61
63{
64 mItemCheckable = checkable;
65}
66
68{
69 mCanReorder = allow;
70}
71
73{
74 return mCanReorder;
75}
76
77void QgsMapLayerModel::checkAll( Qt::CheckState checkState )
78{
79 QMap<QString, Qt::CheckState>::iterator i = mLayersChecked.begin();
80 for ( ; i != mLayersChecked.end(); ++i )
81 {
82 *i = checkState;
83 }
84 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ) );
85}
86
87void QgsMapLayerModel::setAllowEmptyLayer( bool allowEmpty, const QString &text, const QIcon &icon )
88{
89 mEmptyText = text;
90 mEmptyIcon = icon;
91 if ( allowEmpty == mAllowEmpty )
92 return;
93
94 if ( allowEmpty )
95 {
96 beginInsertRows( QModelIndex(), 0, 0 );
97 mAllowEmpty = true;
98 endInsertRows();
99 }
100 else
101 {
102 beginRemoveRows( QModelIndex(), 0, 0 );
103 mAllowEmpty = false;
104 endRemoveRows();
105 }
106}
107
109{
110 if ( mShowCrs == showCrs )
111 return;
112
113 mShowCrs = showCrs;
114 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector<int>() << Qt::DisplayRole );
115}
116
117QList<QgsMapLayer *> QgsMapLayerModel::layersChecked( Qt::CheckState checkState )
118{
119 QList<QgsMapLayer *> layers;
120 const auto constMLayers = mLayers;
121 for ( QgsMapLayer *layer : constMLayers )
122 {
123 if ( mLayersChecked[layer->id()] == checkState )
124 {
125 layers.append( layer );
126 }
127 }
128 return layers;
129}
130
131void QgsMapLayerModel::setLayersChecked( const QList<QgsMapLayer *> &layers )
132{
133 QMap<QString, Qt::CheckState>::iterator i = mLayersChecked.begin();
134 for ( ; i != mLayersChecked.end(); ++i )
135 {
136 *i = Qt::Unchecked;
137 }
138 for ( const QgsMapLayer *layer : layers )
139 {
140 mLayersChecked[ layer->id() ] = Qt::Checked;
141 }
142 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector<int>() << Qt::CheckStateRole );
143}
144
146{
147 int r = mLayers.indexOf( layer );
148 if ( r >= 0 && mAllowEmpty )
149 r++;
150 return index( r, 0 );
151}
152
153QgsMapLayer *QgsMapLayerModel::layerFromIndex( const QModelIndex &index ) const
154{
155 return mProject->mapLayer( index.data( static_cast< int >( CustomRole::LayerId ) ).toString() );
156}
157
158void QgsMapLayerModel::setAdditionalItems( const QStringList &items )
159{
160 if ( items == mAdditionalItems )
161 return;
162
163 int offset = 0;
164 if ( mAllowEmpty )
165 offset++;
166
167 offset += mLayers.count();
168
169 //remove existing
170 if ( !mAdditionalItems.isEmpty() )
171 {
172 beginRemoveRows( QModelIndex(), offset, offset + mAdditionalItems.count() - 1 );
173 mAdditionalItems.clear();
174 endRemoveRows();
175 }
176
177 //add new
178 beginInsertRows( QModelIndex(), offset, offset + items.count() - 1 );
179 mAdditionalItems = items;
180 endInsertRows();
181}
182
183void QgsMapLayerModel::setAdditionalLayers( const QList<QgsMapLayer *> &layers )
184{
185 if ( layers == _qgis_listQPointerToRaw( mAdditionalLayers ) )
186 return;
187
188 QStringList layerIdsToRemove;
189 for ( QgsMapLayer *layer : std::as_const( mAdditionalLayers ) )
190 {
191 if ( layer )
192 layerIdsToRemove << layer->id();
193 }
194 removeLayers( layerIdsToRemove );
195
196 for ( QgsMapLayer *layer : layers )
197 {
198 if ( layer )
199 {
200 addLayers( { layer } );
201 const QString layerId = layer->id();
202 connect( layer, &QgsMapLayer::willBeDeleted, this, [this, layerId] { removeLayers( {layerId} ); } );
203 }
204 }
205
206 mAdditionalLayers = _qgis_listRawToQPointer( layers );
207}
208
209QList<QgsMapLayer *> QgsMapLayerModel::additionalLayers() const
210{
211 return _qgis_listQPointerToRaw( mAdditionalLayers );
212}
213
214void QgsMapLayerModel::removeLayers( const QStringList &layerIds )
215{
216 int offset = 0;
217 if ( mAllowEmpty )
218 offset++;
219
220 for ( const QString &layerId : layerIds )
221 {
222 QModelIndex startIndex = index( 0, 0 );
223 QModelIndexList list = match( startIndex, static_cast< int >( CustomRole::LayerId ), layerId, 1 );
224 if ( !list.isEmpty() )
225 {
226 QModelIndex index = list[0];
227 beginRemoveRows( QModelIndex(), index.row(), index.row() );
228 mLayersChecked.remove( layerId );
229 mLayers.removeAt( index.row() - offset );
230 endRemoveRows();
231 }
232 }
233}
234
235void QgsMapLayerModel::addLayers( const QList<QgsMapLayer *> &layers )
236{
237 if ( !layers.empty( ) )
238 {
239 int offset = 0;
240 if ( mAllowEmpty )
241 offset++;
242
243 beginInsertRows( QModelIndex(), mLayers.count() + offset, mLayers.count() + layers.count() - 1 + offset );
244 const auto constLayers = layers;
245 for ( QgsMapLayer *layer : constLayers )
246 {
247 mLayers.append( layer );
248 mLayersChecked.insert( layer->id(), Qt::Unchecked );
249 }
250 endInsertRows();
251 }
252}
253
254QModelIndex QgsMapLayerModel::index( int row, int column, const QModelIndex &parent ) const
255{
256 int offset = 0;
257 if ( mAllowEmpty )
258 offset++;
259
260 if ( hasIndex( row, column, parent ) )
261 {
262 QgsMapLayer *layer = nullptr;
263 if ( row - offset >= 0 && row - offset < mLayers.count() )
264 layer = mLayers.at( row - offset );
265
266 return createIndex( row, column, layer );
267 }
268
269 return QModelIndex();
270
271}
272
273QModelIndex QgsMapLayerModel::parent( const QModelIndex &child ) const
274{
275 Q_UNUSED( child )
276 return QModelIndex();
277}
278
279
280int QgsMapLayerModel::rowCount( const QModelIndex &parent ) const
281{
282 if ( parent.isValid() )
283 return 0;
284
285 return ( mAllowEmpty ? 1 : 0 ) + mLayers.length() + mAdditionalItems.count();
286}
287
288int QgsMapLayerModel::columnCount( const QModelIndex &parent ) const
289{
290 Q_UNUSED( parent )
291 return 1;
292}
293
294
295QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
296{
297 if ( !index.isValid() )
298 return QVariant();
299
300 bool isEmpty = index.row() == 0 && mAllowEmpty;
301 int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
302
303 switch ( role )
304 {
305 case Qt::DisplayRole:
306 case Qt::EditRole:
307 {
308 if ( index.row() == 0 && mAllowEmpty )
309 return mEmptyText;
310
311 if ( additionalIndex >= 0 )
312 return mAdditionalItems.at( additionalIndex );
313
314 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
315 if ( !layer )
316 return QVariant();
317
318 if ( !mShowCrs || !layer->isSpatial() || role == Qt::EditRole )
319 {
320 return layer->name();
321 }
322 else
323 {
324 return tr( "%1 [%2]" ).arg( layer->name(), layer->crs().authid() );
325 }
326 }
327
328 case static_cast< int >( CustomRole::LayerId ):
329 {
330 if ( isEmpty || additionalIndex >= 0 )
331 return QVariant();
332
333 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
334 return layer ? layer->id() : QVariant();
335 }
336
337 case static_cast< int >( CustomRole::Layer ):
338 {
339 if ( isEmpty || additionalIndex >= 0 )
340 return QVariant();
341
342 return QVariant::fromValue<QgsMapLayer *>( mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) ) );
343 }
344
345 case static_cast< int >( CustomRole::Empty ):
346 return isEmpty;
347
348 case static_cast< int >( CustomRole::Additional ):
349 return additionalIndex >= 0;
350
351 case Qt::CheckStateRole:
352 {
353 if ( mItemCheckable )
354 {
355 if ( isEmpty || additionalIndex >= 0 )
356 return QVariant();
357
358 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
359 return layer ? mLayersChecked[layer->id()] : QVariant();
360 }
361
362 return QVariant();
363 }
364
365 case Qt::ToolTipRole:
366 {
367 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
368 if ( layer )
369 {
370 QStringList parts;
371 QString title = !layer->metadata().title().isEmpty() ? layer->metadata().title() : ( layer->serverProperties()->title().isEmpty() ? layer->serverProperties()->shortName() : layer->serverProperties()->title() );
372 if ( title.isEmpty() )
373 title = layer->name();
374 title = "<b>" + title + "</b>";
375 if ( layer->isSpatial() && layer->crs().isValid() )
376 {
377 QString layerCrs = layer->crs().authid();
378 if ( !std::isnan( layer->crs().coordinateEpoch() ) )
379 {
380 layerCrs += QStringLiteral( " @ %1" ).arg( qgsDoubleToString( layer->crs().coordinateEpoch(), 3 ) );
381 }
382 if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
383 title = tr( "%1 (%2 - %3)" ).arg( title, QgsWkbTypes::displayString( vl->wkbType() ), layerCrs );
384 else
385 title = tr( "%1 (%2)" ).arg( title, layerCrs );
386 }
387 parts << title;
388
389 QString abstract = !layer->metadata().abstract().isEmpty() ? layer->metadata().abstract() : layer->serverProperties()->abstract();
390 if ( !abstract.isEmpty() )
391 parts << "<br/>" + abstract.replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
392 parts << "<i>" + layer->publicSource() + "</i>";
393 return parts.join( QLatin1String( "<br/>" ) );
394 }
395 return QVariant();
396 }
397
398 case Qt::DecorationRole:
399 {
400 if ( isEmpty )
401 return mEmptyIcon.isNull() ? QVariant() : mEmptyIcon;
402
403 if ( additionalIndex >= 0 )
404 return QVariant();
405
406 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
407 if ( !layer )
408 return QVariant();
409
410 return iconForLayer( layer );
411 }
412
413 default:
414 break;
415 }
416
417 return QVariant();
418}
419
420QHash<int, QByteArray> QgsMapLayerModel::roleNames() const
421{
422 QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
423 roles[static_cast< int >( CustomRole::LayerId ) ] = "layerId";
424 roles[static_cast< int >( CustomRole::Layer )] = "layer";
425
426 return roles;
427}
428
429Qt::ItemFlags QgsMapLayerModel::flags( const QModelIndex &index ) const
430{
431 if ( !index.isValid() )
432 {
433 if ( mCanReorder )
434 return Qt::ItemIsDropEnabled;
435 else
436 return Qt::ItemFlags();
437 }
438
439 bool isEmpty = index.row() == 0 && mAllowEmpty;
440 int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
441
442 Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
443
444 if ( mCanReorder && !isEmpty && additionalIndex < 0 )
445 {
446 flags |= Qt::ItemIsDragEnabled;
447 }
448
449 if ( mItemCheckable && !isEmpty && additionalIndex < 0 )
450 {
451 flags |= Qt::ItemIsUserCheckable;
452 }
453 return flags;
454}
455
456bool QgsMapLayerModel::insertRows( int row, int count, const QModelIndex &parent )
457{
458 if ( parent.isValid() )
459 return false;
460
461 int offset = 0;
462 if ( mAllowEmpty )
463 offset++;
464
465 beginInsertRows( parent, row, row + count - 1 );
466 for ( int i = row; i < row + count; ++i )
467 mLayers.insert( i - offset, nullptr );
468 endInsertRows();
469
470 return true;
471}
472
473bool QgsMapLayerModel::removeRows( int row, int count, const QModelIndex &parent )
474{
475 if ( parent.isValid() || row < 0 )
476 return false;
477
478 int offset = 0;
479 if ( mAllowEmpty )
480 {
481 if ( row == 0 )
482 return false;
483
484 offset++;
485 }
486
487 if ( row - offset > mLayers.count() - 1 )
488 {
489 return false;
490 }
491
492 beginRemoveRows( parent, row, row + count - 1 );
493 for ( int i = 0; i != count; ++i )
494 mLayers.removeAt( row - offset );
495 endRemoveRows();
496
497 return true;
498}
499
501{
502 QStringList types;
503 types << QStringLiteral( "application/qgis.layermodeldata" );
504 return types;
505}
506
507bool QgsMapLayerModel::canDropMimeData( const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex & ) const
508{
509 if ( !mCanReorder || action != Qt::MoveAction || !data->hasFormat( QStringLiteral( "application/qgis.layermodeldata" ) ) )
510 return false;
511 return true;
512}
513
514QMimeData *QgsMapLayerModel::mimeData( const QModelIndexList &indexes ) const
515{
516 std::unique_ptr< QMimeData > mimeData = std::make_unique< QMimeData >();
517
518 QByteArray encodedData;
519 QDataStream stream( &encodedData, QIODevice::WriteOnly );
520 QSet< QString > addedLayers;
521
522 for ( const QModelIndex &i : indexes )
523 {
524 if ( i.isValid() )
525 {
526 const QString id = data( index( i.row(), 0, i.parent() ), static_cast< int >( CustomRole::LayerId ) ).toString();
527 if ( !addedLayers.contains( id ) )
528 {
529 addedLayers.insert( id );
530 stream << id;
531 }
532 }
533 }
534 mimeData->setData( QStringLiteral( "application/qgis.layermodeldata" ), encodedData );
535 return mimeData.release();
536}
537
538bool QgsMapLayerModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
539{
540 if ( !canDropMimeData( data, action, row, column, parent ) || row < 0 )
541 return false;
542
543 if ( action == Qt::IgnoreAction )
544 return true;
545 else if ( action != Qt::MoveAction )
546 return false;
547
548 QByteArray encodedData = data->data( QStringLiteral( "application/qgis.layermodeldata" ) );
549 QDataStream stream( &encodedData, QIODevice::ReadOnly );
550 QStringList newItems;
551 int rows = 0;
552
553 while ( !stream.atEnd() )
554 {
555 QString text;
556 stream >> text;
557 newItems << text;
558 ++rows;
559 }
560
561 insertRows( row, rows, QModelIndex() );
562 for ( const QString &text : std::as_const( newItems ) )
563 {
564 QModelIndex idx = index( row, 0, QModelIndex() );
565 setData( idx, text, static_cast< int >( CustomRole::LayerId ) );
566 row++;
567 }
568
569 return true;
570}
571
573{
574 return Qt::MoveAction;
575}
576
578{
579 return QgsIconUtils::iconForLayer( layer );
580}
581
582bool QgsMapLayerModel::setData( const QModelIndex &index, const QVariant &value, int role )
583{
584 if ( !index.isValid() )
585 return false;
586
587 bool isEmpty = index.row() == 0 && mAllowEmpty;
588 int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
589
590 switch ( role )
591 {
592 case Qt::CheckStateRole:
593 {
594 if ( !isEmpty && additionalIndex < 0 )
595 {
596 QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
597 mLayersChecked[layer->id()] = ( Qt::CheckState )value.toInt();
598 emit dataChanged( index, index, QVector< int >() << Qt::CheckStateRole );
599 return true;
600 }
601 break;
602 }
603
604 case static_cast< int >( CustomRole::LayerId ):
605 if ( !isEmpty && additionalIndex < 0 )
606 {
607 mLayers[index.row() - ( mAllowEmpty ? 1 : 0 )] = mProject->mapLayer( value.toString() );
608 emit dataChanged( index, index );
609 return true;
610 }
611 break;
612
613 default:
614 break;
615 }
616
617 return false;
618}
QString abstract() const
Returns a free-form description of the resource.
QString title() const
Returns the human readable name of the resource, typically displayed in search results.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
double coordinateEpoch() const
Returns the coordinate epoch, as a decimal year.
static QIcon iconForLayer(const QgsMapLayer *layer)
Returns the icon corresponding to a specified map layer.
QList< QPointer< QgsMapLayer > > mAdditionalLayers
void setShowCrs(bool showCrs)
Sets whether the CRS of layers is also included in the model's display role.
void setItemsCanBeReordered(bool allow)
Sets whether items in the model can be reordered via drag and drop.
QHash< int, QByteArray > roleNames() const override
Returns strings for all roles supported by this model.
Qt::ItemFlags flags(const QModelIndex &index) const override
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QList< QgsMapLayer * > layersChecked(Qt::CheckState checkState=Qt::Checked)
Returns the list of layers which are checked (or unchecked)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QModelIndex parent(const QModelIndex &child) const override
QgsProject * mProject
void setProject(QgsProject *project)
Sets the QgsProject from which map layers are shown.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QModelIndex indexFromLayer(QgsMapLayer *layer) const
indexFromLayer returns the model index for a given layer
void setAllowEmptyLayer(bool allowEmpty, const QString &text=QString(), const QIcon &icon=QIcon())
Sets whether an optional empty layer ("not set") option is present in the model.
void setAdditionalItems(const QStringList &items)
Sets a list of additional (non map layer) items to include at the end of the model.
QList< QgsMapLayer * > additionalLayers() const
Returns the list of additional layers added to the model.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setItemsCheckable(bool checkable)
Defines if layers should be selectable in the widget.
static QIcon iconForLayer(QgsMapLayer *layer)
Returns the icon corresponding to a specified map layer.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QgsMapLayer * layerFromIndex(const QModelIndex &index) const
Returns the map layer corresponding to the specified index.
Qt::DropActions supportedDropActions() const override
void setLayersChecked(const QList< QgsMapLayer * > &layers)
Sets which layers are checked in the model.
void checkAll(Qt::CheckState checkState)
checkAll changes the checkstate for all the layers
void removeLayers(const QStringList &layerIds)
QStringList mimeTypes() const override
@ Additional
True if index corresponds to an additional (non map layer) item.
@ Layer
Stores pointer to the map layer itself.
@ LayerId
Stores the map layer ID.
@ Empty
True if index corresponds to the empty (not set) value.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
bool itemsCanBeReordered() const
Returns true if items in the model can be reordered via drag and drop.
QMap< QString, Qt::CheckState > mLayersChecked
QgsMapLayerModel(QObject *parent=nullptr, QgsProject *project=nullptr)
QgsMapLayerModel creates a model to display layers in widgets.
QList< QgsMapLayer * > mLayers
void setAdditionalLayers(const QList< QgsMapLayer * > &layers)
Sets a list of additional layers to include in the model.
void addLayers(const QList< QgsMapLayer * > &layers)
QMimeData * mimeData(const QModelIndexList &indexes) const override
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QString abstract() const
Returns the abstract of the layerused by QGIS Server in GetCapabilities request.
Base class for all map layer types.
Definition qgsmaplayer.h:76
QString name
Definition qgsmaplayer.h:80
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:83
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
QString id
Definition qgsmaplayer.h:79
QgsLayerMetadata metadata
Definition qgsmaplayer.h:82
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Represents a vector layer which manages a vector based data sets.
static QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:5875