QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsmaplayerlistutils.h
Go to the documentation of this file.
1 #ifndef QGSMAPLAYERLISTUTILS_H
2 #define QGSMAPLAYERLISTUTILS_H
3 
4 //
5 // W A R N I N G
6 // -------------
7 //
8 // This file is not part of the QGIS API. It exists purely as an
9 // implementation detail. This header file may change from version to
10 // version without notice, or even be removed.
11 //
12 
13 #include <QPointer>
14 
15 #include "qgsmaplayer.h"
16 #include "qgsmaplayerref.h"
17 
19 
20 inline QList<QgsMapLayer *> _qgis_listRefToRaw( const QList< QgsMapLayerRef > &layers )
21 {
23  lst.reserve( layers.count() );
24  Q_FOREACH ( const QgsMapLayerRef &layer, layers )
25  {
26  if ( layer )
27  lst.append( layer.get() );
28  }
29  return lst;
30 }
31 
32 inline QList< QgsMapLayerRef > _qgis_listRawToRef( const QList<QgsMapLayer *> &layers )
33 {
35  lst.reserve( layers.count() );
36  Q_FOREACH ( QgsMapLayer *layer, layers )
37  {
38  lst.append( QgsMapLayerRef( layer ) );
39  }
40  return lst;
41 }
42 
43 inline void _qgis_removeLayers( QList< QgsMapLayerRef > &list, QList< QgsMapLayer *> layersToRemove )
44 {
46  while ( it.hasNext() )
47  {
48  QgsMapLayerRef &ref = it.next();
49  if ( layersToRemove.contains( ref.get() ) )
50  it.remove();
51  }
52 }
53 
54 
56 
57 #endif // QGSMAPLAYERLISTUTILS_H
Base class for all map layer types.
Definition: qgsmaplayer.h:49
Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet...
_LayerRef< QgsMapLayer > QgsMapLayerRef
void reserve(int alloc)
int count(const T &value) const
void append(const T &value)
bool contains(const T &value) const
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer...