QGIS API Documentation 3.41.0-Master (88383c3d16f)
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
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 if ( mProject == ( project ? project : QgsProject::instance() ) ) // skip-keyword-check
46 return;
47
48 // remove layers from previous project
49 if ( mProject )
50 {
51 removeLayers( mProject->mapLayers().keys() );
53 disconnect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
54 }
55
56 mProject = project ? project : QgsProject::instance(); // skip-keyword-check
57
59 connect( mProject, static_cast < void ( QgsProject::* )( const QStringList & ) >( &QgsProject::layersWillBeRemoved ), this, &QgsMapLayerModel::removeLayers );
60 addLayers( mProject->mapLayers().values() );
61}
62
63
65{
66 mItemCheckable = checkable;
67}
68
70{
71 mCanReorder = allow;
72}
73
75{
76 return mCanReorder;
77}
78
79void QgsMapLayerModel::checkAll( Qt::CheckState checkState )
80{
81 QMap<QString, Qt::CheckState>::iterator i = mLayersChecked.begin();
82 for ( ; i != mLayersChecked.end(); ++i )
83 {
84 *i = checkState;
85 }
86 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ) );
87}
88
89void QgsMapLayerModel::setAllowEmptyLayer( bool allowEmpty, const QString &text, const QIcon &icon )
90{
91 mEmptyText = text;
92 mEmptyIcon = icon;
93 if ( allowEmpty == mAllowEmpty )
94 return;
95
96 if ( allowEmpty )
97 {
98 beginInsertRows( QModelIndex(), 0, 0 );
99 mAllowEmpty = true;
100 endInsertRows();
101 }
102 else
103 {
104 beginRemoveRows( QModelIndex(), 0, 0 );
105 mAllowEmpty = false;
106 endRemoveRows();
107 }
108}
109
111{
112 if ( mShowCrs == showCrs )
113 return;
114
115 mShowCrs = showCrs;
116 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector<int>() << Qt::DisplayRole );
117}
118
119QList<QgsMapLayer *> QgsMapLayerModel::layersChecked( Qt::CheckState checkState )
120{
121 QList<QgsMapLayer *> layers;
122 const auto constMLayers = mLayers;
123 for ( QgsMapLayer *layer : constMLayers )
124 {
125 if ( mLayersChecked[layer->id()] == checkState )
126 {
127 layers.append( layer );
128 }
129 }
130 return layers;
131}
132
133void QgsMapLayerModel::setLayersChecked( const QList<QgsMapLayer *> &layers )
134{
135 QMap<QString, Qt::CheckState>::iterator i = mLayersChecked.begin();
136 for ( ; i != mLayersChecked.end(); ++i )
137 {
138 *i = Qt::Unchecked;
139 }
140 for ( const QgsMapLayer *layer : layers )
141 {
142 mLayersChecked[ layer->id() ] = Qt::Checked;
143 }
144 emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ), QVector<int>() << Qt::CheckStateRole );
145}
146
148{
149 int r = mLayers.indexOf( layer );
150 if ( r >= 0 && mAllowEmpty )
151 r++;
152 return index( r, 0 );
153}
154
155QgsMapLayer *QgsMapLayerModel::layerFromIndex( const QModelIndex &index ) const
156{
157 return mProject->mapLayer( index.data( static_cast< int >( CustomRole::LayerId ) ).toString() );
158}
159
160void QgsMapLayerModel::setAdditionalItems( const QStringList &items )
161{
162 if ( items == mAdditionalItems )
163 return;
164
165 int offset = 0;
166 if ( mAllowEmpty )
167 offset++;
168
169 offset += mLayers.count();
170
171 //remove existing
172 if ( !mAdditionalItems.isEmpty() )
173 {
174 beginRemoveRows( QModelIndex(), offset, offset + mAdditionalItems.count() - 1 );
175 mAdditionalItems.clear();
176 endRemoveRows();
177 }
178
179 //add new
180 beginInsertRows( QModelIndex(), offset, offset + items.count() - 1 );
181 mAdditionalItems = items;
182 endInsertRows();
183}
184
185void QgsMapLayerModel::setAdditionalLayers( const QList<QgsMapLayer *> &layers )
186{
187 if ( layers == _qgis_listQPointerToRaw( mAdditionalLayers ) )
188 return;
189
190 QStringList layerIdsToRemove;
191 for ( QgsMapLayer *layer : std::as_const( mAdditionalLayers ) )
192 {
193 if ( layer )
194 layerIdsToRemove << layer->id();
195 }
196 removeLayers( layerIdsToRemove );
197
198 for ( QgsMapLayer *layer : layers )
199 {
200 if ( layer )
201 {
202 addLayers( { layer } );
203 const QString layerId = layer->id();
204 connect( layer, &QgsMapLayer::willBeDeleted, this, [this, layerId] { removeLayers( {layerId} ); } );
205 }
206 }
207
208 mAdditionalLayers = _qgis_listRawToQPointer( layers );
209}
210
211QList<QgsMapLayer *> QgsMapLayerModel::additionalLayers() const
212{
213 return _qgis_listQPointerToRaw( mAdditionalLayers );
214}
215
216void QgsMapLayerModel::removeLayers( const QStringList &layerIds )
217{
218 int offset = 0;
219 if ( mAllowEmpty )
220 offset++;
221
222 for ( const QString &layerId : layerIds )
223 {
224 QModelIndex startIndex = index( 0, 0 );
225 QModelIndexList list = match( startIndex, static_cast< int >( CustomRole::LayerId ), layerId, 1 );
226 if ( !list.isEmpty() )
227 {
228 QModelIndex index = list[0];
229 beginRemoveRows( QModelIndex(), index.row(), index.row() );
230 mLayersChecked.remove( layerId );
231 mLayers.removeAt( index.row() - offset );
232 endRemoveRows();
233 }
234 }
235}
236
237void QgsMapLayerModel::addLayers( const QList<QgsMapLayer *> &layers )
238{
239 if ( !layers.empty( ) )
240 {
241 int offset = 0;
242 if ( mAllowEmpty )
243 offset++;
244
245 beginInsertRows( QModelIndex(), mLayers.count() + offset, mLayers.count() + layers.count() - 1 + offset );
246 const auto constLayers = layers;
247 for ( QgsMapLayer *layer : constLayers )
248 {
249 mLayers.append( layer );
250 mLayersChecked.insert( layer->id(), Qt::Unchecked );
251 }
252 endInsertRows();
253 }
254}
255
256QModelIndex QgsMapLayerModel::index( int row, int column, const QModelIndex &parent ) const
257{
258 int offset = 0;
259 if ( mAllowEmpty )
260 offset++;
261
262 if ( hasIndex( row, column, parent ) )
263 {
264 QgsMapLayer *layer = nullptr;
265 if ( row - offset >= 0 && row - offset < mLayers.count() )
266 layer = mLayers.at( row - offset );
267
268 return createIndex( row, column, layer );
269 }
270
271 return QModelIndex();
272
273}
274
275QModelIndex QgsMapLayerModel::parent( const QModelIndex &child ) const
276{
277 Q_UNUSED( child )
278 return QModelIndex();
279}
280
281
282int QgsMapLayerModel::rowCount( const QModelIndex &parent ) const
283{
284 if ( parent.isValid() )
285 return 0;
286
287 return ( mAllowEmpty ? 1 : 0 ) + mLayers.length() + mAdditionalItems.count();
288}
289
290int QgsMapLayerModel::columnCount( const QModelIndex &parent ) const
291{
292 Q_UNUSED( parent )
293 return 1;
294}
295
296
297QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
298{
299 if ( !index.isValid() )
300 return QVariant();
301
302 bool isEmpty = index.row() == 0 && mAllowEmpty;
303 int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
304
305 switch ( role )
306 {
307 case Qt::DisplayRole:
308 case Qt::EditRole:
309 {
310 if ( index.row() == 0 && mAllowEmpty )
311 return mEmptyText;
312
313 if ( additionalIndex >= 0 )
314 return mAdditionalItems.at( additionalIndex );
315
316 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
317 if ( !layer )
318 return QVariant();
319
320 if ( !mShowCrs || !layer->isSpatial() || role == Qt::EditRole )
321 {
322 return layer->name();
323 }
324 else
325 {
326 return tr( "%1 [%2]" ).arg( layer->name(), layer->crs().authid() );
327 }
328 }
329
330 case static_cast< int >( CustomRole::LayerId ):
331 {
332 if ( isEmpty || additionalIndex >= 0 )
333 return QVariant();
334
335 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
336 return layer ? layer->id() : QVariant();
337 }
338
339 case static_cast< int >( CustomRole::Layer ):
340 {
341 if ( isEmpty || additionalIndex >= 0 )
342 return QVariant();
343
344 return QVariant::fromValue<QgsMapLayer *>( mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) ) );
345 }
346
347 case static_cast< int >( CustomRole::Empty ):
348 return isEmpty;
349
350 case static_cast< int >( CustomRole::Additional ):
351 return additionalIndex >= 0;
352
353 case Qt::CheckStateRole:
354 {
355 if ( mItemCheckable )
356 {
357 if ( isEmpty || additionalIndex >= 0 )
358 return QVariant();
359
360 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
361 return layer ? mLayersChecked[layer->id()] : QVariant();
362 }
363
364 return QVariant();
365 }
366
367 case Qt::ToolTipRole:
368 {
369 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
370 if ( layer )
371 {
372 QStringList parts;
373 QString title = !layer->metadata().title().isEmpty() ? layer->metadata().title() : ( layer->serverProperties()->title().isEmpty() ? layer->serverProperties()->shortName() : layer->serverProperties()->title() );
374 if ( title.isEmpty() )
375 title = layer->name();
376 title = "<b>" + title + "</b>";
377 if ( layer->isSpatial() && layer->crs().isValid() )
378 {
379 QString layerCrs = layer->crs().authid();
380 if ( !std::isnan( layer->crs().coordinateEpoch() ) )
381 {
382 layerCrs += QStringLiteral( " @ %1" ).arg( qgsDoubleToString( layer->crs().coordinateEpoch(), 3 ) );
383 }
384 if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
385 title = tr( "%1 (%2 - %3)" ).arg( title, QgsWkbTypes::displayString( vl->wkbType() ), layerCrs );
386 else
387 title = tr( "%1 (%2)" ).arg( title, layerCrs );
388 }
389 parts << title;
390
391 QString abstract = !layer->metadata().abstract().isEmpty() ? layer->metadata().abstract() : layer->serverProperties()->abstract();
392 if ( !abstract.isEmpty() )
393 parts << "<br/>" + abstract.replace( QLatin1String( "\n" ), QLatin1String( "<br/>" ) );
394 parts << "<i>" + layer->publicSource() + "</i>";
395 return parts.join( QLatin1String( "<br/>" ) );
396 }
397 return QVariant();
398 }
399
400 case Qt::DecorationRole:
401 {
402 if ( isEmpty )
403 return mEmptyIcon.isNull() ? QVariant() : mEmptyIcon;
404
405 if ( additionalIndex >= 0 )
406 return QVariant();
407
408 QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
409 if ( !layer )
410 return QVariant();
411
412 return iconForLayer( layer );
413 }
414
415 default:
416 break;
417 }
418
419 return QVariant();
420}
421
422QHash<int, QByteArray> QgsMapLayerModel::roleNames() const
423{
424 QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
425 roles[static_cast< int >( CustomRole::LayerId ) ] = "layerId";
426 roles[static_cast< int >( CustomRole::Layer )] = "layer";
427
428 return roles;
429}
430
431Qt::ItemFlags QgsMapLayerModel::flags( const QModelIndex &index ) const
432{
433 if ( !index.isValid() )
434 {
435 if ( mCanReorder )
436 return Qt::ItemIsDropEnabled;
437 else
438 return Qt::ItemFlags();
439 }
440
441 bool isEmpty = index.row() == 0 && mAllowEmpty;
442 int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
443
444 Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
445
446 if ( mCanReorder && !isEmpty && additionalIndex < 0 )
447 {
448 flags |= Qt::ItemIsDragEnabled;
449 }
450
451 if ( mItemCheckable && !isEmpty && additionalIndex < 0 )
452 {
453 flags |= Qt::ItemIsUserCheckable;
454 }
455 return flags;
456}
457
458bool QgsMapLayerModel::insertRows( int row, int count, const QModelIndex &parent )
459{
460 if ( parent.isValid() )
461 return false;
462
463 int offset = 0;
464 if ( mAllowEmpty )
465 offset++;
466
467 beginInsertRows( parent, row, row + count - 1 );
468 for ( int i = row; i < row + count; ++i )
469 mLayers.insert( i - offset, nullptr );
470 endInsertRows();
471
472 return true;
473}
474
475bool QgsMapLayerModel::removeRows( int row, int count, const QModelIndex &parent )
476{
477 if ( parent.isValid() || row < 0 )
478 return false;
479
480 int offset = 0;
481 if ( mAllowEmpty )
482 {
483 if ( row == 0 )
484 return false;
485
486 offset++;
487 }
488
489 if ( row - offset > mLayers.count() - 1 )
490 {
491 return false;
492 }
493
494 beginRemoveRows( parent, row, row + count - 1 );
495 for ( int i = 0; i != count; ++i )
496 mLayers.removeAt( row - offset );
497 endRemoveRows();
498
499 return true;
500}
501
503{
504 QStringList types;
505 types << QStringLiteral( "application/qgis.layermodeldata" );
506 return types;
507}
508
509bool QgsMapLayerModel::canDropMimeData( const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex & ) const
510{
511 if ( !mCanReorder || action != Qt::MoveAction || !data->hasFormat( QStringLiteral( "application/qgis.layermodeldata" ) ) )
512 return false;
513 return true;
514}
515
516QMimeData *QgsMapLayerModel::mimeData( const QModelIndexList &indexes ) const
517{
518 auto mimeData = std::make_unique< QMimeData >();
519
520 QByteArray encodedData;
521 QDataStream stream( &encodedData, QIODevice::WriteOnly );
522 QSet< QString > addedLayers;
523
524 for ( const QModelIndex &i : indexes )
525 {
526 if ( i.isValid() )
527 {
528 const QString id = data( index( i.row(), 0, i.parent() ), static_cast< int >( CustomRole::LayerId ) ).toString();
529 if ( !addedLayers.contains( id ) )
530 {
531 addedLayers.insert( id );
532 stream << id;
533 }
534 }
535 }
536 mimeData->setData( QStringLiteral( "application/qgis.layermodeldata" ), encodedData );
537 return mimeData.release();
538}
539
540bool QgsMapLayerModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
541{
542 if ( !canDropMimeData( data, action, row, column, parent ) || row < 0 )
543 return false;
544
545 if ( action == Qt::IgnoreAction )
546 return true;
547 else if ( action != Qt::MoveAction )
548 return false;
549
550 QByteArray encodedData = data->data( QStringLiteral( "application/qgis.layermodeldata" ) );
551 QDataStream stream( &encodedData, QIODevice::ReadOnly );
552 QStringList newItems;
553 int rows = 0;
554
555 while ( !stream.atEnd() )
556 {
557 QString text;
558 stream >> text;
559 newItems << text;
560 ++rows;
561 }
562
563 insertRows( row, rows, QModelIndex() );
564 for ( const QString &text : std::as_const( newItems ) )
565 {
566 QModelIndex idx = index( row, 0, QModelIndex() );
567 setData( idx, text, static_cast< int >( CustomRole::LayerId ) );
568 row++;
569 }
570
571 return true;
572}
573
575{
576 return Qt::MoveAction;
577}
578
580{
581 return QgsIconUtils::iconForLayer( layer );
582}
583
584bool QgsMapLayerModel::setData( const QModelIndex &index, const QVariant &value, int role )
585{
586 if ( !index.isValid() )
587 return false;
588
589 bool isEmpty = index.row() == 0 && mAllowEmpty;
590 int additionalIndex = index.row() - ( mAllowEmpty ? 1 : 0 ) - mLayers.count();
591
592 switch ( role )
593 {
594 case Qt::CheckStateRole:
595 {
596 if ( !isEmpty && additionalIndex < 0 )
597 {
598 QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
599 mLayersChecked[layer->id()] = ( Qt::CheckState )value.toInt();
600 emit dataChanged( index, index, QVector< int >() << Qt::CheckStateRole );
601 return true;
602 }
603 break;
604 }
605
606 case static_cast< int >( CustomRole::LayerId ):
607 if ( !isEmpty && additionalIndex < 0 )
608 {
609 mLayers[index.row() - ( mAllowEmpty ? 1 : 0 )] = mProject->mapLayer( value.toString() );
610 emit dataChanged( index, index );
611 return true;
612 }
613 break;
614
615 default:
616 break;
617 }
618
619 return false;
620}
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:6042