Merge QgsMapLayerRegistry into QgsProject

All methods/signals of QgsMapLayerRegistry moved verbatim to QgsProject.
This commit is contained in:
Martin Dobias 2016-12-10 15:18:12 +08:00
parent 8ec3eaf456
commit d56a97d4fe
277 changed files with 1795 additions and 2009 deletions

View File

@ -250,6 +250,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
- removeLegendLayerAction() moved to QgisInterface::removeCustomActionForLayerType()
- QgsLegendModel was removed.
- QgsMapCanvasMap. It is an internal class used by map canvas.
- QgsMapLayerRegistry. Its functionality has been moved to QgsProject.
- QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.
- QgsPseudoColorShader. This shader has been broken for some time and was replaced by QgsSingleBandPseudoColorRenderer.
- QgsRendererV2DataDefinedMenus was removed. Use QgsDataDefinedButton instead.

View File

@ -83,7 +83,6 @@
%Include qgsmaplayerlegend.sip
%Include qgsmaplayermodel.sip
%Include qgsmaplayerproxymodel.sip
%Include qgsmaplayerregistry.sip
%Include qgsmaplayerrenderer.sip
%Include qgsmaplayerstylemanager.sip
%Include qgsmaprenderercache.sip

View File

@ -2,7 +2,7 @@
* Layer tree node points to a map layer.
*
* When using with existing QgsMapLayer instance, it is expected that the layer
* has been registered in QgsMapLayerRegistry earlier.
* has been registered in QgsProject earlier.
*
* The node can exist also without a valid instance of a layer (just ID). That
* means the referenced layer does not need to be loaded in order to use it

View File

@ -17,7 +17,7 @@ class QgsLayerTreeRegistryBridge : QObject
%End
public:
explicit QgsLayerTreeRegistryBridge( QgsLayerTreeGroup* root, QObject *parent /TransferThis/ = 0 );
explicit QgsLayerTreeRegistryBridge( QgsLayerTreeGroup* root, QgsProject* project, QObject *parent /TransferThis/ = 0 );
void setEnabled( bool enabled );
bool isEnabled() const;

View File

@ -54,7 +54,7 @@ class QgsMapLayer : QObject
*/
QgsMapLayer::LayerType type() const;
/** Returns the layer's unique ID, which is used to access this layer from QgsMapLayerRegistry. */
/** Returns the layer's unique ID, which is used to access this layer from QgsProject. */
QString id() const;
/**

View File

@ -1,297 +0,0 @@
/** \ingroup core
* \class QgsMapLayerRegistry
* This class tracks map layers that are currently loaded and provides
* various methods to retrieve matching layers from the registry.
*/
class QgsMapLayerRegistry : QObject
{
%TypeHeaderCode
#include <qgsmaplayerregistry.h>
%End
public:
//! Returns the instance pointer, creating the object on the first call
static QgsMapLayerRegistry * instance();
~QgsMapLayerRegistry();
//! Returns the number of registered layers.
int count() const;
/** Retrieve a pointer to a registered layer by layer ID.
* @param theLayerId ID of layer to retrieve
* @returns matching layer, or nullptr if no matching layer found
* @see mapLayersByName()
* @see mapLayers()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
QgsMapLayer* mapLayer( const QString& theLayerId ) const;
/** Retrieve a list of matching registered layers by layer name.
* @param layerName name of layers to match
* @returns list of matching layers
* @see mapLayer()
* @see mapLayers()
*/
QList<QgsMapLayer *> mapLayersByName( const QString& layerName ) const;
/** Returns a map of all registered layers by layer ID.
* @see mapLayer()
* @see mapLayersByName()
* @see layers()
*/
QMap<QString, QgsMapLayer*> mapLayers() const;
/**
* @brief
* Add a list of layers to the map of loaded layers.
*
* The layersAdded() and layerWasAdded() signals will always be emitted.
* The legendLayersAdded() signal is emitted only if addToLegend is true.
*
* @param theMapLayers A list of layer which should be added to the registry
* @param addToLegend If true (by default), the layers will be added to the
* legend and to the main canvas. If you have a private
* layer you can set this parameter to false to hide it.
* @param takeOwnership Ownership will be transferred to the layer registry.
* If you specify false here you have take care of deleting
* the layers yourself. Not available in python.
*
* @return a list of the map layers that were added
* successfully. If a layer is invalid, or already exists in the registry,
* it will not be part of the returned QList.
*
* @note As a side-effect QgsProject is made dirty.
* @note takeOwnership is not available in the Python bindings - the registry will always
* take ownership
* @note added in QGIS 1.8
* @see addMapLayer()
*/
QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *>& theMapLayers /Transfer/,
bool addToLegend = true );
/**
* @brief
* Add a layer to the map of loaded layers.
*
* The layersAdded() and layerWasAdded() signals will always be emitted.
* The legendLayersAdded() signal is emitted only if addToLegend is true.
* If you are adding multiple layers at once, you should use
* addMapLayers() instead.
*
* @param theMapLayer A layer to add to the registry
* @param addToLegend If true (by default), the layer will be added to the
* legend and to the main canvas. If you have a private
* layer you can set this parameter to false to hide it.
* @param takeOwnership Ownership will be transferred to the layer registry.
* If you specify false here you have take care of deleting
* the layer yourself. Not available in python.
*
* @return nullptr if unable to add layer, otherwise pointer to newly added layer
*
* @see addMapLayers
*
* @note As a side-effect QgsProject is made dirty.
* @note Use addMapLayers if adding more than one layer at a time
* @note takeOwnership is not available in the Python bindings - the registry will always
* take ownership
* @see addMapLayers()
*/
QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer /Transfer/, bool addToLegend = true );
/**
* @brief
* Remove a set of layers from the registry by layer ID.
*
* The specified layers will be removed from the registry. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @param theLayerIds list of IDs of the layers to remove
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @note added in QGIS 1.8
* @see removeMapLayer()
* @see removeAllMapLayers()
*/
// TODO QGIS 3.0 - rename theLayerIds to layerIds
void removeMapLayers( const QStringList& theLayerIds );
/**
* @brief
* Remove a set of layers from the registry.
*
* The specified layers will be removed from the registry. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @param layers A list of layers to remove. Null pointers are ignored.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayer()
* @see removeAllMapLayers()
*/
void removeMapLayers( const QList<QgsMapLayer*>& layers );
/**
* @brief
* Remove a layer from the registry by layer ID.
*
* The specified layer will be removed from the registry. If the registry has ownership
* of the layer then it will also be deleted.
*
* @param theLayerId ID of the layer to remove
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayers()
* @see removeAllMapLayers()
*/
// TODO QGIS 3.0 - rename theLayerId to layerId
void removeMapLayer( const QString& theLayerId );
/**
* @brief
* Remove a layer from the registry.
*
* The specified layer will be removed from the registry. If the registry has ownership
* of the layer then it will also be deleted.
*
* @param layer The layer to remove. Null pointers are ignored.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayers()
* @see removeAllMapLayers()
*/
void removeMapLayer( QgsMapLayer* layer );
/**
* Removes all registered layers. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @note Calling this method will cause the removeAll() signal to
* be emitted.
* @see removeMapLayer()
* @see removeMapLayers()
*/
void removeAllMapLayers();
/**
* Reload all registered layer's provider data caches, synchronising the layer
* with any changes in the datasource.
* @see QgsMapLayer::reload()
*/
void reloadAllLayers();
signals:
/**
* Emitted when one or more layers are about to be removed from the registry.
*
* @param theLayerIds A list of IDs for the layers which are to be removed.
* @see layerWillBeRemoved()
* @see layersRemoved()
*/
// TODO QGIS 3.0 - rename theLayerIds to layerIds
void layersWillBeRemoved( const QStringList& theLayerIds );
/**
* Emitted when one or more layers are about to be removed from the registry.
*
* @param layers A list of layers which are to be removed.
* @see layerWillBeRemoved()
* @see layersRemoved()
*/
void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
/**
* Emitted when a layer is about to be removed from the registry.
*
* @param theLayerId The ID of the layer to be removed.
*
* @note Consider using {@link layersWillBeRemoved()} instead
* @see layersWillBeRemoved()
* @see layerRemoved()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
void layerWillBeRemoved( const QString& theLayerId );
/**
* Emitted when a layer is about to be removed from the registry.
*
* @param layer The layer to be removed.
*
* @note Consider using {@link layersWillBeRemoved()} instead
* @see layersWillBeRemoved()
* @see layerRemoved()
*/
void layerWillBeRemoved( QgsMapLayer* layer );
/**
* Emitted after one or more layers were removed from the registry.
*
* @param theLayerIds A list of IDs of the layers which were removed.
* @see layersWillBeRemoved()
*/
//TODO QGIS 3.0 - rename theLayerIds to layerIds
void layersRemoved( const QStringList& theLayerIds );
/**
* Emitted after a layer was removed from the registry.
*
* @param theLayerId The ID of the layer removed.
*
* @note Consider using {@link layersRemoved()} instead
* @see layerWillBeRemoved()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
void layerRemoved( const QString& theLayerId );
/**
* Emitted when all layers are removed, before {@link layersWillBeRemoved()} and
* {@link layerWillBeRemoved()} signals are emitted. The layersWillBeRemoved() and
* layerWillBeRemoved() signals will still be emitted following this signal.
* You can use this signal to do easy (and fast) cleanup.
*/
//TODO QGIS 3.0 - rename to past tense
void removeAll();
/**
* Emitted when one or more layers were added to the registry.
* This signal is also emitted for layers added to the registry,
* but not to the legend.
*
* @param theMapLayers List of layers which have been added.
*
* @see legendLayersAdded()
* @see layerWasAdded()
*/
//TODO QGIS 3.0 - rename theMapLayers to mapLayers
void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
/**
* Emitted when a layer was added to the registry.
*
* @param theMapLayer The ID of the layer which has been added.
*
* @note Consider using {@link layersAdded()} instead
* @see layersAdded()
*/
// TODO QGIS 3.0 - rename theMapLayer to layer
void layerWasAdded( QgsMapLayer* theMapLayer );
/**
* Emitted, when a layer was added to the registry and the legend.
* Layers can also be private layers, which are signalled by
* {@link layersAdded()} and {@link layerWasAdded()} but will not be
* advertised by this signal.
*
* @param theMapLayers List of {@link QgsMapLayer}s which were added to the legend.
*/
//TODO QGIS 3.0 rename theMapLayers to mapLayers
void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
private:
//! private singleton constructor
QgsMapLayerRegistry();
void connectNotify( const char * signal );
};

View File

@ -55,7 +55,7 @@ class QgsMapSettings
//! Get list of layer IDs for map rendering
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
QStringList layers() const;
//! Set list of layer IDs for map rendering. The layers must be registered in QgsMapLayerRegistry.
//! Set list of layer IDs for map rendering. The layers must be registered in QgsProject.
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
void setLayers( const QStringList& layers );

View File

@ -61,7 +61,7 @@ class QgsMapThemeCollection : QObject
};
QgsMapThemeCollection();
QgsMapThemeCollection( QgsProject* project );
/**
* Returns whether a map theme with a matching name exists.

View File

@ -426,6 +426,176 @@ class QgsProject : QObject, QgsExpressionContextGenerator
*/
void setVariables( const QgsStringMap& variables );
//
// Functionality from QgsMapLayerRegistry
//
//! Returns the number of registered layers.
int count() const;
/** Retrieve a pointer to a registered layer by layer ID.
* @param theLayerId ID of layer to retrieve
* @returns matching layer, or nullptr if no matching layer found
* @see mapLayersByName()
* @see mapLayers()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
QgsMapLayer* mapLayer( const QString& theLayerId ) const;
/** Retrieve a list of matching registered layers by layer name.
* @param layerName name of layers to match
* @returns list of matching layers
* @see mapLayer()
* @see mapLayers()
*/
QList<QgsMapLayer *> mapLayersByName( const QString& layerName ) const;
/** Returns a map of all registered layers by layer ID.
* @see mapLayer()
* @see mapLayersByName()
* @see layers()
*/
QMap<QString, QgsMapLayer*> mapLayers() const;
/**
* @brief
* Add a list of layers to the map of loaded layers.
*
* The layersAdded() and layerWasAdded() signals will always be emitted.
* The legendLayersAdded() signal is emitted only if addToLegend is true.
*
* @param theMapLayers A list of layer which should be added to the registry
* @param addToLegend If true (by default), the layers will be added to the
* legend and to the main canvas. If you have a private
* layer you can set this parameter to false to hide it.
* @param takeOwnership Ownership will be transferred to the layer registry.
* If you specify false here you have take care of deleting
* the layers yourself. Not available in python.
*
* @return a list of the map layers that were added
* successfully. If a layer is invalid, or already exists in the registry,
* it will not be part of the returned QList.
*
* @note As a side-effect QgsProject is made dirty.
* @note takeOwnership is not available in the Python bindings - the registry will always
* take ownership
* @note added in QGIS 1.8
* @see addMapLayer()
*/
QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *>& theMapLayers /Transfer/,
bool addToLegend = true );
/**
* @brief
* Add a layer to the map of loaded layers.
*
* The layersAdded() and layerWasAdded() signals will always be emitted.
* The legendLayersAdded() signal is emitted only if addToLegend is true.
* If you are adding multiple layers at once, you should use
* addMapLayers() instead.
*
* @param theMapLayer A layer to add to the registry
* @param addToLegend If true (by default), the layer will be added to the
* legend and to the main canvas. If you have a private
* layer you can set this parameter to false to hide it.
* @param takeOwnership Ownership will be transferred to the layer registry.
* If you specify false here you have take care of deleting
* the layer yourself. Not available in python.
*
* @return nullptr if unable to add layer, otherwise pointer to newly added layer
*
* @see addMapLayers
*
* @note As a side-effect QgsProject is made dirty.
* @note Use addMapLayers if adding more than one layer at a time
* @note takeOwnership is not available in the Python bindings - the registry will always
* take ownership
* @see addMapLayers()
*/
QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer /Transfer/, bool addToLegend = true );
/**
* @brief
* Remove a set of layers from the registry by layer ID.
*
* The specified layers will be removed from the registry. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @param theLayerIds list of IDs of the layers to remove
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @note added in QGIS 1.8
* @see removeMapLayer()
* @see removeAllMapLayers()
*/
// TODO QGIS 3.0 - rename theLayerIds to layerIds
void removeMapLayers( const QStringList& theLayerIds );
/**
* @brief
* Remove a set of layers from the registry.
*
* The specified layers will be removed from the registry. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @param layers A list of layers to remove. Null pointers are ignored.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayer()
* @see removeAllMapLayers()
*/
void removeMapLayers( const QList<QgsMapLayer*>& layers );
/**
* @brief
* Remove a layer from the registry by layer ID.
*
* The specified layer will be removed from the registry. If the registry has ownership
* of the layer then it will also be deleted.
*
* @param theLayerId ID of the layer to remove
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayers()
* @see removeAllMapLayers()
*/
// TODO QGIS 3.0 - rename theLayerId to layerId
void removeMapLayer( const QString& theLayerId );
/**
* @brief
* Remove a layer from the registry.
*
* The specified layer will be removed from the registry. If the registry has ownership
* of the layer then it will also be deleted.
*
* @param layer The layer to remove. Null pointers are ignored.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayers()
* @see removeAllMapLayers()
*/
void removeMapLayer( QgsMapLayer* layer );
/**
* Removes all registered layers. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @note Calling this method will cause the removeAll() signal to
* be emitted.
* @see removeMapLayer()
* @see removeMapLayers()
*/
void removeAllMapLayers();
/**
* Reload all registered layer's provider data caches, synchronising the layer
* with any changes in the datasource.
* @see QgsMapLayer::reload()
*/
void reloadAllLayers();
signals:
//! emitted when project is being read
void readProject( const QDomDocument& );
@ -520,6 +690,116 @@ class QgsProject : QObject, QgsExpressionContextGenerator
*/
void mapThemeCollectionChanged();
//
// signals from QgsMapLayerRegistry
//
/**
* Emitted when one or more layers are about to be removed from the registry.
*
* @param theLayerIds A list of IDs for the layers which are to be removed.
* @see layerWillBeRemoved()
* @see layersRemoved()
*/
// TODO QGIS 3.0 - rename theLayerIds to layerIds
void layersWillBeRemoved( const QStringList& theLayerIds );
/**
* Emitted when one or more layers are about to be removed from the registry.
*
* @param layers A list of layers which are to be removed.
* @see layerWillBeRemoved()
* @see layersRemoved()
*/
void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
/**
* Emitted when a layer is about to be removed from the registry.
*
* @param theLayerId The ID of the layer to be removed.
*
* @note Consider using {@link layersWillBeRemoved()} instead
* @see layersWillBeRemoved()
* @see layerRemoved()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
void layerWillBeRemoved( const QString& theLayerId );
/**
* Emitted when a layer is about to be removed from the registry.
*
* @param layer The layer to be removed.
*
* @note Consider using {@link layersWillBeRemoved()} instead
* @see layersWillBeRemoved()
* @see layerRemoved()
*/
void layerWillBeRemoved( QgsMapLayer* layer );
/**
* Emitted after one or more layers were removed from the registry.
*
* @param theLayerIds A list of IDs of the layers which were removed.
* @see layersWillBeRemoved()
*/
//TODO QGIS 3.0 - rename theLayerIds to layerIds
void layersRemoved( const QStringList& theLayerIds );
/**
* Emitted after a layer was removed from the registry.
*
* @param theLayerId The ID of the layer removed.
*
* @note Consider using {@link layersRemoved()} instead
* @see layerWillBeRemoved()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
void layerRemoved( const QString& theLayerId );
/**
* Emitted when all layers are removed, before {@link layersWillBeRemoved()} and
* {@link layerWillBeRemoved()} signals are emitted. The layersWillBeRemoved() and
* layerWillBeRemoved() signals will still be emitted following this signal.
* You can use this signal to do easy (and fast) cleanup.
*/
//TODO QGIS 3.0 - rename to past tense
void removeAll();
/**
* Emitted when one or more layers were added to the registry.
* This signal is also emitted for layers added to the registry,
* but not to the legend.
*
* @param theMapLayers List of layers which have been added.
*
* @see legendLayersAdded()
* @see layerWasAdded()
*/
//TODO QGIS 3.0 - rename theMapLayers to mapLayers
void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
/**
* Emitted when a layer was added to the registry.
*
* @param theMapLayer The ID of the layer which has been added.
*
* @note Consider using {@link layersAdded()} instead
* @see layersAdded()
*/
// TODO QGIS 3.0 - rename theMapLayer to layer
void layerWasAdded( QgsMapLayer* theMapLayer );
/**
* Emitted, when a layer was added to the registry and the legend.
* Layers can also be private layers, which are signalled by
* {@link layersAdded()} and {@link layerWasAdded()} but will not be
* advertised by this signal.
*
* @param theMapLayers List of {@link QgsMapLayer}s which were added to the legend.
*/
//TODO QGIS 3.0 rename theMapLayers to mapLayers
void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
public slots:
/**
* Flag the project as dirty (modified). If this flag is set, the user will

View File

@ -87,7 +87,7 @@ class QgsSnappingConfig
/**
* Constructor with default parameters defined in global settings
*/
explicit QgsSnappingConfig();
explicit QgsSnappingConfig( QgsProject* project );
~QgsSnappingConfig();

View File

@ -37,7 +37,7 @@ __revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import QObject, QSettings, QFileInfo, QDir, QCoreApplication, pyqtSignal
from qgis.PyQt.QtWidgets import QFileDialog
from qgis.core import QgsApplication, QgsMapLayerRegistry, QgsRectangle, QgsProviderRegistry, QgsLogger, QgsProject
from qgis.core import QgsApplication, QgsRectangle, QgsProviderRegistry, QgsLogger, QgsProject
from qgis.gui import QgsEncodingFileDialog
from osgeo import gdal, ogr, osr
@ -182,9 +182,9 @@ class LayerRegistry(QObject):
LayerRegistry.layers = self.getAllLayers()
LayerRegistry._instance = self
QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers)
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.layerAdded)
QgsMapLayerRegistry.instance().layerWillBeRemoved.connect(self.removeLayer)
QgsProject.instance().removeAll.connect(self.removeAllLayers)
QgsProject.instance().layerWasAdded.connect(self.layerAdded)
QgsProject.instance().layerWillBeRemoved.connect(self.removeLayer)
def getAllLayers(self):
return list(node.layer() for node in QgsProject.instance().layerTreeRoot().findLayers())

View File

@ -26,7 +26,7 @@ __revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import Qt, QCoreApplication, QFile, QFileInfo
from qgis.PyQt.QtWidgets import QWidget, QMessageBox
from qgis.core import QgsMapLayerRegistry, QgsMapLayer
from qgis.core import QgsProject, QgsMapLayer
from .ui_widgetProjection import Ui_GdalToolsWidget as Ui_Widget
from .widgetBatchBase import GdalToolsBaseBatchWidget as BaseBatchWidget
@ -164,7 +164,7 @@ class GdalToolsDialog(QWidget, Ui_Widget, BaseBatchWidget):
def checkLayer(self):
layerList = []
layerMap = QgsMapLayerRegistry.instance().mapLayers()
layerMap = QgsProject.instance().mapLayers()
for name, layer in layerMap.items():
if layer.type() == QgsMapLayer.RasterLayer:
layerList.append(str(layer.source()))

View File

@ -27,7 +27,7 @@ __revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import Qt, pyqtSignal, pyqtProperty
from qgis.PyQt.QtWidgets import QWidget, QComboBox
from qgis.core import QgsMapLayerRegistry, QgsMapLayer
from qgis.core import QgsProject, QgsMapLayer
from .ui_inOutSelector import Ui_GdalToolsInOutSelector
@ -233,7 +233,7 @@ class GdalToolsInOutSelector(QWidget, Ui_GdalToolsInOutSelector):
def layer(self):
if self.getType() != self.FILE and self.combo.currentIndex() >= 0:
layerID = self.combo.itemData(self.combo.currentIndex())
return QgsMapLayerRegistry.instance().mapLayer(layerID)
return QgsProject.instance().mapLayer(layerID)
return None
def filename(self):

View File

@ -25,7 +25,7 @@ from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QAction, QApplication
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsMapLayerRegistry, QgsMapLayer, QgsDataSourceUri
from qgis.core import QgsProject, QgsMapLayer, QgsDataSourceUri
import re
from . import resources_rc # NOQA
@ -57,9 +57,9 @@ class DBManagerPlugin(object):
self.layerAction.setObjectName("dbManagerUpdateSqlLayer")
self.layerAction.triggered.connect(self.onUpdateSqlLayer)
self.iface.addCustomActionForLayerType(self.layerAction, "", QgsMapLayer.VectorLayer, False)
for l in list(QgsMapLayerRegistry.instance().mapLayers().values()):
for l in list(QgsProject.instance().mapLayers().values()):
self.onLayerWasAdded(l)
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.onLayerWasAdded)
QgsProject.instance().layerWasAdded.connect(self.onLayerWasAdded)
def unload(self):
# Remove the plugin menu item and icon
@ -73,7 +73,7 @@ class DBManagerPlugin(object):
self.iface.removeToolBarIcon(self.action)
self.iface.removeCustomActionForLayerType(self.layerAction)
QgsMapLayerRegistry.instance().layerWasAdded.disconnect(self.onLayerWasAdded)
QgsProject.instance().layerWasAdded.disconnect(self.onLayerWasAdded)
if self.dlg is not None:
self.dlg.close()

View File

@ -24,7 +24,7 @@ from builtins import str
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsMapLayerRegistry, QgsVectorLayer, Qgis, QgsWkbTypes
from qgis.core import QgsProject, QgsVectorLayer, Qgis, QgsWkbTypes
from qgis.gui import QgsMessageBar
import os
@ -227,7 +227,7 @@ def run(item, action, mainwindow):
nodeLayers = [layerNode, layerNodeLabel]
edgeLayers = [layerEdge, layerDirectedEdge, layerEdgeLabel, layerEdgeFaceLeft, layerEdgeFaceRight, layerEdgeNextLeft, layerEdgeNextRight]
QgsMapLayerRegistry.instance().addMapLayers(faceLayers, False)
QgsProject.instance().addMapLayers(faceLayers, False)
groupFaces = QgsLayerTreeGroup(u'Faces')
for layer in faceLayers:

View File

@ -26,7 +26,7 @@ from qgis.PyQt.QtCore import QUrl, QTemporaryFile
from ..connector import DBConnector
from ..plugin import Table
from qgis.core import Qgis, QgsDataSourceUri, QgsVirtualLayerDefinition, QgsMapLayerRegistry, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsWkbTypes
from qgis.core import Qgis, QgsDataSourceUri, QgsVirtualLayerDefinition, QgsProject, QgsMapLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsWkbTypes
import sqlite3
@ -98,7 +98,7 @@ class VLayerRegistry(object):
lid = self.layers.get(l)
if lid is None:
return lid
return QgsMapLayerRegistry.instance().mapLayer(lid)
return QgsProject.instance().mapLayer(lid)
class VLayerConnector(DBConnector):
@ -190,7 +190,7 @@ class VLayerConnector(DBConnector):
reg = VLayerRegistry.instance()
VLayerRegistry.instance().reset()
lst = []
for _, l in list(QgsMapLayerRegistry.instance().mapLayers().items()):
for _, l in list(QgsProject.instance().mapLayers().items()):
if l.type() == QgsMapLayer.VectorLayer:
lname = l.name()
@ -277,7 +277,7 @@ class VLayerConnector(DBConnector):
def getTableExtent(self, table, geom):
is_id, t = table
if is_id:
l = QgsMapLayerRegistry.instance().mapLayer(t)
l = QgsProject.instance().mapLayer(t)
else:
l = VLayerRegistry.instance().getLayer(t)
e = l.extent()

View File

@ -24,7 +24,7 @@ from .connector import VLayerConnector
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsVirtualLayerDefinition
from qgis.core import QgsVectorLayer, QgsProject, QgsVirtualLayerDefinition
from ..plugin import DBPlugin, Database, Table, VectorTable, TableField
@ -178,7 +178,7 @@ class LVectorTable(LTable, VectorTable):
return
def toMapLayer(self):
return QgsMapLayerRegistry.instance().mapLayer(self.geomTableName)
return QgsProject.instance().mapLayer(self.geomTableName)
class LTableField(TableField):

View File

@ -23,7 +23,7 @@ email : brush.tyler@gmail.com
from qgis.PyQt.QtCore import pyqtSignal
from qgis.PyQt.QtWidgets import QWidget, QTreeView, QMenu, QLabel
from qgis.core import QgsMapLayerRegistry, QgsMessageLog
from qgis.core import QgsProject, QgsMessageLog
from qgis.gui import QgsMessageBar, QgsMessageBarItem
from .db_model import DBModel, PluginItem
@ -161,7 +161,7 @@ class DBTree(QTreeView):
table = self.currentTable()
if table is not None:
layer = table.toMapLayer()
layers = QgsMapLayerRegistry.instance().addMapLayers([layer])
layers = QgsProject.instance().addMapLayers([layer])
if len(layers) != 1:
QgsMessageLog.logMessage(
self.tr("%1 is an invalid layer - not loaded").replace("%1", layer.publicSource()))

View File

@ -28,7 +28,7 @@ from qgis.PyQt.QtCore import Qt, QSettings, QFileInfo
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QApplication
from qgis.PyQt.QtGui import QCursor
from qgis.core import QgsDataSourceUri, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils, QgsMapLayer, QgsProviderRegistry, QgsCoordinateReferenceSystem, QgsVectorLayerImport, QgsProject, QgsMapLayerRegistry
from qgis.core import QgsDataSourceUri, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils, QgsMapLayer, QgsProviderRegistry, QgsCoordinateReferenceSystem, QgsVectorLayerImport, QgsProject
from qgis.gui import QgsMessageViewer
from qgis.utils import iface
@ -183,7 +183,7 @@ class DlgImportVector(QDialog, Ui_Dialog):
else:
layerId = self.cboInputLayer.itemData(index)
self.inLayer = QgsMapLayerRegistry.instance().mapLayer(layerId)
self.inLayer = QgsProject.instance().mapLayer(layerId)
self.inLayerMustBeDestroyed = False
self.checkSupports()

View File

@ -284,13 +284,13 @@ class DlgSqlLayerWindow(QWidget, Ui_Dialog):
if query.strip().endswith(';'):
query = query.strip()[:-1]
from qgis.core import QgsMapLayer, QgsMapLayerRegistry
from qgis.core import QgsMapLayer
layerType = QgsMapLayer.VectorLayer if self.vectorRadio.isChecked() else QgsMapLayer.RasterLayer
# get a new layer name
names = []
for layer in list(QgsMapLayerRegistry.instance().mapLayers().values()):
for layer in list(QgsProject.instance().mapLayers().values()):
names.append(layer.name())
layerName = self.layerNameEdit.text()
@ -317,8 +317,7 @@ class DlgSqlLayerWindow(QWidget, Ui_Dialog):
if layer == None:
return
from qgis.core import QgsMapLayerRegistry
QgsMapLayerRegistry.instance().addMapLayers([layer], True)
QgsProject.instance().addMapLayers([layer], True)
finally:
QApplication.restoreOverrideCursor()

View File

@ -243,13 +243,13 @@ class DlgSqlWindow(QWidget, Ui_Dialog):
if query.strip().endswith(';'):
query = query.strip()[:-1]
from qgis.core import QgsMapLayer, QgsMapLayerRegistry
from qgis.core import QgsMapLayer
layerType = QgsMapLayer.VectorLayer if self.vectorRadio.isChecked() else QgsMapLayer.RasterLayer
# get a new layer name
names = []
for layer in list(QgsMapLayerRegistry.instance().mapLayers().values()):
for layer in list(QgsProject.instance().mapLayers().values()):
names.append(layer.name())
layerName = self.layerNameEdit.text()
@ -276,8 +276,7 @@ class DlgSqlWindow(QWidget, Ui_Dialog):
if layer is None:
return
from qgis.core import QgsMapLayerRegistry
QgsMapLayerRegistry.instance().addMapLayers([layer], True)
QgsProject.instance().addMapLayers([layer], True)
finally:
QApplication.restoreOverrideCursor()

View File

@ -25,7 +25,7 @@ from qgis.PyQt.QtGui import QColor, QCursor
from qgis.PyQt.QtWidgets import QApplication
from qgis.gui import QgsMapCanvas, QgsMapCanvasLayer, QgsMessageBar
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
from qgis.core import QgsVectorLayer, QgsProject
from .db_plugins.plugin import Table
@ -119,11 +119,11 @@ class LayerPreview(QgsMapCanvas):
# remove old layer (if any) and set new
if self.currentLayer:
QgsMapLayerRegistry.instance().removeMapLayers([self.currentLayer.id()])
QgsProject.instance().removeMapLayers([self.currentLayer.id()])
if vl:
self.setLayerSet([QgsMapCanvasLayer(vl)])
QgsMapLayerRegistry.instance().addMapLayers([vl], False)
QgsProject.instance().addMapLayers([vl], False)
self.zoomToFullExtent()
else:
self.setLayerSet([])

View File

@ -25,7 +25,6 @@ __copyright__ = '(C) 2015, Victor Olaya'
__revision__ = '$Format:%H$'
from qgis.core import QgsMapLayerRegistry
from qgis.PyQt.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QPlainTextEdit, QLineEdit, QComboBox, QCheckBox
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase

View File

@ -34,7 +34,7 @@ import os
from .LAStoolsUtils import LAStoolsUtils
from processing.core.parameters import ParameterExtent
from .LAStoolsAlgorithm import LAStoolsAlgorithm
from qgis.core import QgsMapLayer, QgsMapLayerRegistry
from qgis.core import QgsMapLayer, QgsProject
class lasquery(LAStoolsAlgorithm):
@ -58,7 +58,7 @@ class lasquery(LAStoolsAlgorithm):
aoiCoords = aoi.split(',')
# get layers
layers = QgsMapLayerRegistry.instance().mapLayers()
layers = QgsProject.instance().mapLayers()
# loop over layers
for name, layer in list(layers.items()):

View File

@ -31,7 +31,7 @@ from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout, QSizePolicy
from qgis.PyQt.QtGui import QCursor, QColor, QPalette
from qgis.core import QgsMapLayerRegistry
from qgis.core import QgsProject
from qgis.gui import QgsMessageBar
from qgis.utils import iface
@ -246,6 +246,6 @@ class AlgorithmDialog(AlgorithmDialogBase):
'\nOpen the results dialog to check it.'))
def closeEvent(self, evt):
QgsMapLayerRegistry.instance().layerWasAdded.disconnect(self.mainWidget.layerRegistryChanged)
QgsMapLayerRegistry.instance().layersWillBeRemoved.disconnect(self.mainWidget.layerRegistryChanged)
QgsProject.instance().layerWasAdded.disconnect(self.mainWidget.layerRegistryChanged)
QgsProject.instance().layersWillBeRemoved.disconnect(self.mainWidget.layerRegistryChanged)
super(AlgorithmDialog, self).closeEvent(evt)

View File

@ -35,7 +35,7 @@ from qgis.PyQt.QtWidgets import QApplication, QDialogButtonBox, QDesktopWidget
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
from qgis.utils import iface
from qgis.core import QgsNetworkAccessManager, QgsMapLayerRegistry
from qgis.core import QgsNetworkAccessManager, QgsProject
from processing.core.ProcessingConfig import ProcessingConfig
@ -124,12 +124,12 @@ class AlgorithmDialogBase(BASE, WIDGET):
def setMainWidget(self, widget):
if self.mainWidget is not None:
QgsMapLayerRegistry.instance().layerWasAdded.disconnect(self.mainWidget.layerRegistryChanged)
QgsMapLayerRegistry.instance().layersWillBeRemoved.disconnect(self.mainWidget.layerRegistryChanged)
QgsProject.instance().layerWasAdded.disconnect(self.mainWidget.layerRegistryChanged)
QgsProject.instance().layersWillBeRemoved.disconnect(self.mainWidget.layerRegistryChanged)
self.mainWidget = widget
self.tabWidget.widget(0).layout().addWidget(self.mainWidget)
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerRegistryChanged)
QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layerRegistryChanged)
QgsProject.instance().layerWasAdded.connect(self.mainWidget.layerRegistryChanged)
QgsProject.instance().layersWillBeRemoved.connect(self.mainWidget.layerRegistryChanged)
def error(self, msg):
QApplication.restoreOverrideCursor()

View File

@ -62,7 +62,7 @@ class CommanderWindow(QDialog):
out.write('from qgis.core import *\n')
out.write('import processing\n\n')
out.write('def removeall():\n')
out.write('\tmapreg = QgsMapLayerRegistry.instance()\n')
out.write('\tmapreg = QgsProject.instance()\n')
out.write('\tmapreg.removeAllMapLayers()\n\n')
out.write('def load(*args):\n')
out.write('\tprocessing.load(args[0])\n')

View File

@ -33,7 +33,7 @@ __revision__ = '$Format:%H$'
import os
import locale
from qgis.core import QgsMapLayerRegistry, QgsMapLayer
from qgis.core import QgsMapLayer
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication, QVariant

View File

@ -30,7 +30,7 @@ import os
import traceback
from qgis.PyQt.QtWidgets import QApplication
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import QgsMapLayerRegistry
from qgis.core import QgsProject
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingResults import ProcessingResults
@ -63,7 +63,7 @@ def handleAlgorithmResults(alg, progress=None, showResults=True):
try:
if hasattr(out, "layer") and out.layer is not None:
out.layer.setName(out.description)
QgsMapLayerRegistry.instance().addMapLayers([out.layer])
QgsProject.instance().addMapLayers([out.layer])
else:
if ProcessingConfig.getSetting(
ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):

View File

@ -57,7 +57,7 @@ from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvid
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider
from qgis.core import QgsVectorLayer, QgsRasterLayer, QgsMapLayerRegistry
from qgis.core import QgsVectorLayer, QgsRasterLayer, QgsProject
from qgis.testing import _UnexpectedSuccess
@ -87,7 +87,7 @@ class AlgorithmsTest(object):
:param name: The identifier name used in the test output heading
:param defs: A python dict containing a test algorithm definition
"""
QgsMapLayerRegistry.instance().removeAllMapLayers()
QgsProject.instance().removeAllMapLayers()
params = self.load_params(defs['params'])
@ -181,7 +181,7 @@ class AlgorithmsTest(object):
lyr = QgsRasterLayer(filepath, param['name'], 'gdal')
self.assertTrue(lyr.isValid(), 'Could not load layer "{}"'.format(filepath))
QgsMapLayerRegistry.instance().addMapLayer(lyr)
QgsProject.instance().addMapLayer(lyr)
return lyr
def filepath_from_param(self, param):

View File

@ -38,7 +38,7 @@ from qgis.core import (Qgis,
QgsRasterLayer,
QgsWkbTypes,
QgsVectorLayer,
QgsMapLayerRegistry,
QgsProject,
QgsCoordinateReferenceSystem)
from qgis.gui import QgsSublayersDialog
from qgis.utils import iface
@ -206,7 +206,7 @@ def load(fileName, name=None, crs=None, style=None):
else:
style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POLYGON_STYLE)
qgslayer.loadNamedStyle(style)
QgsMapLayerRegistry.instance().addMapLayers([qgslayer])
QgsProject.instance().addMapLayers([qgslayer])
else:
qgslayer = QgsRasterLayer(fileName, name)
if qgslayer.isValid():
@ -215,7 +215,7 @@ def load(fileName, name=None, crs=None, style=None):
if style is None:
style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE)
qgslayer.loadNamedStyle(style)
QgsMapLayerRegistry.instance().addMapLayers([qgslayer])
QgsProject.instance().addMapLayers([qgslayer])
else:
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)

View File

@ -44,7 +44,7 @@ from osgeo import ogr
from qgis.PyQt.QtCore import QVariant, QSettings
from qgis.core import (Qgis, QgsFields, QgsField, QgsGeometry, QgsRectangle, QgsWkbTypes,
QgsSpatialIndex, QgsMapLayerRegistry, QgsMapLayer, QgsVectorLayer,
QgsSpatialIndex, QgsProject, QgsMapLayer, QgsVectorLayer,
QgsVectorFileWriter, QgsDistanceArea, QgsDataSourceUri, QgsCredentials,
QgsFeatureRequest, QgsWkbTypes)
@ -402,7 +402,7 @@ def duplicateInMemory(layer, newName='', addToRegistry=False):
if addToRegistry:
if memLayer.isValid():
QgsMapLayerRegistry.instance().addMapLayer(memLayer)
QgsProject.instance().addMapLayer(memLayer)
else:
raise RuntimeError('Layer invalid')

View File

@ -20,7 +20,6 @@
#include "qgsatlascomposition.h"
#include "qgscomposition.h"
#include "qgsfieldmodel.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerproxymodel.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgscomposermap.h"

View File

@ -62,7 +62,6 @@
#include "qgsmaplayeractionregistry.h"
#include "qgsgeometry.h"
#include "qgspaperitem.h"
#include "qgsmaplayerregistry.h"
#include "qgsprevieweffect.h"
#include "qgsvectorlayer.h"
#include "qgscomposerimageexportoptionsdialog.h"

View File

@ -25,7 +25,6 @@
#include "qgscomposermultiframecommand.h"
#include "qgscomposertablecolumn.h"
#include "qgscomposermap.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsproject.h"

View File

@ -34,7 +34,6 @@
#include "qgslegendrenderer.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerlegend.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"

View File

@ -31,7 +31,6 @@
#include "qgssymbolselectordialog.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsmaplayerregistry.h"
#include "qgscomposershape.h"
#include "qgspaperitem.h"
#include "qgsproject.h"

View File

@ -98,7 +98,6 @@ typedef SInt32 SRefCon;
#include "qgslogger.h"
#include "qgsdxfexport.h"
#include "qgsmapthemes.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
/** Print usage text
@ -1202,7 +1201,7 @@ int main( int argc, char *argv[] )
{
Q_FOREACH ( const QString& layer, QgsProject::instance()->mapThemeCollection()->mapThemeVisibleLayers( dxfPreset ) )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( layer ) );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layer ) );
if ( !vl )
continue;
layers << qMakePair<QgsVectorLayer *, int>( vl, -1 );
@ -1211,7 +1210,7 @@ int main( int argc, char *argv[] )
}
else
{
Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers() )
Q_FOREACH ( QgsMapLayer *ml, QgsProject::instance()->mapLayers() )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( !vl )

View File

@ -23,7 +23,7 @@
#include "qgisapp.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrectangle.h"
#include "qgscoordinatetransform.h"
@ -63,7 +63,7 @@ QgsOSMDownloadDialog::~QgsOSMDownloadDialog()
void QgsOSMDownloadDialog::populateLayers()
{
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::iterator it;
for ( it = layers.begin(); it != layers.end(); ++it )
{
@ -138,7 +138,7 @@ void QgsOSMDownloadDialog::onCurrentLayerChanged( int index )
return;
QString layerId = cboLayers->itemData( index ).toString();
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerId );
if ( !layer )
return;

View File

@ -18,7 +18,7 @@
#include "qgsosmdatabase.h"
#include "qgsdatasourceuri.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include <QApplication>
@ -174,7 +174,7 @@ void QgsOSMExportDialog::onOK()
uri.setDataSource( QString(), editLayerName->text(), QStringLiteral( "geometry" ) );
QgsVectorLayer* vlayer = new QgsVectorLayer( uri.uri(), editLayerName->text(), QStringLiteral( "spatialite" ) );
if ( vlayer->isValid() )
QgsMapLayerRegistry::instance()->addMapLayer( vlayer );
QgsProject::instance()->addMapLayer( vlayer );
}
QApplication::restoreOverrideCursor();

View File

@ -168,7 +168,6 @@
#include "qgsmapcanvassnappingutils.h"
#include "qgsmapcanvastracer.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmapoverviewcanvas.h"
#include "qgsmapsettings.h"
@ -2802,9 +2801,9 @@ void QgisApp::setupConnections()
this, SLOT( markDirty() ) );
// connect map layer registry
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer *> ) ),
connect( QgsProject::instance(), SIGNAL( layersAdded( QList<QgsMapLayer *> ) ),
this, SLOT( layersWereAdded( QList<QgsMapLayer *> ) ) );
connect( QgsMapLayerRegistry::instance(),
connect( QgsProject::instance(),
SIGNAL( layersWillBeRemoved( QStringList ) ),
this, SLOT( removingLayers( QStringList ) ) );
@ -3717,7 +3716,7 @@ bool QgisApp::addVectorLayers( const QStringList &theLayerQStringList, const QSt
}
// Register this layer with the layers registry
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
Q_FOREACH ( QgsMapLayer *l, myList )
{
bool ok;
@ -4090,7 +4089,7 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
if ( ! myList.isEmpty() )
{
// Register layer(s) with the layers registry
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
Q_FOREACH ( QgsMapLayer *l, myList )
{
bool ok;
@ -4176,7 +4175,7 @@ void QgisApp::addDatabaseLayers( QStringList const & layerPathList, QString cons
//qWarning("incrementing iterator");
}
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
// load default style after adding to process readCustomSymbology signals
Q_FOREACH ( QgsMapLayer *l, myList )
@ -4247,7 +4246,7 @@ void QgisApp::addSelectedVectorLayer( const QString& uri, const QString& layerNa
void QgisApp::replaceSelectedVectorLayer( const QString& oldId, const QString& uri, const QString& layerName, const QString& provider )
{
QgsMapLayer* old = QgsMapLayerRegistry::instance()->mapLayer( oldId );
QgsMapLayer* old = QgsProject::instance()->mapLayer( oldId );
if ( !old )
return;
QgsVectorLayer* oldLayer = static_cast<QgsVectorLayer*>( old );
@ -4255,13 +4254,13 @@ void QgisApp::replaceSelectedVectorLayer( const QString& oldId, const QString& u
if ( !newLayer || !newLayer->isValid() )
return;
QgsMapLayerRegistry::instance()->addMapLayer( newLayer, /*addToLegend*/ false, /*takeOwnership*/ true );
QgsProject::instance()->addMapLayer( newLayer, /*addToLegend*/ false, /*takeOwnership*/ true );
duplicateVectorStyle( oldLayer, newLayer );
// insert the new layer just below the old one
QgsLayerTreeUtils::insertLayerBelow( QgsProject::instance()->layerTreeRoot(), oldLayer, newLayer );
// and remove the old layer
QgsMapLayerRegistry::instance()->removeMapLayer( oldLayer );
QgsProject::instance()->removeMapLayer( oldLayer );
} // QgisApp:replaceSelectedVectorLayer
void QgisApp::addMssqlLayer()
@ -4647,7 +4646,7 @@ void QgisApp::fileOpenAfterLaunch()
// check if a data source is already loaded via command line or filesystem
// empty project with layer loaded, but may not trigger a dirty project at this point
if ( QgsProject::instance() && QgsMapLayerRegistry::instance()->count() > 0 )
if ( QgsProject::instance() && QgsProject::instance()->count() > 0 )
{
return;
}
@ -4807,7 +4806,7 @@ void QgisApp::newMemoryLayer()
QList< QgsMapLayer* > layers;
layers << newLayer;
QgsMapLayerRegistry::instance()->addMapLayers( layers );
QgsProject::instance()->addMapLayers( layers );
newLayer->startEditing();
}
}
@ -7348,7 +7347,7 @@ void QgisApp::deselectAll()
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); ++it )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
@ -7657,7 +7656,7 @@ QgsVectorLayer *QgisApp::pasteAsNewMemoryVector( const QString & theLayerName )
mMapCanvas->freeze();
QgsMapLayerRegistry::instance()->addMapLayer( layer );
QgsProject::instance()->addMapLayer( layer );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
@ -8283,7 +8282,7 @@ void QgisApp::layerSubsetString()
if ( newLayer->isValid() )
{
duplicateVectorStyle( vlayer, newLayer );
QgsMapLayerRegistry::instance()->addMapLayer( newLayer, /*addToLegend*/ false, /*takeOwnership*/ true );
QgsProject::instance()->addMapLayer( newLayer, /*addToLegend*/ false, /*takeOwnership*/ true );
QgsLayerTreeUtils::insertLayerBelow( QgsProject::instance()->layerTreeRoot(), vlayer, newLayer );
mLayerTreeView->setCurrentLayer( newLayer );
// hide the old layer
@ -8375,7 +8374,7 @@ void QgisApp::removingLayers( const QStringList& theLayers )
Q_FOREACH ( const QString &layerId, theLayers )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>(
QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
QgsProject::instance()->mapLayer( layerId ) );
if ( !vlayer || !vlayer->isEditable() )
return;
@ -8385,7 +8384,7 @@ void QgisApp::removingLayers( const QStringList& theLayers )
void QgisApp::removeAllLayers()
{
QgsMapLayerRegistry::instance()->removeAllMapLayers();
QgsProject::instance()->removeAllMapLayers();
}
void QgisApp::removeLayer()
@ -8568,7 +8567,7 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *>& lyrList )
QList<QgsMapLayer *> myList;
myList << dupLayer;
QgsProject::instance()->layerTreeRegistryBridge()->setEnabled( false );
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
QgsProject::instance()->layerTreeRegistryBridge()->setEnabled( true );
QgsLayerTreeLayer* nodeSelectedLyr = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( selectedLyr->id() );
@ -9064,7 +9063,7 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString& currentPage )
if ( oldCapitalise != mySettings.value( QStringLiteral( "/qgis/capitaliseLayerName" ), QVariant( false ) ).toBool() )
{
// if the layer capitalization has changed, we need to update all layer names
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() )
Q_FOREACH ( QgsMapLayer* layer, QgsProject::instance()->mapLayers() )
layer->setName( layer->originalName() );
}
@ -9391,7 +9390,7 @@ QgsVectorLayer* QgisApp::addVectorLayer( const QString& vectorLayerPath, const Q
// Register this layer with the layers registry
QList<QgsMapLayer *> myList;
myList << layer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
bool ok;
layer->loadDefaultStyle( ok );
}
@ -9435,7 +9434,7 @@ void QgisApp::addMapLayer( QgsMapLayer *theMapLayer )
// Register this layer with the layers registry
QList<QgsMapLayer *> myList;
myList << theMapLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
// add it to the mapcanvas collection
// not necessary since adding to registry adds to canvas mMapCanvas->addLayer(theMapLayer);
}
@ -9515,9 +9514,9 @@ bool QgisApp::saveDirty()
bool hasUnsavedEdits = false;
// extra check to see if there are any vector layers with unsaved provider edits
// to ensure user has opportunity to save any editing
if ( QgsMapLayerRegistry::instance()->count() > 0 )
if ( QgsProject::instance()->count() > 0 )
{
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); ++it )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
@ -9552,7 +9551,7 @@ bool QgisApp::saveDirty()
QSettings settings;
bool askThem = settings.value( QStringLiteral( "qgis/askToSaveProjectChanges" ), true ).toBool();
if ( askThem && QgsProject::instance()->isDirty() && QgsMapLayerRegistry::instance()->count() > 0 )
if ( askThem && QgsProject::instance()->isDirty() && QgsProject::instance()->count() > 0 )
{
// flag project as dirty since dirty state of canvas is reset if "dirty"
// is based on a zoom or pan
@ -9581,7 +9580,7 @@ bool QgisApp::saveDirty()
bool QgisApp::checkTasksDependOnProject()
{
QSet< QString > activeTaskDescriptions;
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::const_iterator layerIt = layers.constBegin();
for ( ; layerIt != layers.constEnd(); ++layerIt )
@ -10535,7 +10534,7 @@ void QgisApp::updateLabelToolButtons()
{
bool enableMove = false, enableRotate = false, enablePin = false, enableShowHide = false, enableChange = false;
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); ++it )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( it.value() );
@ -11041,7 +11040,7 @@ bool QgisApp::addRasterLayer( QgsRasterLayer *theRasterLayer )
// register this layer with the central layers registry
QList<QgsMapLayer *> myList;
myList << theRasterLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
QgsProject::instance()->addMapLayers( myList );
return true;
}
@ -11280,7 +11279,7 @@ QgsPluginLayer* QgisApp::addPluginLayer( const QString& uri, const QString& base
layer->setName( baseName );
QgsMapLayerRegistry::instance()->addMapLayer( layer );
QgsProject::instance()->addMapLayer( layer );
return layer;
}

View File

@ -32,7 +32,6 @@
#include "qgscomposer.h"
#include "qgscomposerview.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaptooladvanceddigitizing.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"

View File

@ -20,7 +20,7 @@
#include "qgsdataitem.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayercombobox.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include <QCheckBox>
@ -35,7 +35,7 @@
static QgsMapLayer* _rasterLayer( const QString& filename )
{
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
Q_FOREACH ( QgsMapLayer* layer, layers )
{
if ( layer->type() == QgsMapLayer::RasterLayer && layer->source() == filename )
@ -362,7 +362,7 @@ void QgsAlignRasterDialog::runAlign()
{
QgsRasterLayer* layer = new QgsRasterLayer( item.outputFilename, QFileInfo( item.outputFilename ).baseName() );
if ( layer->isValid() )
QgsMapLayerRegistry::instance()->addMapLayer( layer );
QgsProject::instance()->addMapLayer( layer );
else
delete layer;
}

View File

@ -27,7 +27,6 @@
#include "qgslayertreeviewdefaultactions.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgsrenderer.h"
@ -487,7 +486,7 @@ void QgsAppLayerTreeViewMenuProvider::editVectorSymbol()
return;
QString layerId = action->property( "layerId" ).toString();
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerId ) );
if ( !layer )
return;
@ -516,7 +515,7 @@ void QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor( const QColor& color
return;
QString layerId = action->property( "layerId" ).toString();
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerId ) );
if ( !layer )
return;
@ -608,7 +607,7 @@ void QgsAppLayerTreeViewMenuProvider::setSymbolLegendNodeColor( const QColor &co
QgsSymbol* newSymbol = originalSymbol->clone();
newSymbol->setColor( color );
node->setSymbol( newSymbol );
if ( QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ) )
if ( QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerId ) ) )
{
layer->emitStyleChanged();
}

View File

@ -306,7 +306,7 @@ void QgsAttributeActionDialog::addDefaultActions()
insertRow( pos++, QgsAction::GenericPython, tr( "Clicked coordinates (Run feature actions tool)" ), QStringLiteral( "from qgis.PyQt import QtWidgets\n\nQtWidgets.QMessageBox.information(None, \"Clicked coords\", \"layer: [% @layer_id %]\\ncoords: ([% @click_x %],[% @click_y %])\")" ), QLatin1String( "" ), false, tr( "Clicked Coordinate" ), QSet<QString>() << QStringLiteral( "Canvas" ) );
insertRow( pos++, QgsAction::OpenUrl, tr( "Open file" ), QStringLiteral( "[% \"PATH\" %]" ), QLatin1String( "" ), false, tr( "Open file" ), QSet<QString>() << QStringLiteral( "Feature" ) << QStringLiteral( "Canvas" ) );
insertRow( pos++, QgsAction::OpenUrl, tr( "Search on web based on attribute's value" ), QStringLiteral( "http://www.google.com/search?q=[% \"ATTRIBUTE\" %]" ), QLatin1String( "" ), false, tr( "Search Web" ), QSet<QString>() << QStringLiteral( "Field" ) );
insertRow( pos++, QgsAction::GenericPython, tr( "List feature ids" ), QStringLiteral( "from qgis.PyQt import QtWidgets\n\nlayer = QgsMapLayerRegistry.instance().mapLayer('[% @layer_id %]')\nif layer.selectedFeatureCount():\n ids = layer.selectedFeatureIds()\nelse:\n ids = [f.id() for f in layer.getFeatures()]\n\nQtWidgets.QMessageBox.information(None, \"Feature ids\", ', '.join([str(id) for id in ids]))" ), QLatin1String( "" ), false, tr( "List feature ids" ), QSet<QString>() << QStringLiteral( "Layer" ) );
insertRow( pos++, QgsAction::GenericPython, tr( "List feature ids" ), QStringLiteral( "from qgis.PyQt import QtWidgets\n\nlayer = QgsProject.instance().mapLayer('[% @layer_id %]')\nif layer.selectedFeatureCount():\n ids = layer.selectedFeatureIds()\nelse:\n ids = [f.id() for f in layer.getFeatures()]\n\nQtWidgets.QMessageBox.information(None, \"Feature ids\", ', '.join([str(id) for id in ids]))" ), QLatin1String( "" ), false, tr( "List feature ids" ), QSet<QString>() << QStringLiteral( "Layer" ) );
}
void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item )

View File

@ -18,7 +18,6 @@
#include "qgsattributetypedialog.h"
#include "qgsattributetypeloaddialog.h"
#include "qgsvectordataprovider.h"
#include "qgsmaplayerregistry.h"
#include "qgsmapcanvas.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgisapp.h"

View File

@ -28,7 +28,6 @@
#include "qgsbrowsermodel.h"
#include "qgsbrowsertreeview.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"

View File

@ -23,7 +23,6 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsfieldsproperties.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrelationmanager.h"
#include "qgsvectordataprovider.h"

View File

@ -17,7 +17,7 @@
#include "qgsjoindialog.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayercombobox.h"
@ -68,7 +68,7 @@ QgsJoinDialog::~QgsJoinDialog()
void QgsJoinDialog::setJoinInfo( const QgsVectorJoinInfo& joinInfo )
{
mJoinLayerComboBox->setLayer( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) );
mJoinLayerComboBox->setLayer( QgsProject::instance()->mapLayer( joinInfo.joinLayerId ) );
mJoinFieldComboBox->setField( joinInfo.joinFieldName );
mTargetFieldComboBox->setField( joinInfo.targetFieldName );
mCacheInMemoryCheckBox->setChecked( joinInfo.memoryCache );

View File

@ -20,7 +20,7 @@
#include <qgsfontutils.h>
#include <qgslogger.h>
#include "qgsfeatureiterator.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"
@ -64,7 +64,7 @@ void QgsLabelPropertyDialog::on_buttonBox_clicked( QAbstractButton *button )
void QgsLabelPropertyDialog::init( const QString& layerId, const QString& providerId, int featureId, const QString& labelText )
{
//get feature attributes
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerId ) );
if ( !vlayer )
{
return;

View File

@ -37,7 +37,6 @@
#include "qgsundowidget.h"
#include "qgsrenderer.h"
#include "qgsrendererregistry.h"
#include "qgsmaplayerregistry.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasterlayer.h"
#include "qgsmaplayerconfigwidget.h"
@ -58,7 +57,7 @@ QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas* canvas, const QList<
{
setupUi( this );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( layerAboutToBeRemoved( QgsMapLayer* ) ) );
connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( layerAboutToBeRemoved( QgsMapLayer* ) ) );
QSettings settings;
mLiveApplyCheck->setChecked( settings.value( QStringLiteral( "UI/autoApplyStyling" ), true ).toBool() );

View File

@ -21,7 +21,6 @@
#include "qgslayertreemodel.h"
#include "qgslayertreemodellegendnode.h"
#include "qgslayertreeview.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsproject.h"
#include "qgsrenderer.h"

View File

@ -23,7 +23,6 @@
#include "qgslinestring.h"
#include "qgsmultipoint.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsmapmouseevent.h"
#include "qgspolygon.h"
#include "qgsproject.h"
@ -303,7 +302,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
QStringList::const_iterator lIt = intersectionLayers.constBegin();
for ( ; lIt != intersectionLayers.constEnd(); ++lIt )
{
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( *lIt );
QgsMapLayer* ml = QgsProject::instance()->mapLayer( *lIt );
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( ml );
//can only add topological points if background layer is editable...
if ( vl && vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )

View File

@ -29,7 +29,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayeractionregistry.h"
#include "qgisapp.h"

View File

@ -34,7 +34,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgsmaplayerregistry.h"
#include "qgsrenderer.h"
#include "qgsunittypes.h"

View File

@ -20,7 +20,7 @@
#include "qgsfeatureiterator.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerlabeling.h"
@ -679,7 +679,7 @@ QgsMapToolLabel::LabelDetails::LabelDetails( const QgsLabelPosition& p )
: valid( false )
, pos( p )
{
layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( pos.layerID ) );
layer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( pos.layerID ) );
if ( layer && layer->labeling() )
{
settings = layer->labeling()->settings( layer, pos.providerID );

View File

@ -17,7 +17,6 @@
#include "qgsmaptoolmovelabel.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include <QMouseEvent>

View File

@ -17,7 +17,7 @@
#include "qgsfeatureiterator.h"
#include "qgsmaptooloffsetcurve.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgssnappingutils.h"
#include "qgsvectorlayer.h"
@ -361,7 +361,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
return;
}
QgsVectorLayer* sourceLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( mSourceLayerId ) );
QgsVectorLayer* sourceLayer = dynamic_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( mSourceLayerId ) );
if ( !sourceLayer )
{
return;

View File

@ -20,7 +20,7 @@
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsmaptoolselectutils.h"
@ -198,7 +198,7 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
}
QColor lblcolor = QColor( 54, 129, 255, 63 );
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( pos.layerID );
QgsMapLayer* layer = QgsProject::instance()->mapLayer( pos.layerID );
if ( !layer )
{
continue;

View File

@ -17,7 +17,6 @@
#include "qgsmaptoolrotatelabel.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgspallabeling.h"
#include "qgspointrotationitem.h"
#include "qgsrubberband.h"

View File

@ -25,7 +25,7 @@
#include "qgsproviderregistry.h"
#include "qgisapp.h" // <- for theme icons
#include "qgsvectorlayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsgenericprojectionselector.h"
#include "qgsslconnect.h"
@ -429,7 +429,7 @@ bool QgsNewSpatialiteLayerDialog::apply()
myList << layer;
//addMapLayers returns a list of all successfully added layers
//so we compare that to our original list.
if ( myList == QgsMapLayerRegistry::instance()->addMapLayers( myList ) )
if ( myList == QgsProject::instance()->addMapLayers( myList ) )
return true;
}
else

View File

@ -28,7 +28,6 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsprojectlayergroupdialog.h"
#include "qgsrasterlayer.h"
@ -140,7 +139,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
///////////////////////////////////////////////////////////
// Properties stored in QgsProject
Q_FOREACH ( QgsVectorLayer* layer, QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>() )
Q_FOREACH ( QgsVectorLayer* layer, QgsProject::instance()->layers<QgsVectorLayer*>() )
{
if ( layer->isEditable() )
{
@ -239,7 +238,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
QStringList noIdentifyLayerIdList = QgsProject::instance()->nonIdentifiableLayers();
const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
const QMap<QString, QgsMapLayer*> &mapLayers = QgsProject::instance()->mapLayers();
if ( mMapCanvas->currentLayer() )
{
@ -919,7 +918,7 @@ void QgsProjectProperties::apply()
noIdentifyLayerList << id;
}
bool readonly = twIdentifyLayers->item( i, 3 )->checkState() == Qt::Checked;
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( id ) );
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( id ) );
if ( vl )
vl->setReadOnly( readonly );
}
@ -1211,7 +1210,7 @@ void QgsProjectProperties::on_cbxProjectionEnabled_toggled( bool onFlyEnabled )
if ( !onFlyEnabled )
{
// reset projection to default
const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
const QMap<QString, QgsMapLayer*> &mapLayers = QgsProject::instance()->mapLayers();
if ( mMapCanvas->currentLayer() )
{
@ -1405,7 +1404,7 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked()
crsList << srs.authid();
}
const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
const QMap<QString, QgsMapLayer*> &mapLayers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
{
crsList << it.value()->crs().authid();

View File

@ -16,7 +16,7 @@
***************************************************************************/
#include "qgsrastercalcdialog.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrastercalcnode.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasterlayer.h"
@ -121,7 +121,7 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalcDialog::rasterEntries() const
void QgsRasterCalcDialog::insertAvailableRasterBands()
{
const QMap<QString, QgsMapLayer*>& layers = QgsMapLayerRegistry::instance()->mapLayers();
const QMap<QString, QgsMapLayer*>& layers = QgsProject::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::const_iterator layerIt = layers.constBegin();
bool firstLayer = true;

View File

@ -29,7 +29,6 @@
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaptoolemitpoint.h"
#include "qgsmaptopixel.h"

View File

@ -42,6 +42,7 @@
QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas, QWidget* parent )
: QWidget( parent )
, mProject( project )
, mConfig( project )
, mCanvas( canvas )
, mModeAction( nullptr )
, mTypeAction( nullptr )

View File

@ -14,7 +14,7 @@
***************************************************************************/
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatisticalsummary.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"
#include "qgsvectorlayer.h"
@ -89,7 +89,7 @@ QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *paren
connect( mFieldExpressionWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( refreshStatistics() ) );
connect( mSelectedOnlyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshStatistics() ) );
connect( mButtonRefresh, SIGNAL( clicked( bool ) ), this, SLOT( refreshStatistics() ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersRemoved( QStringList ) ) );
connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersRemoved( QStringList ) ) );
QSettings settings;
Q_FOREACH ( QgsStatisticalSummary::Statistic stat, mDisplayStats )

View File

@ -37,7 +37,6 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerconfigwidgetfactory.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgspluginmetadata.h"
#include "qgspluginregistry.h"
@ -1062,7 +1061,7 @@ void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
joinedLayers.reserve( joins.size() );
for ( int i = 0; i < joins.size(); ++i )
{
joinedLayers.append( QgsMapLayerRegistry::instance()->mapLayer( joins[i].joinLayerId ) );
joinedLayers.append( QgsProject::instance()->mapLayer( joins[i].joinLayerId ) );
}
QgsJoinDialog d( mLayer, joinedLayers );
@ -1072,7 +1071,7 @@ void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
//create attribute index if possible
if ( d.createAttributeIndex() )
{
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) );
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( info.joinLayerId ) );
if ( joinLayer )
{
joinLayer->dataProvider()->createAttributeIndex( joinLayer->fields().indexFromName( info.joinFieldName ) );
@ -1111,7 +1110,7 @@ void QgsVectorLayerProperties::on_mJoinTreeWidget_itemDoubleClicked( QTreeWidget
else
{
// remove already joined layers from possible list to be displayed in dialog
joinedLayers.append( QgsMapLayerRegistry::instance()->mapLayer( joins[i].joinLayerId ) );
joinedLayers.append( QgsProject::instance()->mapLayer( joins[i].joinLayerId ) );
}
}
if ( j == -1 )
@ -1136,7 +1135,7 @@ void QgsVectorLayerProperties::on_mJoinTreeWidget_itemDoubleClicked( QTreeWidget
//create attribute index if possible
if ( d.createAttributeIndex() )
{
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) );
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( info.joinLayerId ) );
if ( joinLayer )
{
joinLayer->dataProvider()->createAttributeIndex( joinLayer->fields().indexFromName( info.joinFieldName ) );
@ -1154,7 +1153,7 @@ void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorJoinInfo& joi
{
QTreeWidgetItem* joinItem = new QTreeWidgetItem();
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( join.joinLayerId ) );
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( join.joinLayerId ) );
if ( !mLayer || !joinLayer )
{
return;

View File

@ -27,7 +27,7 @@
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsconditionalstyle.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsproviderregistry.h"
#include "qgsvectorlayer.h"
#include "qgsrasterlayer.h"
@ -145,9 +145,9 @@ void QgsBrowser::itemClicked( const QModelIndex& index )
mParamWidget = nullptr;
}
// QgsMapLayerRegistry deletes the previous layer(s) for us
// QgsProject deletes the previous layer(s) for us
// TODO: in future we could cache the layers in the registry
QgsMapLayerRegistry::instance()->removeAllMapLayers();
QgsProject::instance()->removeAllMapLayers();
mLayer = nullptr;
// this should probably go to the model and only emit signal when a layer is clicked
@ -236,7 +236,7 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )
QgsDebugMsg( "Layer created" );
QgsMapLayerRegistry::instance()->addMapLayers(
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mLayer );
return true;

View File

@ -149,7 +149,6 @@ SET(QGIS_CORE_SRCS
qgsmaplayerlegend.cpp
qgsmaplayermodel.cpp
qgsmaplayerproxymodel.cpp
qgsmaplayerregistry.cpp
qgsmaplayerstylemanager.cpp
qgsmaprenderercache.cpp
qgsmaprenderercustompainterjob.cpp
@ -474,7 +473,6 @@ SET(QGIS_CORE_MOC_HDRS
qgsmaplayerlegend.h
qgsmaplayermodel.h
qgsmaplayerproxymodel.h
qgsmaplayerregistry.h
qgsmaplayerstylemanager.h
qgsmaprenderercache.h
qgsmaprenderercustompainterjob.h

View File

@ -25,7 +25,6 @@
#include "qgsvectordataprovider.h"
#include "qgsexpression.h"
#include "qgsgeometry.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsmessagelog.h"
#include "qgsexpressioncontext.h"
@ -46,7 +45,7 @@ QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition )
{
//listen out for layer removal
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
}
QgsAtlasComposition::~QgsAtlasComposition()
@ -630,7 +629,7 @@ void QgsAtlasComposition::readXml( const QDomElement& atlasElem, const QDomDocum
// look for stored layer name
mCoverageLayer = nullptr;
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::const_iterator it = layers.begin(); it != layers.end(); ++it )
{
if ( it.key() == atlasElem.attribute( QStringLiteral( "coverageLayer" ) ) )

View File

@ -20,7 +20,6 @@
#include "qgscomposermap.h"
#include "qgscomposerutils.h"
#include "qgsfeatureiterator.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgscomposerframe.h"
#include "qgsatlascomposition.h"
@ -63,7 +62,7 @@ QgsComposerAttributeTableV2::QgsComposerAttributeTableV2( QgsComposition* compos
, mFeatureFilter( QLatin1String( "" ) )
{
//set first vector layer from layer registry as default one
QMap<QString, QgsMapLayer*> layerMap = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*> layerMap = QgsProject::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();
for ( ; mapIt != layerMap.constEnd(); ++mapIt )
{
@ -80,7 +79,7 @@ QgsComposerAttributeTableV2::QgsComposerAttributeTableV2( QgsComposition* compos
//listen for modifications to layer and refresh table when they occur
connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
}
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
if ( mComposition )
{
@ -736,7 +735,7 @@ bool QgsComposerAttributeTableV2::readXml( const QDomElement& itemElem, const QD
}
else
{
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
QgsMapLayer* ml = QgsProject::instance()->mapLayer( layerId );
if ( ml )
{
mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );

View File

@ -22,7 +22,6 @@
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgscomposermodel.h"
#include "qgsmaplayerregistry.h"
#include "qgslayertree.h"
#include "qgslayertreemodel.h"
#include "qgslegendrenderer.h"
@ -422,7 +421,7 @@ static void _readOldLegendGroup( QDomElement& elem, QgsLayerTreeGroup* parentGro
if ( itemElem.tagName() == QLatin1String( "LayerItem" ) )
{
QString layerId = itemElem.attribute( QStringLiteral( "layerId" ) );
if ( QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId ) )
if ( QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerId ) )
{
QgsLayerTreeLayer* nodeLayer = parentGroup->addLayer( layer );
QString userText = itemElem.attribute( QStringLiteral( "userText" ) );

View File

@ -18,7 +18,7 @@
#include "qgscomposerlegendstyle.h"
#include "qgscomposerlegenditem.h"
#include "qgscomposerlegend.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgsrenderer.h"
#include "qgssymbol.h"
@ -288,7 +288,7 @@ void QgsComposerLayerItem::readXml( const QDomElement& itemElem, bool xServerAva
void QgsComposerLayerItem::setDefaultStyle( double scaleDenominator, const QString& rule )
{
// set default style according to number of symbols
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId() ) );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerId() ) );
if ( vLayer )
{
QgsFeatureRenderer* renderer = vLayer->renderer();

View File

@ -22,7 +22,6 @@
#include "qgscomposerutils.h"
#include "qgslogger.h"
#include "qgsmaprenderercustompainterjob.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmaptopixel.h"
#include "qgspainting.h"
@ -560,7 +559,7 @@ QStringList QgsComposerMap::layersToRender( const QgsExpressionContext* context
//need to convert layer names to layer ids
Q_FOREACH ( const QString& name, layerNames )
{
QList< QgsMapLayer* > matchingLayers = QgsMapLayerRegistry::instance()->mapLayersByName( name );
QList< QgsMapLayer* > matchingLayers = QgsProject::instance()->mapLayersByName( name );
Q_FOREACH ( QgsMapLayer* layer, matchingLayers )
{
renderLayerSet << layer->id();
@ -1126,7 +1125,7 @@ bool QgsComposerMap::containsWmsLayer() const
for ( ; layer_it != layers.constEnd(); ++layer_it )
{
currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
currentLayer = QgsProject::instance()->mapLayer( *layer_it );
if ( currentLayer )
{
QgsRasterLayer* currentRasterLayer = qobject_cast<QgsRasterLayer *>( currentLayer );
@ -1172,7 +1171,7 @@ bool QgsComposerMap::containsAdvancedEffects() const
for ( ; layer_it != layers.constEnd(); ++layer_it )
{
currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
currentLayer = QgsProject::instance()->mapLayer( *layer_it );
if ( currentLayer )
{
if ( currentLayer->blendMode() != QPainter::CompositionMode_SourceOver )
@ -1209,11 +1208,11 @@ bool QgsComposerMap::containsAdvancedEffects() const
void QgsComposerMap::connectUpdateSlot()
{
//connect signal from layer registry to update in case of new or deleted layers
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
if ( layerRegistry )
QgsProject* project = QgsProject::instance();
if ( project )
{
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layersChanged() ) );
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layersChanged() ) );
connect( project, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layersChanged() ) );
connect( project, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layersChanged() ) );
}
}
@ -1592,7 +1591,7 @@ void QgsComposerMap::storeCurrentLayerStyles()
mLayerStyleOverrides.clear();
Q_FOREACH ( const QString& layerID, mLayerSet )
{
if ( QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID ) )
if ( QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerID ) )
{
QgsMapLayerStyle style;
style.readFromLayer( layer );
@ -1612,7 +1611,7 @@ void QgsComposerMap::syncLayerSet()
QStringList currentLayerSet;
if ( mKeepLayerSet )
{
currentLayerSet = QgsMapLayerRegistry::instance()->mapLayers().uniqueKeys();
currentLayerSet = QgsProject::instance()->mapLayers().uniqueKeys();
}
else //only consider layers visible in the map
{

View File

@ -36,7 +36,6 @@
#include "qgsfeatureiterator.h"
#include "qgslinesymbollayer.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsunittypes.h"
#include "qgstextlabelfeature.h"
#include "qgscrscache.h"

View File

@ -32,9 +32,7 @@ email : morb at ozemail dot com dot au
#include "qgspoint.h"
#include "qgsrectangle.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgsgeometryvalidator.h"
#include "qgsmulticurve.h"

View File

@ -21,7 +21,6 @@ email : marco.hugentobler at sourcepole dot com
#include "qgsgeometryutils.h"
#include "qgsgeometry.h"
#include "qgsgeos.h"
#include "qgsmaplayerregistry.h"
#include "qgsmultisurface.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
@ -252,7 +251,7 @@ QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
{
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( *aIt ) );
if ( currentLayer )
{
QgsFeatureIds ignoreIds;

View File

@ -18,7 +18,7 @@
#include "qgslayertree.h"
#include "qgslayertreeutils.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include <QDomElement>
#include <QStringList>
@ -77,7 +77,7 @@ QgsLayerTreeGroup* QgsLayerTreeGroup::addGroup( const QString &name )
QgsLayerTreeLayer*QgsLayerTreeGroup::insertLayer( int index, QgsMapLayer* layer )
{
if ( !layer || QgsMapLayerRegistry::instance()->mapLayer( layer->id() ) != layer )
if ( !layer || QgsProject::instance()->mapLayer( layer->id() ) != layer )
return nullptr;
QgsLayerTreeLayer* ll = new QgsLayerTreeLayer( layer );
@ -87,7 +87,7 @@ QgsLayerTreeLayer*QgsLayerTreeGroup::insertLayer( int index, QgsMapLayer* layer
QgsLayerTreeLayer* QgsLayerTreeGroup::addLayer( QgsMapLayer* layer )
{
if ( !layer || QgsMapLayerRegistry::instance()->mapLayer( layer->id() ) != layer )
if ( !layer || QgsProject::instance()->mapLayer( layer->id() ) != layer )
return nullptr;
QgsLayerTreeLayer* ll = new QgsLayerTreeLayer( layer );

View File

@ -17,7 +17,7 @@
#include "qgslayertreeutils.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
QgsLayerTreeLayer::QgsLayerTreeLayer( QgsMapLayer *layer )
@ -26,7 +26,7 @@ QgsLayerTreeLayer::QgsLayerTreeLayer( QgsMapLayer *layer )
, mLayer( nullptr )
, mVisible( Qt::Checked )
{
Q_ASSERT( QgsMapLayerRegistry::instance()->mapLayer( mLayerId ) == layer );
Q_ASSERT( QgsProject::instance()->mapLayer( mLayerId ) == layer );
attachToLayer();
}
@ -53,21 +53,21 @@ QgsLayerTreeLayer::QgsLayerTreeLayer( const QgsLayerTreeLayer& other )
void QgsLayerTreeLayer::attachToLayer()
{
// layer is not necessarily already loaded
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( mLayerId );
QgsMapLayer* l = QgsProject::instance()->mapLayer( mLayerId );
if ( l )
{
mLayer = l;
mLayerName = l->name();
connect( l, SIGNAL( nameChanged() ), this, SLOT( layerNameChanged() ) );
// make sure we are notified if the layer is removed
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( registryLayersWillBeRemoved( QStringList ) ) );
connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( registryLayersWillBeRemoved( QStringList ) ) );
}
else
{
if ( mLayerName.isEmpty() )
mLayerName = QStringLiteral( "(?)" );
// wait for the layer to be eventually loaded
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) );
connect( QgsProject::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) );
}
}
@ -115,7 +115,7 @@ QgsLayerTreeLayer* QgsLayerTreeLayer::readXml( QDomElement& element )
QgsLayerTreeLayer* nodeLayer = nullptr;
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );
QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerID );
if ( layer )
nodeLayer = new QgsLayerTreeLayer( layer );
@ -159,7 +159,7 @@ void QgsLayerTreeLayer::registryLayersAdded( const QList<QgsMapLayer*>& layers )
{
if ( l->id() == mLayerId )
{
disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) );
disconnect( QgsProject::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) );
attachToLayer();
emit layerLoaded();
break;
@ -174,8 +174,8 @@ void QgsLayerTreeLayer::registryLayersWillBeRemoved( const QStringList& layerIds
emit layerWillBeUnloaded();
// stop listening to removal signals and start hoping that the layer may be added again
disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( registryLayersWillBeRemoved( QStringList ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) );
disconnect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( registryLayersWillBeRemoved( QStringList ) ) );
connect( QgsProject::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) );
mLayer = nullptr;
}

View File

@ -24,7 +24,7 @@ class QgsMapLayer;
* Layer tree node points to a map layer.
*
* When using with existing QgsMapLayer instance, it is expected that the layer
* has been registered in QgsMapLayerRegistry earlier.
* has been registered in QgsProject earlier.
*
* The node can exist also without a valid instance of a layer (just ID). That
* means the referenced layer does not need to be loaded in order to use it

View File

@ -15,24 +15,23 @@
#include "qgslayertreeregistrybridge.h"
#include "qgsmaplayerregistry.h"
#include "qgslayertree.h"
#include "qgsproject.h"
#include "qgslogger.h"
QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge( QgsLayerTreeGroup *root, QObject *parent )
QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge( QgsLayerTreeGroup *root, QgsProject* project, QObject *parent )
: QObject( parent )
, mRoot( root )
, mProject( project )
, mRegistryRemovingLayers( false )
, mEnabled( true )
, mNewLayersVisible( true )
, mInsertionPointGroup( root )
, mInsertionPointIndex( 0 )
{
connect( QgsMapLayerRegistry::instance(), SIGNAL( legendLayersAdded( QList<QgsMapLayer*> ) ), this, SLOT( layersAdded( QList<QgsMapLayer*> ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) );
connect( mProject, SIGNAL( legendLayersAdded( QList<QgsMapLayer*> ) ), this, SLOT( layersAdded( QList<QgsMapLayer*> ) ) );
connect( mProject, SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) );
connect( mRoot, SIGNAL( willRemoveChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( groupWillRemoveChildren( QgsLayerTreeNode*, int, int ) ) );
connect( mRoot, SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( groupRemovedChildren() ) );
@ -58,7 +57,7 @@ void QgsLayerTreeRegistryBridge::layersAdded( const QList<QgsMapLayer*>& layers
nodes << nodeLayer;
// check whether the layer is marked as embedded
QString projectFile = QgsProject::instance()->layerIsEmbedded( nodeLayer->layerId() );
QString projectFile = mProject->layerIsEmbedded( nodeLayer->layerId() );
if ( !projectFile.isEmpty() )
{
nodeLayer->setCustomProperty( QStringLiteral( "embedded" ), 1 );
@ -147,5 +146,5 @@ void QgsLayerTreeRegistryBridge::groupRemovedChildren()
void QgsLayerTreeRegistryBridge::removeLayersFromRegistry( const QStringList& layerIds )
{
QgsMapLayerRegistry::instance()->removeMapLayers( layerIds );
mProject->removeMapLayers( layerIds );
}

View File

@ -22,6 +22,7 @@
class QgsLayerTreeGroup;
class QgsLayerTreeNode;
class QgsMapLayer;
class QgsProject;
/** \ingroup core
@ -40,7 +41,7 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
{
Q_OBJECT
public:
explicit QgsLayerTreeRegistryBridge( QgsLayerTreeGroup* root, QObject *parent = nullptr );
explicit QgsLayerTreeRegistryBridge( QgsLayerTreeGroup* root, QgsProject* project, QObject *parent = nullptr );
void setEnabled( bool enabled ) { mEnabled = enabled; }
bool isEnabled() const { return mEnabled; }
@ -68,6 +69,7 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
protected:
QgsLayerTreeGroup* mRoot;
QgsProject* mProject;
QStringList mLayerIdsForRemoval;
bool mRegistryRemovingLayers;
bool mEnabled;

View File

@ -19,7 +19,7 @@
#include "qgsexception.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsproviderregistry.h"
#include "qgsexpression.h"
@ -901,8 +901,8 @@ void QgsApplication::initQgis()
// set the provider plugin path (this creates provider registry)
QgsProviderRegistry::instance( pluginPath() );
// create map layer registry if doesn't exist
QgsMapLayerRegistry::instance();
// create project instance if doesn't exist
QgsProject::instance();
// Make sure we have a NAM created on the main thread.
QgsNetworkAccessManager::instance();

View File

@ -34,7 +34,6 @@
#include "qgsgeometryengine.h"
#include "qgsgeometryutils.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsogcutils.h"
#include "qgsvectorlayer.h"
#include "qgssymbollayerutils.h"
@ -338,11 +337,11 @@ QgsVectorLayer* getVectorLayer( const QVariant& value, QgsExpression* )
if ( !vl )
{
QString layerString = value.toString();
vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerString ) ); //search by id first
vl = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerString ) ); //search by id first
if ( !vl )
{
QList<QgsMapLayer *> layersByName = QgsMapLayerRegistry::instance()->mapLayersByName( layerString );
QList<QgsMapLayer *> layersByName = QgsProject::instance()->mapLayersByName( layerString );
if ( !layersByName.isEmpty() )
{
vl = qobject_cast<QgsVectorLayer*>( layersByName.at( 0 ) );
@ -3349,10 +3348,10 @@ static QVariant fcnGetLayerProperty( const QVariantList& values, const QgsExpres
QString layerIdOrName = getStringValue( values.at( 0 ), parent );
//try to find a matching layer by name
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerIdOrName ); //search by id first
QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerIdOrName ); //search by id first
if ( !layer )
{
QList<QgsMapLayer *> layersByName = QgsMapLayerRegistry::instance()->mapLayersByName( layerIdOrName );
QList<QgsMapLayer *> layersByName = QgsProject::instance()->mapLayersByName( layerIdOrName );
if ( !layersByName.isEmpty() )
{
layer = layersByName.at( 0 );
@ -3430,10 +3429,10 @@ static QVariant fcnGetRasterBandStat( const QVariantList& values, const QgsExpre
QString layerIdOrName = getStringValue( values.at( 0 ), parent );
//try to find a matching layer by name
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerIdOrName ); //search by id first
QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerIdOrName ); //search by id first
if ( !layer )
{
QList<QgsMapLayer *> layersByName = QgsMapLayerRegistry::instance()->mapLayersByName( layerIdOrName );
QList<QgsMapLayer *> layersByName = QgsProject::instance()->mapLayersByName( layerIdOrName );
if ( !layersByName.isEmpty() )
{
layer = layersByName.at( 0 );

View File

@ -18,7 +18,6 @@
#include "qgsogrutils.h"
#include "qgsgeometry.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsrelation.h"
#include "qgsrelationmanager.h"
#include "qgsproject.h"
@ -55,7 +54,7 @@ void QgsJSONExporter::setVectorLayer( const QgsVectorLayer* vectorLayer )
QgsVectorLayer *QgsJSONExporter::vectorLayer() const
{
return qobject_cast< QgsVectorLayer* >( QgsMapLayerRegistry::instance()->mapLayer( mLayerId ) );
return qobject_cast< QgsVectorLayer* >( QgsProject::instance()->mapLayer( mLayerId ) );
}
void QgsJSONExporter::setSourceCrs( const QgsCoordinateReferenceSystem& crs )

View File

@ -22,7 +22,6 @@
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgslayertree.h"
#include "qgsmaplayerregistry.h"
#include "qgslayerdefinition.h"
bool QgsLayerDefinition::loadLayerDefinition( const QString &path, QgsLayerTreeGroup *rootGroup, QString &errorMessage )

View File

@ -20,7 +20,6 @@
#include "qgslayertreemodel.h"
#include "qgslayertreemodellegendnode.h"
#include "qgsmaplayerlegend.h"
#include "qgsmaplayerregistry.h"
#include "qgssymbol.h"
#include "qgsvectorlayer.h"

View File

@ -17,7 +17,7 @@
#include "qgsmaphittest.h"
#include "qgsfeatureiterator.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrendercontext.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsrenderer.h"
@ -58,7 +58,7 @@ void QgsMapHitTest::run()
Q_FOREACH ( const QString& layerID, mSettings.layers() )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerID ) );
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerID ) );
if ( !vl || !vl->renderer() )
continue;

View File

@ -47,7 +47,6 @@
#include "qgsrectangle.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsmaplayerregistry.h"
#include "qgsxmlutils.h"
@ -835,7 +834,7 @@ QList<QgsMapLayer*> QgsMapLayer::fromLayerDefinition( QDomDocument& document, bo
{
layers << layer;
if ( addToRegistry )
QgsMapLayerRegistry::instance()->addMapLayer( layer, addToLegend );
QgsProject::instance()->addMapLayer( layer, addToLegend );
}
}
return layers;
@ -1693,7 +1692,7 @@ static QList<const QgsMapLayer*> _depOutEdges( const QgsMapLayer* vl, const QgsM
{
Q_FOREACH ( const QgsMapLayerDependency& dep, layers )
{
if ( const QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( dep.layerId() ) )
if ( const QgsMapLayer* l = QgsProject::instance()->mapLayer( dep.layerId() ) )
lst << l;
}
}
@ -1701,7 +1700,7 @@ static QList<const QgsMapLayer*> _depOutEdges( const QgsMapLayer* vl, const QgsM
{
Q_FOREACH ( const QgsMapLayerDependency& dep, vl->dependencies() )
{
if ( const QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( dep.layerId() ) )
if ( const QgsMapLayer* l = QgsProject::instance()->mapLayer( dep.layerId() ) )
lst << l;
}
}

View File

@ -75,7 +75,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
QgsMapLayer::LayerType type() const;
//! Returns the layer's unique ID, which is used to access this layer from QgsMapLayerRegistry.
//! Returns the layer's unique ID, which is used to access this layer from QgsProject.
QString id() const;
/**

View File

@ -17,7 +17,7 @@
#include "qgsdataitem.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
@ -29,7 +29,7 @@ QgsMapLayerModel::QgsMapLayerModel( const QList<QgsMapLayer *>& layers, QObject
, mAllowEmpty( false )
, mShowCrs( false )
{
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
addLayers( layers );
}
@ -40,9 +40,9 @@ QgsMapLayerModel::QgsMapLayerModel( QObject *parent )
, mAllowEmpty( false )
, mShowCrs( false )
{
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( addLayers( QList<QgsMapLayer*> ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
addLayers( QgsMapLayerRegistry::instance()->mapLayers().values() );
connect( QgsProject::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( addLayers( QList<QgsMapLayer*> ) ) );
connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
addLayers( QgsProject::instance()->mapLayers().values() );
}
void QgsMapLayerModel::setItemsCheckable( bool checkable )

View File

@ -16,7 +16,7 @@
#include "qgsmaplayerproxymodel.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsrasterlayer.h"
#include "qgsvectordataprovider.h"
@ -57,7 +57,7 @@ void QgsMapLayerProxyModel::setExceptedLayerIds( const QStringList& ids )
Q_FOREACH ( const QString& id, ids )
{
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( id );
QgsMapLayer* l = QgsProject::instance()->mapLayer( id );
if ( l )
mExceptList << l;
}

View File

@ -1,211 +0,0 @@
/***************************************************************************
* QgsMapLayerRegistry.cpp - Singleton class for tracking mMapLayers.
* -------------------
* begin : Sun June 02 2004
* copyright : (C) 2004 by Tim Sutton
* email : tim@linfiniti.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmaplayerregistry.h"
#include "qgsmaplayer.h"
#include "qgslogger.h"
//
// Static calls to enforce singleton behaviour
//
QgsMapLayerRegistry *QgsMapLayerRegistry::instance()
{
static QgsMapLayerRegistry sInstance;
return &sInstance;
}
QgsMapLayerRegistry::QgsMapLayerRegistry( QObject *parent )
: QObject( parent )
{}
QgsMapLayerRegistry::~QgsMapLayerRegistry()
{
removeAllMapLayers();
}
int QgsMapLayerRegistry::count() const
{
return mMapLayers.size();
}
QgsMapLayer * QgsMapLayerRegistry::mapLayer( const QString& theLayerId ) const
{
return mMapLayers.value( theLayerId );
}
QList<QgsMapLayer *> QgsMapLayerRegistry::mapLayersByName( const QString& layerName ) const
{
QList<QgsMapLayer *> myResultList;
Q_FOREACH ( QgsMapLayer* layer, mMapLayers )
{
if ( layer->name() == layerName )
{
myResultList << layer;
}
}
return myResultList;
}
QList<QgsMapLayer *> QgsMapLayerRegistry::addMapLayers(
const QList<QgsMapLayer *>& theMapLayers,
bool addToLegend,
bool takeOwnership )
{
QList<QgsMapLayer *> myResultList;
Q_FOREACH ( QgsMapLayer* myLayer, theMapLayers )
{
if ( !myLayer || !myLayer->isValid() )
{
QgsDebugMsg( "Cannot add invalid layers" );
continue;
}
//check the layer is not already registered!
if ( !mMapLayers.contains( myLayer->id() ) )
{
mMapLayers[myLayer->id()] = myLayer;
myResultList << mMapLayers[myLayer->id()];
if ( takeOwnership )
{
myLayer->setParent( this );
}
connect( myLayer, SIGNAL( destroyed( QObject* ) ), this, SLOT( onMapLayerDeleted( QObject* ) ) );
emit layerWasAdded( myLayer );
}
}
if ( !myResultList.isEmpty() )
{
emit layersAdded( myResultList );
if ( addToLegend )
emit legendLayersAdded( myResultList );
}
return myResultList;
}
QgsMapLayer *
QgsMapLayerRegistry::addMapLayer( QgsMapLayer* theMapLayer,
bool addToLegend,
bool takeOwnership )
{
QList<QgsMapLayer *> addedLayers;
addedLayers = addMapLayers( QList<QgsMapLayer*>() << theMapLayer, addToLegend, takeOwnership );
return addedLayers.isEmpty() ? nullptr : addedLayers[0];
}
void QgsMapLayerRegistry::removeMapLayers( const QStringList& theLayerIds )
{
QList<QgsMapLayer*> layers;
Q_FOREACH ( const QString &myId, theLayerIds )
{
layers << mMapLayers.value( myId );
}
removeMapLayers( layers );
}
void QgsMapLayerRegistry::removeMapLayers( const QList<QgsMapLayer*>& layers )
{
if ( layers.isEmpty() )
return;
QStringList layerIds;
QList<QgsMapLayer*> layerList;
Q_FOREACH ( QgsMapLayer* layer, layers )
{
// check layer and the registry contains it
if ( layer && mMapLayers.contains( layer->id() ) )
{
layerIds << layer->id();
layerList << layer;
}
}
if ( layerIds.isEmpty() )
return;
emit layersWillBeRemoved( layerIds );
emit layersWillBeRemoved( layerList );
Q_FOREACH ( QgsMapLayer* lyr, layerList )
{
QString myId( lyr->id() );
emit layerWillBeRemoved( myId );
emit layerWillBeRemoved( lyr );
mMapLayers.remove( myId );
if ( lyr->parent() == this )
{
delete lyr;
}
emit layerRemoved( myId );
}
emit layersRemoved( layerIds );
}
void QgsMapLayerRegistry::removeMapLayer( const QString& theLayerId )
{
removeMapLayers( QList<QgsMapLayer*>() << mMapLayers.value( theLayerId ) );
}
void QgsMapLayerRegistry::removeMapLayer( QgsMapLayer* layer )
{
if ( layer )
removeMapLayers( QList<QgsMapLayer*>() << layer );
}
void QgsMapLayerRegistry::removeAllMapLayers()
{
emit removeAll();
// now let all observers know to clear themselves,
// and then consequently any of their map legends
removeMapLayers( mMapLayers.keys() );
mMapLayers.clear();
}
void QgsMapLayerRegistry::reloadAllLayers()
{
Q_FOREACH ( QgsMapLayer* layer, mMapLayers )
{
layer->reload();
}
}
void QgsMapLayerRegistry::onMapLayerDeleted( QObject* obj )
{
QString id = mMapLayers.key( static_cast<QgsMapLayer*>( obj ) );
if ( !id.isNull() )
{
QgsDebugMsg( QString( "Map layer deleted without unregistering! %1" ).arg( id ) );
mMapLayers.remove( id );
}
}
QMap<QString, QgsMapLayer*> QgsMapLayerRegistry::mapLayers() const
{
return mMapLayers;
}
#if 0
void QgsMapLayerRegistry::connectNotify( const char * signal )
{
Q_UNUSED( signal );
//QgsDebugMsg("QgsMapLayerRegistry connected to " + QString(signal));
} // QgsMapLayerRegistry::connectNotify
#endif

View File

@ -1,367 +0,0 @@
/***************************************************************************
qgsmaplayerregistry.h
Singleton class for keeping track of loaded layers
-------------------
begin : Sun June 04 2004
copyright : (C) 2004 by Tim Sutton
email : tim@linfiniti.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMAPLAYERREGISTRY_H
#define QGSMAPLAYERREGISTRY_H
#include <QMap>
#include <QObject>
#include <QStringList>
class QString;
class QgsMapLayer;
/** \ingroup core
* \class QgsMapLayerRegistry
* This class tracks map layers that are currently loaded and provides
* various methods to retrieve matching layers from the registry.
*/
class CORE_EXPORT QgsMapLayerRegistry : public QObject
{
Q_OBJECT
public:
//! Returns the instance pointer, creating the object on the first call
static QgsMapLayerRegistry * instance();
~QgsMapLayerRegistry();
//! Returns the number of registered layers.
int count() const;
/** Retrieve a pointer to a registered layer by layer ID.
* @param theLayerId ID of layer to retrieve
* @returns matching layer, or nullptr if no matching layer found
* @see mapLayersByName()
* @see mapLayers()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
QgsMapLayer* mapLayer( const QString& theLayerId ) const;
/** Retrieve a list of matching registered layers by layer name.
* @param layerName name of layers to match
* @returns list of matching layers
* @see mapLayer()
* @see mapLayers()
*/
QList<QgsMapLayer *> mapLayersByName( const QString& layerName ) const;
/** Returns a map of all registered layers by layer ID.
* @see mapLayer()
* @see mapLayersByName()
* @see layers()
*/
QMap<QString, QgsMapLayer*> mapLayers() const;
/** Returns a list of registered map layers with a specified layer type.
*
* Example:
*
* QVector<QgsVectorLayer*> vectorLayers = QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>();
*
* @note not available in Python bindings
* @note added in QGIS 2.16
* @see mapLayers()
*/
template <typename T>
QVector<T> layers() const
{
QVector<T> layers;
QMap<QString, QgsMapLayer*>::const_iterator layerIt = mMapLayers.constBegin();
for ( ; layerIt != mMapLayers.constEnd(); ++layerIt )
{
T tLayer = qobject_cast<T>( layerIt.value() );
if ( tLayer )
{
layers << tLayer;
}
}
return layers;
}
/**
* @brief
* Add a list of layers to the map of loaded layers.
*
* The layersAdded() and layerWasAdded() signals will always be emitted.
* The legendLayersAdded() signal is emitted only if addToLegend is true.
*
* @param theMapLayers A list of layer which should be added to the registry
* @param addToLegend If true (by default), the layers will be added to the
* legend and to the main canvas. If you have a private
* layer you can set this parameter to false to hide it.
* @param takeOwnership Ownership will be transferred to the layer registry.
* If you specify false here you have take care of deleting
* the layers yourself. Not available in python.
*
* @return a list of the map layers that were added
* successfully. If a layer is invalid, or already exists in the registry,
* it will not be part of the returned QList.
*
* @note As a side-effect QgsProject is made dirty.
* @note takeOwnership is not available in the Python bindings - the registry will always
* take ownership
* @note added in QGIS 1.8
* @see addMapLayer()
*/
QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer*>& theMapLayers,
bool addToLegend = true,
bool takeOwnership = true );
/**
* @brief
* Add a layer to the map of loaded layers.
*
* The layersAdded() and layerWasAdded() signals will always be emitted.
* The legendLayersAdded() signal is emitted only if addToLegend is true.
* If you are adding multiple layers at once, you should use
* addMapLayers() instead.
*
* @param theMapLayer A layer to add to the registry
* @param addToLegend If true (by default), the layer will be added to the
* legend and to the main canvas. If you have a private
* layer you can set this parameter to false to hide it.
* @param takeOwnership Ownership will be transferred to the layer registry.
* If you specify false here you have take care of deleting
* the layer yourself. Not available in python.
*
* @return nullptr if unable to add layer, otherwise pointer to newly added layer
*
* @see addMapLayers
*
* @note As a side-effect QgsProject is made dirty.
* @note Use addMapLayers if adding more than one layer at a time
* @note takeOwnership is not available in the Python bindings - the registry will always
* take ownership
* @see addMapLayers()
*/
QgsMapLayer* addMapLayer( QgsMapLayer * theMapLayer, bool addToLegend = true, bool takeOwnership = true );
/**
* @brief
* Remove a set of layers from the registry by layer ID.
*
* The specified layers will be removed from the registry. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @param theLayerIds list of IDs of the layers to remove
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @note added in QGIS 1.8
* @see removeMapLayer()
* @see removeAllMapLayers()
*/
// TODO QGIS 3.0 - rename theLayerIds to layerIds
void removeMapLayers( const QStringList& theLayerIds );
/**
* @brief
* Remove a set of layers from the registry.
*
* The specified layers will be removed from the registry. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @param layers A list of layers to remove. Null pointers are ignored.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayer()
* @see removeAllMapLayers()
*/
//TODO QGIS 3.0 - add PyName alias to avoid list type conversion error
void removeMapLayers( const QList<QgsMapLayer*>& layers );
/**
* @brief
* Remove a layer from the registry by layer ID.
*
* The specified layer will be removed from the registry. If the registry has ownership
* of the layer then it will also be deleted.
*
* @param theLayerId ID of the layer to remove
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayers()
* @see removeAllMapLayers()
*/
// TODO QGIS 3.0 - rename theLayerId to layerId
void removeMapLayer( const QString& theLayerId );
/**
* @brief
* Remove a layer from the registry.
*
* The specified layer will be removed from the registry. If the registry has ownership
* of the layer then it will also be deleted.
*
* @param layer The layer to remove. Null pointers are ignored.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @see removeMapLayers()
* @see removeAllMapLayers()
*/
void removeMapLayer( QgsMapLayer* layer );
/**
* Removes all registered layers. If the registry has ownership
* of any layers these layers will also be deleted.
*
* @note As a side-effect the QgsProject instance is marked dirty.
* @note Calling this method will cause the removeAll() signal to
* be emitted.
* @see removeMapLayer()
* @see removeMapLayers()
*/
void removeAllMapLayers();
/**
* Reload all registered layer's provider data caches, synchronising the layer
* with any changes in the datasource.
* @see QgsMapLayer::reload()
*/
void reloadAllLayers();
signals:
/**
* Emitted when one or more layers are about to be removed from the registry.
*
* @param theLayerIds A list of IDs for the layers which are to be removed.
* @see layerWillBeRemoved()
* @see layersRemoved()
*/
// TODO QGIS 3.0 - rename theLayerIds to layerIds
void layersWillBeRemoved( const QStringList& theLayerIds );
/**
* Emitted when one or more layers are about to be removed from the registry.
*
* @param layers A list of layers which are to be removed.
* @see layerWillBeRemoved()
* @see layersRemoved()
*/
void layersWillBeRemoved( const QList<QgsMapLayer*>& layers );
/**
* Emitted when a layer is about to be removed from the registry.
*
* @param theLayerId The ID of the layer to be removed.
*
* @note Consider using {@link layersWillBeRemoved()} instead
* @see layersWillBeRemoved()
* @see layerRemoved()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
void layerWillBeRemoved( const QString& theLayerId );
/**
* Emitted when a layer is about to be removed from the registry.
*
* @param layer The layer to be removed.
*
* @note Consider using {@link layersWillBeRemoved()} instead
* @see layersWillBeRemoved()
* @see layerRemoved()
*/
void layerWillBeRemoved( QgsMapLayer* layer );
/**
* Emitted after one or more layers were removed from the registry.
*
* @param theLayerIds A list of IDs of the layers which were removed.
* @see layersWillBeRemoved()
*/
//TODO QGIS 3.0 - rename theLayerIds to layerIds
void layersRemoved( const QStringList& theLayerIds );
/**
* Emitted after a layer was removed from the registry.
*
* @param theLayerId The ID of the layer removed.
*
* @note Consider using {@link layersRemoved()} instead
* @see layerWillBeRemoved()
*/
//TODO QGIS 3.0 - rename theLayerId to layerId
void layerRemoved( const QString& theLayerId );
/**
* Emitted when all layers are removed, before {@link layersWillBeRemoved()} and
* {@link layerWillBeRemoved()} signals are emitted. The layersWillBeRemoved() and
* layerWillBeRemoved() signals will still be emitted following this signal.
* You can use this signal to do easy (and fast) cleanup.
*/
//TODO QGIS 3.0 - rename to past tense
void removeAll();
/**
* Emitted when one or more layers were added to the registry.
* This signal is also emitted for layers added to the registry,
* but not to the legend.
*
* @param theMapLayers List of layers which have been added.
*
* @see legendLayersAdded()
* @see layerWasAdded()
*/
//TODO QGIS 3.0 - rename theMapLayers to mapLayers
void layersAdded( const QList<QgsMapLayer *>& theMapLayers );
/**
* Emitted when a layer was added to the registry.
*
* @param theMapLayer The ID of the layer which has been added.
*
* @note Consider using {@link layersAdded()} instead
* @see layersAdded()
*/
// TODO QGIS 3.0 - rename theMapLayer to layer
void layerWasAdded( QgsMapLayer* theMapLayer );
/**
* Emitted, when a layer was added to the registry and the legend.
* Layers can also be private layers, which are signalled by
* {@link layersAdded()} and {@link layerWasAdded()} but will not be
* advertised by this signal.
*
* @param theMapLayers List of {@link QgsMapLayer}s which were added to the legend.
*/
//TODO QGIS 3.0 rename theMapLayers to mapLayers
void legendLayersAdded( const QList<QgsMapLayer*>& theMapLayers );
protected:
#if 0
/** Debugging member
* invoked when a connect() is made to this object
*/
void connectNotify( const char * signal ) override;
#endif
private slots:
void onMapLayerDeleted( QObject* obj );
private:
//! private singleton constructor
QgsMapLayerRegistry( QObject * parent = nullptr );
QMap<QString, QgsMapLayer*> mMapLayers;
};
#endif //QGSMAPLAYERREGISTRY_H

View File

@ -15,7 +15,7 @@
#include "qgsmaprenderercache.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsmaplayer.h"
QgsMapRendererCache::QgsMapRendererCache()
@ -38,7 +38,7 @@ void QgsMapRendererCache::clearInternal()
QMap<QString, QImage>::const_iterator it = mCachedImages.constBegin();
for ( ; it != mCachedImages.constEnd(); ++it )
{
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( it.key() );
QgsMapLayer* layer = QgsProject::instance()->mapLayer( it.key() );
if ( layer )
{
disconnect( layer, SIGNAL( repaintRequested() ), this, SLOT( layerRequestedRepaint() ) );
@ -71,7 +71,7 @@ void QgsMapRendererCache::setCacheImage( const QString& layerId, const QImage& i
mCachedImages[layerId] = img;
// connect to the layer to listen to layer's repaintRequested() signals
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerId );
if ( layer )
{
connect( layer, SIGNAL( repaintRequested() ), this, SLOT( layerRequestedRepaint() ) );
@ -97,7 +97,7 @@ void QgsMapRendererCache::clearCacheImage( const QString& layerId )
mCachedImages.remove( layerId );
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerId );
if ( layer )
{
disconnect( layer, SIGNAL( repaintRequested() ), this, SLOT( layerRequestedRepaint() ) );

View File

@ -18,7 +18,7 @@
#include "qgsfeedback.h"
#include "qgslabelingengine.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsmaplayerrenderer.h"
#include "qgspallabeling.h"
#include "qgsvectorlayer.h"
@ -304,7 +304,7 @@ void QgsMapRendererJob::updateLayerGeometryCaches()
for ( ; it != mGeometryCaches.constEnd(); ++it )
{
const QgsGeometryCache& cache = it.value();
if ( QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( it.key() ) ) )
if ( QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( it.key() ) ) )
* vl->cache() = cache;
}
mGeometryCaches.clear();

View File

@ -24,7 +24,7 @@
#include "qgslogger.h"
#include "qgsrendercontext.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsmaplayerrenderer.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmaprenderercache.h"
@ -191,7 +191,7 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsLabelingEn
QgsDebugMsgLevel( "Rendering at layer item " + layerId, 2 );
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
QgsMapLayer *ml = QgsProject::instance()->mapLayer( layerId );
if ( !ml )
{

View File

@ -22,7 +22,7 @@
#include "qgsmessagelog.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsxmlutils.h"
#include "qgscsexception.h"
#include "qgsgeometry.h"
@ -535,7 +535,6 @@ QgsRectangle QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRe
QgsRectangle QgsMapSettings::fullExtent() const
{
QgsDebugMsg( "called." );
QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
// reset the map canvas extent since the extent may now be smaller
// We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
@ -548,7 +547,7 @@ QgsRectangle QgsMapSettings::fullExtent() const
QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) );
while ( it != mLayers.end() )
{
QgsMapLayer * lyr = registry->mapLayer( *it );
QgsMapLayer * lyr = QgsProject::instance()->mapLayer( *it );
if ( !lyr )
{
QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );

View File

@ -103,7 +103,7 @@ class CORE_EXPORT QgsMapSettings
//! Get list of layer IDs for map rendering
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
QStringList layers() const;
//! Set list of layer IDs for map rendering. The layers must be registered in QgsMapLayerRegistry.
//! Set list of layer IDs for map rendering. The layers must be registered in QgsProject.
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
void setLayers( const QStringList& layers );

View File

@ -18,7 +18,6 @@
#include "qgslayertree.h"
#include "qgslayertreemodel.h"
#include "qgslayertreemodellegendnode.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsproject.h"
#include "qgsrenderer.h"
@ -26,9 +25,10 @@
#include <QInputDialog>
QgsMapThemeCollection::QgsMapThemeCollection()
QgsMapThemeCollection::QgsMapThemeCollection( QgsProject* project )
: mProject( project )
{
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ),
connect( project, SIGNAL( layersRemoved( QStringList ) ),
this, SLOT( registryLayersRemoved( QStringList ) ) );
}
@ -106,7 +106,7 @@ void QgsMapThemeCollection::applyMapThemeCheckedLegendNodesToLayer( const QStrin
if ( !mMapThemes.contains( name ) )
return;
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );
QgsMapLayer* layer = mProject->mapLayer( layerID );
if ( !layer )
return;
@ -141,7 +141,7 @@ QMap<QString, QString> QgsMapThemeCollection::mapThemeStyleOverrides( const QStr
const QgsMapThemeCollection::MapThemeRecord& rec = mMapThemes[presetName];
Q_FOREACH ( const QString& layerID, lst )
{
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );
QgsMapLayer* layer = mProject->mapLayer( layerID );
if ( !layer )
continue;
@ -180,7 +180,7 @@ void QgsMapThemeCollection::reconnectToLayersStyleManager()
Q_FOREACH ( const QString& layerID, layerIDs )
{
if ( QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerID ) )
if ( QgsMapLayer* ml = mProject->mapLayer( layerID ) )
connect( ml->styleManager(), SIGNAL( styleRenamed( QString, QString ) ), this, SLOT( layerStyleRenamed( QString, QString ) ) );
}
}
@ -202,7 +202,7 @@ void QgsMapThemeCollection::readXml( const QDomDocument& doc )
while ( !visPresetLayerElem.isNull() )
{
QString layerID = visPresetLayerElem.attribute( QStringLiteral( "id" ) );
if ( QgsMapLayerRegistry::instance()->mapLayer( layerID ) )
if ( mProject->mapLayer( layerID ) )
{
rec.mVisibleLayerIds << layerID; // only use valid layer IDs
if ( visPresetLayerElem.hasAttribute( QStringLiteral( "style" ) ) )
@ -224,7 +224,7 @@ void QgsMapThemeCollection::readXml( const QDomDocument& doc )
}
QString layerID = checkedLegendNodesElem.attribute( QStringLiteral( "id" ) );
if ( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ) // only use valid IDs
if ( mProject->mapLayer( layerID ) ) // only use valid IDs
rec.mPerLayerCheckedLegendSymbols.insert( layerID, checkedLegendNodes );
checkedLegendNodesElem = checkedLegendNodesElem.nextSiblingElement( QStringLiteral( "checked-legend-nodes" ) );
}

Some files were not shown because too many files have changed in this diff Show More