From d56a97d4fe21f593746f176ceb6f553eca1d4c2e Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Sat, 10 Dec 2016 15:18:12 +0800 Subject: [PATCH] Merge QgsMapLayerRegistry into QgsProject All methods/signals of QgsMapLayerRegistry moved verbatim to QgsProject. --- doc/api_break.dox | 1 + python/core/core.sip | 1 - python/core/layertree/qgslayertreelayer.sip | 2 +- .../layertree/qgslayertreeregistrybridge.sip | 2 +- python/core/qgsmaplayer.sip | 2 +- python/core/qgsmaplayerregistry.sip | 297 -------------- python/core/qgsmapsettings.sip | 2 +- python/core/qgsmapthemecollection.sip | 2 +- python/core/qgsproject.sip | 280 +++++++++++++ python/core/qgssnappingconfig.sip | 2 +- .../GdalTools/tools/GdalTools_utils.py | 8 +- .../plugins/GdalTools/tools/doProjection.py | 4 +- .../plugins/GdalTools/tools/inOutSelector.py | 4 +- .../plugins/db_manager/db_manager_plugin.py | 8 +- .../postgis/plugins/qgis_topoview/__init__.py | 4 +- .../db_plugins/vlayers/connector.py | 8 +- .../db_manager/db_plugins/vlayers/plugin.py | 4 +- python/plugins/db_manager/db_tree.py | 4 +- .../plugins/db_manager/dlg_import_vector.py | 4 +- .../db_manager/dlg_sql_layer_window.py | 7 +- python/plugins/db_manager/dlg_sql_window.py | 7 +- python/plugins/db_manager/layer_preview.py | 6 +- .../algs/gdal/GdalAlgorithmDialog.py | 1 - .../algs/lidar/lastools/lasquery.py | 4 +- .../plugins/processing/gui/AlgorithmDialog.py | 6 +- .../processing/gui/AlgorithmDialogBase.py | 10 +- .../plugins/processing/gui/CommanderWindow.py | 2 +- .../plugins/processing/gui/ParametersPanel.py | 2 +- .../plugins/processing/gui/Postprocessing.py | 4 +- .../processing/tests/AlgorithmsTestBase.py | 6 +- .../plugins/processing/tools/dataobjects.py | 6 +- python/plugins/processing/tools/vector.py | 4 +- .../composer/qgsatlascompositionwidget.cpp | 1 - src/app/composer/qgscomposer.cpp | 1 - .../qgscomposerattributetablewidget.cpp | 1 - src/app/composer/qgscomposerlegendwidget.cpp | 1 - src/app/composer/qgscomposermapwidget.cpp | 1 - src/app/main.cpp | 5 +- .../openstreetmap/qgsosmdownloaddialog.cpp | 6 +- src/app/openstreetmap/qgsosmexportdialog.cpp | 4 +- src/app/qgisapp.cpp | 53 ++- src/app/qgisappinterface.cpp | 1 - src/app/qgsalignrasterdialog.cpp | 6 +- src/app/qgsapplayertreeviewmenuprovider.cpp | 7 +- src/app/qgsattributeactiondialog.cpp | 2 +- src/app/qgsattributetypedialog.cpp | 1 - src/app/qgsbrowserdockwidget.cpp | 1 - src/app/qgsfieldsproperties.cpp | 1 - src/app/qgsjoindialog.cpp | 4 +- src/app/qgslabelpropertydialog.cpp | 4 +- src/app/qgslayerstylingwidget.cpp | 3 +- src/app/qgsmapthemes.cpp | 1 - src/app/qgsmaptooladdfeature.cpp | 3 +- src/app/qgsmaptoolfeatureaction.cpp | 1 - src/app/qgsmaptoolidentifyaction.cpp | 1 - src/app/qgsmaptoollabel.cpp | 4 +- src/app/qgsmaptoolmovelabel.cpp | 1 - src/app/qgsmaptooloffsetcurve.cpp | 4 +- src/app/qgsmaptoolpinlabels.cpp | 4 +- src/app/qgsmaptoolrotatelabel.cpp | 1 - src/app/qgsnewspatialitelayerdialog.cpp | 4 +- src/app/qgsprojectproperties.cpp | 11 +- src/app/qgsrastercalcdialog.cpp | 4 +- src/app/qgsrasterlayerproperties.cpp | 1 - src/app/qgssnappingwidget.cpp | 1 + src/app/qgsstatisticalsummarydockwidget.cpp | 4 +- src/app/qgsvectorlayerproperties.cpp | 11 +- src/browser/qgsbrowser.cpp | 8 +- src/core/CMakeLists.txt | 2 - src/core/composer/qgsatlascomposition.cpp | 5 +- .../composer/qgscomposerattributetablev2.cpp | 7 +- src/core/composer/qgscomposerlegend.cpp | 3 +- src/core/composer/qgscomposerlegenditem.cpp | 4 +- src/core/composer/qgscomposermap.cpp | 19 +- src/core/dxf/qgsdxfexport.cpp | 1 - src/core/geometry/qgsgeometry.cpp | 2 - src/core/geometry/qgsgeometryeditutils.cpp | 3 +- src/core/layertree/qgslayertreegroup.cpp | 6 +- src/core/layertree/qgslayertreelayer.cpp | 18 +- src/core/layertree/qgslayertreelayer.h | 2 +- .../layertree/qgslayertreeregistrybridge.cpp | 13 +- .../layertree/qgslayertreeregistrybridge.h | 4 +- src/core/qgsapplication.cpp | 6 +- src/core/qgsexpression.cpp | 13 +- src/core/qgsjsonutils.cpp | 3 +- src/core/qgslayerdefinition.cpp | 1 - src/core/qgslegendrenderer.cpp | 1 - src/core/qgsmaphittest.cpp | 4 +- src/core/qgsmaplayer.cpp | 7 +- src/core/qgsmaplayer.h | 2 +- src/core/qgsmaplayermodel.cpp | 10 +- src/core/qgsmaplayerproxymodel.cpp | 4 +- src/core/qgsmaplayerregistry.cpp | 211 ---------- src/core/qgsmaplayerregistry.h | 367 ------------------ src/core/qgsmaprenderercache.cpp | 8 +- src/core/qgsmaprenderercustompainterjob.cpp | 4 +- src/core/qgsmaprendererjob.cpp | 4 +- src/core/qgsmapsettings.cpp | 5 +- src/core/qgsmapsettings.h | 2 +- src/core/qgsmapthemecollection.cpp | 16 +- src/core/qgsmapthemecollection.h | 5 +- src/core/qgsofflineediting.cpp | 21 +- src/core/qgspallabeling.cpp | 3 +- src/core/qgspluginlayerregistry.cpp | 6 +- src/core/qgsproject.cpp | 200 +++++++++- src/core/qgsproject.h | 312 +++++++++++++++ src/core/qgsproviderregistry.cpp | 4 +- src/core/qgsrelation.cpp | 6 +- src/core/qgsrelationmanager.cpp | 3 +- src/core/qgssnappingconfig.cpp | 30 +- src/core/qgssnappingconfig.h | 5 +- src/core/qgssnappingutils.cpp | 6 +- src/core/qgstaskmanager.cpp | 4 +- src/core/qgstransaction.cpp | 8 +- src/core/qgsvectorlayer.cpp | 11 +- src/core/qgsvectorlayerfeatureiterator.cpp | 3 +- src/core/qgsvectorlayerjoinbuffer.cpp | 14 +- src/core/qgsvirtuallayerdefinitionutils.cpp | 4 +- src/core/raster/qgsrasterlayer.cpp | 1 - .../attributetable/qgsattributetablemodel.cpp | 1 - .../core/qgseditorwidgetregistry.cpp | 5 +- ...gsrelationreferencesearchwidgetwrapper.cpp | 1 - .../qgsvaluerelationconfigdlg.cpp | 4 +- .../qgsvaluerelationsearchwidgetwrapper.cpp | 1 - .../qgsvaluerelationwidgetfactory.cpp | 1 - .../qgsvaluerelationwidgetwrapper.cpp | 4 +- .../layertree/qgscustomlayerorderwidget.cpp | 6 +- .../qgslayertreeviewdefaultactions.cpp | 4 +- src/gui/qgsattributetypeloaddialog.cpp | 10 +- src/gui/qgsformannotationitem.cpp | 4 +- src/gui/qgshtmlannotationitem.cpp | 4 +- src/gui/qgsmapcanvas.cpp | 9 +- src/gui/qgsmapcanvassnapper.cpp | 3 +- src/gui/qgsmapcanvastracer.cpp | 4 +- src/gui/qgsmapoverviewcanvas.cpp | 6 +- src/gui/qgsmaptoolidentify.cpp | 1 - src/gui/qgsnewgeopackagelayerdialog.cpp | 4 +- .../qgsellipsesymbollayerwidget.cpp | 1 - src/gui/symbology-ng/qgssizescalewidget.cpp | 4 +- .../ui/qgsgeometrycheckerresulttab.cpp | 10 +- .../ui/qgsgeometrycheckersetuptab.cpp | 14 +- .../georeferencer/qgsgcpcanvasitem.cpp | 4 +- .../georeferencer/qgsgeorefplugingui.cpp | 7 +- src/plugins/globe/globe_plugin.cpp | 7 +- src/plugins/globe/qgsglobefeatureidentify.cpp | 4 +- src/plugins/globe/qgsglobewidget.cpp | 5 +- src/plugins/gps_importer/qgsgpsplugin.cpp | 5 +- src/plugins/grass/qgsgrassmoduleinput.cpp | 1 - src/plugins/grass/qgsgrassmoduleoptions.cpp | 6 +- src/plugins/grass/qgsgrassmoduleoptions.h | 2 +- src/plugins/grass/qgsgrassmoduleparam.cpp | 20 +- src/plugins/grass/qgsgrassplugin.cpp | 9 +- .../interpolation/qgsinterpolationdialog.cpp | 6 +- .../offline_editing_plugin.cpp | 7 +- .../offline_editing_plugin_gui.cpp | 1 - .../qgsrasterterrainanalysisdialog.cpp | 6 +- .../qgsrasterterrainanalysisplugin.cpp | 1 - src/plugins/roadgraph/exportdlg.cpp | 8 +- src/plugins/roadgraph/roadgraphplugin.cpp | 3 +- .../spatialquery/qgsspatialquerydialog.cpp | 15 +- .../spatialquery/qgsspatialqueryplugin.cpp | 1 - src/plugins/topology/checkDock.cpp | 15 +- src/plugins/topology/checkDock.h | 2 - src/plugins/topology/rulesDialog.cpp | 30 +- src/plugins/topology/rulesDialog.h | 6 +- src/providers/gdal/qgsgdalprovider.cpp | 2 +- .../virtual/qgsvirtuallayerprovider.cpp | 6 +- .../virtual/qgsvirtuallayersourceselect.cpp | 10 +- .../virtual/qgsvirtuallayersqlitemodule.cpp | 4 +- src/providers/wcs/URI | 2 +- src/server/qgsmaprenderer.cpp | 7 +- src/server/qgsmslayercache.cpp | 8 +- src/server/qgsowsserver.cpp | 1 - src/server/qgsserver.cpp | 4 +- src/server/qgsserverprojectparser.cpp | 19 +- src/server/qgswfsprojectparser.cpp | 4 +- src/server/qgswfsserver.cpp | 5 +- src/server/qgswmsconfigparser.cpp | 6 +- src/server/qgswmsprojectparser.cpp | 8 +- src/server/qgswmsserver.cpp | 35 +- tests/bench/qgsbench.cpp | 4 +- .../src/analysis/testqgsrastercalculator.cpp | 4 +- tests/src/analysis/testqgszonalstatistics.cpp | 4 +- tests/src/app/testqgisappclipboard.cpp | 1 - tests/src/core/testmaprendererjob.cpp | 12 +- tests/src/core/testqgs25drenderer.cpp | 4 +- tests/src/core/testqgsatlascomposition.cpp | 8 +- tests/src/core/testqgsblendmodes.cpp | 12 +- tests/src/core/testqgscentroidfillsymbol.cpp | 4 +- tests/src/core/testqgscomposerdd.cpp | 4 +- tests/src/core/testqgscomposerhtml.cpp | 5 +- tests/src/core/testqgscomposerlabel.cpp | 3 +- tests/src/core/testqgscomposermap.cpp | 9 +- tests/src/core/testqgscomposermapgrid.cpp | 1 - tests/src/core/testqgscomposermapoverview.cpp | 4 +- tests/src/core/testqgscomposerrotation.cpp | 4 +- tests/src/core/testqgscomposerscalebar.cpp | 3 +- tests/src/core/testqgscomposertablev2.cpp | 11 +- tests/src/core/testqgsdiagram.cpp | 3 +- tests/src/core/testqgsellipsemarker.cpp | 4 +- tests/src/core/testqgsexpression.cpp | 11 +- tests/src/core/testqgsfilledmarker.cpp | 4 +- tests/src/core/testqgsfontmarker.cpp | 4 +- tests/src/core/testqgsgradients.cpp | 4 +- .../core/testqgsinvertedpolygonrenderer.cpp | 6 +- tests/src/core/testqgslabelingengine.cpp | 10 +- tests/src/core/testqgslayertree.cpp | 18 +- tests/src/core/testqgslegendrenderer.cpp | 34 +- tests/src/core/testqgslinefillsymbol.cpp | 4 +- .../src/core/testqgsmaplayerstylemanager.cpp | 6 +- tests/src/core/testqgsmaprendererjob.cpp | 8 +- tests/src/core/testqgsmaprotation.cpp | 4 +- tests/src/core/testqgsmarkerlinesymbol.cpp | 4 +- tests/src/core/testqgspainteffect.cpp | 14 +- tests/src/core/testqgspointlocator.cpp | 4 +- .../core/testqgspointpatternfillsymbol.cpp | 4 +- tests/src/core/testqgsrasterfill.cpp | 4 +- tests/src/core/testqgsrasterlayer.cpp | 8 +- tests/src/core/testqgsrastersublayer.cpp | 1 - tests/src/core/testqgsrenderers.cpp | 8 +- tests/src/core/testqgsshapeburst.cpp | 4 +- tests/src/core/testqgssimplemarker.cpp | 4 +- tests/src/core/testqgssnappingutils.cpp | 4 +- tests/src/core/testqgsstyle.cpp | 1 - tests/src/core/testqgssvgmarker.cpp | 4 +- tests/src/core/testqgssymbol.cpp | 8 +- tests/src/core/testqgstaskmanager.cpp | 10 +- tests/src/core/testqgstracer.cpp | 1 - tests/src/core/testqgsvectorlayer.cpp | 10 +- .../src/core/testqgsvectorlayerjoinbuffer.cpp | 31 +- tests/src/gui/testprojectionissues.cpp | 6 +- tests/src/gui/testqgseditorwidgetregistry.cpp | 5 +- .../src/gui/testqgsfieldexpressionwidget.cpp | 17 +- tests/src/gui/testqgsmapcanvas.cpp | 6 +- tests/src/gui/testqgsquickprint.cpp | 8 +- tests/src/gui/testrenderergui.cpp | 3 +- .../src/providers/testqgswcspublicservers.cpp | 6 +- tests/src/python/acceptable_missing_doc.py | 1 - tests/src/python/offlineditingtestbase.py | 4 +- tests/src/python/qgis_interface.py | 4 +- tests/src/python/test_layer_dependencies.py | 12 +- tests/src/python/test_offline_editing_wfs.py | 1 - tests/src/python/test_provider_spatialite.py | 9 +- tests/src/python/test_provider_virtual.py | 83 ++-- tests/src/python/test_qgsarrowsymbollayer.py | 6 +- tests/src/python/test_qgsatlascomposition.py | 8 +- tests/src/python/test_qgsblendmodes.py | 4 +- tests/src/python/test_qgscomposerlabel.py | 4 +- tests/src/python/test_qgscomposerlegend.py | 18 +- tests/src/python/test_qgscomposermap.py | 4 +- tests/src/python/test_qgscomposition.py | 4 +- tests/src/python/test_qgseditwidgets.py | 22 +- tests/src/python/test_qgsfeatureiterator.py | 14 +- .../test_qgsgeometry_avoid_intersections.py | 4 +- .../test_qgsgeometrygeneratorsymbollayer.py | 10 +- tests/src/python/test_qgsjsonutils.py | 3 +- tests/src/python/test_qgslayerdefinition.py | 9 +- tests/src/python/test_qgsmaplayermodel.py | 68 ++-- tests/src/python/test_qgsmaplayerregistry.py | 340 ++++++++-------- .../test_qgsnewgeopackagelayerdialog.py | 16 +- .../src/python/test_qgsnullsymbolrenderer.py | 6 +- tests/src/python/test_qgspallabeling_base.py | 6 +- .../python/test_qgspointclusterrenderer.py | 6 +- .../test_qgspointdisplacementrenderer.py | 6 +- tests/src/python/test_qgsrasterlayer.py | 6 +- tests/src/python/test_qgsrelation.py | 6 +- .../src/python/test_qgsrelationeditwidget.py | 7 +- tests/src/python/test_qgsrelationmanager.py | 6 +- tests/src/python/test_qgsrulebasedrenderer.py | 6 +- .../src/python/test_qgssearchwidgetwrapper.py | 4 +- .../python/test_qgssinglesymbolrenderer.py | 4 +- .../test_qgssymbolexpressionvariables.py | 6 +- tests/src/python/test_qgssymbollayer.py | 14 +- tests/src/python/test_qgsvectorlayer.py | 5 +- .../python/test_qgsvectorlayereditbuffer.py | 1 - tests/src/python/test_qgsvectorlayertools.py | 4 +- tests/src/python/utilities.py | 4 +- 277 files changed, 1795 insertions(+), 2009 deletions(-) delete mode 100644 python/core/qgsmaplayerregistry.sip delete mode 100644 src/core/qgsmaplayerregistry.cpp delete mode 100644 src/core/qgsmaplayerregistry.h diff --git a/doc/api_break.dox b/doc/api_break.dox index 65174cf0d2d..7d4993aa327 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -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. diff --git a/python/core/core.sip b/python/core/core.sip index e4381264f3f..9d0b7b376f1 100644 --- a/python/core/core.sip +++ b/python/core/core.sip @@ -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 diff --git a/python/core/layertree/qgslayertreelayer.sip b/python/core/layertree/qgslayertreelayer.sip index a961dc99eb6..944ab65c4bc 100644 --- a/python/core/layertree/qgslayertreelayer.sip +++ b/python/core/layertree/qgslayertreelayer.sip @@ -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 diff --git a/python/core/layertree/qgslayertreeregistrybridge.sip b/python/core/layertree/qgslayertreeregistrybridge.sip index 2cad830c143..e172034f615 100644 --- a/python/core/layertree/qgslayertreeregistrybridge.sip +++ b/python/core/layertree/qgslayertreeregistrybridge.sip @@ -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; diff --git a/python/core/qgsmaplayer.sip b/python/core/qgsmaplayer.sip index 2e1460d8d34..6c31d509ede 100644 --- a/python/core/qgsmaplayer.sip +++ b/python/core/qgsmaplayer.sip @@ -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; /** diff --git a/python/core/qgsmaplayerregistry.sip b/python/core/qgsmaplayerregistry.sip deleted file mode 100644 index 8eef0f10a48..00000000000 --- a/python/core/qgsmaplayerregistry.sip +++ /dev/null @@ -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 -%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 mapLayersByName( const QString& layerName ) const; - - /** Returns a map of all registered layers by layer ID. - * @see mapLayer() - * @see mapLayersByName() - * @see layers() - */ - QMap 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 addMapLayers( const QList& 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& 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& 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& 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& theMapLayers ); - - private: - //! private singleton constructor - QgsMapLayerRegistry(); - - void connectNotify( const char * signal ); -}; diff --git a/python/core/qgsmapsettings.sip b/python/core/qgsmapsettings.sip index bdf3975209d..47684758cd0 100644 --- a/python/core/qgsmapsettings.sip +++ b/python/core/qgsmapsettings.sip @@ -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 ); diff --git a/python/core/qgsmapthemecollection.sip b/python/core/qgsmapthemecollection.sip index bf4418e2dea..3238418788d 100644 --- a/python/core/qgsmapthemecollection.sip +++ b/python/core/qgsmapthemecollection.sip @@ -61,7 +61,7 @@ class QgsMapThemeCollection : QObject }; - QgsMapThemeCollection(); + QgsMapThemeCollection( QgsProject* project ); /** * Returns whether a map theme with a matching name exists. diff --git a/python/core/qgsproject.sip b/python/core/qgsproject.sip index c6a4406865d..7cdf90349a4 100644 --- a/python/core/qgsproject.sip +++ b/python/core/qgsproject.sip @@ -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 mapLayersByName( const QString& layerName ) const; + + /** Returns a map of all registered layers by layer ID. + * @see mapLayer() + * @see mapLayersByName() + * @see layers() + */ + QMap 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 addMapLayers( const QList& 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& 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& 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& 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& theMapLayers ); + public slots: /** * Flag the project as dirty (modified). If this flag is set, the user will diff --git a/python/core/qgssnappingconfig.sip b/python/core/qgssnappingconfig.sip index aec9f3e5dae..b2fbdbc9f04 100644 --- a/python/core/qgssnappingconfig.sip +++ b/python/core/qgssnappingconfig.sip @@ -87,7 +87,7 @@ class QgsSnappingConfig /** * Constructor with default parameters defined in global settings */ - explicit QgsSnappingConfig(); + explicit QgsSnappingConfig( QgsProject* project ); ~QgsSnappingConfig(); diff --git a/python/plugins/GdalTools/tools/GdalTools_utils.py b/python/plugins/GdalTools/tools/GdalTools_utils.py index 79c86a802bf..81d23e60b4d 100644 --- a/python/plugins/GdalTools/tools/GdalTools_utils.py +++ b/python/plugins/GdalTools/tools/GdalTools_utils.py @@ -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()) diff --git a/python/plugins/GdalTools/tools/doProjection.py b/python/plugins/GdalTools/tools/doProjection.py index dd3d606b8a8..ab26f27fcb3 100644 --- a/python/plugins/GdalTools/tools/doProjection.py +++ b/python/plugins/GdalTools/tools/doProjection.py @@ -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())) diff --git a/python/plugins/GdalTools/tools/inOutSelector.py b/python/plugins/GdalTools/tools/inOutSelector.py index 57baf264679..a4c1f3432f2 100644 --- a/python/plugins/GdalTools/tools/inOutSelector.py +++ b/python/plugins/GdalTools/tools/inOutSelector.py @@ -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): diff --git a/python/plugins/db_manager/db_manager_plugin.py b/python/plugins/db_manager/db_manager_plugin.py index 99e61c266a3..346e1688461 100644 --- a/python/plugins/db_manager/db_manager_plugin.py +++ b/python/plugins/db_manager/db_manager_plugin.py @@ -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() diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py index 60398d55125..db01e975279 100644 --- a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py @@ -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: diff --git a/python/plugins/db_manager/db_plugins/vlayers/connector.py b/python/plugins/db_manager/db_plugins/vlayers/connector.py index ed5d9129351..783858c8cb0 100644 --- a/python/plugins/db_manager/db_plugins/vlayers/connector.py +++ b/python/plugins/db_manager/db_plugins/vlayers/connector.py @@ -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() diff --git a/python/plugins/db_manager/db_plugins/vlayers/plugin.py b/python/plugins/db_manager/db_plugins/vlayers/plugin.py index 023f0679ebb..d5e2c60317f 100644 --- a/python/plugins/db_manager/db_plugins/vlayers/plugin.py +++ b/python/plugins/db_manager/db_plugins/vlayers/plugin.py @@ -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): diff --git a/python/plugins/db_manager/db_tree.py b/python/plugins/db_manager/db_tree.py index 111e09db5eb..f01061e12e5 100644 --- a/python/plugins/db_manager/db_tree.py +++ b/python/plugins/db_manager/db_tree.py @@ -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())) diff --git a/python/plugins/db_manager/dlg_import_vector.py b/python/plugins/db_manager/dlg_import_vector.py index f3eddddebd6..44451bae74a 100644 --- a/python/plugins/db_manager/dlg_import_vector.py +++ b/python/plugins/db_manager/dlg_import_vector.py @@ -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() diff --git a/python/plugins/db_manager/dlg_sql_layer_window.py b/python/plugins/db_manager/dlg_sql_layer_window.py index 5ac41b5c4e9..dc7bc22ad6a 100644 --- a/python/plugins/db_manager/dlg_sql_layer_window.py +++ b/python/plugins/db_manager/dlg_sql_layer_window.py @@ -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() diff --git a/python/plugins/db_manager/dlg_sql_window.py b/python/plugins/db_manager/dlg_sql_window.py index b764fe408a1..c876d63e739 100644 --- a/python/plugins/db_manager/dlg_sql_window.py +++ b/python/plugins/db_manager/dlg_sql_window.py @@ -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() diff --git a/python/plugins/db_manager/layer_preview.py b/python/plugins/db_manager/layer_preview.py index e0525131fd8..469137aad10 100644 --- a/python/plugins/db_manager/layer_preview.py +++ b/python/plugins/db_manager/layer_preview.py @@ -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([]) diff --git a/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py b/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py index 6097ef8edff..b475336fb11 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py @@ -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 diff --git a/python/plugins/processing/algs/lidar/lastools/lasquery.py b/python/plugins/processing/algs/lidar/lastools/lasquery.py index be1c9f5246a..5dbfad8a64d 100644 --- a/python/plugins/processing/algs/lidar/lastools/lasquery.py +++ b/python/plugins/processing/algs/lidar/lastools/lasquery.py @@ -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()): diff --git a/python/plugins/processing/gui/AlgorithmDialog.py b/python/plugins/processing/gui/AlgorithmDialog.py index 01915df38ba..f3ad62bfbea 100644 --- a/python/plugins/processing/gui/AlgorithmDialog.py +++ b/python/plugins/processing/gui/AlgorithmDialog.py @@ -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) diff --git a/python/plugins/processing/gui/AlgorithmDialogBase.py b/python/plugins/processing/gui/AlgorithmDialogBase.py index bbd3a8eac1c..825313cbbdd 100644 --- a/python/plugins/processing/gui/AlgorithmDialogBase.py +++ b/python/plugins/processing/gui/AlgorithmDialogBase.py @@ -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() diff --git a/python/plugins/processing/gui/CommanderWindow.py b/python/plugins/processing/gui/CommanderWindow.py index 75d857e1946..009b8b3e7f8 100644 --- a/python/plugins/processing/gui/CommanderWindow.py +++ b/python/plugins/processing/gui/CommanderWindow.py @@ -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') diff --git a/python/plugins/processing/gui/ParametersPanel.py b/python/plugins/processing/gui/ParametersPanel.py index 312476fc23e..ff3d80353a5 100644 --- a/python/plugins/processing/gui/ParametersPanel.py +++ b/python/plugins/processing/gui/ParametersPanel.py @@ -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 diff --git a/python/plugins/processing/gui/Postprocessing.py b/python/plugins/processing/gui/Postprocessing.py index aa18f13c855..f33f5c99972 100644 --- a/python/plugins/processing/gui/Postprocessing.py +++ b/python/plugins/processing/gui/Postprocessing.py @@ -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): diff --git a/python/plugins/processing/tests/AlgorithmsTestBase.py b/python/plugins/processing/tests/AlgorithmsTestBase.py index 64f87b31ad8..01ac110c33d 100644 --- a/python/plugins/processing/tests/AlgorithmsTestBase.py +++ b/python/plugins/processing/tests/AlgorithmsTestBase.py @@ -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): diff --git a/python/plugins/processing/tools/dataobjects.py b/python/plugins/processing/tools/dataobjects.py index 28f428b7596..061dff6dc84 100644 --- a/python/plugins/processing/tools/dataobjects.py +++ b/python/plugins/processing/tools/dataobjects.py @@ -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) diff --git a/python/plugins/processing/tools/vector.py b/python/plugins/processing/tools/vector.py index bf247091e0f..1413ae5a883 100644 --- a/python/plugins/processing/tools/vector.py +++ b/python/plugins/processing/tools/vector.py @@ -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') diff --git a/src/app/composer/qgsatlascompositionwidget.cpp b/src/app/composer/qgsatlascompositionwidget.cpp index 445429484ee..6ff199d8e53 100644 --- a/src/app/composer/qgsatlascompositionwidget.cpp +++ b/src/app/composer/qgsatlascompositionwidget.cpp @@ -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" diff --git a/src/app/composer/qgscomposer.cpp b/src/app/composer/qgscomposer.cpp index a7dc1073683..294b49e7aaa 100644 --- a/src/app/composer/qgscomposer.cpp +++ b/src/app/composer/qgscomposer.cpp @@ -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" diff --git a/src/app/composer/qgscomposerattributetablewidget.cpp b/src/app/composer/qgscomposerattributetablewidget.cpp index 78dfea418bb..8f37fdab4e9 100644 --- a/src/app/composer/qgscomposerattributetablewidget.cpp +++ b/src/app/composer/qgscomposerattributetablewidget.cpp @@ -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" diff --git a/src/app/composer/qgscomposerlegendwidget.cpp b/src/app/composer/qgscomposerlegendwidget.cpp index 36e1b38e8bc..5c00514e1c4 100644 --- a/src/app/composer/qgscomposerlegendwidget.cpp +++ b/src/app/composer/qgscomposerlegendwidget.cpp @@ -34,7 +34,6 @@ #include "qgslegendrenderer.h" #include "qgsmapcanvas.h" #include "qgsmaplayerlegend.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsvectorlayer.h" diff --git a/src/app/composer/qgscomposermapwidget.cpp b/src/app/composer/qgscomposermapwidget.cpp index f7a7e476428..a59df461457 100644 --- a/src/app/composer/qgscomposermapwidget.cpp +++ b/src/app/composer/qgscomposermapwidget.cpp @@ -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" diff --git a/src/app/main.cpp b/src/app/main.cpp index e1fbfbe323d..2c396ee36e5 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( layer ) ); + QgsVectorLayer *vl = qobject_cast( QgsProject::instance()->mapLayer( layer ) ); if ( !vl ) continue; layers << qMakePair( 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( ml ); if ( !vl ) diff --git a/src/app/openstreetmap/qgsosmdownloaddialog.cpp b/src/app/openstreetmap/qgsosmdownloaddialog.cpp index d8ccbaba950..84f415a95e8 100644 --- a/src/app/openstreetmap/qgsosmdownloaddialog.cpp +++ b/src/app/openstreetmap/qgsosmdownloaddialog.cpp @@ -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 layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); QMap::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; diff --git a/src/app/openstreetmap/qgsosmexportdialog.cpp b/src/app/openstreetmap/qgsosmexportdialog.cpp index 6e76fd2889a..6150ef7d4ef 100644 --- a/src/app/openstreetmap/qgsosmexportdialog.cpp +++ b/src/app/openstreetmap/qgsosmexportdialog.cpp @@ -18,7 +18,7 @@ #include "qgsosmdatabase.h" #include "qgsdatasourceuri.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include @@ -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(); diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 9216ca07dc6..da144657006 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -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 ) ), + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( layersWereAdded( QList ) ) ); - 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( 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 layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); for ( QMap::iterator it = layers.begin(); it != layers.end(); ++it ) { QgsVectorLayer *vl = qobject_cast( 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( - 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& lyrList ) QList 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 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 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 layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); for ( QMap::iterator it = layers.begin(); it != layers.end(); ++it ) { QgsVectorLayer *vl = qobject_cast( 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 layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); QMap::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 layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); for ( QMap::iterator it = layers.begin(); it != layers.end(); ++it ) { QgsVectorLayer *vlayer = qobject_cast( it.value() ); @@ -11041,7 +11040,7 @@ bool QgisApp::addRasterLayer( QgsRasterLayer *theRasterLayer ) // register this layer with the central layers registry QList 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; } diff --git a/src/app/qgisappinterface.cpp b/src/app/qgisappinterface.cpp index dfa6d0f06a4..a93236bd0ad 100644 --- a/src/app/qgisappinterface.cpp +++ b/src/app/qgisappinterface.cpp @@ -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" diff --git a/src/app/qgsalignrasterdialog.cpp b/src/app/qgsalignrasterdialog.cpp index 33f82bfb329..e0edb5b8de0 100644 --- a/src/app/qgsalignrasterdialog.cpp +++ b/src/app/qgsalignrasterdialog.cpp @@ -20,7 +20,7 @@ #include "qgsdataitem.h" #include "qgsmapcanvas.h" #include "qgsmaplayercombobox.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsrasterlayer.h" #include @@ -35,7 +35,7 @@ static QgsMapLayer* _rasterLayer( const QString& filename ) { - QMap layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap 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; } diff --git a/src/app/qgsapplayertreeviewmenuprovider.cpp b/src/app/qgsapplayertreeviewmenuprovider.cpp index b55e0f9f61d..2d02f21e5d7 100644 --- a/src/app/qgsapplayertreeviewmenuprovider.cpp +++ b/src/app/qgsapplayertreeviewmenuprovider.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ); + QgsVectorLayer* layer = dynamic_cast( 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( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ); + QgsVectorLayer* layer = qobject_cast( 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( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ) ) + if ( QgsVectorLayer* layer = qobject_cast( QgsProject::instance()->mapLayer( layerId ) ) ) { layer->emitStyleChanged(); } diff --git a/src/app/qgsattributeactiondialog.cpp b/src/app/qgsattributeactiondialog.cpp index e20e57918ed..43bc8343507 100644 --- a/src/app/qgsattributeactiondialog.cpp +++ b/src/app/qgsattributeactiondialog.cpp @@ -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() << QStringLiteral( "Canvas" ) ); insertRow( pos++, QgsAction::OpenUrl, tr( "Open file" ), QStringLiteral( "[% \"PATH\" %]" ), QLatin1String( "" ), false, tr( "Open file" ), QSet() << 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() << 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() << 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() << QStringLiteral( "Layer" ) ); } void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item ) diff --git a/src/app/qgsattributetypedialog.cpp b/src/app/qgsattributetypedialog.cpp index d49507967cd..939ee5cee06 100644 --- a/src/app/qgsattributetypedialog.cpp +++ b/src/app/qgsattributetypedialog.cpp @@ -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" diff --git a/src/app/qgsbrowserdockwidget.cpp b/src/app/qgsbrowserdockwidget.cpp index 15092c0fa68..04b8ed21c2a 100644 --- a/src/app/qgsbrowserdockwidget.cpp +++ b/src/app/qgsbrowserdockwidget.cpp @@ -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" diff --git a/src/app/qgsfieldsproperties.cpp b/src/app/qgsfieldsproperties.cpp index 688597bc1fc..8fd40de8d1a 100644 --- a/src/app/qgsfieldsproperties.cpp +++ b/src/app/qgsfieldsproperties.cpp @@ -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" diff --git a/src/app/qgsjoindialog.cpp b/src/app/qgsjoindialog.cpp index 4c52f3a4778..ddf971e59d3 100644 --- a/src/app/qgsjoindialog.cpp +++ b/src/app/qgsjoindialog.cpp @@ -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 ); diff --git a/src/app/qgslabelpropertydialog.cpp b/src/app/qgslabelpropertydialog.cpp index b91d4641ca3..45fd2cfb45d 100644 --- a/src/app/qgslabelpropertydialog.cpp +++ b/src/app/qgslabelpropertydialog.cpp @@ -20,7 +20,7 @@ #include #include #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( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ); + QgsVectorLayer* vlayer = dynamic_cast( QgsProject::instance()->mapLayer( layerId ) ); if ( !vlayer ) { return; diff --git a/src/app/qgslayerstylingwidget.cpp b/src/app/qgslayerstylingwidget.cpp index fc59a6903cb..da1a674cea8 100644 --- a/src/app/qgslayerstylingwidget.cpp +++ b/src/app/qgslayerstylingwidget.cpp @@ -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() ); diff --git a/src/app/qgsmapthemes.cpp b/src/app/qgsmapthemes.cpp index 24bc4f0149d..9ea3af0187d 100644 --- a/src/app/qgsmapthemes.cpp +++ b/src/app/qgsmapthemes.cpp @@ -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" diff --git a/src/app/qgsmaptooladdfeature.cpp b/src/app/qgsmaptooladdfeature.cpp index aae5ba68fa4..636b0ffed14 100644 --- a/src/app/qgsmaptooladdfeature.cpp +++ b/src/app/qgsmaptooladdfeature.cpp @@ -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( ml ); //can only add topological points if background layer is editable... if ( vl && vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() ) diff --git a/src/app/qgsmaptoolfeatureaction.cpp b/src/app/qgsmaptoolfeatureaction.cpp index 39341d2f9cb..0337f347dfd 100644 --- a/src/app/qgsmaptoolfeatureaction.cpp +++ b/src/app/qgsmaptoolfeatureaction.cpp @@ -29,7 +29,6 @@ #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" #include "qgsproject.h" -#include "qgsmaplayerregistry.h" #include "qgsmaplayeractionregistry.h" #include "qgisapp.h" diff --git a/src/app/qgsmaptoolidentifyaction.cpp b/src/app/qgsmaptoolidentifyaction.cpp index 097af280805..9fd113fba35 100644 --- a/src/app/qgsmaptoolidentifyaction.cpp +++ b/src/app/qgsmaptoolidentifyaction.cpp @@ -34,7 +34,6 @@ #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" #include "qgsproject.h" -#include "qgsmaplayerregistry.h" #include "qgsrenderer.h" #include "qgsunittypes.h" diff --git a/src/app/qgsmaptoollabel.cpp b/src/app/qgsmaptoollabel.cpp index 18d17ff3d87..6463335fe80 100644 --- a/src/app/qgsmaptoollabel.cpp +++ b/src/app/qgsmaptoollabel.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( pos.layerID ) ); + layer = qobject_cast( QgsProject::instance()->mapLayer( pos.layerID ) ); if ( layer && layer->labeling() ) { settings = layer->labeling()->settings( layer, pos.providerID ); diff --git a/src/app/qgsmaptoolmovelabel.cpp b/src/app/qgsmaptoolmovelabel.cpp index 72790d91261..f715ad9497f 100644 --- a/src/app/qgsmaptoolmovelabel.cpp +++ b/src/app/qgsmaptoolmovelabel.cpp @@ -17,7 +17,6 @@ #include "qgsmaptoolmovelabel.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" #include "qgsrubberband.h" #include "qgsvectorlayer.h" #include diff --git a/src/app/qgsmaptooloffsetcurve.cpp b/src/app/qgsmaptooloffsetcurve.cpp index 9b4bbbc5dce..dc1ef5b935f 100644 --- a/src/app/qgsmaptooloffsetcurve.cpp +++ b/src/app/qgsmaptooloffsetcurve.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( mSourceLayerId ) ); + QgsVectorLayer* sourceLayer = dynamic_cast( QgsProject::instance()->mapLayer( mSourceLayerId ) ); if ( !sourceLayer ) { return; diff --git a/src/app/qgsmaptoolpinlabels.cpp b/src/app/qgsmaptoolpinlabels.cpp index d3a4297d383..3996edd7acc 100644 --- a/src/app/qgsmaptoolpinlabels.cpp +++ b/src/app/qgsmaptoolpinlabels.cpp @@ -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; diff --git a/src/app/qgsmaptoolrotatelabel.cpp b/src/app/qgsmaptoolrotatelabel.cpp index 11baa91ac64..4e287c5d5c4 100644 --- a/src/app/qgsmaptoolrotatelabel.cpp +++ b/src/app/qgsmaptoolrotatelabel.cpp @@ -17,7 +17,6 @@ #include "qgsmaptoolrotatelabel.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" #include "qgspallabeling.h" #include "qgspointrotationitem.h" #include "qgsrubberband.h" diff --git a/src/app/qgsnewspatialitelayerdialog.cpp b/src/app/qgsnewspatialitelayerdialog.cpp index e3f57fcedf0..554c3c847ae 100644 --- a/src/app/qgsnewspatialitelayerdialog.cpp +++ b/src/app/qgsnewspatialitelayerdialog.cpp @@ -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 diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index 5f49af17ae4..f42c8cb13be 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -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() ) + Q_FOREACH ( QgsVectorLayer* layer, QgsProject::instance()->layers() ) { if ( layer->isEditable() ) { @@ -239,7 +238,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa QStringList noIdentifyLayerIdList = QgsProject::instance()->nonIdentifiableLayers(); - const QMap &mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap &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( QgsMapLayerRegistry::instance()->mapLayer( id ) ); + QgsVectorLayer* vl = qobject_cast( 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 &mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap &mapLayers = QgsProject::instance()->mapLayers(); if ( mMapCanvas->currentLayer() ) { @@ -1405,7 +1404,7 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked() crsList << srs.authid(); } - const QMap &mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap &mapLayers = QgsProject::instance()->mapLayers(); for ( QMap::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it ) { crsList << it.value()->crs().authid(); diff --git a/src/app/qgsrastercalcdialog.cpp b/src/app/qgsrastercalcdialog.cpp index e24cae0aa43..edcd35c0128 100644 --- a/src/app/qgsrastercalcdialog.cpp +++ b/src/app/qgsrastercalcdialog.cpp @@ -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 QgsRasterCalcDialog::rasterEntries() const void QgsRasterCalcDialog::insertAvailableRasterBands() { - const QMap& layers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap& layers = QgsProject::instance()->mapLayers(); QMap::const_iterator layerIt = layers.constBegin(); bool firstLayer = true; diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index 30f419b68c1..05b906429d0 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -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" diff --git a/src/app/qgssnappingwidget.cpp b/src/app/qgssnappingwidget.cpp index 1d36134f4aa..627dedc8f55 100644 --- a/src/app/qgssnappingwidget.cpp +++ b/src/app/qgssnappingwidget.cpp @@ -42,6 +42,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas, QWidget* parent ) : QWidget( parent ) , mProject( project ) + , mConfig( project ) , mCanvas( canvas ) , mModeAction( nullptr ) , mTypeAction( nullptr ) diff --git a/src/app/qgsstatisticalsummarydockwidget.cpp b/src/app/qgsstatisticalsummarydockwidget.cpp index 13cb91ddacd..c7513fa0c7b 100644 --- a/src/app/qgsstatisticalsummarydockwidget.cpp +++ b/src/app/qgsstatisticalsummarydockwidget.cpp @@ -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 ) diff --git a/src/app/qgsvectorlayerproperties.cpp b/src/app/qgsvectorlayerproperties.cpp index c2929158177..3d85c6d3f9a 100644 --- a/src/app/qgsvectorlayerproperties.cpp +++ b/src/app/qgsvectorlayerproperties.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) ); + QgsVectorLayer* joinLayer = qobject_cast( 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( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) ); + QgsVectorLayer* joinLayer = qobject_cast( 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( QgsMapLayerRegistry::instance()->mapLayer( join.joinLayerId ) ); + QgsVectorLayer* joinLayer = qobject_cast( QgsProject::instance()->mapLayer( join.joinLayerId ) ); if ( !mLayer || !joinLayer ) { return; diff --git a/src/browser/qgsbrowser.cpp b/src/browser/qgsbrowser.cpp index d6a399c395d..28ccf582a95 100644 --- a/src/browser/qgsbrowser.cpp +++ b/src/browser/qgsbrowser.cpp @@ -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() << mLayer ); return true; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b18910afc21..9577db263dc 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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 diff --git a/src/core/composer/qgsatlascomposition.cpp b/src/core/composer/qgsatlascomposition.cpp index 5d2d8c739e0..aa5ed5cad73 100644 --- a/src/core/composer/qgsatlascomposition.cpp +++ b/src/core/composer/qgsatlascomposition.cpp @@ -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 layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); for ( QMap::const_iterator it = layers.begin(); it != layers.end(); ++it ) { if ( it.key() == atlasElem.attribute( QStringLiteral( "coverageLayer" ) ) ) diff --git a/src/core/composer/qgscomposerattributetablev2.cpp b/src/core/composer/qgscomposerattributetablev2.cpp index f3c9c5626f6..24b047f95b3 100644 --- a/src/core/composer/qgscomposerattributetablev2.cpp +++ b/src/core/composer/qgscomposerattributetablev2.cpp @@ -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 layerMap = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layerMap = QgsProject::instance()->mapLayers(); QMap::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( ml ); diff --git a/src/core/composer/qgscomposerlegend.cpp b/src/core/composer/qgscomposerlegend.cpp index 2bdb645466b..3e31ba4b896 100644 --- a/src/core/composer/qgscomposerlegend.cpp +++ b/src/core/composer/qgscomposerlegend.cpp @@ -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" ) ); diff --git a/src/core/composer/qgscomposerlegenditem.cpp b/src/core/composer/qgscomposerlegenditem.cpp index 82c4cb6f9de..588f34c5c5a 100644 --- a/src/core/composer/qgscomposerlegenditem.cpp +++ b/src/core/composer/qgscomposerlegenditem.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( layerId() ) ); + QgsVectorLayer* vLayer = qobject_cast( QgsProject::instance()->mapLayer( layerId() ) ); if ( vLayer ) { QgsFeatureRenderer* renderer = vLayer->renderer(); diff --git a/src/core/composer/qgscomposermap.cpp b/src/core/composer/qgscomposermap.cpp index c28793663e7..d4ee7dc81f2 100644 --- a/src/core/composer/qgscomposermap.cpp +++ b/src/core/composer/qgscomposermap.cpp @@ -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( 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 { diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index 7f129802f89..8f09565d06a 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -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" diff --git a/src/core/geometry/qgsgeometry.cpp b/src/core/geometry/qgsgeometry.cpp index 32a2ef42bbf..b32ce53ebc7 100644 --- a/src/core/geometry/qgsgeometry.cpp +++ b/src/core/geometry/qgsgeometry.cpp @@ -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" diff --git a/src/core/geometry/qgsgeometryeditutils.cpp b/src/core/geometry/qgsgeometryeditutils.cpp index e689691409a..a77ec629914 100644 --- a/src/core/geometry/qgsgeometryeditutils.cpp +++ b/src/core/geometry/qgsgeometryeditutils.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) ); + currentLayer = dynamic_cast( QgsProject::instance()->mapLayer( *aIt ) ); if ( currentLayer ) { QgsFeatureIds ignoreIds; diff --git a/src/core/layertree/qgslayertreegroup.cpp b/src/core/layertree/qgslayertreegroup.cpp index 04a2e372c30..23949f377f1 100644 --- a/src/core/layertree/qgslayertreegroup.cpp +++ b/src/core/layertree/qgslayertreegroup.cpp @@ -18,7 +18,7 @@ #include "qgslayertree.h" #include "qgslayertreeutils.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include #include @@ -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 ); diff --git a/src/core/layertree/qgslayertreelayer.cpp b/src/core/layertree/qgslayertreelayer.cpp index 3274655f61a..3c848e90b8e 100644 --- a/src/core/layertree/qgslayertreelayer.cpp +++ b/src/core/layertree/qgslayertreelayer.cpp @@ -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 ) ), this, SLOT( registryLayersAdded( QList ) ) ); + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( registryLayersAdded( QList ) ) ); } } @@ -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& layers ) { if ( l->id() == mLayerId ) { - disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( registryLayersAdded( QList ) ) ); + disconnect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( registryLayersAdded( QList ) ) ); 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 ) ), this, SLOT( registryLayersAdded( QList ) ) ); + disconnect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( registryLayersWillBeRemoved( QStringList ) ) ); + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( registryLayersAdded( QList ) ) ); mLayer = nullptr; } diff --git a/src/core/layertree/qgslayertreelayer.h b/src/core/layertree/qgslayertreelayer.h index d9037175680..cf06c32bf4d 100644 --- a/src/core/layertree/qgslayertreelayer.h +++ b/src/core/layertree/qgslayertreelayer.h @@ -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 diff --git a/src/core/layertree/qgslayertreeregistrybridge.cpp b/src/core/layertree/qgslayertreeregistrybridge.cpp index abd587866d9..19eca855e63 100644 --- a/src/core/layertree/qgslayertreeregistrybridge.cpp +++ b/src/core/layertree/qgslayertreeregistrybridge.cpp @@ -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 ) ), this, SLOT( layersAdded( QList ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) ); + connect( mProject, SIGNAL( legendLayersAdded( QList ) ), this, SLOT( layersAdded( QList ) ) ); + 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& 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 ); } diff --git a/src/core/layertree/qgslayertreeregistrybridge.h b/src/core/layertree/qgslayertreeregistrybridge.h index 73817aaf08d..9353ecb7da8 100644 --- a/src/core/layertree/qgslayertreeregistrybridge.h +++ b/src/core/layertree/qgslayertreeregistrybridge.h @@ -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; diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index 734cf5c965b..14c9252481e 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -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(); diff --git a/src/core/qgsexpression.cpp b/src/core/qgsexpression.cpp index f4007cff268..c8614d10399 100644 --- a/src/core/qgsexpression.cpp +++ b/src/core/qgsexpression.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( layerString ) ); //search by id first + vl = qobject_cast( QgsProject::instance()->mapLayer( layerString ) ); //search by id first if ( !vl ) { - QList layersByName = QgsMapLayerRegistry::instance()->mapLayersByName( layerString ); + QList layersByName = QgsProject::instance()->mapLayersByName( layerString ); if ( !layersByName.isEmpty() ) { vl = qobject_cast( 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 layersByName = QgsMapLayerRegistry::instance()->mapLayersByName( layerIdOrName ); + QList 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 layersByName = QgsMapLayerRegistry::instance()->mapLayersByName( layerIdOrName ); + QList layersByName = QgsProject::instance()->mapLayersByName( layerIdOrName ); if ( !layersByName.isEmpty() ) { layer = layersByName.at( 0 ); diff --git a/src/core/qgsjsonutils.cpp b/src/core/qgsjsonutils.cpp index fc3f0a18be3..31325324ea1 100644 --- a/src/core/qgsjsonutils.cpp +++ b/src/core/qgsjsonutils.cpp @@ -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 ) diff --git a/src/core/qgslayerdefinition.cpp b/src/core/qgslayerdefinition.cpp index b2b16b2777b..d53c57ae431 100644 --- a/src/core/qgslayerdefinition.cpp +++ b/src/core/qgslayerdefinition.cpp @@ -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 ) diff --git a/src/core/qgslegendrenderer.cpp b/src/core/qgslegendrenderer.cpp index 5a154629e0f..604664c2f4d 100644 --- a/src/core/qgslegendrenderer.cpp +++ b/src/core/qgslegendrenderer.cpp @@ -20,7 +20,6 @@ #include "qgslayertreemodel.h" #include "qgslayertreemodellegendnode.h" #include "qgsmaplayerlegend.h" -#include "qgsmaplayerregistry.h" #include "qgssymbol.h" #include "qgsvectorlayer.h" diff --git a/src/core/qgsmaphittest.cpp b/src/core/qgsmaphittest.cpp index f2abd5ca876..9faac8f7b63 100644 --- a/src/core/qgsmaphittest.cpp +++ b/src/core/qgsmaphittest.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ); + QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( layerID ) ); if ( !vl || !vl->renderer() ) continue; diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index 5709dbd25c1..5dc07907af0 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -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::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 _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 _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; } } diff --git a/src/core/qgsmaplayer.h b/src/core/qgsmaplayer.h index 0022ad37c6e..e01e4f7e72d 100644 --- a/src/core/qgsmaplayer.h +++ b/src/core/qgsmaplayer.h @@ -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; /** diff --git a/src/core/qgsmaplayermodel.cpp b/src/core/qgsmaplayermodel.cpp index e15b6a157ad..2d861a75cc7 100644 --- a/src/core/qgsmaplayermodel.cpp +++ b/src/core/qgsmaplayermodel.cpp @@ -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& 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 ) ), this, SLOT( addLayers( QList ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) ); - addLayers( QgsMapLayerRegistry::instance()->mapLayers().values() ); + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( addLayers( QList ) ) ); + connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) ); + addLayers( QgsProject::instance()->mapLayers().values() ); } void QgsMapLayerModel::setItemsCheckable( bool checkable ) diff --git a/src/core/qgsmaplayerproxymodel.cpp b/src/core/qgsmaplayerproxymodel.cpp index 0bc93e14497..40397d0af1b 100644 --- a/src/core/qgsmaplayerproxymodel.cpp +++ b/src/core/qgsmaplayerproxymodel.cpp @@ -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; } diff --git a/src/core/qgsmaplayerregistry.cpp b/src/core/qgsmaplayerregistry.cpp deleted file mode 100644 index b589a806927..00000000000 --- a/src/core/qgsmaplayerregistry.cpp +++ /dev/null @@ -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 QgsMapLayerRegistry::mapLayersByName( const QString& layerName ) const -{ - QList myResultList; - Q_FOREACH ( QgsMapLayer* layer, mMapLayers ) - { - if ( layer->name() == layerName ) - { - myResultList << layer; - } - } - return myResultList; -} - -QList QgsMapLayerRegistry::addMapLayers( - const QList& theMapLayers, - bool addToLegend, - bool takeOwnership ) -{ - QList 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 addedLayers; - addedLayers = addMapLayers( QList() << theMapLayer, addToLegend, takeOwnership ); - return addedLayers.isEmpty() ? nullptr : addedLayers[0]; -} - -void QgsMapLayerRegistry::removeMapLayers( const QStringList& theLayerIds ) -{ - QList layers; - Q_FOREACH ( const QString &myId, theLayerIds ) - { - layers << mMapLayers.value( myId ); - } - - removeMapLayers( layers ); -} - -void QgsMapLayerRegistry::removeMapLayers( const QList& layers ) -{ - if ( layers.isEmpty() ) - return; - - QStringList layerIds; - QList 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() << mMapLayers.value( theLayerId ) ); -} - -void QgsMapLayerRegistry::removeMapLayer( QgsMapLayer* layer ) -{ - if ( layer ) - removeMapLayers( QList() << 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( obj ) ); - - if ( !id.isNull() ) - { - QgsDebugMsg( QString( "Map layer deleted without unregistering! %1" ).arg( id ) ); - mMapLayers.remove( id ); - } -} - -QMap 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 diff --git a/src/core/qgsmaplayerregistry.h b/src/core/qgsmaplayerregistry.h deleted file mode 100644 index b8854d98b08..00000000000 --- a/src/core/qgsmaplayerregistry.h +++ /dev/null @@ -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 -#include -#include - -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 mapLayersByName( const QString& layerName ) const; - - /** Returns a map of all registered layers by layer ID. - * @see mapLayer() - * @see mapLayersByName() - * @see layers() - */ - QMap mapLayers() const; - - /** Returns a list of registered map layers with a specified layer type. - * - * Example: - * - * QVector vectorLayers = QgsMapLayerRegistry::instance()->layers(); - * - * @note not available in Python bindings - * @note added in QGIS 2.16 - * @see mapLayers() - */ - template - QVector layers() const - { - QVector layers; - QMap::const_iterator layerIt = mMapLayers.constBegin(); - for ( ; layerIt != mMapLayers.constEnd(); ++layerIt ) - { - T tLayer = qobject_cast( 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 addMapLayers( const QList& 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& 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& 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& 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& 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 mMapLayers; -}; - -#endif //QGSMAPLAYERREGISTRY_H - diff --git a/src/core/qgsmaprenderercache.cpp b/src/core/qgsmaprenderercache.cpp index 0168af7f7d3..a6af60bab0d 100644 --- a/src/core/qgsmaprenderercache.cpp +++ b/src/core/qgsmaprenderercache.cpp @@ -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::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() ) ); diff --git a/src/core/qgsmaprenderercustompainterjob.cpp b/src/core/qgsmaprenderercustompainterjob.cpp index 964c5d16a32..3bdf4e040d1 100644 --- a/src/core/qgsmaprenderercustompainterjob.cpp +++ b/src/core/qgsmaprenderercustompainterjob.cpp @@ -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( QgsMapLayerRegistry::instance()->mapLayer( it.key() ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( it.key() ) ) ) * vl->cache() = cache; } mGeometryCaches.clear(); diff --git a/src/core/qgsmaprendererjob.cpp b/src/core/qgsmaprendererjob.cpp index 90294b9f804..032e483b60e 100644 --- a/src/core/qgsmaprendererjob.cpp +++ b/src/core/qgsmaprendererjob.cpp @@ -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 ) { diff --git a/src/core/qgsmapsettings.cpp b/src/core/qgsmapsettings.cpp index f44c9447a8d..b1e9984caa9 100644 --- a/src/core/qgsmapsettings.cpp +++ b/src/core/qgsmapsettings.cpp @@ -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 ) ); diff --git a/src/core/qgsmapsettings.h b/src/core/qgsmapsettings.h index fd7e50f89c7..8cedcebe202 100644 --- a/src/core/qgsmapsettings.h +++ b/src/core/qgsmapsettings.h @@ -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 ); diff --git a/src/core/qgsmapthemecollection.cpp b/src/core/qgsmapthemecollection.cpp index 9954e4afd49..bfe5460de05 100644 --- a/src/core/qgsmapthemecollection.cpp +++ b/src/core/qgsmapthemecollection.cpp @@ -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 -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 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" ) ); } diff --git a/src/core/qgsmapthemecollection.h b/src/core/qgsmapthemecollection.h index 4fed2179c9c..c0f13890b20 100644 --- a/src/core/qgsmapthemecollection.h +++ b/src/core/qgsmapthemecollection.h @@ -24,6 +24,7 @@ class QDomDocument; class QgsLayerTreeNode; class QgsLayerTreeGroup; +class QgsProject; /** \class QgsMapThemeCollection @@ -112,7 +113,7 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject friend class QgsMapThemeCollection; }; - QgsMapThemeCollection(); + QgsMapThemeCollection( QgsProject* project ); /** * Returns whether a map theme with a matching name exists. @@ -224,6 +225,8 @@ class CORE_EXPORT QgsMapThemeCollection : public QObject typedef QMap MapThemeRecordMap; MapThemeRecordMap mMapThemes; + //! project used to retrieve layers from layer IDs + QgsProject* mProject; }; diff --git a/src/core/qgsofflineediting.cpp b/src/core/qgsofflineediting.cpp index 58e62f929a7..bc875d739bd 100644 --- a/src/core/qgsofflineediting.cpp +++ b/src/core/qgsofflineediting.cpp @@ -23,7 +23,6 @@ #include "qgslayertreegroup.h" #include "qgslayertreelayer.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsofflineediting.h" #include "qgsproject.h" #include "qgsvectordataprovider.h" @@ -58,7 +57,7 @@ extern "C" QgsOfflineEditing::QgsOfflineEditing() { - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layerAdded( QgsMapLayer* ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layerAdded( QgsMapLayer* ) ) ); } QgsOfflineEditing::~QgsOfflineEditing() @@ -107,7 +106,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, Q_FOREACH ( const QString& layerId, layerIds ) { - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerId ); QgsVectorLayer* vl = qobject_cast( layer ); if ( !vl ) continue; @@ -122,7 +121,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, { if ( joinIt->prefix.isNull() ) { - QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( joinIt->joinLayerId ) ); + QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( joinIt->joinLayerId ) ); if ( vl ) joinIt->prefix = vl->name() + '_'; @@ -137,7 +136,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, { emit layerProgressUpdated( i + 1, layerIds.count() ); - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerIds.at( i ) ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerIds.at( i ) ); QgsVectorLayer* vl = qobject_cast( layer ); if ( vl ) { @@ -148,7 +147,7 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, { layerIdMapping.insert( origLayerId, newLayer ); // remove remote layer - QgsMapLayerRegistry::instance()->removeMapLayers( + QgsProject::instance()->removeMapLayers( QStringList() << origLayerId ); } } @@ -216,7 +215,7 @@ void QgsOfflineEditing::synchronize() // restore and sync remote layers QList offlineLayers; - QMap mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap mapLayers = QgsProject::instance()->mapLayers(); for ( QMap::iterator layer_it = mapLayers.begin() ; layer_it != mapLayers.end(); ++layer_it ) { QgsMapLayer* layer = layer_it.value(); @@ -255,7 +254,7 @@ void QgsOfflineEditing::synchronize() QgsVectorLayer* offlineLayer = qobject_cast( layer ); // register this layer with the central layers registry - QgsMapLayerRegistry::instance()->addMapLayers( QList() << remoteLayer, true ); + QgsProject::instance()->addMapLayers( QList() << remoteLayer, true ); // copy style copySymbology( offlineLayer, remoteLayer ); @@ -317,7 +316,7 @@ void QgsOfflineEditing::synchronize() // again with the same path offlineLayer->dataProvider()->invalidateConnections( QgsDataSourceUri( offlineLayer->source() ).database() ); // remove offline layer - QgsMapLayerRegistry::instance()->removeMapLayers( QStringList() << qgisLayerId ); + QgsProject::instance()->removeMapLayers( QStringList() << qgisLayerId ); // disable offline project @@ -588,7 +587,7 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit newLayer->setCustomProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, layer->providerType() ); // register this layer with the central layers registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << newLayer ); // copy style @@ -1205,7 +1204,7 @@ void QgsOfflineEditing::committedFeaturesAdded( const QString& qgisLayerId, cons int layerId = getOrCreateLayerId( db, qgisLayerId ); // get new feature ids from db - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( qgisLayerId ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( qgisLayerId ); QgsDataSourceUri uri = QgsDataSourceUri( layer->source() ); // only store feature ids diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index 497a6bbda53..42a0c8b8e84 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -49,7 +49,6 @@ #include #include -#include #include #include #include @@ -3215,7 +3214,7 @@ bool QgsPalLabeling::willUseLayer( QgsVectorLayer* layer ) bool QgsPalLabeling::staticWillUseLayer( const QString& layerID ) { - QgsVectorLayer* layer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ); + QgsVectorLayer* layer = qobject_cast( QgsProject::instance()->mapLayer( layerID ) ); if ( !layer ) return false; return staticWillUseLayer( layer ); diff --git a/src/core/qgspluginlayerregistry.cpp b/src/core/qgspluginlayerregistry.cpp index 0e2d5708db9..150e90c69e7 100644 --- a/src/core/qgspluginlayerregistry.cpp +++ b/src/core/qgspluginlayerregistry.cpp @@ -19,7 +19,7 @@ #include "qgspluginlayerregistry.h" #include "qgslogger.h" #include "qgspluginlayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" QgsPluginLayerType::QgsPluginLayerType( const QString& name ) : mName( name ) @@ -107,7 +107,7 @@ bool QgsPluginLayerRegistry::removePluginLayerType( const QString& typeName ) return false; // remove all remaining layers of this type - to avoid invalid behaviour - QList layers = QgsMapLayerRegistry::instance()->mapLayers().values(); + QList layers = QgsProject::instance()->mapLayers().values(); Q_FOREACH ( QgsMapLayer* layer, layers ) { if ( layer->type() == QgsMapLayer::PluginLayer ) @@ -115,7 +115,7 @@ bool QgsPluginLayerRegistry::removePluginLayerType( const QString& typeName ) QgsPluginLayer* pl = qobject_cast( layer ); if ( pl->pluginLayerType() == typeName ) { - QgsMapLayerRegistry::instance()->removeMapLayers( + QgsProject::instance()->removeMapLayers( QStringList() << layer->id() ); } } diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index 02815f41d0a..44c29cc6ed2 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -23,7 +23,6 @@ #include "qgslayertreeutils.h" #include "qgslayertreeregistrybridge.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" #include "qgsmessagelog.h" #include "qgspluginlayer.h" #include "qgspluginlayerregistry.h" @@ -318,6 +317,7 @@ void removeKey_( const QString& scope, QgsProject::QgsProject( QObject* parent ) : QObject( parent ) , mBadLayerHandler( new QgsProjectBadLayerHandler() ) + , mSnappingConfig( this ) , mRelationManager( new QgsRelationManager( this ) ) , mRootGroup( new QgsLayerTreeGroup ) , mAutoTransaction( false ) @@ -330,10 +330,10 @@ QgsProject::QgsProject( QObject* parent ) // bind the layer tree to the map layer registry. // whenever layers are added to or removed from the registry, // layer tree will be updated - mLayerTreeRegistryBridge = new QgsLayerTreeRegistryBridge( mRootGroup, this ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( onMapLayersAdded( QList ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ), this, SLOT( cleanTransactionGroups() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QList ) ), this, SLOT( onMapLayersRemoved( QList ) ) ); + mLayerTreeRegistryBridge = new QgsLayerTreeRegistryBridge( mRootGroup, this, this ); + connect( this, SIGNAL( layersAdded( QList ) ), this, SLOT( onMapLayersAdded( QList ) ) ); + connect( this, SIGNAL( layersRemoved( QStringList ) ), this, SLOT( cleanTransactionGroups() ) ); + connect( this, SIGNAL( layersWillBeRemoved( QList ) ), this, SLOT( onMapLayersRemoved( QList ) ) ); } @@ -342,6 +342,8 @@ QgsProject::~QgsProject() delete mBadLayerHandler; delete mRelationManager; delete mRootGroup; + + removeAllMapLayers(); } @@ -453,7 +455,7 @@ void QgsProject::clear() mSnappingConfig.reset(); emit snappingConfigChanged(); - mMapThemeCollection.reset( new QgsMapThemeCollection() ); + mMapThemeCollection.reset( new QgsMapThemeCollection( this ) ); emit mapThemeCollectionChanged(); mRootGroup->removeAllChildren(); @@ -741,7 +743,7 @@ bool QgsProject::addLayer( const QDomElement &layerElem, QList &broken QList myLayers; myLayers << mapLayer; - QgsMapLayerRegistry::instance()->addMapLayers( myLayers ); + addMapLayers( myLayers ); return true; } @@ -905,12 +907,12 @@ bool QgsProject::read() mRootGroup->removeCustomProperty( QStringLiteral( "loading" ) ); - mMapThemeCollection.reset( new QgsMapThemeCollection() ); + mMapThemeCollection.reset( new QgsMapThemeCollection( this ) ); emit mapThemeCollectionChanged(); mMapThemeCollection->readXml( *doc ); // reassign change dependencies now that all layers are loaded - QMap existingMaps = QgsMapLayerRegistry::instance()->mapLayers(); + QMap existingMaps = mapLayers(); for ( QMap::iterator it = existingMaps.begin(); it != existingMaps.end(); it++ ) { it.value()->setDependencies( it.value()->dependencies() ); @@ -1044,7 +1046,7 @@ QgsExpressionContext QgsProject::createExpressionContext() const void QgsProject::onMapLayersAdded( const QList& layers ) { - QMap existingMaps = QgsMapLayerRegistry::instance()->mapLayers(); + QMap existingMaps = mapLayers(); bool tgChanged = false; @@ -1129,7 +1131,7 @@ bool QgsProject::read( QDomNode &layerNode ) { // have to try to update joins for all layers now - a previously added layer may be dependent on this newly // added layer for joins - QVector vectorLayers = QgsMapLayerRegistry::instance()->layers(); + QVector vectorLayers = layers(); Q_FOREACH ( QgsVectorLayer* layer, vectorLayers ) { processLayerJoins( layer ); @@ -1209,7 +1211,7 @@ bool QgsProject::write() emit writeProject( *doc ); // within top level node save list of layers - const QMap &layers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap &layers = mapLayers(); // Iterate over layers in zOrder // Call writeXml() on each @@ -2044,7 +2046,7 @@ bool QgsProject::evaluateDefaultValues() const void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues ) { - Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer* layer, mapLayers().values() ) { QgsVectorLayer* vl = qobject_cast( layer ); if ( vl ) @@ -2174,7 +2176,7 @@ void QgsProject::setAutoTransaction( bool autoTransaction ) mAutoTransaction = autoTransaction; if ( autoTransaction ) - onMapLayersAdded( QgsMapLayerRegistry::instance()->mapLayers().values() ); + onMapLayersAdded( mapLayers().values() ); else cleanTransactionGroups( true ); } @@ -2184,3 +2186,173 @@ QMap, QgsTransactionGroup*> QgsProject::transactionGroup { return mTransactionGroups; } + + +// +// QgsMapLayerRegistry methods +// + + +int QgsProject::count() const +{ + return mMapLayers.size(); +} + +QgsMapLayer * QgsProject::mapLayer( const QString& theLayerId ) const +{ + return mMapLayers.value( theLayerId ); +} + +QList QgsProject::mapLayersByName( const QString& layerName ) const +{ + QList myResultList; + Q_FOREACH ( QgsMapLayer* layer, mMapLayers ) + { + if ( layer->name() == layerName ) + { + myResultList << layer; + } + } + return myResultList; +} + +QList QgsProject::addMapLayers( + const QList& theMapLayers, + bool addToLegend, + bool takeOwnership ) +{ + QList 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 * +QgsProject::addMapLayer( QgsMapLayer* theMapLayer, + bool addToLegend, + bool takeOwnership ) +{ + QList addedLayers; + addedLayers = addMapLayers( QList() << theMapLayer, addToLegend, takeOwnership ); + return addedLayers.isEmpty() ? nullptr : addedLayers[0]; +} + +void QgsProject::removeMapLayers( const QStringList& theLayerIds ) +{ + QList layers; + Q_FOREACH ( const QString &myId, theLayerIds ) + { + layers << mMapLayers.value( myId ); + } + + removeMapLayers( layers ); +} + +void QgsProject::removeMapLayers( const QList& layers ) +{ + if ( layers.isEmpty() ) + return; + + QStringList layerIds; + QList 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 QgsProject::removeMapLayer( const QString& theLayerId ) +{ + removeMapLayers( QList() << mMapLayers.value( theLayerId ) ); +} + +void QgsProject::removeMapLayer( QgsMapLayer* layer ) +{ + if ( layer ) + removeMapLayers( QList() << layer ); +} + +void QgsProject::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 QgsProject::reloadAllLayers() +{ + Q_FOREACH ( QgsMapLayer* layer, mMapLayers ) + { + layer->reload(); + } +} + +void QgsProject::onMapLayerDeleted( QObject* obj ) +{ + QString id = mMapLayers.key( static_cast( obj ) ); + + if ( !id.isNull() ) + { + QgsDebugMsg( QString( "Map layer deleted without unregistering! %1" ).arg( id ) ); + mMapLayers.remove( id ); + } +} + +QMap QgsProject::mapLayers() const +{ + return mMapLayers; +} diff --git a/src/core/qgsproject.h b/src/core/qgsproject.h index f0da974457f..3e91ab3d0c2 100644 --- a/src/core/qgsproject.h +++ b/src/core/qgsproject.h @@ -498,6 +498,204 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera */ 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 mapLayersByName( const QString& layerName ) const; + + /** Returns a map of all registered layers by layer ID. + * @see mapLayer() + * @see mapLayersByName() + * @see layers() + */ + QMap mapLayers() const; + + /** Returns a list of registered map layers with a specified layer type. + * + * Example: + * + * QVector vectorLayers = QgsProject::instance()->layers(); + * + * @note not available in Python bindings + * @note added in QGIS 2.16 + * @see mapLayers() + */ + template + QVector layers() const + { + QVector layers; + QMap::const_iterator layerIt = mMapLayers.constBegin(); + for ( ; layerIt != mMapLayers.constEnd(); ++layerIt ) + { + T tLayer = qobject_cast( 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 addMapLayers( const QList& 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& 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& ); @@ -592,6 +790,116 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera */ 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& 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& 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& theMapLayers ); + public slots: /** @@ -608,6 +916,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera void onMapLayersRemoved( const QList& layers ); void cleanTransactionGroups( bool force = false ); + void onMapLayerDeleted( QObject* obj ); + private: /** @@ -652,6 +962,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera //! @note not available in python bindings void loadEmbeddedNodes( QgsLayerTreeGroup* group ); + QMap mMapLayers; + QString mErrorMessage; QgsProjectBadLayerHandler* mBadLayerHandler; diff --git a/src/core/qgsproviderregistry.cpp b/src/core/qgsproviderregistry.cpp index 5ab4457b156..88aeb8d7e98 100644 --- a/src/core/qgsproviderregistry.cpp +++ b/src/core/qgsproviderregistry.cpp @@ -29,7 +29,7 @@ #include "qgsmessagelog.h" #include "qgsprovidermetadata.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" // typedefs for provider plugin functions of interest @@ -225,7 +225,7 @@ typedef void cleanupProviderFunction_t(); void QgsProviderRegistry::clean() { - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); Providers::const_iterator it = mProviders.begin(); diff --git a/src/core/qgsrelation.cpp b/src/core/qgsrelation.cpp index 6cec7d79c78..5961bd19229 100644 --- a/src/core/qgsrelation.cpp +++ b/src/core/qgsrelation.cpp @@ -18,7 +18,7 @@ #include "qgsapplication.h" #include "qgsfeatureiterator.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" QgsRelation::QgsRelation() @@ -44,7 +44,7 @@ QgsRelation QgsRelation::createFromXml( const QDomNode &node ) QString id = elem.attribute( QStringLiteral( "id" ) ); QString name = elem.attribute( QStringLiteral( "name" ) ); - const QMap& mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap& mapLayers = QgsProject::instance()->mapLayers(); QgsMapLayer* referencingLayer = mapLayers[referencingLayerId]; QgsMapLayer* referencedLayer = mapLayers[referencedLayerId]; @@ -318,7 +318,7 @@ bool QgsRelation::hasEqualDefinition( const QgsRelation& other ) const void QgsRelation::updateRelationStatus() { - const QMap& mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap& mapLayers = QgsProject::instance()->mapLayers(); mReferencingLayer = qobject_cast( mapLayers[mReferencingLayerId] ); mReferencedLayer = qobject_cast( mapLayers[mReferencedLayerId] ); diff --git a/src/core/qgsrelationmanager.cpp b/src/core/qgsrelationmanager.cpp index 437702197c2..b8404ccb394 100644 --- a/src/core/qgsrelationmanager.cpp +++ b/src/core/qgsrelationmanager.cpp @@ -17,7 +17,6 @@ #include "qgsapplication.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" @@ -28,7 +27,7 @@ QgsRelationManager::QgsRelationManager( QgsProject* project ) { connect( project, SIGNAL( readProject( const QDomDocument& ) ), SLOT( readProject( const QDomDocument& ) ) ); connect( project, SIGNAL( writeProject( QDomDocument& ) ), SLOT( writeProject( QDomDocument& ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ), this, SLOT( layersRemoved( QStringList ) ) ); + connect( project, SIGNAL( layersRemoved( QStringList ) ), this, SLOT( layersRemoved( QStringList ) ) ); } void QgsRelationManager::setRelations( const QList& relations ) diff --git a/src/core/qgssnappingconfig.cpp b/src/core/qgssnappingconfig.cpp index d71727ecb76..f56610d4266 100644 --- a/src/core/qgssnappingconfig.cpp +++ b/src/core/qgssnappingconfig.cpp @@ -20,7 +20,6 @@ #include #include "qgslogger.h" -#include "qgsmaplayerregistry.h" #include "qgsvectorlayer.h" #include "qgsproject.h" @@ -105,7 +104,8 @@ bool QgsSnappingConfig::IndividualLayerSettings::operator ==( const QgsSnappingC } -QgsSnappingConfig::QgsSnappingConfig() +QgsSnappingConfig::QgsSnappingConfig( QgsProject* project ) + : mProject( project ) { reset(); } @@ -158,7 +158,7 @@ void QgsSnappingConfig::reset() // set advanced config mIndividualLayerSettings = QHash(); - Q_FOREACH ( QgsMapLayer *ml, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *ml, mProject->mapLayers() ) { QgsVectorLayer* vl = dynamic_cast( ml ); if ( vl ) @@ -334,7 +334,7 @@ void QgsSnappingConfig::readProject( const QDomDocument& doc ) double tolerance = settingElement.attribute( QStringLiteral( "tolerance" ) ).toDouble(); QgsTolerance::UnitType units = ( QgsTolerance::UnitType )settingElement.attribute( QStringLiteral( "units" ) ).toInt(); - QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer* ml = mProject->mapLayer( layerId ); if ( !ml || ml->type() != QgsMapLayer::VectorLayer ) continue; @@ -414,27 +414,27 @@ void QgsSnappingConfig::readLegacySettings() mMode = ActiveLayer; mIndividualLayerSettings.clear(); - QString snapMode = QgsProject::instance()->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/SnappingMode" ) ); + QString snapMode = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/SnappingMode" ) ); - QString snapType = QgsProject::instance()->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ), QStringLiteral( "off" ) ); + QString snapType = mProject->readEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapType" ), QStringLiteral( "off" ) ); if ( snapType == QLatin1String( "to segment" ) ) mType = Segment; else if ( snapType == QLatin1String( "to vertex and segment" ) ) mType = VertexAndSegment; else if ( snapType == QLatin1String( "to vertex" ) ) mType = Vertex; - mTolerance = QgsProject::instance()->readDoubleEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapTolerance" ), 0 ); - mUnits = static_cast< QgsTolerance::UnitType >( QgsProject::instance()->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapToleranceUnit" ), QgsTolerance::ProjectUnits ) ); + mTolerance = mProject->readDoubleEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapTolerance" ), 0 ); + mUnits = static_cast< QgsTolerance::UnitType >( mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/DefaultSnapToleranceUnit" ), QgsTolerance::ProjectUnits ) ); - mIntersectionSnapping = QgsProject::instance()->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/IntersectionSnapping" ), 0 ); + mIntersectionSnapping = mProject->readNumEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/IntersectionSnapping" ), 0 ); //read snapping settings from project bool snappingDefinedInProject, ok; - QStringList layerIdList = QgsProject::instance()->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingList" ), QStringList(), &snappingDefinedInProject ); - QStringList enabledList = QgsProject::instance()->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingEnabledList" ), QStringList(), &ok ); - QStringList toleranceList = QgsProject::instance()->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceList" ), QStringList(), &ok ); - QStringList toleranceUnitList = QgsProject::instance()->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceUnitList" ), QStringList(), &ok ); - QStringList snapToList = QgsProject::instance()->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnapToList" ), QStringList(), &ok ); + QStringList layerIdList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingList" ), QStringList(), &snappingDefinedInProject ); + QStringList enabledList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingEnabledList" ), QStringList(), &ok ); + QStringList toleranceList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceList" ), QStringList(), &ok ); + QStringList toleranceUnitList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnappingToleranceUnitList" ), QStringList(), &ok ); + QStringList snapToList = mProject->readListEntry( QStringLiteral( "Digitizing" ), QStringLiteral( "/LayerSnapToList" ), QStringList(), &ok ); // lists must have the same size, otherwise something is wrong if ( layerIdList.size() != enabledList.size() || @@ -462,7 +462,7 @@ void QgsSnappingConfig::readLegacySettings() QStringList::const_iterator enabledIt( enabledList.constBegin() ); for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt ) { - QgsVectorLayer* vlayer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( *layerIt ) ); + QgsVectorLayer* vlayer = qobject_cast( mProject->mapLayer( *layerIt ) ); if ( !vlayer || !vlayer->hasGeometryType() ) continue; diff --git a/src/core/qgssnappingconfig.h b/src/core/qgssnappingconfig.h index 6dda31a5086..004e695fdf4 100644 --- a/src/core/qgssnappingconfig.h +++ b/src/core/qgssnappingconfig.h @@ -19,6 +19,7 @@ #include "qgstolerance.h" class QDomDocument; +class QgsProject; class QgsVectorLayer; @@ -117,7 +118,7 @@ class CORE_EXPORT QgsSnappingConfig /** * Constructor with default parameters defined in global settings */ - explicit QgsSnappingConfig(); + explicit QgsSnappingConfig( QgsProject* project ); ~QgsSnappingConfig(); @@ -219,6 +220,8 @@ class CORE_EXPORT QgsSnappingConfig private: void readLegacySettings(); + //! associated project for this snapping configuration + QgsProject* mProject; bool mEnabled; SnappingMode mMode; SnappingType mType; diff --git a/src/core/qgssnappingutils.cpp b/src/core/qgssnappingutils.cpp index c0a810fe165..6c65f08ab4b 100644 --- a/src/core/qgssnappingutils.cpp +++ b/src/core/qgssnappingutils.cpp @@ -16,7 +16,6 @@ #include "qgssnappingutils.h" #include "qgsgeometry.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsvectorlayer.h" #include "qgslogger.h" @@ -24,6 +23,7 @@ QgsSnappingUtils::QgsSnappingUtils( QObject* parent ) : QObject( parent ) , mCurrentLayer( nullptr ) + , mSnappingConfig( QgsProject::instance() ) , mStrategy( IndexHybrid ) , mHybridPerLayerFeatureLimit( 50000 ) , mIsIndexing( false ) @@ -280,7 +280,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPoint& pointMap, Qg QList layers; Q_FOREACH ( const QString& layerID, mMapSettings.layers() ) - if ( QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( layerID ) ) ) layers << qMakePair( vl, aoi ); prepareIndex( layers ); @@ -471,7 +471,7 @@ QString QgsSnappingUtils::dump() { Q_FOREACH ( const QString& layerID, mMapSettings.layers() ) { - if ( QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( layerID ) ) ) layers << LayerConfig( vl, QgsPointLocator::Types( mSnappingConfig.type() ), mSnappingConfig.tolerance(), mSnappingConfig.units() ); } } diff --git a/src/core/qgstaskmanager.cpp b/src/core/qgstaskmanager.cpp index 11439a6d033..3c28d0177a0 100644 --- a/src/core/qgstaskmanager.cpp +++ b/src/core/qgstaskmanager.cpp @@ -16,7 +16,7 @@ ***************************************************************************/ #include "qgstaskmanager.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include @@ -325,7 +325,7 @@ QgsTaskManager::QgsTaskManager( QObject* parent ) , mTaskMutex( new QMutex( QMutex::Recursive ) ) , mNextTaskId( 0 ) { - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), + connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) ); } diff --git a/src/core/qgstransaction.cpp b/src/core/qgstransaction.cpp index ec8d34adae0..b35fce65cd2 100644 --- a/src/core/qgstransaction.cpp +++ b/src/core/qgstransaction.cpp @@ -20,7 +20,7 @@ #include "qgstransaction.h" #include "qgslogger.h" #include "qgsdatasourceuri.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsproviderregistry.h" #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" @@ -50,7 +50,7 @@ QgsTransaction* QgsTransaction::create( const QStringList& layerIds ) if ( layerIds.isEmpty() ) return nullptr; - QgsVectorLayer* layer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerIds.first() ) ); + QgsVectorLayer* layer = qobject_cast( QgsProject::instance()->mapLayer( layerIds.first() ) ); if ( !layer ) return nullptr; @@ -85,7 +85,7 @@ QgsTransaction::~QgsTransaction() bool QgsTransaction::addLayer( const QString& layerId ) { - QgsVectorLayer* layer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ); + QgsVectorLayer* layer = qobject_cast( QgsProject::instance()->mapLayer( layerId ) ); return addLayer( layer ); } @@ -113,7 +113,7 @@ bool QgsTransaction::addLayer( QgsVectorLayer* layer ) } connect( this, &QgsTransaction::afterRollback, layer->dataProvider(), &QgsVectorDataProvider::dataChanged ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( onLayersDeleted( QStringList ) ) ); + connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( onLayersDeleted( QStringList ) ) ); mLayers.insert( layer ); if ( mTransactionActive ) diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 9a70c0b4322..6246a7ef63e 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -52,7 +52,6 @@ #include "qgsgeometry.h" #include "qgslogger.h" #include "qgsmaplayerlegend.h" -#include "qgsmaplayerregistry.h" #include "qgsmaptopixel.h" #include "qgsmessagelog.h" #include "qgsogcutils.h" @@ -1412,7 +1411,7 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node ) mJoinBuffer->readXml( layer_node ); updateFields(); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( checkJoinLayerRemove( QString ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( checkJoinLayerRemove( QString ) ) ); QString errorMsg; if ( !readSymbology( layer_node, errorMsg ) ) @@ -1543,7 +1542,7 @@ void QgsVectorLayer::setDataSource( const QString& dataSource, const QString& ba setLegend( QgsMapLayerLegend::defaultVectorLegend( this ) ); } - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( checkJoinLayerRemove( QString ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( checkJoinLayerRemove( QString ) ) ); emit repaintRequested(); } @@ -1596,7 +1595,7 @@ bool QgsVectorLayer::setDataProvider( QString const & provider ) QStringList stuff = reg.capturedTexts(); QString lName = stuff[1]; - const QMap &layers = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap &layers = QgsProject::instance()->mapLayers(); QMap::const_iterator it; for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; ++it ) @@ -4399,7 +4398,7 @@ bool QgsVectorLayer::setDependencies( const QSet& oDeps ) // disconnect layers that are not present in the list of dependencies anymore Q_FOREACH ( const QgsMapLayerDependency& dep, mDependencies ) { - QgsVectorLayer* lyr = static_cast( QgsMapLayerRegistry::instance()->mapLayer( dep.layerId() ) ); + QgsVectorLayer* lyr = static_cast( QgsProject::instance()->mapLayer( dep.layerId() ) ); if ( lyr == nullptr ) continue; disconnect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::dataChanged ); @@ -4419,7 +4418,7 @@ bool QgsVectorLayer::setDependencies( const QSet& oDeps ) // connect to new layers Q_FOREACH ( const QgsMapLayerDependency& dep, mDependencies ) { - QgsVectorLayer* lyr = static_cast( QgsMapLayerRegistry::instance()->mapLayer( dep.layerId() ) ); + QgsVectorLayer* lyr = static_cast( QgsProject::instance()->mapLayer( dep.layerId() ) ); if ( lyr == nullptr ) continue; connect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::dataChanged ); diff --git a/src/core/qgsvectorlayerfeatureiterator.cpp b/src/core/qgsvectorlayerfeatureiterator.cpp index 28a86426a8f..86eb5defc25 100644 --- a/src/core/qgsvectorlayerfeatureiterator.cpp +++ b/src/core/qgsvectorlayerfeatureiterator.cpp @@ -16,7 +16,6 @@ #include "qgsexpressionfieldbuffer.h" #include "qgsgeometrysimplifier.h" -#include "qgsmaplayerregistry.h" #include "qgssimplifymethod.h" #include "qgsvectordataprovider.h" #include "qgsvectorlayereditbuffer.h" @@ -506,7 +505,7 @@ void QgsVectorLayerFeatureIterator::prepareJoin( int fieldIdx ) const QgsVectorJoinInfo* joinInfo = mSource->mJoinBuffer->joinForFieldIndex( fieldIdx, mSource->mFields, sourceLayerIndex ); Q_ASSERT( joinInfo ); - QgsVectorLayer* joinLayer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( joinInfo->joinLayerId ) ); + QgsVectorLayer* joinLayer = qobject_cast( QgsProject::instance()->mapLayer( joinInfo->joinLayerId ) ); Q_ASSERT( joinLayer ); if ( !mFetchJoinInfo.contains( joinInfo ) ) diff --git a/src/core/qgsvectorlayerjoinbuffer.cpp b/src/core/qgsvectorlayerjoinbuffer.cpp index c69d7ede161..f8eb3aef240 100644 --- a/src/core/qgsvectorlayerjoinbuffer.cpp +++ b/src/core/qgsvectorlayerjoinbuffer.cpp @@ -19,7 +19,7 @@ #include "qgsfeatureiterator.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectordataprovider.h" #include @@ -38,7 +38,7 @@ static QList _outEdges( QgsVectorLayer* vl ) QList lst; Q_FOREACH ( const QgsVectorJoinInfo& info, vl->vectorJoins() ) { - if ( QgsVectorLayer* joinVl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) ) ) + if ( QgsVectorLayer* joinVl = qobject_cast( QgsProject::instance()->mapLayer( info.joinLayerId ) ) ) lst << joinVl; } return lst; @@ -87,7 +87,7 @@ bool QgsVectorLayerJoinBuffer::addJoin( const QgsVectorJoinInfo& joinInfo ) // During project load the joined layers possibly do not exist yet so the connection will not be created, // but then QgsProject makes sure to call createJoinCaches() which will do the connection. // Unique connection makes sure we do not respond to one layer's update more times (in case of multiple join) - if ( QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( joinInfo.joinLayerId ) ) ) { connect( vl, &QgsVectorLayer::updatedFields, this, &QgsVectorLayerJoinBuffer::joinedLayerUpdatedFields, Qt::UniqueConnection ); connect( vl, &QgsVectorLayer::layerModified, this, &QgsVectorLayerJoinBuffer::joinedLayerModified, Qt::UniqueConnection ); @@ -111,7 +111,7 @@ bool QgsVectorLayerJoinBuffer::removeJoin( const QString& joinLayerId ) } } - if ( QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( joinLayerId ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( joinLayerId ) ) ) { disconnect( vl, &QgsVectorLayer::updatedFields, this, &QgsVectorLayerJoinBuffer::joinedLayerUpdatedFields ); } @@ -128,7 +128,7 @@ void QgsVectorLayerJoinBuffer::cacheJoinLayer( QgsVectorJoinInfo& joinInfo ) return; } - QgsVectorLayer* cacheLayer = dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) ); + QgsVectorLayer* cacheLayer = dynamic_cast( QgsProject::instance()->mapLayer( joinInfo.joinLayerId ) ); if ( cacheLayer ) { int joinFieldIndex; @@ -213,7 +213,7 @@ void QgsVectorLayerJoinBuffer::updateFields( QgsFields& fields ) QList< QgsVectorJoinInfo>::const_iterator joinIt = mVectorJoins.constBegin(); for ( int joinIdx = 0 ; joinIt != mVectorJoins.constEnd(); ++joinIt, ++joinIdx ) { - QgsVectorLayer* joinLayer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( joinIt->joinLayerId ) ); + QgsVectorLayer* joinLayer = qobject_cast( QgsProject::instance()->mapLayer( joinIt->joinLayerId ) ); if ( !joinLayer ) { continue; @@ -271,7 +271,7 @@ void QgsVectorLayerJoinBuffer::createJoinCaches() cacheJoinLayer( *joinIt ); // make sure we are connected to the joined layer - if ( QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( joinIt->joinLayerId ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( joinIt->joinLayerId ) ) ) { connect( vl, &QgsVectorLayer::updatedFields, this, &QgsVectorLayerJoinBuffer::joinedLayerUpdatedFields, Qt::UniqueConnection ); connect( vl, &QgsVectorLayer::layerModified, this, &QgsVectorLayerJoinBuffer::joinedLayerModified, Qt::UniqueConnection ); diff --git a/src/core/qgsvirtuallayerdefinitionutils.cpp b/src/core/qgsvirtuallayerdefinitionutils.cpp index 5d1d8f12abe..b6ab251b041 100644 --- a/src/core/qgsvirtuallayerdefinitionutils.cpp +++ b/src/core/qgsvirtuallayerdefinitionutils.cpp @@ -17,7 +17,7 @@ email : hugo dot mercier at oslandia dot com #include "qgsvirtuallayerdefinitionutils.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvirtuallayerdefinition.h" QgsVirtualLayerDefinition QgsVirtualLayerDefinitionUtils::fromJoinedLayer( QgsVectorLayer* layer ) @@ -56,7 +56,7 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinitionUtils::fromJoinedLayer( QgsVe Q_FOREACH ( const QgsVectorJoinInfo& join, layer->vectorJoins() ) { QString joinName = QStringLiteral( "j%1" ).arg( ++joinIdx ); - QgsVectorLayer* joinedLayer = static_cast( QgsMapLayerRegistry::instance()->mapLayer( join.joinLayerId ) ); + QgsVectorLayer* joinedLayer = static_cast( QgsProject::instance()->mapLayer( join.joinLayerId ) ); if ( !joinedLayer ) continue; QString prefix = join.prefix.isEmpty() ? joinedLayer->name() + "_" : join.prefix; diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index febade81ce4..2bd065b5c6e 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -23,7 +23,6 @@ email : tim at linfiniti.com #include "qgshuesaturationfilter.h" #include "qgslogger.h" #include "qgsmaplayerlegend.h" -#include "qgsmaplayerregistry.h" #include "qgsmaptopixel.h" #include "qgsmessagelog.h" #include "qgsmultibandcolorrenderer.h" diff --git a/src/gui/attributetable/qgsattributetablemodel.cpp b/src/gui/attributetable/qgsattributetablemodel.cpp index 5d13259cd9b..6743a222c5e 100644 --- a/src/gui/attributetable/qgsattributetablemodel.cpp +++ b/src/gui/attributetable/qgsattributetablemodel.cpp @@ -27,7 +27,6 @@ #include "qgslogger.h" #include "qgsmapcanvas.h" #include "qgsmaplayeractionregistry.h" -#include "qgsmaplayerregistry.h" #include "qgsrenderer.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" diff --git a/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp b/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp index 9b794da3e42..70ede892b9a 100644 --- a/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp +++ b/src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp @@ -19,7 +19,6 @@ #include "qgsmessagelog.h" #include "qgsproject.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" #include "qgseditorwidgetwrapper.h" #include "qgssearchwidgetwrapper.h" @@ -84,8 +83,8 @@ QgsEditorWidgetRegistry::QgsEditorWidgetRegistry() connect( QgsProject::instance(), SIGNAL( readMapLayer( QgsMapLayer*, const QDomElement& ) ), this, SLOT( readMapLayer( QgsMapLayer*, const QDomElement& ) ) ); // connect( QgsProject::instance(), SIGNAL( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ), this, SLOT( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( mapLayerWillBeRemoved( QgsMapLayer* ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( mapLayerAdded( QgsMapLayer* ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( mapLayerWillBeRemoved( QgsMapLayer* ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( mapLayerAdded( QgsMapLayer* ) ) ); } QgsEditorWidgetRegistry::~QgsEditorWidgetRegistry() diff --git a/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp index 13990231e7a..950baefbad2 100644 --- a/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp @@ -16,7 +16,6 @@ #include "qgsrelationreferencesearchwidgetwrapper.h" #include "qgsfields.h" -#include "qgsmaplayerregistry.h" #include "qgsvaluerelationwidgetfactory.h" #include "qgsvectorlayer.h" #include "qgsproject.h" diff --git a/src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp b/src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp index a32d5dc6151..0a2ff6d63e3 100644 --- a/src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp @@ -14,7 +14,7 @@ ***************************************************************************/ #include "qgsvaluerelationconfigdlg.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include "qgsexpressionbuilderdialog.h" @@ -55,7 +55,7 @@ QgsEditorWidgetConfig QgsValueRelationConfigDlg::config() void QgsValueRelationConfigDlg::setConfig( const QgsEditorWidgetConfig& config ) { - QgsVectorLayer* lyr = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( config.value( QStringLiteral( "Layer" ) ).toString() ) ); + QgsVectorLayer* lyr = qobject_cast( QgsProject::instance()->mapLayer( config.value( QStringLiteral( "Layer" ) ).toString() ) ); mLayerName->setLayer( lyr ); mKeyColumn->setField( config.value( QStringLiteral( "Key" ) ).toString() ); mValueColumn->setField( config.value( QStringLiteral( "Value" ) ).toString() ); diff --git a/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp index 063b7dab6c2..ef0feab94b9 100644 --- a/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp @@ -16,7 +16,6 @@ #include "qgsvaluerelationsearchwidgetwrapper.h" #include "qgsfields.h" -#include "qgsmaplayerregistry.h" #include "qgsvaluerelationwidgetfactory.h" #include "qgsvectorlayer.h" #include "qgsfilterlineedit.h" diff --git a/src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp b/src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp index faeafd452df..230f36c4415 100644 --- a/src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp @@ -17,7 +17,6 @@ #include "qgsfeatureiterator.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" #include "qgsvaluerelationconfigdlg.h" #include "qgsvaluerelationsearchwidgetwrapper.h" #include "qgsvectorlayer.h" diff --git a/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp b/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp index 0844aaeac53..279392cd665 100644 --- a/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp @@ -17,7 +17,7 @@ #include "qgis.h" #include "qgsfields.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvaluerelationwidgetfactory.h" #include "qgsvectorlayer.h" #include "qgsfilterlineedit.h" @@ -193,7 +193,7 @@ QgsValueRelationWidgetWrapper::ValueRelationCache QgsValueRelationWidgetWrapper: { ValueRelationCache cache; - QgsVectorLayer* layer = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( config.value( QStringLiteral( "Layer" ) ).toString() ) ); + QgsVectorLayer* layer = qobject_cast( QgsProject::instance()->mapLayer( config.value( QStringLiteral( "Layer" ) ).toString() ) ); if ( !layer ) return cache; diff --git a/src/gui/layertree/qgscustomlayerorderwidget.cpp b/src/gui/layertree/qgscustomlayerorderwidget.cpp index 736a311d486..a0423d00e1b 100644 --- a/src/gui/layertree/qgscustomlayerorderwidget.cpp +++ b/src/gui/layertree/qgscustomlayerorderwidget.cpp @@ -24,7 +24,7 @@ #include "qgslayertreemapcanvasbridge.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" @@ -111,14 +111,14 @@ QVariant CustomLayerOrderModel::data( const QModelIndex& index, int role ) const if ( role == Qt::DisplayRole ) { - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( id ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( id ); if ( layer ) return layer->name(); } if ( role == Qt::UserRole + 1 ) { - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( id ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( id ); if ( layer ) return layer->id(); } diff --git a/src/gui/layertree/qgslayertreeviewdefaultactions.cpp b/src/gui/layertree/qgslayertreeviewdefaultactions.cpp index 9cd6004d1ec..b6f73ef0245 100644 --- a/src/gui/layertree/qgslayertreeviewdefaultactions.cpp +++ b/src/gui/layertree/qgslayertreeviewdefaultactions.cpp @@ -20,7 +20,7 @@ #include "qgslayertreemodel.h" #include "qgslayertreeview.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include @@ -188,7 +188,7 @@ void QgsLayerTreeViewDefaultActions::zoomToGroup( QgsMapCanvas* canvas ) QList layers; Q_FOREACH ( const QString& layerId, groupNode->findLayerIds() ) - layers << QgsMapLayerRegistry::instance()->mapLayer( layerId ); + layers << QgsProject::instance()->mapLayer( layerId ); zoomToLayers( canvas, layers ); } diff --git a/src/gui/qgsattributetypeloaddialog.cpp b/src/gui/qgsattributetypeloaddialog.cpp index bcf396244eb..b10058a0b2a 100644 --- a/src/gui/qgsattributetypeloaddialog.cpp +++ b/src/gui/qgsattributetypeloaddialog.cpp @@ -21,7 +21,7 @@ #include "qgsfeatureiterator.h" #include "qgsvectordataprovider.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include @@ -72,7 +72,7 @@ void QgsAttributeTypeLoadDialog::fillLayerList() { layerComboBox->blockSignals( true ); layerComboBox->clear(); - Q_FOREACH ( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *l, QgsProject::instance()->mapLayers() ) { QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( l ); if ( vl ) @@ -91,7 +91,7 @@ void QgsAttributeTypeLoadDialog::fillComboBoxes( int layerIndex ) keyComboBox->clear(); valueComboBox->clear(); - QgsVectorLayer *vLayer = qobject_cast( layerIndex < 0 ? nullptr : QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerIndex ).toString() ) ); + QgsVectorLayer *vLayer = qobject_cast( layerIndex < 0 ? nullptr : QgsProject::instance()->mapLayer( layerComboBox->itemData( layerIndex ).toString() ) ); if ( vLayer ) { QMap fieldMap = vLayer->dataProvider()->fieldNameMap(); @@ -128,7 +128,7 @@ void QgsAttributeTypeLoadDialog::createPreview( int fieldIndex, bool full ) } int idx = keyComboBox->currentData().toInt(); int idx2 = valueComboBox->currentData().toInt(); - QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentData().toString() ); + QgsMapLayer* dataLayer = QgsProject::instance()->mapLayer( layerComboBox->currentData().toString() ); QgsVectorLayer* vLayer = qobject_cast( dataLayer ); if ( !vLayer ) return; @@ -177,7 +177,7 @@ void QgsAttributeTypeLoadDialog::loadDataToValueMap() mValueMap.clear(); int idx = keyComboBox->currentData().toInt(); int idx2 = valueComboBox->currentData().toInt(); - QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentData().toString() ); + QgsMapLayer* dataLayer = QgsProject::instance()->mapLayer( layerComboBox->currentData().toString() ); QgsVectorLayer* vLayer = qobject_cast( dataLayer ); if ( !vLayer ) return; diff --git a/src/gui/qgsformannotationitem.cpp b/src/gui/qgsformannotationitem.cpp index 936f2a8e9ae..9a417d9e87a 100644 --- a/src/gui/qgsformannotationitem.cpp +++ b/src/gui/qgsformannotationitem.cpp @@ -23,7 +23,7 @@ #include "qgsfeatureiterator.h" #include "qgslogger.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaptool.h" #include "qgsvectorlayer.h" #include @@ -205,7 +205,7 @@ void QgsFormAnnotationItem::readXml( const QDomDocument& doc, const QDomElement& mVectorLayer = nullptr; if ( itemElem.hasAttribute( QStringLiteral( "vectorLayer" ) ) ) { - mVectorLayer = dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( itemElem.attribute( QStringLiteral( "vectorLayer" ), QLatin1String( "" ) ) ) ); + mVectorLayer = dynamic_cast( QgsProject::instance()->mapLayer( itemElem.attribute( QStringLiteral( "vectorLayer" ), QLatin1String( "" ) ) ) ); if ( mVectorLayer ) { QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( setFeatureForMapPosition() ) ); diff --git a/src/gui/qgshtmlannotationitem.cpp b/src/gui/qgshtmlannotationitem.cpp index e66f18dd2d9..10f19ae5f02 100644 --- a/src/gui/qgshtmlannotationitem.cpp +++ b/src/gui/qgshtmlannotationitem.cpp @@ -20,7 +20,7 @@ #include "qgsfeatureiterator.h" #include "qgslogger.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaptool.h" #include "qgsvectorlayer.h" #include "qgsexpression.h" @@ -167,7 +167,7 @@ void QgsHtmlAnnotationItem::readXml( const QDomDocument& doc, const QDomElement& mVectorLayer = nullptr; if ( itemElem.hasAttribute( QStringLiteral( "vectorLayer" ) ) ) { - mVectorLayer = dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( itemElem.attribute( QStringLiteral( "vectorLayer" ), QLatin1String( "" ) ) ) ); + mVectorLayer = dynamic_cast( QgsProject::instance()->mapLayer( itemElem.attribute( QStringLiteral( "vectorLayer" ), QLatin1String( "" ) ) ) ); if ( mVectorLayer ) { QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( setFeatureForMapPosition() ) ); diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 62650bfd5bf..fe7b81f020c 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -47,7 +47,6 @@ email : sherman at mrcc.com #include "qgsmapcanvasmap.h" #include "qgsmapcanvassnappingutils.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsmaptoolpan.h" #include "qgsmaptoolzoom.h" #include "qgsmaptopixel.h" @@ -260,7 +259,7 @@ QgsMapLayer* QgsMapCanvas::layer( int index ) { const QStringList& layers = mapSettings().layers(); if ( index >= 0 && index < ( int ) layers.size() ) - return QgsMapLayerRegistry::instance()->mapLayer( layers[index] ); + return QgsProject::instance()->mapLayer( layers[index] ); else return nullptr; } @@ -596,7 +595,7 @@ void QgsMapCanvas::refreshMap() QStringList layersForGeometryCache; Q_FOREACH ( const QString& id, mSettings.layers() ) { - if ( QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( id ) ) ) + if ( QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( id ) ) ) { if ( vl->isEditable() ) layersForGeometryCache << id; @@ -1644,7 +1643,7 @@ QList QgsMapCanvas::layers() const QList lst; Q_FOREACH ( const QString& layerID, mapSettings().layers() ) { - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerID ); if ( layer ) lst.append( layer ); } @@ -1752,7 +1751,7 @@ void QgsMapCanvas::updateDatumTransformEntries() QString destAuthId = mSettings.destinationCrs().authid(); Q_FOREACH ( const QString& layerID, mSettings.layers() ) { - QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID ); + QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerID ); if ( !layer ) continue; diff --git a/src/gui/qgsmapcanvassnapper.cpp b/src/gui/qgsmapcanvassnapper.cpp index e0792abf500..9a5d503bb8c 100644 --- a/src/gui/qgsmapcanvassnapper.cpp +++ b/src/gui/qgsmapcanvassnapper.cpp @@ -17,7 +17,6 @@ #include "qgsmapcanvassnapper.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" #include "qgsmaptopixel.h" #include "qgsproject.h" #include "qgsvectorlayer.h" @@ -263,7 +262,7 @@ int QgsMapCanvasSnapper::snapToBackgroundLayers( const QgsPoint& point, QList( QgsMapLayerRegistry::instance()->mapLayer( *layerIt ) ); + QgsVectorLayer *vlayer = qobject_cast( QgsProject::instance()->mapLayer( *layerIt ) ); if ( !vlayer || !vlayer->hasGeometryType() ) continue; diff --git a/src/gui/qgsmapcanvastracer.cpp b/src/gui/qgsmapcanvastracer.cpp index ae632be52e5..a22225f5c02 100644 --- a/src/gui/qgsmapcanvastracer.cpp +++ b/src/gui/qgsmapcanvastracer.cpp @@ -16,7 +16,7 @@ #include "qgsapplication.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmessagebar.h" #include "qgsmessagebaritem.h" #include "qgssnappingutils.h" @@ -115,7 +115,7 @@ void QgsMapCanvasTracer::configure() case QgsSnappingConfig::AllLayers: Q_FOREACH ( const QString& layerId, visibleLayerIds ) { - QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ); + QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( layerId ) ); if ( vl ) layers << vl; } diff --git a/src/gui/qgsmapoverviewcanvas.cpp b/src/gui/qgsmapoverviewcanvas.cpp index 99ff2dbc958..9aac70df9b4 100644 --- a/src/gui/qgsmapoverviewcanvas.cpp +++ b/src/gui/qgsmapoverviewcanvas.cpp @@ -18,7 +18,7 @@ #include "qgsmapcanvas.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmapoverviewcanvas.h" #include "qgsmaprenderersequentialjob.h" #include "qgsmaptopixel.h" @@ -231,7 +231,7 @@ void QgsMapOverviewCanvas::setLayerSet( const QStringList& layerSet ) Q_FOREACH ( const QString& layerID, mSettings.layers() ) { - if ( QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerID ) ) + if ( QgsMapLayer* ml = QgsProject::instance()->mapLayer( layerID ) ) disconnect( ml, SIGNAL( repaintRequested() ), this, SLOT( layerRepaintRequested() ) ); } @@ -239,7 +239,7 @@ void QgsMapOverviewCanvas::setLayerSet( const QStringList& layerSet ) Q_FOREACH ( const QString& layerID, mSettings.layers() ) { - if ( QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerID ) ) + if ( QgsMapLayer* ml = QgsProject::instance()->mapLayer( layerID ) ) connect( ml, SIGNAL( repaintRequested() ), this, SLOT( layerRepaintRequested() ) ); } diff --git a/src/gui/qgsmaptoolidentify.cpp b/src/gui/qgsmaptoolidentify.cpp index 7a65771bf8e..02a1e02702b 100644 --- a/src/gui/qgsmaptoolidentify.cpp +++ b/src/gui/qgsmaptoolidentify.cpp @@ -35,7 +35,6 @@ #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" #include "qgsproject.h" -#include "qgsmaplayerregistry.h" #include "qgsrenderer.h" #include "qgsgeometryutils.h" #include "qgsgeometrycollection.h" diff --git a/src/gui/qgsnewgeopackagelayerdialog.cpp b/src/gui/qgsnewgeopackagelayerdialog.cpp index c14e1558f51..cf363fab1d2 100644 --- a/src/gui/qgsnewgeopackagelayerdialog.cpp +++ b/src/gui/qgsnewgeopackagelayerdialog.cpp @@ -23,7 +23,7 @@ #include "qgsapplication.h" #include "qgsproviderregistry.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgscoordinatereferencesystem.h" #include "qgsgenericprojectionselector.h" @@ -499,7 +499,7 @@ bool QgsNewGeoPackageLayerDialog::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 diff --git a/src/gui/symbology-ng/qgsellipsesymbollayerwidget.cpp b/src/gui/symbology-ng/qgsellipsesymbollayerwidget.cpp index 2dee9c7676d..486cef91f66 100644 --- a/src/gui/symbology-ng/qgsellipsesymbollayerwidget.cpp +++ b/src/gui/symbology-ng/qgsellipsesymbollayerwidget.cpp @@ -14,7 +14,6 @@ ***************************************************************************/ #include "qgsellipsesymbollayerwidget.h" #include "qgsellipsesymbollayer.h" -#include "qgsmaplayerregistry.h" #include "qgsvectorlayer.h" #include diff --git a/src/gui/symbology-ng/qgssizescalewidget.cpp b/src/gui/symbology-ng/qgssizescalewidget.cpp index 9344aa23392..c0280bc7996 100644 --- a/src/gui/symbology-ng/qgssizescalewidget.cpp +++ b/src/gui/symbology-ng/qgssizescalewidget.cpp @@ -18,7 +18,7 @@ #include "qgsvectorlayer.h" #include "qgsfeatureiterator.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgssymbol.h" #include "qgslayertreelayer.h" #include "qgslayertreemodellegendnode.h" @@ -105,7 +105,7 @@ QgsSizeScaleWidget::QgsSizeScaleWidget( const QgsVectorLayer * layer, const QgsS : mSymbol( symbol ) // we just use the minimumValue and maximumValue from the layer, unfortunately they are // non const, so we get the layer from the registry instead - , mLayer( layer ? dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( layer->id() ) ) : nullptr ) + , mLayer( layer ? dynamic_cast( QgsProject::instance()->mapLayer( layer->id() ) ) : nullptr ) , mMapCanvas( nullptr ) { setupUi( this ); diff --git a/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp b/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp index 8c35860ded3..2839d67ff15 100644 --- a/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp +++ b/src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp @@ -28,7 +28,7 @@ #include "qgsgeometry.h" #include "qgisinterface.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsproviderregistry.h" #include "qgsrubberband.h" #include "qgsvectorlayer.h" @@ -65,7 +65,7 @@ QgsGeometryCheckerResultTab::QgsGeometryCheckerResultTab( QgisInterface* iface, connect( ui.pushButtonFixWithPrompt, SIGNAL( clicked() ), this, SLOT( fixErrorsWithPrompt() ) ); connect( ui.pushButtonErrorResolutionSettings, SIGNAL( clicked() ), this, SLOT( setDefaultResolutionMethods() ) ); connect( ui.checkBoxHighlight, SIGNAL( clicked() ), this, SLOT( highlightErrors() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( checkRemovedLayer( QStringList ) ) ); + connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( checkRemovedLayer( QStringList ) ) ); connect( ui.pushButtonExport, SIGNAL( clicked() ), this, SLOT( exportErrors() ) ); if (( mFeaturePool->getLayer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeGeometries ) == 0 ) @@ -277,7 +277,7 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString& file ) // Remove existing layer with same uri QStringList toRemove; - Q_FOREACH ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer* maplayer, QgsProject::instance()->mapLayers() ) { if ( dynamic_cast( maplayer ) && static_cast( maplayer )->dataProvider()->dataSourceUri() == layer->dataProvider()->dataSourceUri() ) @@ -287,10 +287,10 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString& file ) } if ( !toRemove.isEmpty() ) { - QgsMapLayerRegistry::instance()->removeMapLayers( toRemove ); + QgsProject::instance()->removeMapLayers( toRemove ); } - QgsMapLayerRegistry::instance()->addMapLayers( QList() << layer ); + QgsProject::instance()->addMapLayers( QList() << layer ); return true; } diff --git a/src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp b/src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp index 768d0370c12..cd09d919729 100644 --- a/src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp +++ b/src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp @@ -24,7 +24,7 @@ #include "qgsfeatureiterator.h" #include "qgisinterface.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include "qgsmapcanvas.h" #include "qgsvectorfilewriter.h" @@ -54,8 +54,8 @@ QgsGeometryCheckerSetupTab::QgsGeometryCheckerSetupTab( QgisInterface* iface , Q connect( mRunButton, SIGNAL( clicked() ), this, SLOT( runChecks() ) ); connect( ui.comboBoxInputLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( validateInput() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( updateLayers() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( updateLayers() ) ); + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( updateLayers() ) ); + connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( updateLayers() ) ); connect( ui.radioButtonOutputNew, SIGNAL( toggled( bool ) ), ui.lineEditOutput, SLOT( setEnabled( bool ) ) ); connect( ui.radioButtonOutputNew, SIGNAL( toggled( bool ) ), ui.pushButtonOutputBrowse, SLOT( setEnabled( bool ) ) ); connect( ui.buttonGroupOutput, SIGNAL( buttonClicked( int ) ), this, SLOT( validateInput() ) ); @@ -87,7 +87,7 @@ void QgsGeometryCheckerSetupTab::updateLayers() QgsMapLayer* currentLayer = isVisible() ? 0 : mIface->mapCanvas()->currentLayer(); int currIdx = -1; int idx = 0; - Q_FOREACH ( QgsVectorLayer* layer, QgsMapLayerRegistry::instance()->layers() ) + Q_FOREACH ( QgsVectorLayer* layer, QgsProject::instance()->layers() ) { ui.comboBoxInputLayer->addItem( layer->name(), layer->id() ); if ( layer->name() == prevLayer ) @@ -203,7 +203,7 @@ void QgsGeometryCheckerSetupTab::runChecks() // Remove existing layer with same uri QStringList toRemove; - Q_FOREACH ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer* maplayer, QgsProject::instance()->mapLayers() ) { if ( dynamic_cast( maplayer ) && static_cast( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) ) @@ -213,7 +213,7 @@ void QgsGeometryCheckerSetupTab::runChecks() } if ( !toRemove.isEmpty() ) { - QgsMapLayerRegistry::instance()->removeMapLayers( toRemove ); + QgsProject::instance()->removeMapLayers( toRemove ); } QString errMsg; @@ -296,7 +296,7 @@ void QgsGeometryCheckerSetupTab::runChecks() layer->setReadOnly( true ); if ( ui.radioButtonOutputNew->isChecked() ) { - QgsMapLayerRegistry::instance()->addMapLayers( QList() << layer ); + QgsProject::instance()->addMapLayers( QList() << layer ); } //! Run * diff --git a/src/plugins/georeferencer/qgsgcpcanvasitem.cpp b/src/plugins/georeferencer/qgsgcpcanvasitem.cpp index 28e46c85b90..89192e3202c 100644 --- a/src/plugins/georeferencer/qgsgcpcanvasitem.cpp +++ b/src/plugins/georeferencer/qgsgcpcanvasitem.cpp @@ -15,7 +15,7 @@ #include "qgsgcpcanvasitem.h" #include "qgsgeorefdatapoint.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsrasterlayer.h" QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsGeorefDataPoint* dataPoint, bool isGCPSource ) @@ -190,7 +190,7 @@ double QgsGCPCanvasItem::residualToScreenFactor() const if ( !canvasLayers.isEmpty() ) { QString layerId = canvasLayers.at( 0 ); - QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer* mapLayer = QgsProject::instance()->mapLayer( layerId ); if ( mapLayer ) { QgsRasterLayer* rasterLayer = dynamic_cast( mapLayer ); diff --git a/src/plugins/georeferencer/qgsgeorefplugingui.cpp b/src/plugins/georeferencer/qgsgeorefplugingui.cpp index 9be22567198..024ebfe15c1 100644 --- a/src/plugins/georeferencer/qgsgeorefplugingui.cpp +++ b/src/plugins/georeferencer/qgsgeorefplugingui.cpp @@ -42,7 +42,6 @@ #include "qgscomposerframe.h" #include "qgsmapcanvas.h" #include "qgsmapcoordsdialog.h" -#include "qgsmaplayerregistry.h" #include "qgsmaptoolzoom.h" #include "qgsmaptoolpan.h" @@ -1108,7 +1107,7 @@ void QgsGeorefPluginGui::setupConnections() connect( mCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) ); connect( mCanvas, SIGNAL( zoomNextStatusChanged( bool ) ), mActionZoomNext, SLOT( setEnabled( bool ) ) ); // Connect when one Layer is removed - Case where change the Projetct in QGIS - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layerWillBeRemoved( QString ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layerWillBeRemoved( QString ) ) ); // Connect extents changed - Use for need add again Raster connect( mCanvas, SIGNAL( extentsChanged() ), this, SLOT( extentsChanged() ) ); @@ -1119,7 +1118,7 @@ void QgsGeorefPluginGui::removeOldLayer() // delete layer (and don't signal it as it's our private layer) if ( mLayer ) { - QgsMapLayerRegistry::instance()->removeMapLayers( + QgsProject::instance()->removeMapLayers( ( QStringList() << mLayer->id() ) ); mLayer = nullptr; } @@ -1165,7 +1164,7 @@ void QgsGeorefPluginGui::addRaster( const QString& file ) mLayer = new QgsRasterLayer( file, QStringLiteral( "Raster" ) ); // so layer is not added to legend - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mLayer, false, false ); // add layer to map canvas diff --git a/src/plugins/globe/globe_plugin.cpp b/src/plugins/globe/globe_plugin.cpp index 4b58ddc7527..ef0f93c52cc 100644 --- a/src/plugins/globe/globe_plugin.cpp +++ b/src/plugins/globe/globe_plugin.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -896,7 +895,7 @@ void GlobePlugin::updateLayers() // Disconnect any previous repaintRequested signals foreach ( const QString& layerId, mTileSource->layerSet() ) { - QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer* mapLayer = QgsProject::instance()->mapLayer( layerId ); if ( mapLayer ) disconnect( mapLayer, SIGNAL( repaintRequested() ), this, SLOT( layerChanged() ) ); if ( dynamic_cast( mapLayer ) ) @@ -906,7 +905,7 @@ void GlobePlugin::updateLayers() mMapNode->getMap()->getModelLayers( modelLayers ); foreach ( const osg::ref_ptr& modelLayer, modelLayers ) { - QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( QString::fromStdString( modelLayer->getName() ) ); + QgsMapLayer* mapLayer = QgsProject::instance()->mapLayer( QString::fromStdString( modelLayer->getName() ) ); if ( mapLayer ) disconnect( mapLayer, SIGNAL( repaintRequested() ), this, SLOT( layerChanged() ) ); if ( dynamic_cast( mapLayer ) ) @@ -917,7 +916,7 @@ void GlobePlugin::updateLayers() Q_FOREACH ( const QString& layerId, selectedLayers ) { - QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer* mapLayer = QgsProject::instance()->mapLayer( layerId ); connect( mapLayer, SIGNAL( repaintRequested() ), this, SLOT( layerChanged() ) ); QgsGlobeVectorLayerConfig* layerConfig = 0; diff --git a/src/plugins/globe/qgsglobefeatureidentify.cpp b/src/plugins/globe/qgsglobefeatureidentify.cpp index 414a456d3fa..f2439c15439 100644 --- a/src/plugins/globe/qgsglobefeatureidentify.cpp +++ b/src/plugins/globe/qgsglobefeatureidentify.cpp @@ -16,7 +16,7 @@ #include "qgsglobefeatureidentify.h" #include "qgsmapcanvas.h" -#include +#include "qgsproject.h" #include #include #include @@ -59,7 +59,7 @@ void QgsGlobeFeatureIdentifyCallback::onHit( osgEarth::ObjectID id ) std::string layerId; if ( feature->getUserValue( "qgisLayerId", layerId ) ) { - QgsVectorLayer* lyr = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( QString::fromStdString( layerId ) ) ); + QgsVectorLayer* lyr = qobject_cast( QgsProject::instance()->mapLayer( QString::fromStdString( layerId ) ) ); #endif if ( lyr ) { diff --git a/src/plugins/globe/qgsglobewidget.cpp b/src/plugins/globe/qgsglobewidget.cpp index 3725529875a..fa2ca83a24e 100644 --- a/src/plugins/globe/qgsglobewidget.cpp +++ b/src/plugins/globe/qgsglobewidget.cpp @@ -16,7 +16,6 @@ #include "qgsglobewidget.h" #include "qgsmapcanvas.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsrasterlayer.h" #include "qgisinterface.h" @@ -86,8 +85,8 @@ QgsGlobeWidget::QgsGlobeWidget( QgisInterface* iface, QWidget *parent ) setAttribute( Qt::WA_DeleteOnClose ); connect( mQgisIface->mapCanvas(), SIGNAL( layersChanged() ), this, SLOT( updateLayerSelectionMenu() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( updateLayerSelectionMenu() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerRemoved( QString ) ), this, SLOT( updateLayerSelectionMenu() ) ); + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( updateLayerSelectionMenu() ) ); + connect( QgsProject::instance(), SIGNAL( layerRemoved( QString ) ), this, SLOT( updateLayerSelectionMenu() ) ); updateLayerSelectionMenu(); } diff --git a/src/plugins/gps_importer/qgsgpsplugin.cpp b/src/plugins/gps_importer/qgsgpsplugin.cpp index 34f4c278d09..088810a7a60 100644 --- a/src/plugins/gps_importer/qgsgpsplugin.cpp +++ b/src/plugins/gps_importer/qgsgpsplugin.cpp @@ -21,7 +21,7 @@ #include "qgisinterface.h" #include "qgisgui.h" #include "qgsapplication.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaplayer.h" #include "qgsvectorlayer.h" #include "qgsdataprovider.h" @@ -123,8 +123,7 @@ void QgsGPSPlugin::run() // find all GPX layers std::vector gpxLayers; QMap::const_iterator iter; - QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance(); - QMap layers = registry->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); for ( iter = layers.constBegin(); iter != layers.constEnd(); ++iter ) { diff --git a/src/plugins/grass/qgsgrassmoduleinput.cpp b/src/plugins/grass/qgsgrassmoduleinput.cpp index de0642c8836..4391b07a5e2 100644 --- a/src/plugins/grass/qgsgrassmoduleinput.cpp +++ b/src/plugins/grass/qgsgrassmoduleinput.cpp @@ -32,7 +32,6 @@ #include "qgsdatasourceuri.h" #include "qgslogger.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" diff --git a/src/plugins/grass/qgsgrassmoduleoptions.cpp b/src/plugins/grass/qgsgrassmoduleoptions.cpp index 38929d4b295..9a3520f6c7d 100644 --- a/src/plugins/grass/qgsgrassmoduleoptions.cpp +++ b/src/plugins/grass/qgsgrassmoduleoptions.cpp @@ -26,7 +26,7 @@ #include "qgslogger.h" #include "qgsmapcanvas.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" @@ -479,7 +479,7 @@ QStringList QgsGrassModuleStandardOptions::checkOutput() QList QgsGrassModuleStandardOptions::grassProviders() { QList providers; - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers().values() ) { if ( layer->type() == QgsMapLayer::VectorLayer ) { @@ -500,7 +500,7 @@ QList QgsGrassModuleStandardOptions::grassProviders() QList QgsGrassModuleStandardOptions::grassRasterProviders() { QList providers; - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers().values() ) { if ( layer->type() == QgsMapLayer::RasterLayer ) { diff --git a/src/plugins/grass/qgsgrassmoduleoptions.h b/src/plugins/grass/qgsgrassmoduleoptions.h index 89a0e5ce55c..70c7aba7b61 100644 --- a/src/plugins/grass/qgsgrassmoduleoptions.h +++ b/src/plugins/grass/qgsgrassmoduleoptions.h @@ -190,7 +190,7 @@ class QgsGrassModuleStandardOptions: public QWidget, public QgsGrassModuleOption */ bool getCurrentMapRegion( QgsGrassModuleInput * param, struct Cell_head *window ); - // List of providers used by layers in QgsMapLayerRegistry + // List of providers used by layers in QgsProject QList grassProviders(); QList grassRasterProviders(); diff --git a/src/plugins/grass/qgsgrassmoduleparam.cpp b/src/plugins/grass/qgsgrassmoduleparam.cpp index 73e35687281..a62e03a3926 100644 --- a/src/plugins/grass/qgsgrassmoduleparam.cpp +++ b/src/plugins/grass/qgsgrassmoduleparam.cpp @@ -23,7 +23,7 @@ #include "qgsdatasourceuri.h" #include "qgslogger.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" @@ -872,9 +872,9 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput( lbl->setBuddy( mLayerPassword ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList ) ), + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), this, SLOT( updateQgisLayers() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ), + connect( QgsProject::instance(), SIGNAL( layersRemoved( QStringList ) ), this, SLOT( updateQgisLayers() ) ); // Fill in QGIS layers @@ -899,7 +899,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers() mLayerComboBox->addItem( tr( "Select a layer" ), QVariant() ); } - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers().values() ) { if ( !layer ) continue; @@ -1263,8 +1263,8 @@ QgsGrassModuleSelection::QgsGrassModuleSelection( connect( mModeComboBox, SIGNAL( currentIndexChanged( int ) ), SLOT( onModeChanged() ) ); l->addWidget( mModeComboBox ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList ) ), SLOT( onLayerChanged() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ), SLOT( onLayerChanged() ) ); + connect( QgsProject::instance(), SIGNAL( layersAdded( QList ) ), SLOT( onLayerChanged() ) ); + connect( QgsProject::instance(), SIGNAL( layersRemoved( QStringList ) ), SLOT( onLayerChanged() ) ); // Fill in layer current fields onLayerChanged(); @@ -1280,7 +1280,7 @@ void QgsGrassModuleSelection::onLayerChanged() QStringList layerIds; // add new layers matching selected input layer if not yet present - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers().values() ) { QgsVectorLayer *vectorLayer = qobject_cast( layer ); if ( vectorLayer && vectorLayer->providerType() == QLatin1String( "grass" ) ) @@ -1363,7 +1363,7 @@ QgsVectorLayer * QgsGrassModuleSelection::currentSelectionLayer() { return 0; } - QgsMapLayer *layer = QgsMapLayerRegistry::instance()->mapLayer( id ); + QgsMapLayer *layer = QgsProject::instance()->mapLayer( id ); return qobject_cast( layer ); } @@ -1377,13 +1377,13 @@ void QgsGrassModuleSelection::onModeChanged() QgsDebugMsg( "uri = " + uri ); QgsVectorLayer *layer = new QgsVectorLayer( uri, name, QStringLiteral( "grass" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( layer ); + QgsProject::instance()->addMapLayer( layer ); onLayerChanged(); // update with added layer } else if ( mModeComboBox->itemData( index ).toInt() == Layer ) { QString id = mModeComboBox->itemData( index, Qt::UserRole + 1 ).toString(); - QgsMapLayer *layer = QgsMapLayerRegistry::instance()->mapLayer( id ); + QgsMapLayer *layer = QgsProject::instance()->mapLayer( id ); QgsVectorLayer *vectorLayer = qobject_cast( layer ); if ( vectorLayer ) { diff --git a/src/plugins/grass/qgsgrassplugin.cpp b/src/plugins/grass/qgsgrassplugin.cpp index 65aa9024d80..b7701762609 100644 --- a/src/plugins/grass/qgsgrassplugin.cpp +++ b/src/plugins/grass/qgsgrassplugin.cpp @@ -39,7 +39,6 @@ #include "qgsproviderregistry.h" #include "qgsrendererregistry.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" #include #include @@ -280,7 +279,7 @@ void QgsGrassPlugin::initGui() connect( QgsGrass::instance(), SIGNAL( newLayer( QString, QString ) ), SLOT( onNewLayer( QString, QString ) ) ); // Connect start/stop editing - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerWasAdded( QgsMapLayer* ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerWasAdded( QgsMapLayer* ) ) ); connect( qGisInterface->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), SLOT( onCurrentLayerChanged( QgsMapLayer* ) ) ); @@ -456,7 +455,7 @@ void QgsGrassPlugin::onFieldsChanged() QString uri = grassProvider->dataSourceUri(); uri.remove( QRegExp( "[^_]*$" ) ); QgsDebugMsg( "uri = " + uri ); - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers().values() ) { if ( !layer || layer->type() != QgsMapLayer::VectorLayer ) { @@ -826,12 +825,12 @@ void QgsGrassPlugin::unload() disconnect( QgsGrass::instance(), SIGNAL( regionPenChanged() ), this, SLOT( displayRegion() ) ); disconnect( QgsGrass::instance(), SIGNAL( newLayer( QString, QString ) ), this, SLOT( onNewLayer( QString, QString ) ) ); - disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerWasAdded( QgsMapLayer* ) ) ); + disconnect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerWasAdded( QgsMapLayer* ) ) ); disconnect( qGisInterface->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( onCurrentLayerChanged( QgsMapLayer* ) ) ); - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers().values() ) { if ( !layer || layer->type() != QgsMapLayer::VectorLayer ) { diff --git a/src/plugins/interpolation/qgsinterpolationdialog.cpp b/src/plugins/interpolation/qgsinterpolationdialog.cpp index ade19e780a7..82e8aa9ce2f 100644 --- a/src/plugins/interpolation/qgsinterpolationdialog.cpp +++ b/src/plugins/interpolation/qgsinterpolationdialog.cpp @@ -23,7 +23,7 @@ #include "qgsidwinterpolatordialog.h" #include "qgstininterpolatordialog.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" #include @@ -40,7 +40,7 @@ QgsInterpolationDialog::QgsInterpolationDialog( QWidget* parent, QgisInterface* restoreGeometry( settings.value( QStringLiteral( "/Interpolation/geometry" ) ).toByteArray() ); //enter available layers into the combo box - QMap mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap mapLayers = QgsProject::instance()->mapLayers(); QMap::iterator layer_it = mapLayers.begin(); for ( ; layer_it != mapLayers.end(); ++layer_it ) @@ -338,7 +338,7 @@ void QgsInterpolationDialog::on_mConfigureInterpolationButton_clicked() QgsVectorLayer* QgsInterpolationDialog::vectorLayerFromName( const QString& name ) { - QMap mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap mapLayers = QgsProject::instance()->mapLayers(); QMap::iterator layer_it = mapLayers.begin(); for ( ; layer_it != mapLayers.end(); ++layer_it ) diff --git a/src/plugins/offline_editing/offline_editing_plugin.cpp b/src/plugins/offline_editing/offline_editing_plugin.cpp index 1a58fe96e5c..e35346ea311 100644 --- a/src/plugins/offline_editing/offline_editing_plugin.cpp +++ b/src/plugins/offline_editing/offline_editing_plugin.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -88,8 +87,8 @@ void QgsOfflineEditingPlugin::initGui() connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( updateActions() ) ); connect( mQGisIface->mainWindow(), SIGNAL( newProject() ), this, SLOT( updateActions() ) ); connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), this, SLOT( updateActions() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateActions() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateActions() ) ); + connect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateActions() ) ); + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateActions() ) ); updateActions(); } @@ -149,7 +148,7 @@ void QgsOfflineEditingPlugin::help() void QgsOfflineEditingPlugin::updateActions() { - bool hasLayers = QgsMapLayerRegistry::instance()->count() > 0; + bool hasLayers = QgsProject::instance()->count() > 0; bool isOfflineProject = mOfflineEditing->isOfflineProject(); mActionConvertProject->setEnabled( hasLayers && !isOfflineProject ); mActionSynchronize->setEnabled( hasLayers && isOfflineProject ); diff --git a/src/plugins/offline_editing/offline_editing_plugin_gui.cpp b/src/plugins/offline_editing/offline_editing_plugin_gui.cpp index ff2e9a7b07e..cb21da80aae 100644 --- a/src/plugins/offline_editing/offline_editing_plugin_gui.cpp +++ b/src/plugins/offline_editing/offline_editing_plugin_gui.cpp @@ -22,7 +22,6 @@ #include "qgslayertree.h" #include "qgslayertreemodel.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" diff --git a/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp b/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp index eccdc650bc4..880117eaec2 100644 --- a/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp +++ b/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp @@ -13,7 +13,7 @@ * * ***************************************************************************/ #include "qgsrasterterrainanalysisdialog.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsrasterlayer.h" #include #include @@ -55,7 +55,7 @@ QgsRasterTerrainAnalysisDialog::QgsRasterTerrainAnalysisDialog( DisplayMode mode //insert available raster layers //enter available layers into the combo box - QMap mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap mapLayers = QgsProject::instance()->mapLayers(); QMap::iterator layer_it = mapLayers.begin(); //insert available input layers @@ -124,7 +124,7 @@ QList< QgsRelief::ReliefColor > QgsRasterTerrainAnalysisDialog::reliefColors() c QString QgsRasterTerrainAnalysisDialog::inputFile() const { - QgsMapLayer* inputLayer = QgsMapLayerRegistry::instance()->mapLayer( mElevationLayerComboBox->currentData().toString() ); + QgsMapLayer* inputLayer = QgsProject::instance()->mapLayer( mElevationLayerComboBox->currentData().toString() ); if ( !inputLayer ) { return QLatin1String( "" ); diff --git a/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp b/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp index 323eee942be..eb0774680ac 100644 --- a/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp +++ b/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp @@ -19,7 +19,6 @@ #include "qgis.h" #include "qgisinterface.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsaspectfilter.h" #include "qgshillshadefilter.h" #include "qgsslopefilter.h" diff --git a/src/plugins/roadgraph/exportdlg.cpp b/src/plugins/roadgraph/exportdlg.cpp index 257c9404d9e..24d0f45168e 100644 --- a/src/plugins/roadgraph/exportdlg.cpp +++ b/src/plugins/roadgraph/exportdlg.cpp @@ -22,7 +22,7 @@ // Qgis includes #include -#include +#include #include #include @@ -50,7 +50,7 @@ RgExportDlg::RgExportDlg( QWidget* parent, Qt::WindowFlags fl ) //fill list of layers mcbLayers->insertItem( 0, tr( "New temporary layer" ), QVariant( "-1" ) ); - QMap mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap mapLayers = QgsProject::instance()->mapLayers(); QMap::iterator layer_it = mapLayers.begin(); for ( ; layer_it != mapLayers.end(); ++layer_it ) @@ -90,12 +90,12 @@ QgsVectorLayer* RgExportDlg::mapLayer() const myLayer->updateFields(); QList myList; myList << myLayer; - QgsMapLayerRegistry::instance()->addMapLayers( myList ); + QgsProject::instance()->addMapLayers( myList ); } else { // return selected layer - myLayer = dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ); + myLayer = dynamic_cast( QgsProject::instance()->mapLayer( layerId ) ); } return myLayer; diff --git a/src/plugins/roadgraph/roadgraphplugin.cpp b/src/plugins/roadgraph/roadgraphplugin.cpp index 7dcdc22717d..0a019bfb6c9 100644 --- a/src/plugins/roadgraph/roadgraphplugin.cpp +++ b/src/plugins/roadgraph/roadgraphplugin.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -197,7 +196,7 @@ QgisInterface* RoadGraphPlugin::iface() const QgsGraphDirector* RoadGraphPlugin::director() const { - QList< QgsMapLayer* > mapLayers = QgsMapLayerRegistry::instance()->mapLayersByName( mSettings->mLayerName ); + QList< QgsMapLayer* > mapLayers = QgsProject::instance()->mapLayersByName( mSettings->mLayerName ); if ( mapLayers.isEmpty() ) return nullptr; diff --git a/src/plugins/spatialquery/qgsspatialquerydialog.cpp b/src/plugins/spatialquery/qgsspatialquerydialog.cpp index 5024835b809..4de03dd0338 100644 --- a/src/plugins/spatialquery/qgsspatialquerydialog.cpp +++ b/src/plugins/spatialquery/qgsspatialquerydialog.cpp @@ -23,7 +23,6 @@ #include "qgis.h" #include "qgsapplication.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsvectordataprovider.h" @@ -63,7 +62,7 @@ QgsSpatialQueryDialog::~QgsSpatialQueryDialog() bool QgsSpatialQueryDialog::hasPossibleQuery( QString &msg ) { // Count the number of vector layer - QMap layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); QMapIterator item( layers ); QgsMapLayer * mapLayer = nullptr; QgsVectorLayer * lyr = nullptr; @@ -298,7 +297,7 @@ bool QgsSpatialQueryDialog::addLayerSubset( const QString& name, const QString& delete addLyr; return false; } - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << addLyr ); return true; } // bool QgsSpatialQueryDialog::addLayerSubset( QString name, QString subset ) @@ -352,9 +351,9 @@ QString QgsSpatialQueryDialog::getDescriptionInvalidFeaturesShow( bool isTarget void QgsSpatialQueryDialog::connectAll() { - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), + connect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( signal_qgis_layerWasAdded( QgsMapLayer* ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( signal_qgis_layerWillBeRemoved( QString ) ) ); connect( ckbLogProcessing, SIGNAL( clicked( bool ) ), this, SLOT( on_ckbLogProcessing_clicked( bool ) ) ); @@ -362,9 +361,9 @@ void QgsSpatialQueryDialog::connectAll() void QgsSpatialQueryDialog::disconnectAll() { - disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), + disconnect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( signal_qgis_layerWasAdded( QgsMapLayer* ) ) ); - disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), + disconnect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( signal_qgis_layerWillBeRemoved( QString ) ) ); if ( mLayerTarget ) @@ -532,7 +531,7 @@ void QgsSpatialQueryDialog::populateCbTargetLayer() { cbTargetLayer->blockSignals( true ); - QMap layers = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layers = QgsProject::instance()->mapLayers(); QMapIterator item( layers ); QgsMapLayer * mapLayer = nullptr; QgsVectorLayer * lyr = nullptr; diff --git a/src/plugins/spatialquery/qgsspatialqueryplugin.cpp b/src/plugins/spatialquery/qgsspatialqueryplugin.cpp index 878687f0ff3..86451b14d3f 100644 --- a/src/plugins/spatialquery/qgsspatialqueryplugin.cpp +++ b/src/plugins/spatialquery/qgsspatialqueryplugin.cpp @@ -23,7 +23,6 @@ // #include "qgisinterface.h" #include "qgsapplication.h" -#include "qgsmaplayerregistry.h" #include "qgsmessagebar.h" // diff --git a/src/plugins/topology/checkDock.cpp b/src/plugins/topology/checkDock.cpp index ce4098c9ce3..3ab9875acc9 100644 --- a/src/plugins/topology/checkDock.cpp +++ b/src/plugins/topology/checkDock.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -59,7 +59,6 @@ checkDock::checkDock( QgisInterface* qIface, QWidget* parent ) mErrorTableView->setSelectionBehavior( QAbstractItemView::SelectRows ); mErrorTableView->verticalHeader()->setDefaultSectionSize( 20 ); - mLayerRegistry = QgsMapLayerRegistry::instance(); mConfigureDialog = new rulesDialog( mTest->testMap(), qIface, parent ); mTestTable = mConfigureDialog->rulesTable(); @@ -89,7 +88,7 @@ checkDock::checkDock( QgisInterface* qIface, QWidget* parent ) connect( mFixButton, SIGNAL( clicked() ), this, SLOT( fix() ) ); connect( mErrorTableView, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( errorListClicked( const QModelIndex & ) ) ); - connect( mLayerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( parseErrorListByLayer( QString ) ) ); + connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( parseErrorListByLayer( QString ) ) ); connect( this, SIGNAL( visibilityChanged( bool ) ), this, SLOT( updateRubberBands( bool ) ) ); connect( qgsInterface, SIGNAL( newProjectCreated() ), mConfigureDialog, SLOT( clearRules() ) ); @@ -151,7 +150,7 @@ void checkDock::deleteErrors() void checkDock::parseErrorListByLayer( const QString& layerId ) { - QgsVectorLayer *layer = qobject_cast( mLayerRegistry->mapLayer( layerId ) ); + QgsVectorLayer *layer = qobject_cast( QgsProject::instance()->mapLayer( layerId ) ); QList::Iterator it = mErrorList.begin(); while ( it != mErrorList.end() ) @@ -329,17 +328,17 @@ void checkDock::runTests( ValidateType type ) QString layer2Str = mTestTable->item( i, 5 )->text(); // test if layer1 is in the registry - if ( !(( QgsVectorLayer* )mLayerRegistry->mapLayers().contains( layer1Str ) ) ) + if ( !(( QgsVectorLayer* )QgsProject::instance()->mapLayers().contains( layer1Str ) ) ) { QgsMessageLog::logMessage( tr( "Layer %1 not found in registry." ).arg( layer1Str ), tr( "Topology plugin" ) ); return; } - QgsVectorLayer* layer1 = ( QgsVectorLayer* )mLayerRegistry->mapLayer( layer1Str ); + QgsVectorLayer* layer1 = ( QgsVectorLayer* )QgsProject::instance()->mapLayer( layer1Str ); QgsVectorLayer* layer2 = nullptr; - if (( QgsVectorLayer* )mLayerRegistry->mapLayers().contains( layer2Str ) ) - layer2 = ( QgsVectorLayer* )mLayerRegistry->mapLayer( layer2Str ); + if (( QgsVectorLayer* )QgsProject::instance()->mapLayers().contains( layer2Str ) ) + layer2 = ( QgsVectorLayer* )QgsProject::instance()->mapLayer( layer2Str ); QProgressDialog progress( testName, tr( "Abort" ), 0, layer1->featureCount(), this ); progress.setWindowModality( Qt::WindowModal ); diff --git a/src/plugins/topology/checkDock.h b/src/plugins/topology/checkDock.h index 8eb37d9e5c8..3c35f9ebf88 100644 --- a/src/plugins/topology/checkDock.h +++ b/src/plugins/topology/checkDock.h @@ -31,7 +31,6 @@ #include "topolTest.h" #include "dockModel.h" -class QgsMapLayerRegistry; class QgsRubberBand; class QgsVertexMarker; class QgisApp; @@ -128,7 +127,6 @@ class checkDock : public QgsDockWidget, private Ui::checkDock QTableWidget* mTestTable; topolTest* mTest; - QgsMapLayerRegistry* mLayerRegistry; /** * Runs tests from the test table diff --git a/src/plugins/topology/rulesDialog.cpp b/src/plugins/topology/rulesDialog.cpp index eef862e302b..9b46c037b46 100644 --- a/src/plugins/topology/rulesDialog.cpp +++ b/src/plugins/topology/rulesDialog.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -76,13 +75,12 @@ void rulesDialog::setHorizontalHeaderItems() mRulesTable->setHorizontalHeaderLabels( labels ); } -void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry ) +void rulesDialog::readTest( int index, QgsProject* project ) { QString testName; QString layer1Id; QString layer2Id; QString tolerance; - QgsProject* project = QgsProject::instance(); QString postfix = QStringLiteral( "%1" ).arg( index ); testName = project->readEntry( QStringLiteral( "Topol" ), "/testname_" + postfix, QLatin1String( "" ) ); @@ -91,10 +89,10 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry ) layer2Id = project->readEntry( QStringLiteral( "Topol" ), "/layer2_" + postfix, QLatin1String( "" ) ); QgsVectorLayer* l1; - if ( !( QgsVectorLayer* )layerRegistry->mapLayers().contains( layer1Id ) ) + if ( !( QgsVectorLayer* )project->mapLayers().contains( layer1Id ) ) return; - l1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layer1Id ); + l1 = ( QgsVectorLayer* )project->mapLayer( layer1Id ); if ( !l1 ) return; @@ -104,11 +102,11 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry ) if ( mTestConfMap[testName].useSecondLayer ) { - if ( !( QgsVectorLayer* )layerRegistry->mapLayers().contains( layer2Id ) ) + if ( !( QgsVectorLayer* )project->mapLayers().contains( layer2Id ) ) return; else { - l2 = ( QgsVectorLayer* )layerRegistry->mapLayer( layer2Id ); + l2 = ( QgsVectorLayer* )project->mapLayer( layer2Id ); layer2Name = l2->name(); } } @@ -149,12 +147,12 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry ) void rulesDialog::projectRead() { clearRules(); - QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance(); + QgsProject* project = QgsProject::instance(); int testCount = QgsProject::instance()->readNumEntry( QStringLiteral( "Topol" ), QStringLiteral( "/testCount" ) ); mRulesTable->clearContents(); for ( int i = 0; i < testCount; ++i ) - readTest( i, layerRegistry ); + readTest( i, project ); } void rulesDialog::showControls( const QString& testName ) @@ -167,15 +165,14 @@ void rulesDialog::showControls( const QString& testName ) mLayer2Box->clear(); mLayer2Box->addItem( tr( "No layer" ) ); TopologyRule topologyRule = mTestConfMap[testName]; - QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance(); - QList layerList = layerRegistry->mapLayers().keys(); + QList layerList = QgsProject::instance()->mapLayers().keys(); if ( topologyRule.useSecondLayer ) { mLayer2Box->setVisible( true ); for ( int i = 0; i < layerList.count(); ++i ) { - QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layerList[i] ); + QgsVectorLayer* v1 = ( QgsVectorLayer* )QgsProject::instance()->mapLayer( layerList[i] ); if ( !v1 ) { @@ -318,8 +315,7 @@ void rulesDialog::updateRuleItems( const QString &layerName ) QString layerId = mLayer1Box->currentData().toString(); - QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance(); - QgsVectorLayer* vlayer = ( QgsVectorLayer* )layerRegistry->mapLayer( layerId ); + QgsVectorLayer* vlayer = ( QgsVectorLayer* )QgsProject::instance()->mapLayer( layerId ); if ( !vlayer ) { @@ -340,9 +336,7 @@ void rulesDialog::updateRuleItems( const QString &layerName ) void rulesDialog::initGui() { - QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance(); - - QList layerList = layerRegistry->mapLayers().keys(); + QList layerList = QgsProject::instance()->mapLayers().keys(); mLayer1Box->clear(); mLayer1Box->addItem( tr( "No layer" ) ); @@ -353,7 +347,7 @@ void rulesDialog::initGui() mLayer1Box->blockSignals( true ); for ( int i = 0; i < layerList.size(); ++i ) { - QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layerList[i] ); + QgsVectorLayer* v1 = ( QgsVectorLayer* )QgsProject::instance()->mapLayer( layerList[i] ); qDebug() << "layerid = " + layerList[i]; // add layer name to the layer combo boxes diff --git a/src/plugins/topology/rulesDialog.h b/src/plugins/topology/rulesDialog.h index e0b1e3c0b39..3f9f882de2f 100644 --- a/src/plugins/topology/rulesDialog.h +++ b/src/plugins/topology/rulesDialog.h @@ -26,7 +26,7 @@ #include "topolTest.h" class QgisInterface; -class QgsMapLayerRegistry; +class QgsProject; class rulesDialog : public QDialog, private Ui::rulesDialog { @@ -64,9 +64,9 @@ class rulesDialog : public QDialog, private Ui::rulesDialog /* * Reads a test from the project * @param index test index - * @param layerRegistry pointer to a QgsMapLayerRegistry instance + * @param project pointer to QgsProject */ - void readTest( int index, QgsMapLayerRegistry* layerRegistry ); + void readTest( int index, QgsProject* project ); /* * Sets the horizontal header for tet table */ diff --git a/src/providers/gdal/qgsgdalprovider.cpp b/src/providers/gdal/qgsgdalprovider.cpp index e70b0cf79e6..2b42b7f1771 100644 --- a/src/providers/gdal/qgsgdalprovider.cpp +++ b/src/providers/gdal/qgsgdalprovider.cpp @@ -2612,7 +2612,7 @@ void QgsGdalProvider::initBaseDataset() //set up the coordinat transform - in the case of raster this is mainly used to convert //the inverese projection of the map extents of the canvas when zooming in etc. so //that they match the coordinate system of this layer - //QgsDebugMsg( "Layer registry has " + QString::number( QgsMapLayerRegistry::instance()->count() ) + "layers" ); + //QgsDebugMsg( "Layer registry has " + QString::number( QgsProject::instance()->count() ) + "layers" ); //metadata(); diff --git a/src/providers/virtual/qgsvirtuallayerprovider.cpp b/src/providers/virtual/qgsvirtuallayerprovider.cpp index 6b1f0a02f3a..9fff878460f 100644 --- a/src/providers/virtual/qgsvirtuallayerprovider.cpp +++ b/src/providers/virtual/qgsvirtuallayerprovider.cpp @@ -28,7 +28,7 @@ extern "C" #include "qgsvirtuallayerdefinition.h" #include "qgsvirtuallayerfeatureiterator.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsdatasourceuri.h" #include "qgslogger.h" @@ -104,7 +104,7 @@ bool QgsVirtualLayerProvider::loadSourceLayers() { if ( layer.isReferenced() ) { - QgsMapLayer *l = QgsMapLayerRegistry::instance()->mapLayer( layer.reference() ); + QgsMapLayer *l = QgsProject::instance()->mapLayer( layer.reference() ); if ( !l ) { PROVIDER_ERROR( QString( "Cannot find layer %1" ).arg( layer.reference() ) ); @@ -232,7 +232,7 @@ bool QgsVirtualLayerProvider::createIt() } // is it in loaded layers ? bool found = false; - Q_FOREACH ( const QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( const QgsMapLayer *l, QgsProject::instance()->mapLayers() ) { if ( l->type() != QgsMapLayer::VectorLayer ) continue; diff --git a/src/providers/virtual/qgsvirtuallayersourceselect.cpp b/src/providers/virtual/qgsvirtuallayersourceselect.cpp index 27a7404fa65..3e1341820c1 100644 --- a/src/providers/virtual/qgsvirtuallayersourceselect.cpp +++ b/src/providers/virtual/qgsvirtuallayersourceselect.cpp @@ -21,7 +21,7 @@ email : hugo dot mercier at oslandia dot com #include #include #include -#include +#include #include #include #include @@ -106,7 +106,7 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget* parent, Qt::W } // configure auto completion with table and column names - Q_FOREACH ( QgsMapLayer* l, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer* l, QgsProject::instance()->mapLayers() ) { if ( l->type() == QgsMapLayer::VectorLayer ) { @@ -134,7 +134,7 @@ void QgsVirtualLayerSourceSelect::onLayerComboChanged( int idx ) return; QString lid = mLayerNameCombo->itemData( idx ).toString(); - QgsVectorLayer* l = static_cast( QgsMapLayerRegistry::instance()->mapLayer( lid ) ); + QgsVectorLayer* l = static_cast( QgsProject::instance()->mapLayer( lid ) ); if ( !l ) return; QgsVirtualLayerDefinition def = QgsVirtualLayerDefinition::fromUrl( QUrl::fromEncoded( l->source().toUtf8() ) ); @@ -295,7 +295,7 @@ void QgsVirtualLayerSourceSelect::onImportLayer() QStringList ids = mEmbeddedSelectionDialog->layers(); Q_FOREACH ( const QString& id, ids ) { - QgsVectorLayer *vl = static_cast( QgsMapLayerRegistry::instance()->mapLayer( id ) ); + QgsVectorLayer *vl = static_cast( QgsProject::instance()->mapLayer( id ) ); addEmbeddedLayer( vl->name(), vl->providerType(), vl->dataProvider()->encoding(), vl->source() ); } } @@ -315,7 +315,7 @@ void QgsVirtualLayerSourceSelect::on_buttonBox_accepted() if ( idx != -1 ) { QString id( mLayerNameCombo->itemData( idx ).toString() ); - if ( !id.isEmpty() && mLayerNameCombo->currentText() == QgsMapLayerRegistry::instance()->mapLayer( id )->name() ) + if ( !id.isEmpty() && mLayerNameCombo->currentText() == QgsProject::instance()->mapLayer( id )->name() ) { int r = QMessageBox::warning( nullptr, tr( "Warning" ), tr( "A virtual layer of this name already exists, would you like to overwrite it?" ), QMessageBox::Yes | QMessageBox::No ); if ( r == QMessageBox::Yes ) diff --git a/src/providers/virtual/qgsvirtuallayersqlitemodule.cpp b/src/providers/virtual/qgsvirtuallayersqlitemodule.cpp index 83b0cbf6c59..89c63a27fc3 100644 --- a/src/providers/virtual/qgsvirtuallayersqlitemodule.cpp +++ b/src/providers/virtual/qgsvirtuallayersqlitemodule.cpp @@ -26,7 +26,7 @@ email : hugo dot mercier at oslandia dot com #include #include #include -#include +#include #include #include "qgsinterval.h" #include @@ -354,7 +354,7 @@ int vtableCreateConnect( sqlite3* sql, void* aux, int argc, const char* const* a { layerid = layerid.mid( 1, layerid.size() - 2 ); } - QgsMapLayer *l = QgsMapLayerRegistry::instance()->mapLayer( layerid ); + QgsMapLayer *l = QgsProject::instance()->mapLayer( layerid ); if ( !l || l->type() != QgsMapLayer::VectorLayer ) { if ( outErr ) diff --git a/src/providers/wcs/URI b/src/providers/wcs/URI index dde222b1b78..481794594a8 100644 --- a/src/providers/wcs/URI +++ b/src/providers/wcs/URI @@ -41,7 +41,7 @@ Python console example, adds new layer to map canvas: layer = QgsRasterLayer( QString(uri.encodedUri()), "WCS test", "wcs" ) layer.isValid() - QgsMapLayerRegistry.instance().addMapLayer(layer) + QgsProject.instance().addMapLayer(layer) another standalone script, downloads WCS layer to local file: diff --git a/src/server/qgsmaprenderer.cpp b/src/server/qgsmaprenderer.cpp index 7f48c2f8b9d..4fecf4b2c00 100644 --- a/src/server/qgsmaprenderer.cpp +++ b/src/server/qgsmaprenderer.cpp @@ -25,7 +25,6 @@ #include "qgsmaplayerrenderer.h" #include "qgsmaptopixel.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsmapsettings.h" #include "qgsdistancearea.h" #include "qgsproject.h" @@ -379,7 +378,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale ) QgsDebugMsg( "If there is a QPaintEngine error here, it is caused by an emit call" ); //emit drawingProgress(myRenderCounter++, mLayerSet.size()); - QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer *ml = QgsProject::instance()->mapLayer( layerId ); if ( !ml ) { @@ -902,14 +901,12 @@ QgsRectangle QgsMapRenderer::fullExtent() if ( !mFullExtent.isNull() ) return mFullExtent; - QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance(); - // iterate through the map layers and test each layers extent // against the current min and max values QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayerSet.count() ) ); Q_FOREACH ( const QString layerId, mLayerSet ) { - QgsMapLayer * lyr = registry->mapLayer( layerId ); + QgsMapLayer * lyr = QgsProject::instance()->mapLayer( layerId ); if ( !lyr ) { QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( layerId ) ); diff --git a/src/server/qgsmslayercache.cpp b/src/server/qgsmslayercache.cpp index ec7554175f3..6e2f965cb78 100644 --- a/src/server/qgsmslayercache.cpp +++ b/src/server/qgsmslayercache.cpp @@ -17,7 +17,7 @@ #include "qgsmslayercache.h" #include "qgsmessagelog.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaplayer.h" #include "qgsvectorlayer.h" #include "qgslogger.h" @@ -189,9 +189,9 @@ void QgsMSLayerCache::removeLeastUsedEntry() void QgsMSLayerCache::freeEntryRessources( QgsMSLayerCacheEntry& entry ) { - // remove layer from QgsMapLayerRegistry before delete it - if ( QgsMapLayerRegistry::instance()->mapLayer( entry.layerPointer->id() ) ) - QgsMapLayerRegistry::instance()->removeMapLayer( entry.layerPointer->id() ); + // remove layer from QgsProject before delete it + if ( QgsProject::instance()->mapLayer( entry.layerPointer->id() ) ) + QgsProject::instance()->removeMapLayer( entry.layerPointer->id() ); delete entry.layerPointer; diff --git a/src/server/qgsowsserver.cpp b/src/server/qgsowsserver.cpp index 1524c42c4ff..841d0d11bdc 100644 --- a/src/server/qgsowsserver.cpp +++ b/src/server/qgsowsserver.cpp @@ -16,7 +16,6 @@ ***************************************************************************/ #include "qgsowsserver.h" -#include "qgsmaplayerregistry.h" #include "qgsmessagelog.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" diff --git a/src/server/qgsserver.cpp b/src/server/qgsserver.cpp index 72e54ee0ed4..741731fd144 100644 --- a/src/server/qgsserver.cpp +++ b/src/server/qgsserver.cpp @@ -28,6 +28,7 @@ #include "qgsgetrequesthandler.h" #include "qgspostrequesthandler.h" #include "qgssoaprequesthandler.h" +#include "qgsproject.h" #include "qgsproviderregistry.h" #include "qgslogger.h" #include "qgswmsserver.h" @@ -36,7 +37,6 @@ #include "qgsmapserviceexception.h" #include "qgspallabeling.h" #include "qgsnetworkaccessmanager.h" -#include "qgsmaplayerregistry.h" #include "qgsserverlogger.h" #include "qgseditorwidgetregistry.h" #ifdef HAVE_SERVER_PYTHON_PLUGINS @@ -452,7 +452,7 @@ QPair QgsServer::handleRequest( const QString& queryStri int logLevel = QgsServerLogger::instance()->logLevel(); QTime time; //used for measuring request time if loglevel < 1 - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); // Clean up Expression Context // because each call to QgsMapLayer::draw add items to QgsExpressionContext scope diff --git a/src/server/qgsserverprojectparser.cpp b/src/server/qgsserverprojectparser.cpp index d15e39318d2..20f1f3b6337 100644 --- a/src/server/qgsserverprojectparser.cpp +++ b/src/server/qgsserverprojectparser.cpp @@ -22,7 +22,6 @@ #include "qgsconfigparserutils.h" #include "qgscsexception.h" #include "qgsdatasourceuri.h" -#include "qgsmaplayerregistry.h" #include "qgsmslayercache.h" #include "qgsrasterlayer.h" #include "qgsvectorlayerjoinbuffer.h" @@ -234,8 +233,8 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement& if ( layer ) { - if ( !QgsMapLayerRegistry::instance()->mapLayer( id ) ) - QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false ); + if ( !QgsProject::instance()->mapLayer( id ) ) + QgsProject::instance()->addMapLayer( layer, false, false ); if ( layer->type() == QgsMapLayer::VectorLayer ) { QgsVectorLayer* vlayer = qobject_cast( layer ); @@ -285,8 +284,8 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement& return nullptr; } // Insert layer in registry and cache before addValueRelationLayersForLayer - if ( !QgsMapLayerRegistry::instance()->mapLayer( id ) ) - QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false ); + if ( !QgsProject::instance()->mapLayer( id ) ) + QgsProject::instance()->addMapLayer( layer, false, false ); if ( useCache ) { QgsMSLayerCache::instance()->insertLayer( absoluteUri, id, layer, mProjectPath ); @@ -1567,9 +1566,9 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl { QString id = joinNodeList.at( i ).toElement().attribute( QStringLiteral( "joinLayerId" ) ); QgsMapLayer* layer = mapLayerFromLayerId( id ); - if ( layer && !QgsMapLayerRegistry::instance()->mapLayer( id ) ) + if ( layer && !QgsProject::instance()->mapLayer( id ) ) { - QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false ); + QgsProject::instance()->addMapLayer( layer, false, false ); } } } @@ -1590,14 +1589,14 @@ void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLaye continue; QString layerId = cfg.value( QStringLiteral( "Layer" ) ).toString(); - if ( QgsMapLayerRegistry::instance()->mapLayer( layerId ) ) + if ( QgsProject::instance()->mapLayer( layerId ) ) continue; QgsMapLayer *layer = mapLayerFromLayerId( layerId ); if ( !layer ) continue; - QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false ); + QgsProject::instance()->addMapLayer( layer, false, false ); } } @@ -1629,7 +1628,7 @@ void QgsServerProjectParser::addGetFeatureLayers( const QDomElement& layerElem ) if ( ml ) { - QgsMapLayerRegistry::instance()->addMapLayer( ml, false, false ); + QgsProject::instance()->addMapLayer( ml, false, false ); } idx += rx.matchedLength(); } diff --git a/src/server/qgswfsprojectparser.cpp b/src/server/qgswfsprojectparser.cpp index bae0849e71a..4e5f6003a26 100644 --- a/src/server/qgswfsprojectparser.cpp +++ b/src/server/qgswfsprojectparser.cpp @@ -18,7 +18,7 @@ #include "qgswfsprojectparser.h" #include "qgsconfigcache.h" #include "qgsconfigparserutils.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectordataprovider.h" #include "qgsmapserviceexception.h" #include "qgsaccesscontrol.h" @@ -495,7 +495,7 @@ void QgsWfsProjectParser::describeFeatureType( const QString& aTypeName, QDomEle } } } - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); return; } diff --git a/src/server/qgswfsserver.cpp b/src/server/qgswfsserver.cpp index 56477c5692e..73fea062fed 100644 --- a/src/server/qgswfsserver.cpp +++ b/src/server/qgswfsserver.cpp @@ -20,7 +20,6 @@ #include "qgsfeatureiterator.h" #include "qgsgeometry.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" #include "qgsmaprenderer.h" #include "qgsmaptopixel.h" #include "qgsmessagelog.h" @@ -731,7 +730,7 @@ int QgsWfsServer::getFeature( QgsRequestHandler& request, const QString& format QgsMessageLog::logMessage( mErrors.join( QStringLiteral( "\n" ) ) ); - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); if ( featureCounter <= startIndex ) startGetFeature( request, format, layerPrec, layerCrs, &searchRect ); endGetFeature( request, format ); @@ -1202,7 +1201,7 @@ int QgsWfsServer::getFeature( QgsRequestHandler& request, const QString& format } - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); if ( featureCounter <= startIndex ) startGetFeature( request, format, layerPrec, layerCrs, &searchRect ); endGetFeature( request, format ); diff --git a/src/server/qgswmsconfigparser.cpp b/src/server/qgswmsconfigparser.cpp index 50b4d40aefc..1eba3419bf6 100644 --- a/src/server/qgswmsconfigparser.cpp +++ b/src/server/qgswmsconfigparser.cpp @@ -17,7 +17,7 @@ #include "qgswmsconfigparser.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmapserviceexception.h" #include "qgscomposerlabel.h" @@ -344,7 +344,7 @@ QStringList QgsWmsConfigParser::addHighlightLayers( const QMap layer->setRenderer( renderer.take() ); layerSet.prepend( layer.data()->id() ); highlightLayers.append( layer.data()->id() ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << layer.take() ); + QgsProject::instance()->addMapLayers( QList() << layer.take() ); } return highlightLayers; } @@ -534,7 +534,7 @@ void QgsWmsConfigParser::removeHighlightLayers( const QStringList& layerIds ) QStringList::const_iterator idIt = layerIds.constBegin(); for ( ; idIt != layerIds.constEnd(); ++idIt ) { - QgsMapLayerRegistry::instance()->removeMapLayers( QStringList() << *idIt ); + QgsProject::instance()->removeMapLayers( QStringList() << *idIt ); } } diff --git a/src/server/qgswmsprojectparser.cpp b/src/server/qgswmsprojectparser.cpp index ff0128abb42..db23f1ed87c 100644 --- a/src/server/qgswmsprojectparser.cpp +++ b/src/server/qgswmsprojectparser.cpp @@ -20,7 +20,7 @@ #include "qgsconfigparserutils.h" #include "qgslogger.h" #include "qgsmaplayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaplayerstylemanager.h" #include "qgsmapserviceexception.h" #include "qgspallabeling.h" @@ -535,10 +535,10 @@ QgsComposition* QgsWmsProjectParser::initComposition( const QString& composerTem QgsLayerTreeGroup* root = model->rootGroup(); QStringList layerIds = root->findLayerIds(); // for each layer find in the layer tree - // load it if the layer id is not QgsMapLayerRegistry + // load it if the layer id is not QgsProject Q_FOREACH ( const QString& layerId, layerIds ) { - QgsMapLayer * layer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer * layer = QgsProject::instance()->mapLayer( layerId ); if ( layer ) { continue; @@ -559,7 +559,7 @@ QgsComposition* QgsWmsProjectParser::initComposition( const QString& composerTem layer = mProjectParser->createLayerFromElement( layerElemIt.value(), true ); } } - QgsMapLayerRegistry::instance()->addMapLayer( layer ); + QgsProject::instance()->addMapLayer( layer ); } legend->updateLegend(); } diff --git a/src/server/qgswmsserver.cpp b/src/server/qgswmsserver.cpp index 3b5004b60f3..5f93b0bca8e 100644 --- a/src/server/qgswmsserver.cpp +++ b/src/server/qgswmsserver.cpp @@ -29,7 +29,6 @@ #include "qgslegendrenderer.h" #include "qgsmaplayer.h" #include "qgsmaplayerlegend.h" -#include "qgsmaplayerregistry.h" #include "qgsmaprenderer.h" #include "qgsmaptopixel.h" #include "qgsproject.h" @@ -840,7 +839,7 @@ QImage* QgsWmsServer::getLegendGraphics() Q_FOREACH ( const QString& layerId, layerIds ) { // get layer - QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer *ml = QgsProject::instance()->mapLayer( layerId ); // create tree layer node QgsLayerTreeLayer *layer = rootGroup.addLayer( ml ); // store the layer's name @@ -943,7 +942,7 @@ QImage* QgsWmsServer::getLegendGraphics() legendNode->drawSymbol( legendSettings, &ctx, itemHeight ); } - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); return paintImage; } @@ -999,11 +998,11 @@ QImage* QgsWmsServer::getLegendGraphics() // reset layers' name Q_FOREACH ( const QString& layerId, layerIds ) { - QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId ); + QgsMapLayer *ml = QgsProject::instance()->mapLayer( layerId ); ml->setName( layerNameMap[ layerId ] ); } // clear map layer registry - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); return paintImage; } @@ -1024,7 +1023,7 @@ void QgsWmsServer::runHitTest( QPainter* painter, HitTest& hitTest ) Q_FOREACH ( const QString& layerID, mMapRenderer->layerSet() ) { - QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer( layerID ) ); + QgsVectorLayer* vl = qobject_cast( QgsProject::instance()->mapLayer( layerID ) ); if ( !vl || !vl->renderer() ) continue; @@ -1287,7 +1286,7 @@ QByteArray* QgsWmsServer::getPrint( const QString& formatString ) delete theImage; #ifdef HAVE_SERVER_PYTHON_PLUGINS - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers() ) { if ( !mAccessControl->layerReadPermission( layer ) ) { @@ -1435,7 +1434,7 @@ QImage* QgsWmsServer::getMap( HitTest* hitTest ) mMapRenderer->setLayerSet( layerSet ); #ifdef HAVE_SERVER_PYTHON_PLUGINS - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers() ) { if ( !mAccessControl->layerReadPermission( layer ) ) { @@ -1482,7 +1481,7 @@ QImage* QgsWmsServer::getMap( HitTest* hitTest ) // QgsMessageLog::logMessage( "clearing filters" ); if ( !hitTest ) - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); //#ifdef QGISDEBUG // theImage->save( QDir::tempPath() + QDir::separator() + "lastrender.png" ); @@ -1695,7 +1694,7 @@ int QgsWmsServer::getFeatureInfo( QDomDocument& result, const QString& version ) } } - //get the layer registered in QgsMapLayerRegistry and apply possible filters + //get the layer registered in QgsProject and apply possible filters ( void )layerSet( layersList, stylesList, mMapRenderer->destinationCrs() ); //scoped pointer to restore all original layer filters (subsetStrings) when pointer goes out of scope @@ -1777,7 +1776,7 @@ int QgsWmsServer::getFeatureInfo( QDomDocument& result, const QString& version ) { continue; } - QgsMapLayer * registeredMapLayer = QgsMapLayerRegistry::instance()->mapLayer( currentLayer->id() ); + QgsMapLayer * registeredMapLayer = QgsProject::instance()->mapLayer( currentLayer->id() ); if ( registeredMapLayer ) { currentLayer = registeredMapLayer; @@ -1909,7 +1908,7 @@ int QgsWmsServer::getFeatureInfo( QDomDocument& result, const QString& version ) //force restoration of original filters filterRestorer.reset(); - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); delete featuresRect; return 0; } @@ -2643,7 +2642,7 @@ QStringList QgsWmsServer::layerSet( const QStringList &layersList, ( theMapLayer->minimumScale() <= scaleDenominator && theMapLayer->maximumScale() >= scaleDenominator ) ) { layerKeys.push_front( theMapLayer->id() ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << theMapLayer, false, false ); } } @@ -2695,7 +2694,7 @@ void QgsWmsServer::applyRequestedLayerFilters( const QStringList& layerList , QH //we need to find the maplayer objects matching the layer name QList layersToFilter; - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers() ) { if ( layer ) { @@ -2760,7 +2759,7 @@ void QgsWmsServer::applyAccessControlLayersFilters( const QStringList& layerList { Q_FOREACH ( const QString& layerName, layerList ) { - QList mapLayers = QgsMapLayerRegistry::instance()->mapLayersByName( layerName ); + QList mapLayers = QgsProject::instance()->mapLayersByName( layerName ); Q_FOREACH ( QgsMapLayer* mapLayer, mapLayers ) { applyAccessControlLayerFilters( mapLayer, originalLayerFilters ); @@ -2922,7 +2921,7 @@ QStringList QgsWmsServer::applyFeatureSelections( const QStringList& layerList ) QString layerName = layerIdSplit.at( 0 ); QgsVectorLayer* vLayer = nullptr; - Q_FOREACH ( QgsMapLayer *layer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->mapLayers() ) { if ( layer ) { @@ -2962,7 +2961,7 @@ QStringList QgsWmsServer::applyFeatureSelections( const QStringList& layerList ) void QgsWmsServer::clearFeatureSelections( const QStringList& layerIds ) const { - const QMap& layerMap = QgsMapLayerRegistry::instance()->mapLayers(); + const QMap& layerMap = QgsProject::instance()->mapLayers(); Q_FOREACH ( const QString& id, layerIds ) { @@ -3258,7 +3257,7 @@ void QgsWmsServer::convertFeatureInfoToSIA2045( QDomDocument& doc ) QString currentLayerId = currentLayerElem.attribute( QStringLiteral( "id" ) ); if ( !currentLayerId.isEmpty() ) { - QgsMapLayer* currentLayer = QgsMapLayerRegistry::instance()->mapLayer( currentLayerId ); + QgsMapLayer* currentLayer = QgsProject::instance()->mapLayer( currentLayerId ); if ( currentLayer ) { QString WMSPropertyAttributesString = currentLayer->customProperty( QStringLiteral( "WMSPropertyAttributes" ) ).toString(); diff --git a/tests/bench/qgsbench.cpp b/tests/bench/qgsbench.cpp index 122bf6c12ef..ede1c2e787f 100644 --- a/tests/bench/qgsbench.cpp +++ b/tests/bench/qgsbench.cpp @@ -39,7 +39,6 @@ #endif #include "qgsbench.h" #include "qgslogger.h" -#include "qgsmaplayerregistry.h" #include "qgsmaprendererparalleljob.h" #include "qgsmaprenderersequentialjob.h" #include "qgsproject.h" @@ -142,7 +141,6 @@ QgsBench::~QgsBench() bool QgsBench::openProject( const QString & theFileName ) { - // QgsProject loads layers to QgsMapLayerRegistry singleton QFileInfo file( theFileName ); if ( ! QgsProject::instance()->read( file ) ) { @@ -177,7 +175,7 @@ void QgsBench::render() QgsDebugMsg( "extent: " + mMapSettings.extent().toString() ); - QMap layersMap = QgsMapLayerRegistry::instance()->mapLayers(); + QMap layersMap = QgsProject::instance()->mapLayers(); QStringList layers( layersMap.keys() ); diff --git a/tests/src/analysis/testqgsrastercalculator.cpp b/tests/src/analysis/testqgsrastercalculator.cpp index 5400448f2e2..825076af9e9 100644 --- a/tests/src/analysis/testqgsrastercalculator.cpp +++ b/tests/src/analysis/testqgsrastercalculator.cpp @@ -20,7 +20,7 @@ Email : nyall dot dawson at gmail dot com #include "qgsrasterlayer.h" #include "qgsrastermatrix.h" #include "qgsapplication.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" Q_DECLARE_METATYPE( QgsRasterCalcNode::Operator ) @@ -86,7 +86,7 @@ void TestQgsRasterCalculator::initTestCase() mpLandsatRasterLayer4326 = new QgsRasterLayer( landsat4326RasterFileInfo.filePath(), landsat4326RasterFileInfo.completeBaseName() ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpLandsatRasterLayer << mpLandsatRasterLayer4326 ); } diff --git a/tests/src/analysis/testqgszonalstatistics.cpp b/tests/src/analysis/testqgszonalstatistics.cpp index 3d3b3b0dd90..db49b263855 100644 --- a/tests/src/analysis/testqgszonalstatistics.cpp +++ b/tests/src/analysis/testqgszonalstatistics.cpp @@ -20,7 +20,7 @@ #include "qgsfeatureiterator.h" #include "qgsvectorlayer.h" #include "qgszonalstatistics.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" /** \ingroup UnitTests * This is a unit test for the zonal statistics class @@ -71,7 +71,7 @@ void TestQgsZonalStatistics::initTestCase() } mVectorLayer = new QgsVectorLayer( myTempPath + "polys.shp", QStringLiteral( "poly" ), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mVectorLayer ); mRasterPath = myTempPath + "edge_problem.asc"; diff --git a/tests/src/app/testqgisappclipboard.cpp b/tests/src/app/testqgisappclipboard.cpp index 29ff947d152..cf85574a903 100644 --- a/tests/src/app/testqgisappclipboard.cpp +++ b/tests/src/app/testqgisappclipboard.cpp @@ -25,7 +25,6 @@ #include "qgsfeaturestore.h" #include #include -#include #include #include "qgsgeometry.h" #include "qgspointv2.h" diff --git a/tests/src/core/testmaprendererjob.cpp b/tests/src/core/testmaprendererjob.cpp index 8da62a8fbf6..336fdace027 100644 --- a/tests/src/core/testmaprendererjob.cpp +++ b/tests/src/core/testmaprendererjob.cpp @@ -17,7 +17,7 @@ #include #include "qgsapplication.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaprenderercache.h" #include "qgsmaprendererjob.h" #include "qgsvectorlayer.h" @@ -51,7 +51,7 @@ static QString _loadLayer( QString path ) { QgsMapLayer* layer = new QgsVectorLayer( path, "testlayer", "ogr" ); Q_ASSERT( layer->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayer( layer ); + QgsProject::instance()->addMapLayer( layer ); return layer->id(); } @@ -225,7 +225,7 @@ void TestQgsMapRendererJob::testErrors() { QgsVectorLayer* l = new QgsVectorLayer( "/data/gis/sas/trans-trail-l.dbf", "test", "ogr" ); QVERIFY( l->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayer( l ); + QgsProject::instance()->addMapLayer( l ); QgsMapSettings settings( _mapSettings( QStringList( l->id() ) ) ); l->setRenderer( nullptr ); // this has to produce an error @@ -237,7 +237,7 @@ void TestQgsMapRendererJob::testErrors() QCOMPARE( job.errors().count(), 1 ); QCOMPARE( job.errors()[0].layerID, l->id() ); - QgsMapLayerRegistry::instance()->removeMapLayer( l->id() ); + QgsProject::instance()->removeMapLayer( l->id() ); QString fakeLayerID = "non-existing layer ID"; QgsMapSettings settings2( _mapSettings( QStringList( fakeLayerID ) ) ); @@ -254,7 +254,7 @@ void TestQgsMapRendererJob::testCache() { QgsVectorLayer* l = new QgsVectorLayer( "/data/gis/sas/trans-trail-l.dbf", "test", "ogr" ); QVERIFY( l->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayer( l ); + QgsProject::instance()->addMapLayer( l ); QgsMapSettings settings( _mapSettings( QStringList( l->id() ) ) ); QgsMapRendererCache cache; @@ -285,7 +285,7 @@ void TestQgsMapRendererJob::testCache() QVERIFY( timeCachedMS < 10 ); qDebug( "CACHING %d vs %d (ms)", timeNotCachedMS, timeCachedMS ); - QgsMapLayerRegistry::instance()->removeMapLayer( l->id() ); + QgsProject::instance()->removeMapLayer( l->id() ); } diff --git a/tests/src/core/testqgs25drenderer.cpp b/tests/src/core/testqgs25drenderer.cpp index b7cce290be3..2d6932da78b 100644 --- a/tests/src/core/testqgs25drenderer.cpp +++ b/tests/src/core/testqgs25drenderer.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include "qgscomposition.h" @@ -91,7 +91,7 @@ void TestQgs25DRenderer::initTestCase() QgsExpressionContextUtils::setLayerVariable( mpPolysLayer, QStringLiteral( "qgis_25d_angle" ), 45 ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); mMapSettings.setLayers( QStringList() << mpPolysLayer->id() ); diff --git a/tests/src/core/testqgsatlascomposition.cpp b/tests/src/core/testqgsatlascomposition.cpp index 618f5f38b86..a079e6b8e86 100644 --- a/tests/src/core/testqgsatlascomposition.cpp +++ b/tests/src/core/testqgsatlascomposition.cpp @@ -22,7 +22,7 @@ #include "qgscomposermapoverview.h" #include "qgsatlascomposition.h" #include "qgscomposerlabel.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" #include "qgssymbol.h" @@ -111,7 +111,7 @@ void TestQgsAtlasComposition::initTestCase() simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); mVectorLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mVectorLayer ); + QgsProject::instance()->addMapLayers( QList() << mVectorLayer ); mReport = QStringLiteral( "

Composer Atlas Tests

\n" ); } @@ -424,14 +424,14 @@ void TestQgsAtlasComposition::test_signals() void TestQgsAtlasComposition::test_remove_layer() { - QgsMapLayerRegistry::instance()->addMapLayer( mVectorLayer2 ); + QgsProject::instance()->addMapLayer( mVectorLayer2 ); mAtlas->setCoverageLayer( mVectorLayer2 ); mAtlas->setEnabled( true ); QSignalSpy spyToggled( mAtlas, SIGNAL( toggled( bool ) ) ); //remove coverage layer while atlas is enabled - QgsMapLayerRegistry::instance()->removeMapLayer( mVectorLayer2->id() ); + QgsProject::instance()->removeMapLayer( mVectorLayer2->id() ); mVectorLayer2 = 0; QVERIFY( !mAtlas->enabled() ); diff --git a/tests/src/core/testqgsblendmodes.cpp b/tests/src/core/testqgsblendmodes.cpp index 47ccf1bdb28..0f15740dc71 100644 --- a/tests/src/core/testqgsblendmodes.cpp +++ b/tests/src/core/testqgsblendmodes.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include "qgsrasterdataprovider.h" @@ -97,7 +97,7 @@ void TestQgsBlendModes::initTestCase() QFileInfo myPointFileInfo( myPointsFileName ); mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); //create a poly layer that will be used in tests @@ -110,7 +110,7 @@ void TestQgsBlendModes::initTestCase() simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); mpPolysLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //create a line layer that will be used in tests @@ -119,7 +119,7 @@ void TestQgsBlendModes::initTestCase() mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), myLineFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); mpLinesLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpLinesLayer ); //create two raster layers @@ -131,9 +131,9 @@ void TestQgsBlendModes::initTestCase() QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer1->dataProvider(), 1, 2, 3 ); mRasterLayer1->setRenderer( rasterRenderer ); mRasterLayer2->setRenderer(( QgsRasterRenderer* ) rasterRenderer->clone() ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mRasterLayer1 ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mRasterLayer2 ); // points extent was not always reliable diff --git a/tests/src/core/testqgscentroidfillsymbol.cpp b/tests/src/core/testqgscentroidfillsymbol.cpp index 1030548b4ab..115ec1f01c3 100644 --- a/tests/src/core/testqgscentroidfillsymbol.cpp +++ b/tests/src/core/testqgscentroidfillsymbol.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -98,7 +98,7 @@ void TestQgsCentroidFillSymbol::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //setup gradient fill diff --git a/tests/src/core/testqgscomposerdd.cpp b/tests/src/core/testqgscomposerdd.cpp index 600846f3277..81a37eb24fc 100644 --- a/tests/src/core/testqgscomposerdd.cpp +++ b/tests/src/core/testqgscomposerdd.cpp @@ -19,7 +19,7 @@ #include "qgscomposition.h" #include "qgscomposermap.h" #include "qgscomposertexttable.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmapsettings.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" @@ -78,7 +78,7 @@ void TestQgsComposerDD::initTestCase() simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); mVectorLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mVectorLayer ); + QgsProject::instance()->addMapLayers( QList() << mVectorLayer ); //create composition with composer map mMapSettings->setLayers( QStringList() << mVectorLayer->id() ); diff --git a/tests/src/core/testqgscomposerhtml.cpp b/tests/src/core/testqgscomposerhtml.cpp index c6873bfba6b..58674cc1133 100644 --- a/tests/src/core/testqgscomposerhtml.cpp +++ b/tests/src/core/testqgscomposerhtml.cpp @@ -22,7 +22,6 @@ #include "qgsmultirenderchecker.h" #include "qgsfontutils.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" #include "qgsrelationmanager.h" #include "qgsvectordataprovider.h" #include "qgsproject.h" @@ -281,7 +280,7 @@ void TestQgsComposerHtml::javascriptSetFeature() f3.setAttributes( QgsAttributes() << "foobar" << 124 << 554 ); QVERIFY( pr->addFeatures( QgsFeatureList() << f1 << f2 << f3 ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << childLayer << parentLayer ); + QgsProject::instance()->addMapLayers( QList() << childLayer << parentLayer ); //atlas mComposition->atlasComposition().setCoverageLayer( parentLayer ); @@ -321,7 +320,7 @@ void TestQgsComposerHtml::javascriptSetFeature() delete htmlItem; QVERIFY( result ); - QgsMapLayerRegistry::instance()->removeMapLayers( QList() << childLayer << parentLayer ); + QgsProject::instance()->removeMapLayers( QList() << childLayer << parentLayer ); } diff --git a/tests/src/core/testqgscomposerlabel.cpp b/tests/src/core/testqgscomposerlabel.cpp index 3927caaace5..33b7d3613bc 100644 --- a/tests/src/core/testqgscomposerlabel.cpp +++ b/tests/src/core/testqgscomposerlabel.cpp @@ -18,7 +18,6 @@ #include "qgsapplication.h" #include "qgscomposition.h" #include "qgscomposerlabel.h" -#include "qgsmaplayerregistry.h" #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" #include "qgsmultirenderchecker.h" @@ -77,7 +76,7 @@ void TestQgsComposerLabel::initTestCase() mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mVectorLayer ); + QgsProject::instance()->addMapLayers( QList() << mVectorLayer ); //create composition with composer map mMapSettings->setLayers( QStringList() << mVectorLayer->id() ); diff --git a/tests/src/core/testqgscomposermap.cpp b/tests/src/core/testqgscomposermap.cpp index b32d04fe5f0..cd3d7159a47 100644 --- a/tests/src/core/testqgscomposermap.cpp +++ b/tests/src/core/testqgscomposermap.cpp @@ -19,7 +19,6 @@ #include "qgscomposition.h" #include "qgsmultirenderchecker.h" #include "qgscomposermap.h" -#include "qgsmaplayerregistry.h" #include "qgsmultibandcolorrenderer.h" #include "qgsrasterlayer.h" #include "qgsrasterdataprovider.h" @@ -79,22 +78,22 @@ void TestQgsComposerMap::initTestCase() rasterFileInfo.completeBaseName() ); QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 ); mRasterLayer->setRenderer( rasterRenderer ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mRasterLayer ); + QgsProject::instance()->addMapLayers( QList() << mRasterLayer ); QFileInfo pointFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/points.shp" ); mPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(), pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mPointsLayer ); + QgsProject::instance()->addMapLayers( QList() << mPointsLayer ); QFileInfo polyFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/polys.shp" ); mPolysLayer = new QgsVectorLayer( polyFileInfo.filePath(), polyFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mPolysLayer ); + QgsProject::instance()->addMapLayers( QList() << mPolysLayer ); QFileInfo lineFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/lines.shp" ); mLinesLayer = new QgsVectorLayer( lineFileInfo.filePath(), lineFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mLinesLayer ); + QgsProject::instance()->addMapLayers( QList() << mLinesLayer ); } void TestQgsComposerMap::cleanupTestCase() diff --git a/tests/src/core/testqgscomposermapgrid.cpp b/tests/src/core/testqgscomposermapgrid.cpp index 915c8a96097..bc78f2cc0a2 100644 --- a/tests/src/core/testqgscomposermapgrid.cpp +++ b/tests/src/core/testqgscomposermapgrid.cpp @@ -20,7 +20,6 @@ #include "qgsmultirenderchecker.h" #include "qgscomposermap.h" #include "qgscomposermapgrid.h" -#include "qgsmaplayerregistry.h" #include "qgsfontutils.h" #include #include diff --git a/tests/src/core/testqgscomposermapoverview.cpp b/tests/src/core/testqgscomposermapoverview.cpp index c44633ef4da..39c1e00bbd2 100644 --- a/tests/src/core/testqgscomposermapoverview.cpp +++ b/tests/src/core/testqgscomposermapoverview.cpp @@ -20,7 +20,7 @@ #include "qgsmultirenderchecker.h" #include "qgscomposermap.h" #include "qgscomposermapoverview.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmultibandcolorrenderer.h" #include "qgsrasterlayer.h" #include "qgsrasterdataprovider.h" @@ -74,7 +74,7 @@ void TestQgsComposerMapOverview::initTestCase() QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 1, 2, 3 ); mRasterLayer->setRenderer( rasterRenderer ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mRasterLayer ); + QgsProject::instance()->addMapLayers( QList() << mRasterLayer ); //create composition with composer map mMapSettings->setLayers( QStringList() << mRasterLayer->id() ); diff --git a/tests/src/core/testqgscomposerrotation.cpp b/tests/src/core/testqgscomposerrotation.cpp index 2c4d0497a30..459090349a3 100644 --- a/tests/src/core/testqgscomposerrotation.cpp +++ b/tests/src/core/testqgscomposerrotation.cpp @@ -23,7 +23,7 @@ #include "qgscomposerlabel.h" #include "qgsmultibandcolorrenderer.h" #include "qgsrasterlayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsfontutils.h" #include "qgsrasterdataprovider.h" #include @@ -80,7 +80,7 @@ void TestQgsComposerRotation::initTestCase() QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 1, 2, 3 ); mRasterLayer->setRenderer( rasterRenderer ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mRasterLayer ); + QgsProject::instance()->addMapLayers( QList() << mRasterLayer ); mMapSettings->setLayers( QStringList() << mRasterLayer->id() ); mMapSettings->setCrsTransformEnabled( false ); diff --git a/tests/src/core/testqgscomposerscalebar.cpp b/tests/src/core/testqgscomposerscalebar.cpp index bdeff0a4aff..eda01a84bd2 100644 --- a/tests/src/core/testqgscomposerscalebar.cpp +++ b/tests/src/core/testqgscomposerscalebar.cpp @@ -20,7 +20,6 @@ #include "qgsmultirenderchecker.h" #include "qgscomposermap.h" #include "qgscomposerscalebar.h" -#include "qgsmaplayerregistry.h" #include "qgsmultibandcolorrenderer.h" #include "qgsrasterlayer.h" #include "qgsrasterdataprovider.h" @@ -87,7 +86,7 @@ void TestQgsComposerScaleBar::initTestCase() QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 ); mRasterLayer->setRenderer( rasterRenderer ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mRasterLayer ); + QgsProject::instance()->addMapLayers( QList() << mRasterLayer ); //create composition with composer map mMapSettings->setLayers( QStringList() << mRasterLayer->id() ); diff --git a/tests/src/core/testqgscomposertablev2.cpp b/tests/src/core/testqgscomposertablev2.cpp index 3066e249498..a5c5f876cc0 100644 --- a/tests/src/core/testqgscomposertablev2.cpp +++ b/tests/src/core/testqgscomposertablev2.cpp @@ -27,7 +27,6 @@ #include "qgsfeature.h" #include "qgsmultirenderchecker.h" #include "qgsfontutils.h" -#include "qgsmaplayerregistry.h" #include "qgsproject.h" #include "qgsrelationmanager.h" @@ -103,7 +102,7 @@ void TestQgsComposerTableV2::initTestCase() mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( mVectorLayer ); + QgsProject::instance()->addMapLayer( mVectorLayer ); mMapSettings->setLayers( QStringList() << mVectorLayer->id() ); mMapSettings->setCrsTransformEnabled( false ); @@ -438,7 +437,7 @@ void TestQgsComposerTableV2::attributeTableAtlasSource() vectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( vectorLayer ); + QgsProject::instance()->addMapLayer( vectorLayer ); mComposition->atlasComposition().setCoverageLayer( vectorLayer ); mComposition->atlasComposition().setEnabled( true ); QVERIFY( mComposition->atlasComposition().beginRender() ); @@ -480,7 +479,7 @@ void TestQgsComposerTableV2::attributeTableAtlasSource() mComposition->atlasComposition().endRender(); //try for a crash when removing current atlas layer - QgsMapLayerRegistry::instance()->removeMapLayer( vectorLayer->id() ); + QgsProject::instance()->removeMapLayer( vectorLayer->id() ); table->refreshAttributes(); mComposition->removeMultiFrame( table ); @@ -495,7 +494,7 @@ void TestQgsComposerTableV2::attributeTableRelationSource() vectorFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( atlasLayer ); + QgsProject::instance()->addMapLayer( atlasLayer ); //setup atlas mComposition->atlasComposition().setCoverageLayer( atlasLayer ); @@ -566,7 +565,7 @@ void TestQgsComposerTableV2::attributeTableRelationSource() mComposition->atlasComposition().endRender(); //try for a crash when removing current atlas layer - QgsMapLayerRegistry::instance()->removeMapLayer( atlasLayer->id() ); + QgsProject::instance()->removeMapLayer( atlasLayer->id() ); table->refreshAttributes(); diff --git a/tests/src/core/testqgsdiagram.cpp b/tests/src/core/testqgsdiagram.cpp index 9a5d0418d1a..57b2f5dc20f 100644 --- a/tests/src/core/testqgsdiagram.cpp +++ b/tests/src/core/testqgsdiagram.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include //qgis test includes #include "qgsmultirenderchecker.h" @@ -89,7 +88,7 @@ class TestQgsDiagram : public QObject myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayer( mPointsLayer ); + QgsProject::instance()->addMapLayer( mPointsLayer ); // Create map composition to draw on mMapSettings->setLayers( QStringList() << mPointsLayer->id() ); diff --git a/tests/src/core/testqgsellipsemarker.cpp b/tests/src/core/testqgsellipsemarker.cpp index 5c2936d9e83..67fb434e521 100644 --- a/tests/src/core/testqgsellipsemarker.cpp +++ b/tests/src/core/testqgsellipsemarker.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include "qgsmarkersymbollayer.h" @@ -99,7 +99,7 @@ void TestQgsEllipseMarkerSymbol::initTestCase() pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); //setup symbol diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index 5d725b93fe3..d255629ad04 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -29,7 +29,6 @@ #include "qgsexpressioncontext.h" #include "qgsrelationmanager.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" #include "qgsvectordataprovider.h" #include "qgsdistancearea.h" #include "qgsrasterlayer.h" @@ -87,7 +86,7 @@ class TestQgsExpression: public QObject QFileInfo pointFileInfo( pointsFileName ); mPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(), pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( mPointsLayer ); + QgsProject::instance()->addMapLayer( mPointsLayer ); mPointsLayer->setTitle( QStringLiteral( "layer title" ) ); mPointsLayer->setAbstract( QStringLiteral( "layer abstract" ) ); mPointsLayer->setKeywordList( QStringLiteral( "layer,keywords" ) ); @@ -101,7 +100,7 @@ class TestQgsExpression: public QObject QFileInfo rasterFileInfo( rasterFileName ); mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(), rasterFileInfo.completeBaseName() ); - QgsMapLayerRegistry::instance()->addMapLayer( mRasterLayer ); + QgsProject::instance()->addMapLayer( mRasterLayer ); // test memory layer for get_feature tests mMemoryLayer = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer&field=col2:string" ), QStringLiteral( "test" ), QStringLiteral( "memory" ) ); @@ -119,7 +118,7 @@ class TestQgsExpression: public QObject f4.setAttribute( QStringLiteral( "col1" ), 41 ); f4.setAttribute( QStringLiteral( "col2" ), "test4" ); mMemoryLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 << f4 ); - QgsMapLayerRegistry::instance()->addMapLayer( mMemoryLayer ); + QgsProject::instance()->addMapLayer( mMemoryLayer ); // test layer for aggregates mAggregatesLayer = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer&field=col2:string&field=col3:integer" ), QStringLiteral( "aggregate_layer" ), QStringLiteral( "memory" ) ); @@ -155,7 +154,7 @@ class TestQgsExpression: public QObject af6.setAttribute( QStringLiteral( "col2" ), "test4" ); af6.setAttribute( QStringLiteral( "col3" ), 3 ); mAggregatesLayer->dataProvider()->addFeatures( QgsFeatureList() << af1 << af2 << af3 << af4 << af5 << af6 ); - QgsMapLayerRegistry::instance()->addMapLayer( mAggregatesLayer ); + QgsProject::instance()->addMapLayer( mAggregatesLayer ); mChildLayer = new QgsVectorLayer( QStringLiteral( "Point?field=parent:integer&field=col2:string&field=col3:integer" ), QStringLiteral( "child_layer" ), QStringLiteral( "memory" ) ); QVERIFY( mChildLayer->isValid() ); @@ -180,7 +179,7 @@ class TestQgsExpression: public QObject cf5.setAttribute( QStringLiteral( "col2" ), QVariant( QVariant::String ) ); cf5.setAttribute( QStringLiteral( "col3" ), 7 ); mChildLayer->dataProvider()->addFeatures( QgsFeatureList() << cf1 << cf2 << cf3 << cf4 << cf5 ); - QgsMapLayerRegistry::instance()->addMapLayer( mChildLayer ); + QgsProject::instance()->addMapLayer( mChildLayer ); QgsRelation rel; rel.setRelationId( QStringLiteral( "my_rel" ) ); diff --git a/tests/src/core/testqgsfilledmarker.cpp b/tests/src/core/testqgsfilledmarker.cpp index d05388c9802..b586213b5bd 100644 --- a/tests/src/core/testqgsfilledmarker.cpp +++ b/tests/src/core/testqgsfilledmarker.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include "qgsmarkersymbollayer.h" @@ -97,7 +97,7 @@ void TestQgsFilledMarkerSymbol::initTestCase() pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); //setup symbol diff --git a/tests/src/core/testqgsfontmarker.cpp b/tests/src/core/testqgsfontmarker.cpp index d4ee38ba1e2..4271d22af56 100644 --- a/tests/src/core/testqgsfontmarker.cpp +++ b/tests/src/core/testqgsfontmarker.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include "qgsmarkersymbollayer.h" @@ -97,7 +97,7 @@ void TestQgsFontMarkerSymbol::initTestCase() pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); //setup symbol diff --git a/tests/src/core/testqgsgradients.cpp b/tests/src/core/testqgsgradients.cpp index cb53659c780..fd530be44f9 100644 --- a/tests/src/core/testqgsgradients.cpp +++ b/tests/src/core/testqgsgradients.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -107,7 +107,7 @@ void TestQgsGradients::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //setup gradient fill diff --git a/tests/src/core/testqgsinvertedpolygonrenderer.cpp b/tests/src/core/testqgsinvertedpolygonrenderer.cpp index cf3742e7fd7..5d2415cbd96 100644 --- a/tests/src/core/testqgsinvertedpolygonrenderer.cpp +++ b/tests/src/core/testqgsinvertedpolygonrenderer.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include //qgis test includes #include "qgsmultirenderchecker.h" @@ -95,7 +95,7 @@ void TestQgsInvertedPolygon::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mpPolysLayer ); + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); mMapSettings.setLayers( QStringList() << mpPolysLayer->id() ); mReport += QLatin1String( "

Inverted Polygon Renderer Tests

\n" ); @@ -159,7 +159,7 @@ void TestQgsInvertedPolygon::curvedPolygons() QgsVectorLayer* curvedLayer = new QgsVectorLayer( myCurvedPolyFileInfo.filePath() + "|layername=polys", myCurvedPolyFileInfo.completeBaseName(), "ogr" ); curvedLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << curvedLayer ); + QgsProject::instance()->addMapLayers( QList() << curvedLayer ); mReport += "

Inverted polygon renderer, curved polygons test

\n"; mMapSettings.setLayers( QStringList() << curvedLayer->id() ); diff --git a/tests/src/core/testqgslabelingengine.cpp b/tests/src/core/testqgslabelingengine.cpp index 2ca9e17537c..c6bd56193f5 100644 --- a/tests/src/core/testqgslabelingengine.cpp +++ b/tests/src/core/testqgslabelingengine.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -84,12 +84,12 @@ void TestQgsLabelingEngine::init() QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp"; vl = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) ); Q_ASSERT( vl->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayer( vl ); + QgsProject::instance()->addMapLayer( vl ); } void TestQgsLabelingEngine::cleanup() { - QgsMapLayerRegistry::instance()->removeMapLayer( vl->id() ); + QgsProject::instance()->removeMapLayer( vl->id() ); vl = 0; } @@ -353,7 +353,7 @@ void TestQgsLabelingEngine::zOrder() QString filename = QStringLiteral( TEST_DATA_DIR ) + "/points.shp"; QgsVectorLayer* vl2 = new QgsVectorLayer( filename, QStringLiteral( "points" ), QStringLiteral( "ogr" ) ); Q_ASSERT( vl2->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayer( vl2 ); + QgsProject::instance()->addMapLayer( vl2 ); QgsPalLayerSettings pls2( pls1 ); format = pls2.format(); @@ -399,7 +399,7 @@ void TestQgsLabelingEngine::zOrder() img = job.renderedImage(); //cleanup - QgsMapLayerRegistry::instance()->removeMapLayer( vl2 ); + QgsProject::instance()->removeMapLayer( vl2 ); } void TestQgsLabelingEngine::testEncodeDecodePositionOrder() diff --git a/tests/src/core/testqgslayertree.cpp b/tests/src/core/testqgslayertree.cpp index 7f21b94b24a..d5b1fdbd488 100644 --- a/tests/src/core/testqgslayertree.cpp +++ b/tests/src/core/testqgslayertree.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -119,7 +119,7 @@ void TestQgsLayerTree::testLayerNameChanged() QCOMPARE( arguments.at( 0 ).value(), n ); QCOMPARE( arguments.at( 1 ).toString(), QString( "changed 1" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << vl ); + QgsProject::instance()->addMapLayers( QList() << vl ); // set name via map layer vl->setName( "changed 2" ); @@ -137,7 +137,7 @@ void TestQgsLayerTree::testLayerNameChanged() QCOMPARE( arguments.at( 0 ).value(), n ); QCOMPARE( arguments.at( 1 ).toString(), QString( "changed 3" ) ); - QgsMapLayerRegistry::instance()->removeMapLayers( QList() << vl ); + QgsProject::instance()->removeMapLayers( QList() << vl ); mRoot->removeChildNode( n ); } @@ -294,7 +294,7 @@ void TestQgsLayerTree::testShowHideAllSymbolNodes() QgsVectorLayer* vl = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ); QVERIFY( vl->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << vl ); + QgsProject::instance()->addMapLayers( QList() << vl ); //create a categorized renderer for layer QgsCategorizedSymbolRenderer* renderer = new QgsCategorizedSymbolRenderer(); @@ -335,7 +335,7 @@ void TestQgsLayerTree::testShowHideAllSymbolNodes() //cleanup delete m; delete root; - QgsMapLayerRegistry::instance()->removeMapLayers( QList() << vl ); + QgsProject::instance()->removeMapLayers( QList() << vl ); } void TestQgsLayerTree::testFindLegendNode() @@ -344,7 +344,7 @@ void TestQgsLayerTree::testFindLegendNode() QgsVectorLayer* vl = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ); QVERIFY( vl->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << vl ); + QgsProject::instance()->addMapLayers( QList() << vl ); //create a categorized renderer for layer QgsCategorizedSymbolRenderer* renderer = new QgsCategorizedSymbolRenderer(); @@ -377,7 +377,7 @@ void TestQgsLayerTree::testFindLegendNode() //cleanup delete m; delete root; - QgsMapLayerRegistry::instance()->removeMapLayers( QList() << vl ); + QgsProject::instance()->removeMapLayers( QList() << vl ); } void TestQgsLayerTree::testLegendSymbolCategorized() @@ -438,7 +438,7 @@ void TestQgsLayerTree::testRendererLegend( QgsFeatureRenderer* renderer ) QgsVectorLayer* vl = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ); QVERIFY( vl->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << vl ); + QgsProject::instance()->addMapLayers( QList() << vl ); vl->setRenderer( renderer ); //create legend with symbology nodes for renderer @@ -479,7 +479,7 @@ void TestQgsLayerTree::testRendererLegend( QgsFeatureRenderer* renderer ) //cleanup delete m; delete root; - QgsMapLayerRegistry::instance()->removeMapLayers( QList() << vl ); + QgsProject::instance()->removeMapLayers( QList() << vl ); } diff --git a/tests/src/core/testqgslegendrenderer.cpp b/tests/src/core/testqgslegendrenderer.cpp index 7125571ab3a..24e1d1763f5 100644 --- a/tests/src/core/testqgslegendrenderer.cpp +++ b/tests/src/core/testqgslegendrenderer.cpp @@ -25,7 +25,7 @@ #include "qgslayertreemodel.h" #include "qgslayertreemodellegendnode.h" #include "qgsmaplayerlegend.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgslegendrenderer.h" #include "qgsrasterlayer.h" #include "qgsrenderchecker.h" @@ -163,14 +163,14 @@ void TestQgsLegendRenderer::cleanupTestCase() void TestQgsLegendRenderer::init() { mVL1 = new QgsVectorLayer( QStringLiteral( "LineString" ), QStringLiteral( "Line Layer" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( mVL1 ); + QgsProject::instance()->addMapLayer( mVL1 ); QgsLineSymbol* sym1 = new QgsLineSymbol(); sym1->setColor( Qt::magenta ); mVL1->setRenderer( new QgsSingleSymbolRenderer( sym1 ) ); mVL2 = new QgsVectorLayer( QStringLiteral( "Polygon" ), QStringLiteral( "Polygon Layer" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( mVL2 ); + QgsProject::instance()->addMapLayer( mVL2 ); QgsFillSymbol* sym2 = new QgsFillSymbol(); sym2->setColor( Qt::cyan ); @@ -203,12 +203,12 @@ void TestQgsLegendRenderer::init() pr->addFeatures( features ); mVL3->updateFields(); } - QgsMapLayerRegistry::instance()->addMapLayer( mVL3 ); + QgsProject::instance()->addMapLayer( mVL3 ); static char raster_array[] = { 1, 2, 2, 1 }; QString rasterUri = QStringLiteral( "MEM:::DATAPOINTER=%1,PIXELS=2,LINES=2" ).arg(( qulonglong ) raster_array ); mRL = new QgsRasterLayer( rasterUri, QStringLiteral( "Raster Layer" ), QStringLiteral( "gdal" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( mRL ); + QgsProject::instance()->addMapLayer( mRL ); QgsCategoryList cats; QgsMarkerSymbol* sym3_1 = new QgsMarkerSymbol(); @@ -236,7 +236,7 @@ void TestQgsLegendRenderer::cleanup() delete mRoot; mRoot = 0; - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); } @@ -403,7 +403,7 @@ void TestQgsLegendRenderer::testFilterByMap() mapSettings.setOutputSize( QSize( 400, 100 ) ); mapSettings.setOutputDpi( 96 ); QStringList ll; - Q_FOREACH ( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *l, QgsProject::instance()->mapLayers() ) { ll << l->id(); } @@ -446,7 +446,7 @@ void TestQgsLegendRenderer::testFilterByMapSameSymbol() pr->addFeatures( features ); vl4->updateFields(); } - QgsMapLayerRegistry::instance()->addMapLayer( vl4 ); + QgsProject::instance()->addMapLayer( vl4 ); //setup categorized renderer with duplicate symbols QgsCategoryList cats; @@ -482,7 +482,7 @@ void TestQgsLegendRenderer::testFilterByMapSameSymbol() _renderLegend( testName, &legendModel, settings ); QVERIFY( _verifyImage( testName, mReport ) ); - QgsMapLayerRegistry::instance()->removeMapLayer( vl4 ); + QgsProject::instance()->removeMapLayer( vl4 ); } bool TestQgsLegendRenderer::_testLegendColumns( int itemCount, int columnCount, const QString& testName ) @@ -496,7 +496,7 @@ bool TestQgsLegendRenderer::_testLegendColumns( int itemCount, int columnCount, for ( int i = 1; i <= itemCount; ++i ) { QgsVectorLayer* vl = new QgsVectorLayer( QStringLiteral( "Polygon" ), QStringLiteral( "Layer %1" ).arg( i ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( vl ); + QgsProject::instance()->addMapLayer( vl ); vl->setRenderer( new QgsSingleSymbolRenderer( sym->clone() ) ); root->addLayer( vl ); layers << vl; @@ -512,7 +512,7 @@ bool TestQgsLegendRenderer::_testLegendColumns( int itemCount, int columnCount, Q_FOREACH ( QgsVectorLayer* l, layers ) { - QgsMapLayerRegistry::instance()->removeMapLayer( l ); + QgsProject::instance()->removeMapLayer( l ); } return result; } @@ -573,7 +573,7 @@ void TestQgsLegendRenderer::testFilterByPolygon() mapSettings.setOutputSize( QSize( 400, 100 ) ); mapSettings.setOutputDpi( 96 ); QStringList ll; - Q_FOREACH ( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *l, QgsProject::instance()->mapLayers() ) { ll << l->id(); } @@ -610,7 +610,7 @@ void TestQgsLegendRenderer::testFilterByExpression() mapSettings.setOutputSize( QSize( 400, 100 ) ); mapSettings.setOutputDpi( 96 ); QStringList ll; - Q_FOREACH ( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer *l, QgsProject::instance()->mapLayers() ) { ll << l->id(); } @@ -642,7 +642,7 @@ void TestQgsLegendRenderer::testFilterByExpression() void TestQgsLegendRenderer::testDiagramAttributeLegend() { QgsVectorLayer* vl4 = new QgsVectorLayer( QStringLiteral( "Point" ), QStringLiteral( "Point Layer" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( vl4 ); + QgsProject::instance()->addMapLayer( vl4 ); QgsDiagramSettings ds; ds.categoryColors = QList() << QColor( 255, 0, 0 ) << QColor( 0, 255, 0 ); @@ -675,13 +675,13 @@ void TestQgsLegendRenderer::testDiagramAttributeLegend() _renderLegend( QStringLiteral( "legend_diagram_attributes" ), &legendModel, settings ); QVERIFY( _verifyImage( "legend_diagram_attributes", mReport ) ); - QgsMapLayerRegistry::instance()->removeMapLayer( vl4 ); + QgsProject::instance()->removeMapLayer( vl4 ); } void TestQgsLegendRenderer::testDiagramSizeLegend() { QgsVectorLayer* vl4 = new QgsVectorLayer( QStringLiteral( "Point" ), QStringLiteral( "Point Layer" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( vl4 ); + QgsProject::instance()->addMapLayer( vl4 ); QgsDiagramSettings ds; ds.categoryColors = QList() << QColor( 255, 0, 0 ) << QColor( 0, 255, 0 ); @@ -715,7 +715,7 @@ void TestQgsLegendRenderer::testDiagramSizeLegend() _renderLegend( QStringLiteral( "legend_diagram_size" ), &legendModel, settings ); QVERIFY( _verifyImage( "legend_diagram_size", mReport ) ); - QgsMapLayerRegistry::instance()->removeMapLayer( vl4 ); + QgsProject::instance()->removeMapLayer( vl4 ); } QTEST_MAIN( TestQgsLegendRenderer ) diff --git a/tests/src/core/testqgslinefillsymbol.cpp b/tests/src/core/testqgslinefillsymbol.cpp index c738c5446d1..7dc457f374b 100644 --- a/tests/src/core/testqgslinefillsymbol.cpp +++ b/tests/src/core/testqgslinefillsymbol.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -100,7 +100,7 @@ void TestQgsLineFillSymbol::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //setup gradient fill diff --git a/tests/src/core/testqgsmaplayerstylemanager.cpp b/tests/src/core/testqgsmaplayerstylemanager.cpp index 65e04cf377c..d498336e1f4 100644 --- a/tests/src/core/testqgsmaplayerstylemanager.cpp +++ b/tests/src/core/testqgsmaplayerstylemanager.cpp @@ -17,7 +17,7 @@ #include #include "qgsapplication.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmaplayerstylemanager.h" #include "qgssinglesymbolrenderer.h" #include "qgsvectorlayer.h" @@ -60,12 +60,12 @@ void TestQgsMapLayerStyleManager::cleanupTestCase() void TestQgsMapLayerStyleManager::init() { mVL = new QgsVectorLayer( QStringLiteral( "LineString" ), QStringLiteral( "Line Layer" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( mVL ); + QgsProject::instance()->addMapLayer( mVL ); } void TestQgsMapLayerStyleManager::cleanup() { - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); } void TestQgsMapLayerStyleManager::testDefault() diff --git a/tests/src/core/testqgsmaprendererjob.cpp b/tests/src/core/testqgsmaprendererjob.cpp index d8f73dc3699..11864855665 100644 --- a/tests/src/core/testqgsmaprendererjob.cpp +++ b/tests/src/core/testqgsmaprendererjob.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include //qgs unit test utility class #include "qgsrenderchecker.h" @@ -183,7 +183,7 @@ void TestQgsMapRendererJob::initTestCase() myPolyFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); QVERIFY( mpPolysLayer->isValid() ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( QList() << mpPolysLayer ); + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); // add the test layer to the maprender mMapSettings->setLayers( QStringList() << mpPolysLayer->id() ); mReport += QLatin1String( "

Map Render Tests

\n" ); @@ -285,7 +285,7 @@ void TestQgsMapRendererJob::testFourAdjacentTiles() QFAIL( errorMsg.toLocal8Bit().data() ); } - QgsMapLayerRegistry::instance()->addMapLayers( QList() << vectorLayer ); + QgsProject::instance()->addMapLayers( QList() << vectorLayer ); QImage globalImage( 512, 512, QImage::Format_ARGB32_Premultiplied ); globalImage.fill( Qt::white ); @@ -317,7 +317,7 @@ void TestQgsMapRendererJob::testFourAdjacentTiles() globalPainter.drawImage( globalImageX, globalImageY, img ); } - QgsMapLayerRegistry::instance()->removeMapLayers( QStringList() << vectorLayer->id() ); + QgsProject::instance()->removeMapLayers( QStringList() << vectorLayer->id() ); QString renderedImagePath = QDir::tempPath() + "/" + QTest::currentDataTag() + QStringLiteral( ".png" ); globalImage.save( renderedImagePath ); diff --git a/tests/src/core/testqgsmaprotation.cpp b/tests/src/core/testqgsmaprotation.cpp index 3643ef892cb..d165dbac2bb 100644 --- a/tests/src/core/testqgsmaprotation.cpp +++ b/tests/src/core/testqgsmaprotation.cpp @@ -24,7 +24,7 @@ #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" #include "qgsmultibandcolorrenderer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsapplication.h" #include "qgspallabeling.h" #include "qgsfontutils.h" @@ -107,7 +107,7 @@ void TestQgsMapRotation::initTestCase() mapLayers << mLinesLayer; // Register all layers with the registry - QgsMapLayerRegistry::instance()->addMapLayers( mapLayers ); + QgsProject::instance()->addMapLayers( mapLayers ); // This is needed to correctly set rotation center, // the actual size doesn't matter as QgsRenderChecker will diff --git a/tests/src/core/testqgsmarkerlinesymbol.cpp b/tests/src/core/testqgsmarkerlinesymbol.cpp index b61b3db7cfb..fb22d983eb6 100644 --- a/tests/src/core/testqgsmarkerlinesymbol.cpp +++ b/tests/src/core/testqgsmarkerlinesymbol.cpp @@ -24,7 +24,7 @@ #include "qgsrasterlayer.h" #include "qgsvectorlayer.h" #include "qgsmultibandcolorrenderer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsapplication.h" #include "qgspallabeling.h" #include "qgsfontutils.h" @@ -90,7 +90,7 @@ void TestQgsMarkerLineSymbol::initTestCase() mapLayers << mLinesLayer; // Register all layers with the registry - QgsMapLayerRegistry::instance()->addMapLayers( mapLayers ); + QgsProject::instance()->addMapLayers( mapLayers ); // This is needed to correctly set rotation center, // the actual size doesn't matter as QgsRenderChecker will diff --git a/tests/src/core/testqgspainteffect.cpp b/tests/src/core/testqgspainteffect.cpp index 16a6c08bf9e..7c6e62ea946 100644 --- a/tests/src/core/testqgspainteffect.cpp +++ b/tests/src/core/testqgspainteffect.cpp @@ -32,7 +32,7 @@ #include "qgsmapsettings.h" #include "qgsvectorlayer.h" #include "qgsapplication.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgssymbol.h" #include "qgssinglesymbolrenderer.h" #include "qgsfillsymbollayer.h" @@ -702,7 +702,7 @@ void TestQgsPaintEffect::layerEffectPolygon() QgsVectorSimplifyMethod simplifyMethod; simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); polysLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << polysLayer ); + QgsProject::instance()->addMapLayers( QList() << polysLayer ); QgsMapSettings ms; QgsSimpleFillSymbolLayer* fill = new QgsSimpleFillSymbolLayer; @@ -733,7 +733,7 @@ void TestQgsPaintEffect::layerEffectLine() QgsVectorSimplifyMethod simplifyMethod; simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); lineLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << lineLayer ); + QgsProject::instance()->addMapLayers( QList() << lineLayer ); QgsMapSettings ms; QgsSimpleLineSymbolLayer* line = new QgsSimpleLineSymbolLayer; @@ -762,7 +762,7 @@ void TestQgsPaintEffect::layerEffectMarker() QFileInfo pointFileInfo( pointFileName ); QgsVectorLayer* pointLayer = new QgsVectorLayer( pointFileInfo.filePath(), pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << pointLayer ); + QgsProject::instance()->addMapLayers( QList() << pointLayer ); QgsMapSettings ms; QgsSimpleMarkerSymbolLayer* marker = new QgsSimpleMarkerSymbolLayer; @@ -793,7 +793,7 @@ void TestQgsPaintEffect::vectorLayerEffect() QgsVectorSimplifyMethod simplifyMethod; simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); polysLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << polysLayer ); + QgsProject::instance()->addMapLayers( QList() << polysLayer ); QgsMapSettings ms; QgsSimpleFillSymbolLayer* fill = new QgsSimpleFillSymbolLayer; @@ -828,7 +828,7 @@ void TestQgsPaintEffect::mapUnits() QgsVectorSimplifyMethod simplifyMethod; simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); lineLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << lineLayer ); + QgsProject::instance()->addMapLayers( QList() << lineLayer ); QgsMapSettings ms; QgsSimpleLineSymbolLayer* line = new QgsSimpleLineSymbolLayer; @@ -864,7 +864,7 @@ void TestQgsPaintEffect::composer() QgsVectorSimplifyMethod simplifyMethod; simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); lineLayer->setSimplifyMethod( simplifyMethod ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << lineLayer ); + QgsProject::instance()->addMapLayers( QList() << lineLayer ); QgsMapSettings ms; QgsSimpleLineSymbolLayer* line = new QgsSimpleLineSymbolLayer; diff --git a/tests/src/core/testqgspointlocator.cpp b/tests/src/core/testqgspointlocator.cpp index 206f90c13ec..64b699a397a 100644 --- a/tests/src/core/testqgspointlocator.cpp +++ b/tests/src/core/testqgspointlocator.cpp @@ -21,7 +21,7 @@ #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" #include "qgsgeometry.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgspointlocator.h" #include "qgspolygon.h" @@ -92,7 +92,7 @@ class TestQgsPointLocator : public QObject flist << ff; mVL->dataProvider()->addFeatures( flist ); - QgsMapLayerRegistry::instance()->addMapLayer( mVL ); + QgsProject::instance()->addMapLayer( mVL ); } void cleanupTestCase() diff --git a/tests/src/core/testqgspointpatternfillsymbol.cpp b/tests/src/core/testqgspointpatternfillsymbol.cpp index 65e6d0e6377..50738fe3d2d 100644 --- a/tests/src/core/testqgspointpatternfillsymbol.cpp +++ b/tests/src/core/testqgspointpatternfillsymbol.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -100,7 +100,7 @@ void TestQgsPointPatternFillSymbol::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //setup symbol diff --git a/tests/src/core/testqgsrasterfill.cpp b/tests/src/core/testqgsrasterfill.cpp index 5d7239308aa..c93d8899571 100644 --- a/tests/src/core/testqgsrasterfill.cpp +++ b/tests/src/core/testqgsrasterfill.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -101,7 +101,7 @@ void TestQgsRasterFill::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //setup raster fill diff --git a/tests/src/core/testqgsrasterlayer.cpp b/tests/src/core/testqgsrasterlayer.cpp index aa181ca6bc7..dc848aa1247 100644 --- a/tests/src/core/testqgsrasterlayer.cpp +++ b/tests/src/core/testqgsrasterlayer.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -175,7 +175,7 @@ void TestQgsRasterLayer::initTestCase() geoJp2RasterFileInfo.completeBaseName() ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpRasterLayer << mpLandsatRasterLayer << mpFloat32RasterLayer @@ -583,9 +583,9 @@ void TestQgsRasterLayer::registry() myRasterFileInfo.completeBaseName() ); QVERIFY( mypLayer->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mypLayer, false ); - QgsMapLayerRegistry::instance()->removeMapLayers( + QgsProject::instance()->removeMapLayers( QStringList() << mypLayer->id() ); } diff --git a/tests/src/core/testqgsrastersublayer.cpp b/tests/src/core/testqgsrastersublayer.cpp index 8278ddbe335..54f57bba69b 100644 --- a/tests/src/core/testqgsrastersublayer.cpp +++ b/tests/src/core/testqgsrastersublayer.cpp @@ -31,7 +31,6 @@ #include #include #include "qgsrasterdataprovider.h" -#include #include #include #include diff --git a/tests/src/core/testqgsrenderers.cpp b/tests/src/core/testqgsrenderers.cpp index bb3071c5f82..833aef889d1 100644 --- a/tests/src/core/testqgsrenderers.cpp +++ b/tests/src/core/testqgsrenderers.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include //qgis test includes #include "qgsmultirenderchecker.h" @@ -96,7 +96,7 @@ void TestQgsRenderers::initTestCase() mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); // @@ -107,7 +107,7 @@ void TestQgsRenderers::initTestCase() mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), myPolyFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); @@ -119,7 +119,7 @@ void TestQgsRenderers::initTestCase() mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), myLineFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpLinesLayer ); // // We only need maprender instead of mapcanvas diff --git a/tests/src/core/testqgsshapeburst.cpp b/tests/src/core/testqgsshapeburst.cpp index 42eeccc082b..db251350f73 100644 --- a/tests/src/core/testqgsshapeburst.cpp +++ b/tests/src/core/testqgsshapeburst.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -104,7 +104,7 @@ void TestQgsShapeburst::initTestCase() mpPolysLayer->setSimplifyMethod( simplifyMethod ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); //setup shapeburst fill diff --git a/tests/src/core/testqgssimplemarker.cpp b/tests/src/core/testqgssimplemarker.cpp index 27d738db151..dcb65a1139e 100644 --- a/tests/src/core/testqgssimplemarker.cpp +++ b/tests/src/core/testqgssimplemarker.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include "qgsmarkersymbollayer.h" @@ -102,7 +102,7 @@ void TestQgsSimpleMarkerSymbol::initTestCase() pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); //setup symbol diff --git a/tests/src/core/testqgssnappingutils.cpp b/tests/src/core/testqgssnappingutils.cpp index 6a63cb1f4d0..ac8919b23de 100644 --- a/tests/src/core/testqgssnappingutils.cpp +++ b/tests/src/core/testqgssnappingutils.cpp @@ -21,7 +21,7 @@ #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" #include "qgsgeometry.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgssnappingutils.h" #include "qgssnappingconfig.h" @@ -74,7 +74,7 @@ class TestQgsSnappingUtils : public QObject flist << ff; mVL->dataProvider()->addFeatures( flist ); - QgsMapLayerRegistry::instance()->addMapLayer( mVL ); + QgsProject::instance()->addMapLayer( mVL ); } void cleanupTestCase() diff --git a/tests/src/core/testqgsstyle.cpp b/tests/src/core/testqgsstyle.cpp index 94e853bce06..df597ca6043 100644 --- a/tests/src/core/testqgsstyle.cpp +++ b/tests/src/core/testqgsstyle.cpp @@ -26,7 +26,6 @@ #include "qgscolorramp.h" #include "qgscptcityarchive.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" #include "qgslinesymbollayer.h" #include "qgsfillsymbollayer.h" #include "qgssinglesymbolrenderer.h" diff --git a/tests/src/core/testqgssvgmarker.cpp b/tests/src/core/testqgssvgmarker.cpp index 02bca206e83..d8f74c4a02e 100644 --- a/tests/src/core/testqgssvgmarker.cpp +++ b/tests/src/core/testqgssvgmarker.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include "qgsmarkersymbollayer.h" @@ -95,7 +95,7 @@ void TestQgsSvgMarkerSymbol::initTestCase() pointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); //setup symbol diff --git a/tests/src/core/testqgssymbol.cpp b/tests/src/core/testqgssymbol.cpp index 551f079f00e..e6d3a5fb41d 100644 --- a/tests/src/core/testqgssymbol.cpp +++ b/tests/src/core/testqgssymbol.cpp @@ -26,7 +26,7 @@ #include "qgscolorramp.h" #include "qgscptcityarchive.h" #include "qgsvectorlayer.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgslinesymbollayer.h" #include "qgsfillsymbollayer.h" #include "qgssinglesymbolrenderer.h" @@ -113,7 +113,7 @@ void TestQgsSymbol::initTestCase() mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); // @@ -124,7 +124,7 @@ void TestQgsSymbol::initTestCase() mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), myPolyFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); @@ -136,7 +136,7 @@ void TestQgsSymbol::initTestCase() mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), myLineFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpLinesLayer ); mReport += QLatin1String( "

StyleV2 Tests

\n" ); diff --git a/tests/src/core/testqgstaskmanager.cpp b/tests/src/core/testqgstaskmanager.cpp index 797c1b3ccd9..e766dc9c662 100644 --- a/tests/src/core/testqgstaskmanager.cpp +++ b/tests/src/core/testqgstaskmanager.cpp @@ -16,7 +16,7 @@ ***************************************************************************/ #include "qgstaskmanager.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsvectorlayer.h" #include "qgsapplication.h" #include @@ -1017,7 +1017,7 @@ void TestQgsTaskManager::layerDependencies() QVERIFY( layer2->isValid() ); QgsVectorLayer* layer3 = new QgsVectorLayer( "Point?field=col1:string&field=col2:string&field=col3:string", "layer3", "memory" ); QVERIFY( layer3->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayers( QList< QgsMapLayer* >() << layer1 << layer2 << layer3 ); + QgsProject::instance()->addMapLayers( QList< QgsMapLayer* >() << layer1 << layer2 << layer3 ); QgsTaskManager manager; @@ -1034,10 +1034,10 @@ void TestQgsTaskManager::layerDependencies() QCOMPARE( task->status(), QgsTask::OnHold ); //removing layer1 should have no effect - QgsMapLayerRegistry::instance()->removeMapLayers( QList< QgsMapLayer* >() << layer1 ); + QgsProject::instance()->removeMapLayers( QList< QgsMapLayer* >() << layer1 ); QCOMPARE( task->status(), QgsTask::OnHold ); //removing layer3 should cancel task - QgsMapLayerRegistry::instance()->removeMapLayers( QList< QgsMapLayer* >() << layer3 ); + QgsProject::instance()->removeMapLayers( QList< QgsMapLayer* >() << layer3 ); while ( task->status() != QgsTask::Terminated ) { QCoreApplication::processEvents(); @@ -1045,7 +1045,7 @@ void TestQgsTaskManager::layerDependencies() flushEvents(); QCOMPARE( task->status(), QgsTask::Terminated ); - QgsMapLayerRegistry::instance()->removeMapLayers( QList< QgsMapLayer* >() << layer2 ); + QgsProject::instance()->removeMapLayers( QList< QgsMapLayer* >() << layer2 ); } void TestQgsTaskManager::managerWithSubTasks() diff --git a/tests/src/core/testqgstracer.cpp b/tests/src/core/testqgstracer.cpp index 0da6e314605..7e9d4f0735a 100644 --- a/tests/src/core/testqgstracer.cpp +++ b/tests/src/core/testqgstracer.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/tests/src/core/testqgsvectorlayer.cpp b/tests/src/core/testqgsvectorlayer.cpp index 9399b7e2b38..3734edd01ff 100644 --- a/tests/src/core/testqgsvectorlayer.cpp +++ b/tests/src/core/testqgsvectorlayer.cpp @@ -28,7 +28,7 @@ #include "qgsfeatureiterator.h" #include #include -#include +#include #include #include //qgis test includes @@ -124,7 +124,7 @@ void TestQgsVectorLayer::initTestCase() mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(), myDbfFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpNonSpatialLayer ); // //create a point layer that will be used in all tests... @@ -134,7 +134,7 @@ void TestQgsVectorLayer::initTestCase() mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), myPointFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPointsLayer ); // @@ -145,7 +145,7 @@ void TestQgsVectorLayer::initTestCase() mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), myPolyFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpPolysLayer ); @@ -157,7 +157,7 @@ void TestQgsVectorLayer::initTestCase() mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), myLineFileInfo.completeBaseName(), QStringLiteral( "ogr" ) ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayers( + QgsProject::instance()->addMapLayers( QList() << mpLinesLayer ); mReport += QLatin1String( "

Vector Renderer Tests

\n" ); diff --git a/tests/src/core/testqgsvectorlayerjoinbuffer.cpp b/tests/src/core/testqgsvectorlayerjoinbuffer.cpp index ad0d040b2d9..68b87d47cc2 100644 --- a/tests/src/core/testqgsvectorlayerjoinbuffer.cpp +++ b/tests/src/core/testqgsvectorlayerjoinbuffer.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -156,7 +155,7 @@ void TestVectorLayerJoinBuffer::initTestCase() QgsVectorLayer* vl = mLayers.value( QPair( QStringLiteral( "A" ), provider ) ); vl->dataProvider()->addFeatures( QgsFeatureList() << fA1 << fA2 ); QVERIFY( vl->featureCount() == 2 ); - QgsMapLayerRegistry::instance()->addMapLayer( vl ); + QgsProject::instance()->addMapLayer( vl ); } Q_FOREACH ( const QString provider, mProviders ) @@ -164,7 +163,7 @@ void TestVectorLayerJoinBuffer::initTestCase() QgsVectorLayer* vl = mLayers.value( QPair( QStringLiteral( "B" ), provider ) ); vl->dataProvider()->addFeatures( QgsFeatureList() << fB1 << fB2 ); QVERIFY( vl->featureCount() == 2 ); - QgsMapLayerRegistry::instance()->addMapLayer( vl ); + QgsProject::instance()->addMapLayer( vl ); } Q_FOREACH ( const QString provider, mProviders ) @@ -172,7 +171,7 @@ void TestVectorLayerJoinBuffer::initTestCase() QgsVectorLayer* vl = mLayers.value( QPair( QStringLiteral( "C" ), provider ) ); vl->dataProvider()->addFeatures( QgsFeatureList() << fC1 ); QVERIFY( vl->featureCount() == 1 ); - QgsMapLayerRegistry::instance()->addMapLayer( vl ); + QgsProject::instance()->addMapLayer( vl ); } Q_FOREACH ( const QString provider, mProviders ) @@ -180,10 +179,10 @@ void TestVectorLayerJoinBuffer::initTestCase() QgsVectorLayer* vl = mLayers.value( QPair( QStringLiteral( "X" ), provider ) ); vl->dataProvider()->addFeatures( QgsFeatureList() << fX1 ); QVERIFY( vl->featureCount() == 1 ); - QgsMapLayerRegistry::instance()->addMapLayer( vl ); + QgsProject::instance()->addMapLayer( vl ); } - QVERIFY( QgsMapLayerRegistry::instance()->mapLayers().count() == 4*mProviders.count() ); + QVERIFY( QgsProject::instance()->mapLayers().count() == 4*mProviders.count() ); } void TestVectorLayerJoinBuffer::init() @@ -376,7 +375,7 @@ void TestVectorLayerJoinBuffer::testJoinSubset() QFETCH( bool, memoryCache ); QFETCH( QString, provider ); - QVERIFY( QgsMapLayerRegistry::instance()->mapLayers().count() == 4*mProviders.count() ); + QVERIFY( QgsProject::instance()->mapLayers().count() == 4*mProviders.count() ); QgsVectorLayer* vlA = mLayers.value( QPair( QStringLiteral( "A" ), provider ) ); QgsVectorLayer* vlX = mLayers.value( QPair( QStringLiteral( "X" ), provider ) ); @@ -475,16 +474,16 @@ void TestVectorLayerJoinBuffer::testJoinLayerDefinitionFile() { bool r; - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); // Create two layers QgsVectorLayer* layerA = new QgsVectorLayer( QStringLiteral( "Point?crs=epsg:4326&field=key:integer&field=value:double&index=yes" ), QStringLiteral( "layerA" ), QStringLiteral( "memory" ) ); QVERIFY( layerA ); - QgsMapLayerRegistry::instance()->addMapLayer( layerA ); + QgsProject::instance()->addMapLayer( layerA ); QgsVectorLayer* layerB = new QgsVectorLayer( QStringLiteral( "Point?crs=epsg:4326&field=id:integer&index=yes" ), QStringLiteral( "layerB" ), QStringLiteral( "memory" ) ); QVERIFY( layerB ); - QgsMapLayerRegistry::instance()->addMapLayer( layerB ); + QgsProject::instance()->addMapLayer( layerB ); // Create vector join QgsVectorJoinInfo joinInfo; @@ -503,14 +502,14 @@ void TestVectorLayerJoinBuffer::testJoinLayerDefinitionFile() QVERIFY2( r, errorMessage.toUtf8().constData() ); // Clear - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); // Load QLR r = QgsLayerDefinition::loadLayerDefinition( qlrDoc, QgsProject::instance()->layerTreeRoot(), errorMessage ); QVERIFY2( r, errorMessage.toUtf8().constData() ); // Get layer - QList mapLayers = QgsMapLayerRegistry::instance()->mapLayersByName( QStringLiteral( "layerB" ) ); + QList mapLayers = QgsProject::instance()->mapLayersByName( QStringLiteral( "layerB" ) ); QCOMPARE( mapLayers.count(), 1 ); QgsVectorLayer* vLayer = dynamic_cast( mapLayers.value( 0 ) ); @@ -538,8 +537,8 @@ void TestVectorLayerJoinBuffer::testCacheUpdate() QVERIFY( vlA->isValid() ); QgsVectorLayer* vlB = new QgsVectorLayer( QStringLiteral( "Point?field=id_b:integer&field=value_b" ), QStringLiteral( "cacheB" ), QStringLiteral( "memory" ) ); QVERIFY( vlB->isValid() ); - QgsMapLayerRegistry::instance()->addMapLayer( vlA ); - QgsMapLayerRegistry::instance()->addMapLayer( vlB ); + QgsProject::instance()->addMapLayer( vlA ); + QgsProject::instance()->addMapLayer( vlB ); QgsFeature fA1( vlA->dataProvider()->fields(), 1 ); fA1.setAttribute( QStringLiteral( "id_a" ), 1 ); @@ -600,8 +599,8 @@ void TestVectorLayerJoinBuffer::testCacheUpdate() QCOMPARE( fA2.attribute( "id_a" ).toInt(), 3 ); QCOMPARE( fA2.attribute( "B_value_b" ).toInt(), 12 ); - QgsMapLayerRegistry::instance()->removeMapLayer( vlA ); - QgsMapLayerRegistry::instance()->removeMapLayer( vlB ); + QgsProject::instance()->removeMapLayer( vlA ); + QgsProject::instance()->removeMapLayer( vlB ); } diff --git a/tests/src/gui/testprojectionissues.cpp b/tests/src/gui/testprojectionissues.cpp index dd76357171c..58bf0bae69b 100644 --- a/tests/src/gui/testprojectionissues.cpp +++ b/tests/src/gui/testprojectionissues.cpp @@ -17,7 +17,7 @@ #include "qgsapplication.h" #include "qgsmapcanvas.h" -#include "qgsmaplayerregistry.h" +#include "qgsproject.h" #include "qgsmultibandcolorrenderer.h" #include "qgsrasterdataprovider.h" #include "qgsrasterlayer.h" @@ -66,11 +66,11 @@ void TestProjectionIssues::initTestCase() QList mapLayers; mapLayers.append( mRasterLayer ); - QgsMapLayerRegistry::instance()->addMapLayers( mapLayers ); + QgsProject::instance()->addMapLayers( mapLayers ); // Add all layers in registry to the canvas QList canvasLayers; - Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers() ) + Q_FOREACH ( QgsMapLayer* layer, QgsProject::instance()->mapLayers() ) { canvasLayers.append( QgsMapCanvasLayer( layer ) ); } diff --git a/tests/src/gui/testqgseditorwidgetregistry.cpp b/tests/src/gui/testqgseditorwidgetregistry.cpp index 2322699188d..46611467623 100644 --- a/tests/src/gui/testqgseditorwidgetregistry.cpp +++ b/tests/src/gui/testqgseditorwidgetregistry.cpp @@ -18,7 +18,6 @@ #include "qgseditorwidgetautoconf.h" #include "qgsproject.h" #include "qgsrelationmanager.h" -#include "qgsmaplayerregistry.h" class TestQgsEditorWidgetRegistry: public QObject @@ -117,8 +116,8 @@ class TestQgsEditorWidgetRegistry: public QObject //build two layers QgsVectorLayer vl1( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=name:string&field=fk:int" ), QStringLiteral( "vl1" ), QStringLiteral( "memory" ) ); QgsVectorLayer vl2( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=col1:string" ), QStringLiteral( "vl2" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( &vl1, false, false ); - QgsMapLayerRegistry::instance()->addMapLayer( &vl2, false, false ); + QgsProject::instance()->addMapLayer( &vl1, false, false ); + QgsProject::instance()->addMapLayer( &vl2, false, false ); //create a relation between them QgsRelation relation; diff --git a/tests/src/gui/testqgsfieldexpressionwidget.cpp b/tests/src/gui/testqgsfieldexpressionwidget.cpp index 97c87e9d208..c21a813a0de 100644 --- a/tests/src/gui/testqgsfieldexpressionwidget.cpp +++ b/tests/src/gui/testqgsfieldexpressionwidget.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -74,12 +73,12 @@ void TestQgsFieldExpressionWidget::initTestCase() mLayerA = new QgsVectorLayer( QStringLiteral( "Point?field=id_a:integer" ), QStringLiteral( "A" ), QStringLiteral( "memory" ) ); QVERIFY( mLayerA->isValid() ); QVERIFY( mLayerA->fields().count() == 1 ); - QgsMapLayerRegistry::instance()->addMapLayer( mLayerA ); + QgsProject::instance()->addMapLayer( mLayerA ); // LAYER B // mLayerB = new QgsVectorLayer( QStringLiteral( "Point?field=id_b:integer&field=value_b" ), QStringLiteral( "B" ), QStringLiteral( "memory" ) ); QVERIFY( mLayerB->isValid() ); QVERIFY( mLayerB->fields().count() == 2 ); - QgsMapLayerRegistry::instance()->addMapLayer( mLayerB ); + QgsProject::instance()->addMapLayer( mLayerB ); // init widget mWidget = new QgsFieldExpressionWidget(); @@ -139,7 +138,7 @@ void TestQgsFieldExpressionWidget::testRemoveJoin() void TestQgsFieldExpressionWidget::asExpression() { QgsVectorLayer* layer = new QgsVectorLayer( QStringLiteral( "point?field=fld:int&field=fld2:int&field=fld3:int" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( layer ); + QgsProject::instance()->addMapLayer( layer ); QScopedPointer< QgsFieldExpressionWidget > widget( new QgsFieldExpressionWidget() ); widget->setLayer( layer ); @@ -160,13 +159,13 @@ void TestQgsFieldExpressionWidget::asExpression() widget->setField( QStringLiteral( "fld3" ) ); QCOMPARE( widget->asExpression(), QString( "\"fld3\"" ) ); - QgsMapLayerRegistry::instance()->removeMapLayer( layer ); + QgsProject::instance()->removeMapLayer( layer ); } void TestQgsFieldExpressionWidget::testIsValid() { QgsVectorLayer* layer = new QgsVectorLayer( QStringLiteral( "point?field=fld:int&field=name%20with%20space:string" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( layer ); + QgsProject::instance()->addMapLayer( layer ); QScopedPointer< QgsFieldExpressionWidget > widget( new QgsFieldExpressionWidget() ); widget->setLayer( layer ); @@ -217,13 +216,13 @@ void TestQgsFieldExpressionWidget::testIsValid() QCOMPARE( spy.last().at( 0 ).toString(), QString( "2 *" ) ); QVERIFY( !spy.last().at( 1 ).toBool() ); - QgsMapLayerRegistry::instance()->removeMapLayer( layer ); + QgsProject::instance()->removeMapLayer( layer ); } void TestQgsFieldExpressionWidget::testFilters() { QgsVectorLayer* layer = new QgsVectorLayer( QStringLiteral( "point?field=intfld:int&field=stringfld:string&field=string2fld:string&field=longfld:long&field=doublefld:double&field=datefld:date&field=timefld:time&field=datetimefld:datetime" ), QStringLiteral( "x" ), QStringLiteral( "memory" ) ); - QgsMapLayerRegistry::instance()->addMapLayer( layer ); + QgsProject::instance()->addMapLayer( layer ); QScopedPointer< QgsFieldExpressionWidget > widget( new QgsFieldExpressionWidget() ); widget->setLayer( layer ); @@ -270,7 +269,7 @@ void TestQgsFieldExpressionWidget::testFilters() QCOMPARE( widget->mCombo->count(), 1 ); QCOMPARE( widget->mCombo->itemText( 0 ), QString( "timefld" ) ); - QgsMapLayerRegistry::instance()->removeMapLayer( layer ); + QgsProject::instance()->removeMapLayer( layer ); } QTEST_MAIN( TestQgsFieldExpressionWidget ) diff --git a/tests/src/gui/testqgsmapcanvas.cpp b/tests/src/gui/testqgsmapcanvas.cpp index 1c51ebaca76..86273e678c0 100644 --- a/tests/src/gui/testqgsmapcanvas.cpp +++ b/tests/src/gui/testqgsmapcanvas.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -143,7 +143,7 @@ void TestQgsMapCanvas::testMagnification() QList layers; layers.append( layer ); mCanvas->setLayerSet( layers ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << layer ); + QgsProject::instance()->addMapLayers( QList() << layer ); mCanvas->setExtent( layer->extent() ); @@ -222,7 +222,7 @@ void TestQgsMapCanvas::testMagnificationExtent() QList layers; layers.append( layer ); mCanvas->setLayerSet( layers ); - QgsMapLayerRegistry::instance()->addMapLayers( QList() << layer ); + QgsProject::instance()->addMapLayers( QList() << layer ); // zoomToFullExtent mCanvas->zoomToFullExtent(); diff --git a/tests/src/gui/testqgsquickprint.cpp b/tests/src/gui/testqgsquickprint.cpp index 1154ceb9cd7..05aab48082d 100644 --- a/tests/src/gui/testqgsquickprint.cpp +++ b/tests/src/gui/testqgsquickprint.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include //qgis test includes #include @@ -82,7 +82,7 @@ void TestQgsQuickPrint::initTestCase() mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), myPointFileInfo.completeBaseName(), "ogr" ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayer( mpPointsLayer ); + QgsProject::instance()->addMapLayer( mpPointsLayer ); // //create a poly layer that will be used in all tests... @@ -92,7 +92,7 @@ void TestQgsQuickPrint::initTestCase() mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), myPolyFileInfo.completeBaseName(), "ogr" ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer ); + QgsProject::instance()->addMapLayer( mpPolysLayer ); // // Create a line layer that will be used in all tests... @@ -102,7 +102,7 @@ void TestQgsQuickPrint::initTestCase() mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), myLineFileInfo.completeBaseName(), "ogr" ); // Register the layer with the registry - QgsMapLayerRegistry::instance()->addMapLayer( mpLinesLayer ); + QgsProject::instance()->addMapLayer( mpLinesLayer ); // // We only need maprender instead of mapcanvas // since maprender does not require a qui diff --git a/tests/src/gui/testrenderergui.cpp b/tests/src/gui/testrenderergui.cpp index 88697386f60..d021036bc21 100644 --- a/tests/src/gui/testrenderergui.cpp +++ b/tests/src/gui/testrenderergui.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -44,7 +43,7 @@ void TestRendererGUI::loadLayers() { // load just first vector layer QList canvasLayers; - foreach ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) + foreach ( QgsMapLayer* layer, QgsProject::instance()->mapLayers().values() ) { if ( layer->type() == QgsMapLayer::VectorLayer ) canvasLayers << QgsMapCanvasLayer( layer ); diff --git a/tests/src/providers/testqgswcspublicservers.cpp b/tests/src/providers/testqgswcspublicservers.cpp index 281db5bf69d..660e7b3418d 100644 --- a/tests/src/providers/testqgswcspublicservers.cpp +++ b/tests/src/providers/testqgswcspublicservers.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -457,7 +457,7 @@ void TestQgsWcsPublicServers::test() myLog << provider + "_max:" + QString::number( myStats.maximumValue ); } - QgsMapLayerRegistry::instance()->addMapLayer( myLayer, false ); + QgsProject::instance()->addMapLayer( myLayer, false ); QgsMapSettings mapSettings; mapSettings.setLayers( QStringList( myLayer->id() ) ); @@ -524,7 +524,7 @@ void TestQgsWcsPublicServers::test() myStream << myLog.join( QStringLiteral( "\n" ) ); myLogFile.close(); - QgsMapLayerRegistry::instance()->removeAllMapLayers(); + QgsProject::instance()->removeAllMapLayers(); } if ( !mCoverage.isEmpty() && ! myCoverageFound ) { diff --git a/tests/src/python/acceptable_missing_doc.py b/tests/src/python/acceptable_missing_doc.py index 78fa12f8e39..1ce05cd2787 100644 --- a/tests/src/python/acceptable_missing_doc.py +++ b/tests/src/python/acceptable_missing_doc.py @@ -1548,7 +1548,6 @@ ACCEPTABLE_MISSING_ADDED_NOTE = [ "QgsRendererWidget", "QgsComposerLabel", "QgsRuleBasedRenderer::Rule", - "QgsMapLayerRegistry", "QgsMapRendererCache", "QgsDataSourceUri", "QgsVectorLayerSelectionManager", diff --git a/tests/src/python/offlineditingtestbase.py b/tests/src/python/offlineditingtestbase.py index d50f28c9832..aa7e4779e14 100644 --- a/tests/src/python/offlineditingtestbase.py +++ b/tests/src/python/offlineditingtestbase.py @@ -36,7 +36,7 @@ from qgis.core import ( QgsPoint, QgsFeatureRequest, QgsExpression, - QgsMapLayerRegistry, + QgsProject, QgsOfflineEditing, ) @@ -76,7 +76,7 @@ class OfflineTestBase(object): layer.addFeatures(features) assert layer.commitChanges() # Add the online layer - self.registry = QgsMapLayerRegistry.instance() + self.registry = QgsProject.instance() self.registry.removeAllMapLayers() assert self.registry.addMapLayer(self._getOnlineLayer('test_point')) is not None diff --git a/tests/src/python/qgis_interface.py b/tests/src/python/qgis_interface.py index 74c5860b75f..ed968efb823 100644 --- a/tests/src/python/qgis_interface.py +++ b/tests/src/python/qgis_interface.py @@ -26,7 +26,7 @@ __copyright__ = ('Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk and ' import qgis # NOQA from qgis.PyQt.QtCore import QObject -from qgis.core import QgsMapLayerRegistry +from qgis.core import QgsProject class QgisInterface(QObject): @@ -68,7 +68,7 @@ class QgisInterface(QObject): def activeLayer(self): """Get pointer to the active layer (layer selected in the legend)""" - myLayers = QgsMapLayerRegistry.instance().mapLayers() + myLayers = QgsProject.instance().mapLayers() for myItem in myLayers: return myLayers[myItem] diff --git a/tests/src/python/test_layer_dependencies.py b/tests/src/python/test_layer_dependencies.py index b4936694f53..1c67606559e 100644 --- a/tests/src/python/test_layer_dependencies.py +++ b/tests/src/python/test_layer_dependencies.py @@ -15,7 +15,7 @@ __revision__ = '$Format:%H$' import qgis # NOQA import os -from qgis.core import (QgsMapLayerRegistry, +from qgis.core import (QgsProject, QgsVectorLayer, QgsMapSettings, QgsSnappingUtils, @@ -77,7 +77,7 @@ class TestLayerDependencies(unittest.TestCase): assert (cls.linesLayer.isValid()) cls.pointsLayer2 = QgsVectorLayer("dbname='%s' table=\"node2\" (geom) sql=" % fn, "_points2", "spatialite") assert (cls.pointsLayer2.isValid()) - QgsMapLayerRegistry.instance().addMapLayers([cls.pointsLayer, cls.linesLayer, cls.pointsLayer2]) + QgsProject.instance().addMapLayers([cls.pointsLayer, cls.linesLayer, cls.pointsLayer2]) # save the project file fo = tempfile.NamedTemporaryFile() @@ -213,7 +213,7 @@ class TestLayerDependencies(unittest.TestCase): def test_signalConnection(self): # remove all layers - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # set dependencies and add back layers self.pointsLayer = QgsVectorLayer("dbname='%s' table=\"node\" (geom) sql=" % self.fn, "points", "spatialite") assert (self.pointsLayer.isValid()) @@ -224,9 +224,9 @@ class TestLayerDependencies(unittest.TestCase): self.pointsLayer.setDependencies([QgsMapLayerDependency(self.linesLayer.id())]) self.pointsLayer2.setDependencies([QgsMapLayerDependency(self.pointsLayer.id())]) # this should update connections between layers - QgsMapLayerRegistry.instance().addMapLayers([self.pointsLayer]) - QgsMapLayerRegistry.instance().addMapLayers([self.linesLayer]) - QgsMapLayerRegistry.instance().addMapLayers([self.pointsLayer2]) + QgsProject.instance().addMapLayers([self.pointsLayer]) + QgsProject.instance().addMapLayers([self.linesLayer]) + QgsProject.instance().addMapLayers([self.pointsLayer2]) ms = QgsMapSettings() ms.setOutputSize(QSize(100, 100)) diff --git a/tests/src/python/test_offline_editing_wfs.py b/tests/src/python/test_offline_editing_wfs.py index 771885ba516..7eb91707333 100644 --- a/tests/src/python/test_offline_editing_wfs.py +++ b/tests/src/python/test_offline_editing_wfs.py @@ -39,7 +39,6 @@ from time import sleep from utilities import unitTestDataPath, waitServer from qgis.core import ( QgsVectorLayer, - QgsMapLayerRegistry, QgsAuthManager ) diff --git a/tests/src/python/test_provider_spatialite.py b/tests/src/python/test_provider_spatialite.py index e9249422fbb..6ddc5ded03e 100644 --- a/tests/src/python/test_provider_spatialite.py +++ b/tests/src/python/test_provider_spatialite.py @@ -25,7 +25,6 @@ from qgis.core import (QgsVectorLayer, QgsFeature, QgsGeometry, QgsProject, - QgsMapLayerRegistry, QgsField, QgsFieldConstraints, QgsVectorLayerUtils) @@ -373,8 +372,8 @@ class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase): self.assertTrue(artist.isValid()) track = QgsVectorLayer("dbname=%s table=test_relation_b (geometry)" % self.dbname, "test_relation_b", "spatialite") self.assertTrue(track.isValid()) - QgsMapLayerRegistry.instance().addMapLayer(artist) - QgsMapLayerRegistry.instance().addMapLayer(track) + QgsProject.instance().addMapLayer(artist) + QgsProject.instance().addMapLayer(track) try: relMgr = QgsProject.instance().relationManager() relations = relMgr.discoverRelations([], [artist, track]) @@ -388,8 +387,8 @@ class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase): self.assertEqual([2], a2t.referencingFields()) self.assertEqual([0], a2t.referencedFields()) finally: - QgsMapLayerRegistry.instance().removeMapLayer(track.id()) - QgsMapLayerRegistry.instance().removeMapLayer(artist.id()) + QgsProject.instance().removeMapLayer(track.id()) + QgsProject.instance().removeMapLayer(artist.id()) def testNotNullConstraint(self): vl = QgsVectorLayer("dbname=%s table=test_constraints key='id'" % self.dbname, "test_constraints", diff --git a/tests/src/python/test_provider_virtual.py b/tests/src/python/test_provider_virtual.py index 32336307698..a9082d2d2ea 100644 --- a/tests/src/python/test_provider_virtual.py +++ b/tests/src/python/test_provider_virtual.py @@ -19,7 +19,6 @@ from qgis.core import (QgsVectorLayer, QgsFeature, QgsFeatureRequest, QgsGeometry, - QgsMapLayerRegistry, QgsRectangle, QgsVirtualLayerDefinition, QgsVirtualLayerDefinitionUtils, @@ -89,12 +88,12 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_CsvNoGeometry(self): l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) l2 = QgsVectorLayer("?layer_ref=" + l1.id(), "vtab", "virtual", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) def test_source_escaping(self): # the source contains ':' @@ -139,18 +138,18 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_DynamicGeometry(self): l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/testextpt.txt")).toString() + "?type=csv&delimiter=%7C&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) query = toPercent("select *,makepoint(x,y) as geom from vtab1") l2 = QgsVectorLayer("?layer_ref=%s&query=%s&geometry=geom:point:0&uid=id" % (l1.id(), query), "vtab", "virtual", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().removeMapLayer(l1) + QgsProject.instance().removeMapLayer(l1) def test_ShapefileWithGeometry(self): l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) # use a temporary file l2 = QgsVectorLayer("?layer_ref=" + l1.id(), "vtab", "virtual", False) @@ -159,12 +158,12 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): l2 = QgsVectorLayer("?layer_ref=%s:nn" % l1.id(), "vtab", "virtual", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) def test_Query(self): l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) ref_sum = sum(f.attributes()[0] for f in l1.getFeatures()) query = toPercent("SELECT * FROM vtab1") @@ -227,38 +226,38 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): l2 = QgsVectorLayer("?layer_ref=%s&query=%s&geometry=geo" % (l1.id(), query), "vtab", "virtual", False) self.assertEqual(l2.isValid(), False) - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) def test_QueryUrlEncoding(self): l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) query = toPercent("SELECT * FROM vtab1") l2 = QgsVectorLayer("?layer_ref=%s&query=%s&uid=ObjectId&nogeometry" % (l1.id(), query), "vtab", "virtual", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) def test_QueryTableName(self): l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) query = toPercent("SELECT * FROM vt") l2 = QgsVectorLayer("?layer_ref=%s:vt&query=%s&uid=ObJeCtId&nogeometry" % (l1.id(), query), "vtab", "virtual", False) self.assertEqual(l2.isValid(), True) self.assertEqual(l2.dataProvider().wkbType(), 100) # NoGeometry - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) def test_Join(self): l1 = QgsVectorLayer(os.path.join(self.testDataDir, "points.shp"), "points", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) l2 = QgsVectorLayer(os.path.join(self.testDataDir, "points_relations.shp"), "points_relations", "ogr", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) ref_sum = sum(f.attributes()[1] for f in l2.getFeatures()) # use a temporary file @@ -270,8 +269,8 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): ref_sum2 = sum(f.id() for f in l3.getFeatures()) self.assertEqual(ref_sum, ref_sum2) - QgsMapLayerRegistry.instance().removeMapLayer(l1) - QgsMapLayerRegistry.instance().removeMapLayer(l2) + QgsProject.instance().removeMapLayer(l1) + QgsProject.instance().removeMapLayer(l2) def test_geometryTypes(self): @@ -284,7 +283,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): for wkb_type, wkt_type, wkt in geo: l = QgsVectorLayer("%s?crs=epsg:4326" % wkt_type, "m1", "memory", False) self.assertEqual(l.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l) + QgsProject.instance().addMapLayer(l) f1 = QgsFeature(1) g = QgsGeometry.fromWkt(wkt_type + wkt) @@ -297,7 +296,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(l2.dataProvider().featureCount(), 1) self.assertEqual(l2.dataProvider().wkbType(), wkb_type) - QgsMapLayerRegistry.instance().removeMapLayer(l.id()) + QgsProject.instance().removeMapLayer(l.id()) def test_embeddedLayer(self): source = toPercent(os.path.join(self.testDataDir, "france_parts.shp")) @@ -321,12 +320,12 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): source = toPercent(os.path.join(self.testDataDir, "france_parts.shp")) l = QgsVectorLayer("?layer=ogr:%s" % source, "vtab", "virtual", False) self.assertEqual(l.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l) + QgsProject.instance().addMapLayer(l) l2 = QgsVectorLayer("?layer_ref=" + l.id(), "vtab2", "virtual", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().removeMapLayer(l.id()) + QgsProject.instance().removeMapLayer(l.id()) def test_no_geometry(self): df = QgsVirtualLayerDefinition() @@ -393,35 +392,35 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_refLayer(self): l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) l2 = QgsVectorLayer("?layer_ref=" + l1.id(), "vtab", "virtual", False) self.assertEqual(l2.isValid(), True) # now delete the layer - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) # check that it does not crash print((sum([f.id() for f in l2.getFeatures()]))) def test_refLayers(self): l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) # cf qgis bug #12266 for i in range(10): q = toPercent("select * from t" + str(i)) l2 = QgsVectorLayer("?layer_ref=%s:t%d&query=%s&uid=id" % (l1.id(), i, q), "vtab", "virtual", False) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) self.assertEqual(l2.isValid(), True) s = sum([f.id() for f in l2.dataProvider().getFeatures()]) # NOQA self.assertEqual(sum([f.id() for f in l2.getFeatures()]), 21) - QgsMapLayerRegistry.instance().removeMapLayer(l2.id()) + QgsProject.instance().removeMapLayer(l2.id()) def test_refLayers2(self): l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) # referenced layers cannot be stored ! tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString() @@ -432,7 +431,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_sql(self): l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) l3 = QgsVectorLayer("?query=SELECT * FROM test", "tt", "virtual") @@ -443,7 +442,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_sql2(self): l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) query = toPercent("SELECT * FROM france_parts") l4 = QgsVectorLayer("?query=%s&uid=ObjectId" % query, "tt", "virtual") @@ -500,7 +499,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_sql3(self): l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) # unnamed column query = toPercent("SELECT count(*)") @@ -576,7 +575,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_sql4(self): l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) query = toPercent("SELECT OBJECTId from france_parts") l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False) @@ -588,7 +587,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): # test space and upper case l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "FranCe parts", "ogr", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) query = toPercent('SELECT OBJECTId from "FranCe parts"') l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False) @@ -645,7 +644,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_queryOnMemoryLayer(self): ml = QgsVectorLayer("Point?srid=EPSG:4326&field=a:int", "mem", "memory") self.assertEqual(ml.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(ml) + QgsProject.instance().addMapLayer(ml) ml.startEditing() f1 = QgsFeature(ml.fields()) @@ -670,12 +669,12 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): # make a virtual layer with living references and save it to a project l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) query = toPercent("SELECT * FROM france_parts") l2 = QgsVectorLayer("?query=%s" % query, "aa", "virtual", False) self.assertEqual(l2.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) self.assertEqual(len(l2.dependencies()), 1) ll0 = l2.dependencies().pop() @@ -684,7 +683,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): query = toPercent("SELECT t1.objectid, t2.name_0 FROM france_parts as t1, aa as t2") l3 = QgsVectorLayer("?query=%s" % query, "bb", "virtual", False) self.assertEqual(l3.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l3) + QgsProject.instance().addMapLayer(l3) self.assertEqual(len(l2.dependencies()), 1) ll0 = l2.dependencies().pop() @@ -697,14 +696,14 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): QgsProject.instance().setFileName(temp) QgsProject.instance().write() - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) QgsProject.instance().clear() QgsProject.instance().setFileName(temp) QgsProject.instance().read() # make sure the 3 layers are loaded back - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayers()), 3) + self.assertEqual(len(QgsProject.instance().mapLayers()), 3) def test_qgisExpressionFunctions(self): QgsProject.instance().setTitle('project') @@ -738,7 +737,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): def test_layer_with_accents(self): l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "françéà", "ogr", False) self.assertEqual(l1.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) df = QgsVirtualLayerDefinition() df.setQuery('select * from "françéà"') @@ -748,7 +747,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): ids = [f.id() for f in vl.getFeatures()] self.assertEqual(len(ids), 4) - QgsMapLayerRegistry.instance().removeMapLayer(l1.id()) + QgsProject.instance().removeMapLayer(l1.id()) def test_joined_layers_conversion(self): v1 = QgsVectorLayer("Point?field=id:integer&field=b_id:integer&field=c_id:integer&field=name:string", "A", "memory") @@ -757,7 +756,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(v2.isValid(), True) v3 = QgsVectorLayer("Point?field=id:integer&field=cname:string", "C", "memory") self.assertEqual(v3.isValid(), True) - QgsMapLayerRegistry.instance().addMapLayers([v1, v2, v3]) + QgsProject.instance().addMapLayers([v1, v2, v3]) joinInfo = QgsVectorJoinInfo() joinInfo.targetFieldName = "b_id" joinInfo.joinLayerId = v2.id() @@ -801,7 +800,7 @@ class TestQgsVirtualLayerProvider(unittest.TestCase, ProviderTestCase): 'LEFT JOIN {} AS j1 ON t."b_id"=j1."id" ' + 'LEFT JOIN {} AS j2 ON t."c_id"=j2."id"').format(v1.id(), v2.id(), v3.id())) - QgsMapLayerRegistry.instance().removeMapLayers([v1.id(), v2.id(), v3.id()]) + QgsProject.instance().removeMapLayers([v1.id(), v2.id(), v3.id()]) if __name__ == '__main__': diff --git a/tests/src/python/test_qgsarrowsymbollayer.py b/tests/src/python/test_qgsarrowsymbollayer.py index 723c3a170fb..0604719f5af 100644 --- a/tests/src/python/test_qgsarrowsymbollayer.py +++ b/tests/src/python/test_qgsarrowsymbollayer.py @@ -35,7 +35,7 @@ from qgis.core import ( QgsSingleSymbolRenderer, QgsLineSymbol, QgsFillSymbol, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsArrowSymbolLayer, QgsSymbol, @@ -60,7 +60,7 @@ class TestQgsArrowSymbolLayer(unittest.TestCase): lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp') self.lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(self.lines_layer) + QgsProject.instance().addMapLayer(self.lines_layer) # Create style sym2 = QgsLineSymbol.createSimple({'color': '#fdbf6f'}) @@ -73,7 +73,7 @@ class TestQgsArrowSymbolLayer(unittest.TestCase): self.mapsettings.setBackgroundColor(QColor("white")) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_1(self): sym = self.lines_layer.renderer().symbol() diff --git a/tests/src/python/test_qgsatlascomposition.py b/tests/src/python/test_qgsatlascomposition.py index 663eebf617f..ba9c28d157b 100644 --- a/tests/src/python/test_qgsatlascomposition.py +++ b/tests/src/python/test_qgsatlascomposition.py @@ -22,7 +22,7 @@ import tempfile from qgis.testing import start_app, unittest from utilities import unitTestDataPath from qgis.PyQt.QtCore import QFileInfo, QRectF, qWarning -from qgis.core import QgsUnitTypes, QgsVectorLayer, QgsMapLayerRegistry, QgsMapSettings, QgsCoordinateReferenceSystem, \ +from qgis.core import QgsUnitTypes, QgsVectorLayer, QgsProject, QgsMapSettings, QgsCoordinateReferenceSystem, \ QgsComposition, QgsFillSymbol, QgsSingleSymbolRenderer, QgsComposerLabel, QgsComposerMap, QgsFontUtils, \ QgsRectangle, QgsComposerLegend, QgsFeature, QgsGeometry, QgsPoint, QgsRendererCategory, QgsCategorizedSymbolRenderer, QgsMarkerSymbol from qgscompositionchecker import QgsCompositionChecker @@ -40,7 +40,7 @@ class TestQgsAtlasComposition(unittest.TestCase): vectorFileInfo = QFileInfo(tmppath + "/france_parts.shp") mVectorLayer = QgsVectorLayer(vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr") - QgsMapLayerRegistry.instance().addMapLayers([mVectorLayer]) + QgsProject.instance().addMapLayers([mVectorLayer]) # create composition with composer map self.mapSettings = QgsMapSettings() @@ -282,7 +282,7 @@ class TestQgsAtlasComposition(unittest.TestCase): QgsRendererCategory(2, QgsMarkerSymbol.createSimple({"color": "0,0,255"}), "blue")]) ptLayer.setRenderer(r) - QgsMapLayerRegistry.instance().addMapLayer(ptLayer) + QgsProject.instance().addMapLayer(ptLayer) # add the point layer to the map settings layers = self.mapSettings.layers() @@ -311,7 +311,7 @@ class TestQgsAtlasComposition(unittest.TestCase): # restore state self.mapSettings.setLayers([layers[1]]) self.mComposition.removeComposerItem(legend) - QgsMapLayerRegistry.instance().removeMapLayer(ptLayer.id()) + QgsProject.instance().removeMapLayer(ptLayer.id()) if __name__ == '__main__': diff --git a/tests/src/python/test_qgsblendmodes.py b/tests/src/python/test_qgsblendmodes.py index 337cc98f1fa..5161b032247 100644 --- a/tests/src/python/test_qgsblendmodes.py +++ b/tests/src/python/test_qgsblendmodes.py @@ -32,7 +32,7 @@ from qgis.PyQt.QtGui import QPainter, QColor from qgis.core import (QgsVectorLayer, QgsVectorSimplifyMethod, - QgsMapLayerRegistry, + QgsProject, QgsMultiRenderChecker, QgsRasterLayer, QgsMultiBandColorRenderer, @@ -58,7 +58,7 @@ class TestQgsBlendModes(unittest.TestCase): self.iface = get_iface() # initialize class MapRegistry, Canvas, MapRenderer, Map and PAL - self.mMapRegistry = QgsMapLayerRegistry.instance() + self.mMapRegistry = QgsProject.instance() # create point layer myShpFile = os.path.join(TEST_DATA_DIR, 'points.shp') diff --git a/tests/src/python/test_qgscomposerlabel.py b/tests/src/python/test_qgscomposerlabel.py index 53f17291145..a33ae41208c 100644 --- a/tests/src/python/test_qgscomposerlabel.py +++ b/tests/src/python/test_qgscomposerlabel.py @@ -18,7 +18,7 @@ import qgis # NOQA from qgis.testing import start_app, unittest from qgis.PyQt.QtCore import QFileInfo, QDate, QDateTime -from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsMapSettings, QgsComposition, QgsComposerLabel, QgsFeatureRequest, QgsFeature, QgsExpression +from qgis.core import QgsVectorLayer, QgsProject, QgsMapSettings, QgsComposition, QgsComposerLabel, QgsFeatureRequest, QgsFeature, QgsExpression from utilities import unitTestDataPath start_app() @@ -31,7 +31,7 @@ class TestQgsComposerLabel(unittest.TestCase): vectorFileInfo = QFileInfo(TEST_DATA_DIR + "/france_parts.shp") mVectorLayer = QgsVectorLayer(vectorFileInfo.filePath(), vectorFileInfo.completeBaseName(), "ogr") - QgsMapLayerRegistry.instance().addMapLayers([mVectorLayer]) + QgsProject.instance().addMapLayers([mVectorLayer]) # create composition with composer map mapSettings = QgsMapSettings() diff --git a/tests/src/python/test_qgscomposerlegend.py b/tests/src/python/test_qgscomposerlegend.py index 327a5f0d865..a9203038ba2 100644 --- a/tests/src/python/test_qgscomposerlegend.py +++ b/tests/src/python/test_qgscomposerlegend.py @@ -20,7 +20,7 @@ from qgis.core import (QgsComposerLegend, QgsComposition, QgsMapSettings, QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsMarkerSymbol, QgsSingleSymbolRenderer, QgsRectangle @@ -43,7 +43,7 @@ class TestQgsComposerLegend(unittest.TestCase): point_path = os.path.join(TEST_DATA_DIR, 'points.shp') point_layer = QgsVectorLayer(point_path, 'points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayers([point_layer]) + QgsProject.instance().addMapLayers([point_layer]) marker_symbol = QgsMarkerSymbol.createSimple({'color': '#ff0000', 'outline_style': 'no', 'size': '5', 'size_unit': 'MapUnit'}) @@ -75,14 +75,14 @@ class TestQgsComposerLegend(unittest.TestCase): result, message = checker.testComposition() self.assertTrue(result, message) - QgsMapLayerRegistry.instance().removeMapLayers([point_layer.id()]) + QgsProject.instance().removeMapLayers([point_layer.id()]) def testResizeWithMapContent(self): """Test test legend resizes to match map content""" point_path = os.path.join(TEST_DATA_DIR, 'points.shp') point_layer = QgsVectorLayer(point_path, 'points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayers([point_layer]) + QgsProject.instance().addMapLayers([point_layer]) s = QgsMapSettings() s.setLayers([point_layer.id()]) @@ -113,14 +113,14 @@ class TestQgsComposerLegend(unittest.TestCase): result, message = checker.testComposition() self.assertTrue(result, message) - QgsMapLayerRegistry.instance().removeMapLayers([point_layer.id()]) + QgsProject.instance().removeMapLayers([point_layer.id()]) def testResizeDisabled(self): """Test that test legend does not resize if auto size is disabled""" point_path = os.path.join(TEST_DATA_DIR, 'points.shp') point_layer = QgsVectorLayer(point_path, 'points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayers([point_layer]) + QgsProject.instance().addMapLayers([point_layer]) s = QgsMapSettings() s.setLayers([point_layer.id()]) @@ -155,14 +155,14 @@ class TestQgsComposerLegend(unittest.TestCase): result, message = checker.testComposition() self.assertTrue(result, message) - QgsMapLayerRegistry.instance().removeMapLayers([point_layer.id()]) + QgsProject.instance().removeMapLayers([point_layer.id()]) def testResizeDisabledCrop(self): """Test that if legend resizing is disabled, and legend is too small, then content is cropped""" point_path = os.path.join(TEST_DATA_DIR, 'points.shp') point_layer = QgsVectorLayer(point_path, 'points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayers([point_layer]) + QgsProject.instance().addMapLayers([point_layer]) s = QgsMapSettings() s.setLayers([point_layer.id()]) @@ -197,7 +197,7 @@ class TestQgsComposerLegend(unittest.TestCase): result, message = checker.testComposition() self.assertTrue(result, message) - QgsMapLayerRegistry.instance().removeMapLayers([point_layer.id()]) + QgsProject.instance().removeMapLayers([point_layer.id()]) if __name__ == '__main__': unittest.main() diff --git a/tests/src/python/test_qgscomposermap.py b/tests/src/python/test_qgscomposermap.py index b4463fa4926..db85844e126 100644 --- a/tests/src/python/test_qgscomposermap.py +++ b/tests/src/python/test_qgscomposermap.py @@ -25,7 +25,7 @@ from qgis.core import (QgsComposerMap, QgsRasterLayer, QgsComposition, QgsMapSettings, - QgsMapLayerRegistry, + QgsProject, QgsMultiBandColorRenderer, ) @@ -51,7 +51,7 @@ class TestQgsComposerMap(unittest.TestCase): mRasterLayer.setRenderer(rasterRenderer) #pipe = mRasterLayer.pipe() #assert pipe.set(rasterRenderer), 'Cannot set pipe renderer' - QgsMapLayerRegistry.instance().addMapLayers([mRasterLayer]) + QgsProject.instance().addMapLayers([mRasterLayer]) # create composition with composer map self.mMapSettings = QgsMapSettings() diff --git a/tests/src/python/test_qgscomposition.py b/tests/src/python/test_qgscomposition.py index 9eb79db54c4..b44d1212812 100644 --- a/tests/src/python/test_qgscomposition.py +++ b/tests/src/python/test_qgscomposition.py @@ -23,7 +23,7 @@ from qgis.core import (QgsComposition, QgsPoint, QgsRasterLayer, QgsMultiBandColorRenderer, - QgsMapLayerRegistry, + QgsProject, QgsMapSettings ) @@ -99,7 +99,7 @@ class TestQgsComposition(unittest.TestCase): myPipe = myRasterLayer.pipe() assert myPipe.set(myRenderer), "Cannot set pipe renderer" - QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer]) + QgsProject.instance().addMapLayers([myRasterLayer]) myMapSettings = QgsMapSettings() myMapSettings.setLayers([myRasterLayer.id()]) diff --git a/tests/src/python/test_qgseditwidgets.py b/tests/src/python/test_qgseditwidgets.py index 939004556b7..ba6660bc7ad 100644 --- a/tests/src/python/test_qgseditwidgets.py +++ b/tests/src/python/test_qgseditwidgets.py @@ -14,7 +14,7 @@ __revision__ = '$Format:%H$' import qgis # NOQA -from qgis.core import (QgsMapLayerRegistry, QgsFeature, QgsGeometry, QgsPoint, QgsProject, QgsRelation, QgsVectorLayer, NULL, +from qgis.core import (QgsProject, QgsFeature, QgsGeometry, QgsPoint, QgsProject, QgsRelation, QgsVectorLayer, NULL, QgsField) from qgis.gui import QgsEditorWidgetRegistry @@ -75,7 +75,7 @@ class TestQgsTextEditWidget(unittest.TestCase): layer.dataProvider().addAttributes([QgsField('max', QVariant.String, 'string', 10), QgsField('nomax', QVariant.String, 'string', 0)]) layer.updateFields() - QgsMapLayerRegistry.instance().addMapLayer(layer) + QgsProject.instance().addMapLayer(layer) reg = QgsEditorWidgetRegistry.instance() config = {'IsMultiline': 'True'} @@ -93,13 +93,13 @@ class TestQgsTextEditWidget(unittest.TestCase): self.assertEqual(w.value(), 'this_is_a_') - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_ValueMap_representValue(self): layer = QgsVectorLayer("none?field=number1:integer&field=number2:double&field=text1:string&field=number3:integer&field=number4:double&field=text2:string", "layer", "memory") assert layer.isValid() - QgsMapLayerRegistry.instance().addMapLayer(layer) + QgsProject.instance().addMapLayer(layer) f = QgsFeature() f.setAttributes([2, 2.5, 'NULL', None, None, None]) assert layer.dataProvider().addFeatures([f]) @@ -127,12 +127,12 @@ class TestQgsTextEditWidget(unittest.TestCase): self.assertEqual(factory.representValue(layer, 4, config, None, None), '(NULL)') self.assertEqual(factory.representValue(layer, 5, config, None, None), '(NULL)') - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_ValueMap_set_get(self): layer = QgsVectorLayer("none?field=number:integer", "layer", "memory") assert layer.isValid() - QgsMapLayerRegistry.instance().addMapLayer(layer) + QgsProject.instance().addMapLayer(layer) reg = QgsEditorWidgetRegistry.instance() configWdg = reg.createConfigWidget('ValueMap', layer, 0, None) @@ -144,7 +144,7 @@ class TestQgsTextEditWidget(unittest.TestCase): configWdg.setConfig(config) self.assertEqual(configWdg.config(), config) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_ValueRelation_representValue(self): @@ -154,7 +154,7 @@ class TestQgsTextEditWidget(unittest.TestCase): second_layer = QgsVectorLayer("none?field=pkid:integer&field=decoded:string", "second_layer", "memory") assert second_layer.isValid() - QgsMapLayerRegistry.instance().addMapLayer(second_layer) + QgsProject.instance().addMapLayer(second_layer) f = QgsFeature() f.setAttributes([123]) assert first_layer.dataProvider().addFeatures([f]) @@ -190,7 +190,7 @@ class TestQgsTextEditWidget(unittest.TestCase): config = {'Layer': second_layer.id(), 'Key': 'pkid', 'Value': 'invalid'} self.assertEqual(factory.representValue(first_layer, 0, config, None, '456'), '(456)') - QgsMapLayerRegistry.instance().removeMapLayer(second_layer.id()) + QgsProject.instance().removeMapLayer(second_layer.id()) def test_RelationReference_representValue(self): @@ -200,7 +200,7 @@ class TestQgsTextEditWidget(unittest.TestCase): second_layer = QgsVectorLayer("none?field=pkid:integer&field=decoded:string", "second_layer", "memory") assert second_layer.isValid() - QgsMapLayerRegistry.instance().addMapLayers([first_layer, second_layer]) + QgsProject.instance().addMapLayers([first_layer, second_layer]) f = QgsFeature() f.setAttributes([123]) assert first_layer.dataProvider().addFeatures([f]) @@ -278,7 +278,7 @@ class TestQgsTextEditWidget(unittest.TestCase): second_layer.setDisplayExpression('decoded') self.assertEqual(factory.representValue(first_layer, 0, config, None, '123'), '123') - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() if __name__ == '__main__': unittest.main() diff --git a/tests/src/python/test_qgsfeatureiterator.py b/tests/src/python/test_qgsfeatureiterator.py index 7f72bb963c3..eb829a8dcc2 100644 --- a/tests/src/python/test_qgsfeatureiterator.py +++ b/tests/src/python/test_qgsfeatureiterator.py @@ -16,7 +16,7 @@ import qgis # NOQA import os -from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsField, NULL, QgsMapLayerRegistry, QgsVectorJoinInfo +from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsField, NULL, QgsProject, QgsVectorJoinInfo from qgis.testing import start_app, unittest from qgis.PyQt.QtCore import QVariant @@ -173,7 +173,7 @@ class TestQgsFeatureIterator(unittest.TestCase): self.assertTrue(pr.addFeatures([f])) layer.addExpressionField('"fldint"*2', QgsField('exp1', QVariant.LongLong)) - QgsMapLayerRegistry.instance().addMapLayers([layer, joinLayer]) + QgsProject.instance().addMapLayers([layer, joinLayer]) join = QgsVectorJoinInfo() join.targetFieldName = "exp1" @@ -193,7 +193,7 @@ class TestQgsFeatureIterator(unittest.TestCase): self.assertEqual(attrs[4], 246) self.assertFalse(fi.nextFeature(f)) - QgsMapLayerRegistry.instance().removeMapLayers([layer.id(), joinLayer.id()]) + QgsProject.instance().removeMapLayers([layer.id(), joinLayer.id()]) def test_JoinUsingExpression2(self): """ test joining a layer using a virtual field (the other way!) """ @@ -215,7 +215,7 @@ class TestQgsFeatureIterator(unittest.TestCase): f.setAttributes(["test", 123]) self.assertTrue(pr.addFeatures([f])) - QgsMapLayerRegistry.instance().addMapLayers([layer, joinLayer]) + QgsProject.instance().addMapLayers([layer, joinLayer]) join = QgsVectorJoinInfo() join.targetFieldName = "fldint" @@ -235,7 +235,7 @@ class TestQgsFeatureIterator(unittest.TestCase): self.assertEqual(attrs[4], 321) self.assertFalse(fi.nextFeature(f)) - QgsMapLayerRegistry.instance().removeMapLayers([layer.id(), joinLayer.id()]) + QgsProject.instance().removeMapLayers([layer.id(), joinLayer.id()]) def test_JoinUsingFeatureRequestExpression(self): """ test requesting features using a filter expression which requires joined columns """ @@ -258,7 +258,7 @@ class TestQgsFeatureIterator(unittest.TestCase): f2.setAttributes(["test", 124]) self.assertTrue(pr.addFeatures([f1, f2])) - QgsMapLayerRegistry.instance().addMapLayers([layer, joinLayer]) + QgsProject.instance().addMapLayers([layer, joinLayer]) join = QgsVectorJoinInfo() join.targetFieldName = "fldint" @@ -273,7 +273,7 @@ class TestQgsFeatureIterator(unittest.TestCase): self.assertEqual(f['fldint'], 124) self.assertEqual(f['joinlayer_z'], 654) - QgsMapLayerRegistry.instance().removeMapLayers([layer.id(), joinLayer.id()]) + QgsProject.instance().removeMapLayers([layer.id(), joinLayer.id()]) if __name__ == '__main__': diff --git a/tests/src/python/test_qgsgeometry_avoid_intersections.py b/tests/src/python/test_qgsgeometry_avoid_intersections.py index 9c0a0ca1c76..fd7658312a1 100644 --- a/tests/src/python/test_qgsgeometry_avoid_intersections.py +++ b/tests/src/python/test_qgsgeometry_avoid_intersections.py @@ -14,7 +14,7 @@ __revision__ = '$Format:%H$' import qgis # NOQA -from qgis.core import QgsVectorLayer, QgsFeature, QgsGeometry, QgsProject, QgsMapLayerRegistry +from qgis.core import QgsVectorLayer, QgsFeature, QgsGeometry, QgsProject from qgis.testing import start_app, unittest @@ -49,7 +49,7 @@ class TestQgsGeometryAvoidIntersections(unittest.TestCase): # create a layer with some polygons that will be used as a source for "avoid intersections" l = QgsVectorLayer('MultiPolygon', 'test_layer', 'memory') assert l.isValid() - QgsMapLayerRegistry.instance().addMapLayer(l) + QgsProject.instance().addMapLayer(l) QgsProject.instance().writeEntry("Digitizing", "/AvoidIntersectionsList", [l.id()]) features = [] diff --git a/tests/src/python/test_qgsgeometrygeneratorsymbollayer.py b/tests/src/python/test_qgsgeometrygeneratorsymbollayer.py index 16c76fa7499..487ab10836d 100644 --- a/tests/src/python/test_qgsgeometrygeneratorsymbollayer.py +++ b/tests/src/python/test_qgsgeometrygeneratorsymbollayer.py @@ -35,7 +35,7 @@ from qgis.core import ( QgsFillSymbol, QgsLineSymbol, QgsMarkerSymbol, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsGeometryGeneratorSymbolLayer, QgsSymbol, @@ -63,9 +63,9 @@ class TestQgsGeometryGeneratorSymbolLayerV2(unittest.TestCase): self.polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr') self.points_layer = QgsVectorLayer(points_shp, 'Points', 'ogr') self.lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(self.polys_layer) - QgsMapLayerRegistry.instance().addMapLayer(self.lines_layer) - QgsMapLayerRegistry.instance().addMapLayer(self.points_layer) + QgsProject.instance().addMapLayer(self.polys_layer) + QgsProject.instance().addMapLayer(self.lines_layer) + QgsProject.instance().addMapLayer(self.points_layer) # Create style sym1 = QgsFillSymbol.createSimple({'color': '#fdbf6f'}) @@ -82,7 +82,7 @@ class TestQgsGeometryGeneratorSymbolLayerV2(unittest.TestCase): self.mapsettings.setExtent(QgsRectangle(-133, 22, -70, 52)) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_marker(self): sym = self.polys_layer.renderer().symbol() diff --git a/tests/src/python/test_qgsjsonutils.py b/tests/src/python/test_qgsjsonutils.py index cbff8291c6d..030139ae74b 100644 --- a/tests/src/python/test_qgsjsonutils.py +++ b/tests/src/python/test_qgsjsonutils.py @@ -19,7 +19,6 @@ from qgis.core import (QgsJSONUtils, QgsJSONExporter, QgsCoordinateReferenceSystem, QgsProject, - QgsMapLayerRegistry, QgsFeature, QgsField, QgsFields, @@ -449,7 +448,7 @@ class TestQgsJSONUtils(unittest.TestCase): f3.setAttributes(["foobar", 124, 554]) assert pr.addFeatures([f1, f2, f3]) - QgsMapLayerRegistry.instance().addMapLayers([child, parent]) + QgsProject.instance().addMapLayers([child, parent]) rel = QgsRelation() rel.setRelationId('rel1') diff --git a/tests/src/python/test_qgslayerdefinition.py b/tests/src/python/test_qgslayerdefinition.py index e788fa93f7e..6bf5a77a85c 100644 --- a/tests/src/python/test_qgslayerdefinition.py +++ b/tests/src/python/test_qgslayerdefinition.py @@ -15,7 +15,6 @@ __revision__ = '$Format:%H$' import qgis # NOQA from qgis.core import (QgsProject, - QgsMapLayerRegistry, QgsLayerDefinition ) @@ -100,16 +99,16 @@ class TestQgsLayerDefinition(unittest.TestCase): def testVectorAndRaster(self): # Load a simple QLR containing a vector layer and a raster layer. - QgsMapLayerRegistry.instance().removeAllMapLayers() - layers = QgsMapLayerRegistry.instance().mapLayers() + QgsProject.instance().removeAllMapLayers() + layers = QgsProject.instance().mapLayers() self.assertEqual(len(layers), 0) (result, errMsg) = QgsLayerDefinition.loadLayerDefinition(TEST_DATA_DIR + '/vector_and_raster.qlr', QgsProject.instance().layerTreeRoot()) self.assertTrue(result) - layers = QgsMapLayerRegistry.instance().mapLayers() + layers = QgsProject.instance().mapLayers() self.assertEqual(len(layers), 2) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() if __name__ == '__main__': unittest.main() diff --git a/tests/src/python/test_qgsmaplayermodel.py b/tests/src/python/test_qgsmaplayermodel.py index 91edee04609..1faef0c96bb 100644 --- a/tests/src/python/test_qgsmaplayermodel.py +++ b/tests/src/python/test_qgsmaplayermodel.py @@ -14,7 +14,7 @@ __revision__ = '$Format:%H$' import qgis # NOQA -from qgis.core import QgsVectorLayer, QgsMapLayerRegistry, QgsMapLayerModel +from qgis.core import QgsVectorLayer, QgsProject, QgsMapLayerModel from qgis.PyQt.QtCore import Qt, QModelIndex from qgis.testing import start_app, unittest @@ -61,29 +61,29 @@ class TestQgsMapLayerModel(unittest.TestCase): self.assertEqual(m.rowCount(QModelIndex()), 0) l1 = create_layer('l1') - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) self.assertEqual(m.rowCount(QModelIndex()), 1) l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayer(l2) + QgsProject.instance().addMapLayer(l2) self.assertEqual(m.rowCount(QModelIndex()), 2) - QgsMapLayerRegistry.instance().removeMapLayer(l1) + QgsProject.instance().removeMapLayer(l1) self.assertEqual(m.rowCount(QModelIndex()), 1) - QgsMapLayerRegistry.instance().removeMapLayer(l2) + QgsProject.instance().removeMapLayer(l2) self.assertEqual(m.rowCount(QModelIndex()), 0) # try creating a model when layers already exist in registry l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertEqual(m.rowCount(QModelIndex()), 2) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) self.assertEqual(m.rowCount(QModelIndex()), 0) def testCheckAll(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() m.setItemsCheckable(True) self.assertFalse(m.layersChecked()) @@ -97,12 +97,12 @@ class TestQgsMapLayerModel(unittest.TestCase): self.assertFalse(m.layersChecked()) self.assertEqual(set(m.layersChecked(Qt.Unchecked)), set([l1, l2])) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testAllowEmpty(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertEqual(m.rowCount(QModelIndex()), 2) @@ -116,19 +116,19 @@ class TestQgsMapLayerModel(unittest.TestCase): # add layers after allow empty is true m.setAllowEmptyLayer(True) l3 = create_layer('l3') - QgsMapLayerRegistry.instance().addMapLayers([l3]) + QgsProject.instance().addMapLayers([l3]) self.assertEqual(m.rowCount(QModelIndex()), 4) self.assertFalse(m.data(m.index(0, 0), Qt.DisplayRole)) self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l1') self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'l2') self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'l3') - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id(), l3.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id(), l3.id()]) def testAdditionalItems(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertEqual(m.rowCount(QModelIndex()), 2) @@ -147,7 +147,7 @@ class TestQgsMapLayerModel(unittest.TestCase): self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'a') self.assertEqual(m.data(m.index(4, 0), Qt.DisplayRole), 'b') - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) self.assertEqual(m.rowCount(QModelIndex()), 3) self.assertFalse(m.data(m.index(0, 0), Qt.DisplayRole)) @@ -157,7 +157,7 @@ class TestQgsMapLayerModel(unittest.TestCase): def testIndexFromLayer(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() l3 = create_layer('l3') # not in registry @@ -169,12 +169,12 @@ class TestQgsMapLayerModel(unittest.TestCase): self.assertEqual(m.indexFromLayer(l1).row(), 1) self.assertEqual(m.indexFromLayer(l2).row(), 2) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testDisplayRole(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertEqual(m.data(m.index(0, 0), Qt.DisplayRole), 'l1') self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l2') @@ -183,12 +183,12 @@ class TestQgsMapLayerModel(unittest.TestCase): self.assertEqual(m.data(m.index(1, 0), Qt.DisplayRole), 'l1') self.assertEqual(m.data(m.index(2, 0), Qt.DisplayRole), 'l2') - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testDisplayRoleShowCrs(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() m.setShowCrs(True) self.assertEqual(m.data(m.index(0, 0), Qt.DisplayRole), 'l1 [EPSG:3111]') @@ -201,12 +201,12 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertEqual(m.data(m.index(3, 0), Qt.DisplayRole), 'a') - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testLayerIdRole(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertEqual(m.data(m.index(0, 0), QgsMapLayerModel.LayerIdRole), l1.id()) self.assertEqual(m.data(m.index(1, 0), QgsMapLayerModel.LayerIdRole), l2.id()) @@ -218,12 +218,12 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertFalse(m.data(m.index(3, 0), QgsMapLayerModel.LayerIdRole)) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testLayerRole(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertEqual(m.data(m.index(0, 0), QgsMapLayerModel.LayerRole), l1) self.assertEqual(m.data(m.index(1, 0), QgsMapLayerModel.LayerRole), l2) @@ -235,12 +235,12 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertFalse(m.data(m.index(3, 0), QgsMapLayerModel.LayerRole)) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testIsEmptyRole(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.EmptyRole)) self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.EmptyRole)) @@ -252,12 +252,12 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertFalse(m.data(m.index(3, 0), QgsMapLayerModel.EmptyRole)) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testIsAdditionalRole(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() self.assertFalse(m.data(m.index(0, 0), QgsMapLayerModel.AdditionalRole)) self.assertFalse(m.data(m.index(1, 0), QgsMapLayerModel.AdditionalRole)) @@ -272,12 +272,12 @@ class TestQgsMapLayerModel(unittest.TestCase): self.assertFalse(m.data(m.index(2, 0), QgsMapLayerModel.AdditionalRole)) self.assertTrue(m.data(m.index(3, 0), QgsMapLayerModel.AdditionalRole)) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testCheckStateRole(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() # not checkable @@ -302,12 +302,12 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertFalse(m.data(m.index(3, 0), Qt.CheckStateRole)) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testFlags(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() # not checkable @@ -331,12 +331,12 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertFalse(m.flags(m.index(3, 0)) & Qt.ItemIsUserCheckable) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) def testSetData(self): l1 = create_layer('l1') l2 = create_layer('l2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) m = QgsMapLayerModel() # set checked @@ -355,7 +355,7 @@ class TestQgsMapLayerModel(unittest.TestCase): m.setAdditionalItems(['a']) self.assertFalse(m.setData(m.index(3, 0), True, Qt.CheckStateRole)) - QgsMapLayerRegistry.instance().removeMapLayers([l1.id(), l2.id()]) + QgsProject.instance().removeMapLayers([l1.id(), l2.id()]) if __name__ == '__main__': unittest.main() diff --git a/tests/src/python/test_qgsmaplayerregistry.py b/tests/src/python/test_qgsmaplayerregistry.py index 3d9bc21394c..59928955b29 100644 --- a/tests/src/python/test_qgsmaplayerregistry.py +++ b/tests/src/python/test_qgsmaplayerregistry.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -"""QGIS Unit tests for QgsMapLayerRegistry. +"""QGIS Unit tests for QgsProject. .. note:: 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 @@ -12,7 +12,7 @@ __copyright__ = 'Copyright 2015, The QGIS Project' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' -from qgis.core import QgsMapLayerRegistry, QgsVectorLayer, QgsMapLayer +from qgis.core import QgsProject, QgsVectorLayer, QgsMapLayer from qgis.testing import start_app, unittest from qgis.PyQt.QtCore import QT_VERSION_STR import sip @@ -30,77 +30,77 @@ def createLayer(name): return QgsVectorLayer("Point?field=x:string", name, "memory") -class TestQgsMapLayerRegistry(unittest.TestCase): +class TestQgsProjectMapLayers(unittest.TestCase): def setUp(self): pass def testInstance(self): """ test retrieving global instance """ - self.assertTrue(QgsMapLayerRegistry.instance()) + self.assertTrue(QgsProject.instance()) # register a layer to the singleton - QgsMapLayerRegistry.instance().addMapLayer(createLayer('test')) + QgsProject.instance().addMapLayer(createLayer('test')) # check that the same instance is returned - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_addMapLayer(self): """ test adding individual map layers to registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() l1 = createLayer('test') - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayer(l1), l1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + self.assertEqual(QgsProject.instance().addMapLayer(l1), l1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(QgsProject.instance().count(), 1) # adding a second layer should leave existing layers intact l2 = createLayer('test2') - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayer(l2), l2) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test2')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + self.assertEqual(QgsProject.instance().addMapLayer(l2), l2) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test2')), 1) + self.assertEqual(QgsProject.instance().count(), 2) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_addMapLayerAlreadyAdded(self): """ test that already added layers can't be readded to registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() l1 = createLayer('test') - QgsMapLayerRegistry.instance().addMapLayer(l1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayer(l1), None) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + QgsProject.instance().addMapLayer(l1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(QgsProject.instance().count(), 1) + self.assertEqual(QgsProject.instance().addMapLayer(l1), None) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(QgsProject.instance().count(), 1) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_addMapLayerInvalid(self): """ test that invalid map layersd can't be added to registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayer(QgsVectorLayer("Point?field=x:string", 'test', "xxx")), None) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 0) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) + self.assertEqual(QgsProject.instance().addMapLayer(QgsVectorLayer("Point?field=x:string", 'test', "xxx")), None) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 0) + self.assertEqual(QgsProject.instance().count(), 0) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() @unittest.skipIf(not use_signal_spy, "No QSignalSpy available") def test_addMapLayerSignals(self): """ test that signals are correctly emitted when adding map layer""" - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() - layer_was_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layerWasAdded) - layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layersAdded) - legend_layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().legendLayersAdded) + layer_was_added_spy = QSignalSpy(QgsProject.instance().layerWasAdded) + layers_added_spy = QSignalSpy(QgsProject.instance().layersAdded) + legend_layers_added_spy = QSignalSpy(QgsProject.instance().legendLayersAdded) l1 = createLayer('test') - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) # can't seem to actually test the data which was emitted, so best we can do is test # the signal count @@ -109,13 +109,13 @@ class TestQgsMapLayerRegistry(unittest.TestCase): self.assertEqual(len(legend_layers_added_spy), 1) # layer not added to legend - QgsMapLayerRegistry.instance().addMapLayer(createLayer('test2'), False) + QgsProject.instance().addMapLayer(createLayer('test2'), False) self.assertEqual(len(layer_was_added_spy), 2) self.assertEqual(len(layers_added_spy), 2) self.assertEqual(len(legend_layers_added_spy), 1) # try readding a layer already in the registry - QgsMapLayerRegistry.instance().addMapLayer(l1) + QgsProject.instance().addMapLayer(l1) # should be no extra signals emitted self.assertEqual(len(layer_was_added_spy), 2) self.assertEqual(len(layers_added_spy), 2) @@ -123,63 +123,63 @@ class TestQgsMapLayerRegistry(unittest.TestCase): def test_addMapLayers(self): """ test adding multiple map layers to registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() l1 = createLayer('test') l2 = createLayer('test2') - self.assertEqual(set(QgsMapLayerRegistry.instance().addMapLayers([l1, l2])), set([l1, l2])) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test2')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + self.assertEqual(set(QgsProject.instance().addMapLayers([l1, l2])), set([l1, l2])) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test2')), 1) + self.assertEqual(QgsProject.instance().count(), 2) # adding more layers should leave existing layers intact l3 = createLayer('test3') l4 = createLayer('test4') - self.assertEqual(set(QgsMapLayerRegistry.instance().addMapLayers([l3, l4])), set([l3, l4])) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test2')), 1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test3')), 1) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test4')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 4) + self.assertEqual(set(QgsProject.instance().addMapLayers([l3, l4])), set([l3, l4])) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test2')), 1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test3')), 1) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test4')), 1) + self.assertEqual(QgsProject.instance().count(), 4) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_addMapLayersInvalid(self): """ test that invalid map layersd can't be added to registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayers([QgsVectorLayer("Point?field=x:string", 'test', "xxx")]), []) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 0) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) + self.assertEqual(QgsProject.instance().addMapLayers([QgsVectorLayer("Point?field=x:string", 'test', "xxx")]), []) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 0) + self.assertEqual(QgsProject.instance().count(), 0) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_addMapLayersAlreadyAdded(self): """ test that already added layers can't be readded to registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() l1 = createLayer('test') - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayers([l1]), [l1]) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) - self.assertEqual(QgsMapLayerRegistry.instance().addMapLayers([l1]), []) - self.assertEqual(len(QgsMapLayerRegistry.instance().mapLayersByName('test')), 1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + self.assertEqual(QgsProject.instance().addMapLayers([l1]), [l1]) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(QgsProject.instance().count(), 1) + self.assertEqual(QgsProject.instance().addMapLayers([l1]), []) + self.assertEqual(len(QgsProject.instance().mapLayersByName('test')), 1) + self.assertEqual(QgsProject.instance().count(), 1) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() @unittest.skipIf(not use_signal_spy, "No QSignalSpy available") def test_addMapLayersSignals(self): """ test that signals are correctly emitted when adding map layers""" - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() - layer_was_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layerWasAdded) - layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().layersAdded) - legend_layers_added_spy = QSignalSpy(QgsMapLayerRegistry.instance().legendLayersAdded) + layer_was_added_spy = QSignalSpy(QgsProject.instance().layerWasAdded) + layers_added_spy = QSignalSpy(QgsProject.instance().layersAdded) + legend_layers_added_spy = QSignalSpy(QgsProject.instance().legendLayersAdded) l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) # can't seem to actually test the data which was emitted, so best we can do is test # the signal count @@ -188,13 +188,13 @@ class TestQgsMapLayerRegistry(unittest.TestCase): self.assertEqual(len(legend_layers_added_spy), 1) # layer not added to legend - QgsMapLayerRegistry.instance().addMapLayers([createLayer('test3'), createLayer('test4')], False) + QgsProject.instance().addMapLayers([createLayer('test3'), createLayer('test4')], False) self.assertEqual(len(layer_was_added_spy), 4) self.assertEqual(len(layers_added_spy), 2) self.assertEqual(len(legend_layers_added_spy), 1) # try readding a layer already in the registry - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) # should be no extra signals emitted self.assertEqual(len(layer_was_added_spy), 4) self.assertEqual(len(layers_added_spy), 2) @@ -202,99 +202,99 @@ class TestQgsMapLayerRegistry(unittest.TestCase): def test_mapLayerById(self): """ test retrieving map layer by ID """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - self.assertEqual(QgsMapLayerRegistry.instance().mapLayer('bad'), None) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayer(None), None) + self.assertEqual(QgsProject.instance().mapLayer('bad'), None) + self.assertEqual(QgsProject.instance().mapLayer(None), None) l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayer('bad'), None) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayer(None), None) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayer(l1.id()), l1) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayer(l2.id()), l2) + self.assertEqual(QgsProject.instance().mapLayer('bad'), None) + self.assertEqual(QgsProject.instance().mapLayer(None), None) + self.assertEqual(QgsProject.instance().mapLayer(l1.id()), l1) + self.assertEqual(QgsProject.instance().mapLayer(l2.id()), l2) def test_mapLayersByName(self): """ test retrieving map layer by name """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName('bad'), []) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName(None), []) + self.assertEqual(QgsProject.instance().mapLayersByName('bad'), []) + self.assertEqual(QgsProject.instance().mapLayersByName(None), []) l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName('bad'), []) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName(None), []) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName('test'), [l1]) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName('test2'), [l2]) + self.assertEqual(QgsProject.instance().mapLayersByName('bad'), []) + self.assertEqual(QgsProject.instance().mapLayersByName(None), []) + self.assertEqual(QgsProject.instance().mapLayersByName('test'), [l1]) + self.assertEqual(QgsProject.instance().mapLayersByName('test2'), [l2]) #duplicate name l3 = createLayer('test') - QgsMapLayerRegistry.instance().addMapLayer(l3) - self.assertEqual(set(QgsMapLayerRegistry.instance().mapLayersByName('test')), set([l1, l3])) + QgsProject.instance().addMapLayer(l3) + self.assertEqual(set(QgsProject.instance().mapLayersByName('test')), set([l1, l3])) def test_mapLayers(self): """ test retrieving map layers list """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - self.assertEqual(QgsMapLayerRegistry.instance().mapLayers(), {}) + self.assertEqual(QgsProject.instance().mapLayers(), {}) l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) + QgsProject.instance().addMapLayers([l1, l2]) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayers(), {l1.id(): l1, l2.id(): l2}) + self.assertEqual(QgsProject.instance().mapLayers(), {l1.id(): l1, l2.id(): l2}) def test_removeMapLayersById(self): """ test removing map layers by ID """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - QgsMapLayerRegistry.instance().removeMapLayers(['bad']) - QgsMapLayerRegistry.instance().removeMapLayers([None]) + QgsProject.instance().removeMapLayers(['bad']) + QgsProject.instance().removeMapLayers([None]) l1 = createLayer('test') l2 = createLayer('test2') l3 = createLayer('test3') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2, l3]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 3) + QgsProject.instance().addMapLayers([l1, l2, l3]) + self.assertEqual(QgsProject.instance().count(), 3) #remove bad layers - QgsMapLayerRegistry.instance().removeMapLayers(['bad']) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 3) - QgsMapLayerRegistry.instance().removeMapLayers([None]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 3) + QgsProject.instance().removeMapLayers(['bad']) + self.assertEqual(QgsProject.instance().count(), 3) + QgsProject.instance().removeMapLayers([None]) + self.assertEqual(QgsProject.instance().count(), 3) # remove valid layers l1_id = l1.id() - QgsMapLayerRegistry.instance().removeMapLayers([l1_id]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().removeMapLayers([l1_id]) + self.assertEqual(QgsProject.instance().count(), 2) # double remove - QgsMapLayerRegistry.instance().removeMapLayers([l1_id]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().removeMapLayers([l1_id]) + self.assertEqual(QgsProject.instance().count(), 2) # test that layer has been deleted self.assertTrue(sip.isdeleted(l1)) # remove multiple - QgsMapLayerRegistry.instance().removeMapLayers([l2.id(), l3.id()]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) + QgsProject.instance().removeMapLayers([l2.id(), l3.id()]) + self.assertEqual(QgsProject.instance().count(), 0) self.assertTrue(sip.isdeleted(l2)) # try removing a layer not in the registry l4 = createLayer('test4') - QgsMapLayerRegistry.instance().removeMapLayers([l4.id()]) + QgsProject.instance().removeMapLayers([l4.id()]) self.assertFalse(sip.isdeleted(l4)) # fails on qt5 due to removeMapLayers list type conversion - needs a PyName alias @@ -302,147 +302,147 @@ class TestQgsMapLayerRegistry(unittest.TestCase): @unittest.expectedFailure(QT_VERSION_STR[0] == '5') def test_removeMapLayersByLayer(self): """ test removing map layers by layer""" - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - QgsMapLayerRegistry.instance().removeMapLayers([None]) + QgsProject.instance().removeMapLayers([None]) l1 = createLayer('test') l2 = createLayer('test2') l3 = createLayer('test3') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2, l3]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 3) + QgsProject.instance().addMapLayers([l1, l2, l3]) + self.assertEqual(QgsProject.instance().count(), 3) #remove bad layers - QgsMapLayerRegistry.instance().removeMapLayers([None]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 3) + QgsProject.instance().removeMapLayers([None]) + self.assertEqual(QgsProject.instance().count(), 3) # remove valid layers - QgsMapLayerRegistry.instance().removeMapLayers([l1]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().removeMapLayers([l1]) + self.assertEqual(QgsProject.instance().count(), 2) # test that layer has been deleted self.assertTrue(sip.isdeleted(l1)) # remove multiple - QgsMapLayerRegistry.instance().removeMapLayers([l2, l3]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) + QgsProject.instance().removeMapLayers([l2, l3]) + self.assertEqual(QgsProject.instance().count(), 0) self.assertTrue(sip.isdeleted(l2)) self.assertTrue(sip.isdeleted(l3)) def test_removeMapLayerById(self): """ test removing a map layer by ID """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - QgsMapLayerRegistry.instance().removeMapLayer('bad') - QgsMapLayerRegistry.instance().removeMapLayer(None) + QgsProject.instance().removeMapLayer('bad') + QgsProject.instance().removeMapLayer(None) l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().addMapLayers([l1, l2]) + self.assertEqual(QgsProject.instance().count(), 2) #remove bad layers - QgsMapLayerRegistry.instance().removeMapLayer('bad') - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) - QgsMapLayerRegistry.instance().removeMapLayer(None) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().removeMapLayer('bad') + self.assertEqual(QgsProject.instance().count(), 2) + QgsProject.instance().removeMapLayer(None) + self.assertEqual(QgsProject.instance().count(), 2) # remove valid layers l1_id = l1.id() - QgsMapLayerRegistry.instance().removeMapLayer(l1_id) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + QgsProject.instance().removeMapLayer(l1_id) + self.assertEqual(QgsProject.instance().count(), 1) # double remove - QgsMapLayerRegistry.instance().removeMapLayer(l1_id) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + QgsProject.instance().removeMapLayer(l1_id) + self.assertEqual(QgsProject.instance().count(), 1) # test that layer has been deleted self.assertTrue(sip.isdeleted(l1)) # remove second layer - QgsMapLayerRegistry.instance().removeMapLayer(l2.id()) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) + QgsProject.instance().removeMapLayer(l2.id()) + self.assertEqual(QgsProject.instance().count(), 0) self.assertTrue(sip.isdeleted(l2)) # try removing a layer not in the registry l3 = createLayer('test3') - QgsMapLayerRegistry.instance().removeMapLayer(l3.id()) + QgsProject.instance().removeMapLayer(l3.id()) self.assertFalse(sip.isdeleted(l3)) def test_removeMapLayerByLayer(self): """ test removing a map layer by layer """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # test no crash with empty registry - QgsMapLayerRegistry.instance().removeMapLayer('bad') - QgsMapLayerRegistry.instance().removeMapLayer(None) + QgsProject.instance().removeMapLayer('bad') + QgsProject.instance().removeMapLayer(None) l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().addMapLayers([l1, l2]) + self.assertEqual(QgsProject.instance().count(), 2) #remove bad layers - QgsMapLayerRegistry.instance().removeMapLayer(None) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().removeMapLayer(None) + self.assertEqual(QgsProject.instance().count(), 2) l3 = createLayer('test3') - QgsMapLayerRegistry.instance().removeMapLayer(l3) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) + QgsProject.instance().removeMapLayer(l3) + self.assertEqual(QgsProject.instance().count(), 2) # remove valid layers - QgsMapLayerRegistry.instance().removeMapLayer(l1) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + QgsProject.instance().removeMapLayer(l1) + self.assertEqual(QgsProject.instance().count(), 1) # test that layer has been deleted self.assertTrue(sip.isdeleted(l1)) # remove second layer - QgsMapLayerRegistry.instance().removeMapLayer(l2) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) + QgsProject.instance().removeMapLayer(l2) + self.assertEqual(QgsProject.instance().count(), 0) self.assertTrue(sip.isdeleted(l2)) # try removing a layer not in the registry l3 = createLayer('test3') - QgsMapLayerRegistry.instance().removeMapLayer(l3) + QgsProject.instance().removeMapLayer(l3) self.assertFalse(sip.isdeleted(l3)) def test_removeAllMapLayers(self): """ test removing all map layers from registry """ - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() l1 = createLayer('test') l2 = createLayer('test2') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2]) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 2) - QgsMapLayerRegistry.instance().removeAllMapLayers() - self.assertEqual(QgsMapLayerRegistry.instance().count(), 0) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName('test'), []) - self.assertEqual(QgsMapLayerRegistry.instance().mapLayersByName('test2'), []) + QgsProject.instance().addMapLayers([l1, l2]) + self.assertEqual(QgsProject.instance().count(), 2) + QgsProject.instance().removeAllMapLayers() + self.assertEqual(QgsProject.instance().count(), 0) + self.assertEqual(QgsProject.instance().mapLayersByName('test'), []) + self.assertEqual(QgsProject.instance().mapLayersByName('test2'), []) @unittest.skipIf(not use_signal_spy, "No QSignalSpy available") def test_addRemoveLayersSignals(self): """ test that signals are correctly emitted when removing map layers""" - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() - layers_will_be_removed_spy = QSignalSpy(QgsMapLayerRegistry.instance().layersWillBeRemoved) - layer_will_be_removed_spy_str = QSignalSpy(QgsMapLayerRegistry.instance().layerWillBeRemoved[str]) - layer_will_be_removed_spy_layer = QSignalSpy(QgsMapLayerRegistry.instance().layerWillBeRemoved[QgsMapLayer]) - layers_removed_spy = QSignalSpy(QgsMapLayerRegistry.instance().layersRemoved) - layer_removed_spy = QSignalSpy(QgsMapLayerRegistry.instance().layerRemoved) - remove_all_spy = QSignalSpy(QgsMapLayerRegistry.instance().removeAll) + layers_will_be_removed_spy = QSignalSpy(QgsProject.instance().layersWillBeRemoved) + layer_will_be_removed_spy_str = QSignalSpy(QgsProject.instance().layerWillBeRemoved[str]) + layer_will_be_removed_spy_layer = QSignalSpy(QgsProject.instance().layerWillBeRemoved[QgsMapLayer]) + layers_removed_spy = QSignalSpy(QgsProject.instance().layersRemoved) + layer_removed_spy = QSignalSpy(QgsProject.instance().layerRemoved) + remove_all_spy = QSignalSpy(QgsProject.instance().removeAll) l1 = createLayer('l1') l2 = createLayer('l2') l3 = createLayer('l3') l4 = createLayer('l4') - QgsMapLayerRegistry.instance().addMapLayers([l1, l2, l3, l4]) + QgsProject.instance().addMapLayers([l1, l2, l3, l4]) # remove 1 layer - QgsMapLayerRegistry.instance().removeMapLayer(l1) + QgsProject.instance().removeMapLayer(l1) # can't seem to actually test the data which was emitted, so best we can do is test # the signal count self.assertEqual(len(layers_will_be_removed_spy), 1) @@ -451,20 +451,20 @@ class TestQgsMapLayerRegistry(unittest.TestCase): self.assertEqual(len(layers_removed_spy), 1) self.assertEqual(len(layer_removed_spy), 1) self.assertEqual(len(remove_all_spy), 0) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 3) + self.assertEqual(QgsProject.instance().count(), 3) # remove 2 layers at once - QgsMapLayerRegistry.instance().removeMapLayers([l2.id(), l3.id()]) + QgsProject.instance().removeMapLayers([l2.id(), l3.id()]) self.assertEqual(len(layers_will_be_removed_spy), 2) self.assertEqual(len(layer_will_be_removed_spy_str), 3) self.assertEqual(len(layer_will_be_removed_spy_layer), 3) self.assertEqual(len(layers_removed_spy), 2) self.assertEqual(len(layer_removed_spy), 3) self.assertEqual(len(remove_all_spy), 0) - self.assertEqual(QgsMapLayerRegistry.instance().count(), 1) + self.assertEqual(QgsProject.instance().count(), 1) # remove all - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() self.assertEqual(len(layers_will_be_removed_spy), 3) self.assertEqual(len(layer_will_be_removed_spy_str), 4) self.assertEqual(len(layer_will_be_removed_spy_layer), 4) @@ -473,7 +473,7 @@ class TestQgsMapLayerRegistry(unittest.TestCase): self.assertEqual(len(remove_all_spy), 1) #remove some layers which aren't in the registry - QgsMapLayerRegistry.instance().removeMapLayers(['asdasd']) + QgsProject.instance().removeMapLayers(['asdasd']) self.assertEqual(len(layers_will_be_removed_spy), 3) self.assertEqual(len(layer_will_be_removed_spy_str), 4) self.assertEqual(len(layer_will_be_removed_spy_layer), 4) @@ -482,7 +482,7 @@ class TestQgsMapLayerRegistry(unittest.TestCase): self.assertEqual(len(remove_all_spy), 1) l5 = createLayer('test5') - QgsMapLayerRegistry.instance().removeMapLayer(l5) + QgsProject.instance().removeMapLayer(l5) self.assertEqual(len(layers_will_be_removed_spy), 3) self.assertEqual(len(layer_will_be_removed_spy_str), 4) self.assertEqual(len(layer_will_be_removed_spy_layer), 4) @@ -491,9 +491,9 @@ class TestQgsMapLayerRegistry(unittest.TestCase): self.assertEqual(len(remove_all_spy), 1) def test_RemoveLayerShouldNotSegFault(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() - reg = QgsMapLayerRegistry.instance() + reg = QgsProject.instance() # Should not segfault reg.removeMapLayers(['not_exists']) reg.removeMapLayer('not_exists2') diff --git a/tests/src/python/test_qgsnewgeopackagelayerdialog.py b/tests/src/python/test_qgsnewgeopackagelayerdialog.py index 5125707d034..396c8561669 100644 --- a/tests/src/python/test_qgsnewgeopackagelayerdialog.py +++ b/tests/src/python/test_qgsnewgeopackagelayerdialog.py @@ -22,7 +22,7 @@ from qgis.PyQt.QtCore import QObject, QCoreApplication, QSettings, Qt, QEventLoo from qgis.PyQt.QtWidgets import QApplication, QWidget, QLineEdit, QDialogButtonBox, QTreeWidget, QComboBox, QPushButton, QToolButton from qgis.PyQt.QtTest import QTest -from qgis.core import Qgis, QgsMapLayerRegistry, QgsWkbTypes +from qgis.core import Qgis, QgsProject, QgsWkbTypes from qgis.gui import QgsNewGeoPackageLayerDialog from qgis.testing import (start_app, unittest @@ -146,12 +146,12 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase): QTest.mouseClick(ok_button, Qt.LeftButton) self.assertTrue(self.accepted) - layers = QgsMapLayerRegistry.instance().mapLayers() + layers = QgsProject.instance().mapLayers() self.assertEqual(len(layers), 1) layer = layers[list(layers.keys())[0]] self.assertEqual(layer.name(), 'test') self.assertEqual(layer.geometryType(), QgsWkbTypes.PointGeometry) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() ds = ogr.Open(dbname) lyr = ds.GetLayer(0) @@ -205,7 +205,7 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase): dialog.setProperty('question_existing_db_answer_add_new_layer', None) self.assertTrue(self.accepted) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() ds = ogr.Open(dbname) self.assertEqual(ds.GetLayerCount(), 2) ds = None @@ -217,7 +217,7 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase): dialog.setProperty('question_existing_db_answer_overwrite', None) self.assertTrue(self.accepted) - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() ds = ogr.Open(dbname) self.assertEqual(ds.GetLayerCount(), 1) ds = None @@ -244,11 +244,11 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase): # Only check with OGR 2.0 since the IDENTIFIER and DESCRIPTION creation options don't exist in OGR 1.11 if version_num >= GDAL_COMPUTE_VERSION(2, 0, 0): - layers = QgsMapLayerRegistry.instance().mapLayers() + layers = QgsProject.instance().mapLayers() self.assertEqual(len(layers), 1) layer = layers[list(layers.keys())[0]] self.assertEqual(layer.name(), 'my_identifier') - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() ds = ogr.Open(dbname) sql_lyr = ds.ExecuteSQL('SELECT * FROM gpkg_contents') @@ -262,7 +262,7 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase): self.assertEqual(identifier, 'my_identifier') self.assertEqual(description, 'my_description') else: - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() # Try invalid path mDatabaseEdit.setText('/this/is/invalid/test.gpkg') diff --git a/tests/src/python/test_qgsnullsymbolrenderer.py b/tests/src/python/test_qgsnullsymbolrenderer.py index 1644a47603e..65c2aedd827 100644 --- a/tests/src/python/test_qgsnullsymbolrenderer.py +++ b/tests/src/python/test_qgsnullsymbolrenderer.py @@ -30,7 +30,7 @@ import os from qgis.PyQt.QtCore import QSize from qgis.core import (QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsMultiRenderChecker, QgsNullSymbolRenderer, @@ -52,7 +52,7 @@ class TestQgsNullSymbolRenderer(unittest.TestCase): self.iface = get_iface() myShpFile = os.path.join(TEST_DATA_DIR, 'polys.shp') self.layer = QgsVectorLayer(myShpFile, 'Polys', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(self.layer) + QgsProject.instance().addMapLayer(self.layer) self.renderer = QgsNullSymbolRenderer() self.layer.setRenderer(self.renderer) @@ -65,7 +65,7 @@ class TestQgsNullSymbolRenderer(unittest.TestCase): self.mapsettings.setLayers(rendered_layers) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def testRender(self): # test no features are rendered diff --git a/tests/src/python/test_qgspallabeling_base.py b/tests/src/python/test_qgspallabeling_base.py index 02685a4f7f9..1dab378bf43 100644 --- a/tests/src/python/test_qgspallabeling_base.py +++ b/tests/src/python/test_qgspallabeling_base.py @@ -36,7 +36,7 @@ from qgis.PyQt.QtGui import QFont, QColor from qgis.core import ( QgsCoordinateReferenceSystem, QgsDataSourceUri, - QgsMapLayerRegistry, + QgsProject, QgsMapSettings, QgsPalLabeling, QgsPalLayerSettings, @@ -76,7 +76,7 @@ class TestQgsPalLabeling(unittest.TestCase): _TestFont = getTestFont() # Roman at 12 pt """:type: QFont""" _MapRegistry = None - """:type: QgsMapLayerRegistry""" + """:type: QgsProject""" _MapSettings = None """:type: QgsMapSettings""" _Canvas = None @@ -113,7 +113,7 @@ class TestQgsPalLabeling(unittest.TestCase): # initialize class MapRegistry, Canvas, MapRenderer, Map and PAL # noinspection PyArgumentList - cls._MapRegistry = QgsMapLayerRegistry.instance() + cls._MapRegistry = QgsProject.instance() cls._MapSettings = cls.getBaseMapSettings() osize = cls._MapSettings.outputSize() diff --git a/tests/src/python/test_qgspointclusterrenderer.py b/tests/src/python/test_qgspointclusterrenderer.py index 6ae986493ad..a24c1291fb6 100644 --- a/tests/src/python/test_qgspointclusterrenderer.py +++ b/tests/src/python/test_qgspointclusterrenderer.py @@ -30,7 +30,7 @@ from qgis.PyQt.QtGui import QColor from qgis.PyQt.QtXml import (QDomDocument, QDomElement) from qgis.core import (QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsMultiRenderChecker, QgsPointClusterRenderer, @@ -57,7 +57,7 @@ class TestQgsPointClusterRenderer(unittest.TestCase): def setUp(self): myShpFile = os.path.join(TEST_DATA_DIR, 'points.shp') self.layer = QgsVectorLayer(myShpFile, 'Points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(self.layer) + QgsProject.instance().addMapLayer(self.layer) self.renderer = QgsPointClusterRenderer() sym1 = QgsMarkerSymbol.createSimple({'color': '#ff00ff', 'size': '3', 'outline_style': 'no'}) @@ -74,7 +74,7 @@ class TestQgsPointClusterRenderer(unittest.TestCase): self.mapsettings.setLayers(rendered_layers) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def _setProperties(self, r): """ set properties for a renderer for testing with _checkProperties""" diff --git a/tests/src/python/test_qgspointdisplacementrenderer.py b/tests/src/python/test_qgspointdisplacementrenderer.py index b5637cadb7f..2472d3b28f7 100644 --- a/tests/src/python/test_qgspointdisplacementrenderer.py +++ b/tests/src/python/test_qgspointdisplacementrenderer.py @@ -32,7 +32,7 @@ from qgis.PyQt.QtCore import QSize from qgis.PyQt.QtXml import (QDomDocument, QDomElement) from qgis.core import (QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsMultiRenderChecker, QgsPointDisplacementRenderer, @@ -59,7 +59,7 @@ class TestQgsPointDisplacementRenderer(unittest.TestCase): def setUp(self): myShpFile = os.path.join(TEST_DATA_DIR, 'points.shp') self.layer = QgsVectorLayer(myShpFile, 'Points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(self.layer) + QgsProject.instance().addMapLayer(self.layer) self.renderer = QgsPointDisplacementRenderer() sym1 = QgsMarkerSymbol.createSimple({'color': '#ff00ff', 'size': '3', 'outline_style': 'no'}) @@ -79,7 +79,7 @@ class TestQgsPointDisplacementRenderer(unittest.TestCase): self.mapsettings.setLayers(rendered_layers) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def _setProperties(self, r): """ set properties for a renderer for testing with _checkProperties""" diff --git a/tests/src/python/test_qgsrasterlayer.py b/tests/src/python/test_qgsrasterlayer.py index 55ed8874931..9c3d30ab2e2 100644 --- a/tests/src/python/test_qgsrasterlayer.py +++ b/tests/src/python/test_qgsrasterlayer.py @@ -24,7 +24,7 @@ from qgis.core import (QgsRaster, QgsRasterLayer, QgsColorRampShader, QgsContrastEnhancement, - QgsMapLayerRegistry, + QgsProject, QgsMapSettings, QgsPoint, QgsRasterShader, @@ -132,7 +132,7 @@ class TestQgsRasterLayer(unittest.TestCase): rasterRenderer.setRasterTransparency(rasterTransparency) - QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer, ]) + QgsProject.instance().addMapLayers([myRasterLayer, ]) myMapSettings = QgsMapSettings() myMapSettings.setLayers([myRasterLayer.id()]) @@ -155,7 +155,7 @@ class TestQgsRasterLayer(unittest.TestCase): myMessage = 'Raster not loaded: %s' % myPath assert myRasterLayer.isValid(), myMessage # crash on next line - QgsMapLayerRegistry.instance().addMapLayers([myRasterLayer]) + QgsProject.instance().addMapLayers([myRasterLayer]) def testShaderCrash(self): """Check if we assign a shader and then reassign it no crash occurs.""" diff --git a/tests/src/python/test_qgsrelation.py b/tests/src/python/test_qgsrelation.py index f9762bb10e4..6380e1698cc 100644 --- a/tests/src/python/test_qgsrelation.py +++ b/tests/src/python/test_qgsrelation.py @@ -19,7 +19,7 @@ from qgis.core import (QgsVectorLayer, QgsRelation, QgsGeometry, QgsPoint, - QgsMapLayerRegistry + QgsProject ) from qgis.testing import start_app, unittest @@ -72,10 +72,10 @@ class TestQgsRelation(unittest.TestCase): def setUp(self): self.referencedLayer = createReferencedLayer() self.referencingLayer = createReferencingLayer() - QgsMapLayerRegistry.instance().addMapLayers([self.referencedLayer, self.referencingLayer]) + QgsProject.instance().addMapLayers([self.referencedLayer, self.referencingLayer]) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def test_isValid(self): rel = QgsRelation() diff --git a/tests/src/python/test_qgsrelationeditwidget.py b/tests/src/python/test_qgsrelationeditwidget.py index d184500b4f8..21e81790db5 100644 --- a/tests/src/python/test_qgsrelationeditwidget.py +++ b/tests/src/python/test_qgsrelationeditwidget.py @@ -21,7 +21,6 @@ from qgis.core import ( QgsVectorLayer, QgsProject, QgsRelation, - QgsMapLayerRegistry, QgsTransaction, QgsFeatureRequest, QgsVectorLayerTools @@ -57,9 +56,9 @@ class TestQgsRelationEditWidget(unittest.TestCase): cls.vl_a = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' table="qgis_test"."authors" sql=', 'authors', 'postgres') cls.vl_link = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' table="qgis_test"."books_authors" sql=', 'books_authors', 'postgres') - QgsMapLayerRegistry.instance().addMapLayer(cls.vl_b) - QgsMapLayerRegistry.instance().addMapLayer(cls.vl_a) - QgsMapLayerRegistry.instance().addMapLayer(cls.vl_link) + QgsProject.instance().addMapLayer(cls.vl_b) + QgsProject.instance().addMapLayer(cls.vl_a) + QgsProject.instance().addMapLayer(cls.vl_link) cls.relMgr = QgsProject.instance().relationManager() diff --git a/tests/src/python/test_qgsrelationmanager.py b/tests/src/python/test_qgsrelationmanager.py index 3dcd90080fb..f203357af0f 100644 --- a/tests/src/python/test_qgsrelationmanager.py +++ b/tests/src/python/test_qgsrelationmanager.py @@ -17,7 +17,7 @@ import qgis # NOQA from qgis.core import (QgsVectorLayer, QgsRelation, QgsRelationManager, - QgsMapLayerRegistry + QgsProject ) from qgis.testing import start_app, unittest @@ -42,10 +42,10 @@ class TestQgsRelationManager(unittest.TestCase): def setUp(self): self.referencedLayer = createReferencedLayer() self.referencingLayer = createReferencingLayer() - QgsMapLayerRegistry.instance().addMapLayers([self.referencedLayer, self.referencingLayer]) + QgsProject.instance().addMapLayers([self.referencedLayer, self.referencingLayer]) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def createRelation(self): rel = QgsRelation() diff --git a/tests/src/python/test_qgsrulebasedrenderer.py b/tests/src/python/test_qgsrulebasedrenderer.py index bfb12bc2d67..1a8b57dab4a 100644 --- a/tests/src/python/test_qgsrulebasedrenderer.py +++ b/tests/src/python/test_qgsrulebasedrenderer.py @@ -30,7 +30,7 @@ import os from qgis.PyQt.QtCore import QSize from qgis.core import (QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsMultiRenderChecker, QgsRuleBasedRenderer, @@ -57,7 +57,7 @@ class TestQgsRulebasedRenderer(unittest.TestCase): self.iface = get_iface() myShpFile = os.path.join(TEST_DATA_DIR, 'rectangles.shp') layer = QgsVectorLayer(myShpFile, 'Points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(layer) + QgsProject.instance().addMapLayer(layer) # Create rulebased style sym1 = QgsFillSymbol.createSimple({'color': '#fdbf6f'}) @@ -84,7 +84,7 @@ class TestQgsRulebasedRenderer(unittest.TestCase): self.mapsettings.setLayers(rendered_layers) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def testElse(self): # Setup rendering check diff --git a/tests/src/python/test_qgssearchwidgetwrapper.py b/tests/src/python/test_qgssearchwidgetwrapper.py index 82b9fed2e1e..ccbd555b01e 100644 --- a/tests/src/python/test_qgssearchwidgetwrapper.py +++ b/tests/src/python/test_qgssearchwidgetwrapper.py @@ -22,7 +22,7 @@ from qgis.gui import (QgsSearchWidgetWrapper, QgsDateTimeSearchWidgetWrapper) from qgis.core import (QgsVectorLayer, QgsFeature, - QgsMapLayerRegistry, + QgsProject, ) from qgis.PyQt.QtCore import QDateTime, QDate, QTime from qgis.PyQt.QtWidgets import QWidget @@ -179,7 +179,7 @@ class PyQgsValueRelationSearchWidgetWrapper(unittest.TestCase): f3 = QgsFeature(parent_layer.fields(), 3) f3.setAttributes(['c', 3, 'value c']) parent_layer.dataProvider().addFeatures([f1, f2, f3]) - QgsMapLayerRegistry.instance().addMapLayers([layer, parent_layer]) + QgsProject.instance().addMapLayers([layer, parent_layer]) config = {"Layer": parent_layer.id(), "Key": 'stringkey', diff --git a/tests/src/python/test_qgssinglesymbolrenderer.py b/tests/src/python/test_qgssinglesymbolrenderer.py index 880e2611f08..a8aaaaaf48b 100644 --- a/tests/src/python/test_qgssinglesymbolrenderer.py +++ b/tests/src/python/test_qgssinglesymbolrenderer.py @@ -30,7 +30,7 @@ import os from qgis.PyQt.QtCore import QSize from qgis.core import (QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsMultiRenderChecker, QgsSingleSymbolRenderer, @@ -50,7 +50,7 @@ class TestQgsSingleSymbolRenderer(unittest.TestCase): self.iface = get_iface() myShpFile = os.path.join(TEST_DATA_DIR, 'polys_overlapping.shp') layer = QgsVectorLayer(myShpFile, 'Polys', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(layer) + QgsProject.instance().addMapLayer(layer) # Create rulebased style sym1 = QgsFillSymbol.createSimple({'color': '#fdbf6f'}) diff --git a/tests/src/python/test_qgssymbolexpressionvariables.py b/tests/src/python/test_qgssymbolexpressionvariables.py index d00e0a835f7..6738a276b83 100644 --- a/tests/src/python/test_qgssymbolexpressionvariables.py +++ b/tests/src/python/test_qgssymbolexpressionvariables.py @@ -31,7 +31,7 @@ from qgis.PyQt.QtCore import QSize from qgis.core import ( QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsRectangle, QgsMultiRenderChecker, QgsSingleSymbolRenderer, @@ -53,7 +53,7 @@ class TestQgsSymbolExpressionVariables(unittest.TestCase): def setUp(self): myShpFile = os.path.join(TEST_DATA_DIR, 'polys.shp') self.layer = QgsVectorLayer(myShpFile, 'Polys', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(self.layer) + QgsProject.instance().addMapLayer(self.layer) self.iface = get_iface() rendered_layers = [self.layer.id()] @@ -64,7 +64,7 @@ class TestQgsSymbolExpressionVariables(unittest.TestCase): self.mapsettings.setLayers(rendered_layers) def tearDown(self): - QgsMapLayerRegistry.instance().removeAllMapLayers() + QgsProject.instance().removeAllMapLayers() def testPartNum(self): # Create rulebased style diff --git a/tests/src/python/test_qgssymbollayer.py b/tests/src/python/test_qgssymbollayer.py index 5fa7ee132c3..2cb8f8461a1 100644 --- a/tests/src/python/test_qgssymbollayer.py +++ b/tests/src/python/test_qgssymbollayer.py @@ -67,7 +67,7 @@ from qgis.core import (QgsCentroidFillSymbolLayer, QgsRenderChecker, QgsRectangle, QgsVectorLayer, - QgsMapLayerRegistry, + QgsProject, QgsMultiRenderChecker, QgsSingleSymbolRenderer, QgsDataDefined @@ -405,7 +405,7 @@ class TestQgsSymbolLayer(unittest.TestCase): polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp') polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(polys_layer) + QgsProject.instance().addMapLayer(polys_layer) layer = QgsSimpleFillSymbolLayer() layer.setDataDefinedProperty("enabled", QgsDataDefined("Name='Lake'")) @@ -427,7 +427,7 @@ class TestQgsSymbolLayer(unittest.TestCase): renderchecker.setControlPathPrefix('symbol_layer') renderchecker.setControlName('expected_filllayer_ddenabled') self.assertTrue(renderchecker.runTest('filllayer_ddenabled')) - QgsMapLayerRegistry.instance().removeMapLayer(polys_layer) + QgsProject.instance().removeMapLayer(polys_layer) def testRenderLineLayerDisabled(self): """ test that rendering a line symbol with disabled layer works""" @@ -470,7 +470,7 @@ class TestQgsSymbolLayer(unittest.TestCase): lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp') lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(lines_layer) + QgsProject.instance().addMapLayer(lines_layer) layer = QgsSimpleLineSymbolLayer() layer.setDataDefinedProperty("enabled", QgsDataDefined("Name='Highway'")) @@ -492,7 +492,7 @@ class TestQgsSymbolLayer(unittest.TestCase): renderchecker.setControlPathPrefix('symbol_layer') renderchecker.setControlName('expected_linelayer_ddenabled') self.assertTrue(renderchecker.runTest('linelayer_ddenabled')) - QgsMapLayerRegistry.instance().removeMapLayer(lines_layer) + QgsProject.instance().removeMapLayer(lines_layer) def testRenderMarkerLayerDisabled(self): """ test that rendering a marker symbol with disabled layer works""" @@ -533,7 +533,7 @@ class TestQgsSymbolLayer(unittest.TestCase): points_shp = os.path.join(TEST_DATA_DIR, 'points.shp') points_layer = QgsVectorLayer(points_shp, 'Points', 'ogr') - QgsMapLayerRegistry.instance().addMapLayer(points_layer) + QgsProject.instance().addMapLayer(points_layer) layer = QgsSimpleMarkerSymbolLayer() layer.setDataDefinedProperty("enabled", QgsDataDefined("Class='Biplane'")) @@ -556,7 +556,7 @@ class TestQgsSymbolLayer(unittest.TestCase): renderchecker.setControlPathPrefix('symbol_layer') renderchecker.setControlName('expected_markerlayer_ddenabled') self.assertTrue(renderchecker.runTest('markerlayer_ddenabled')) - QgsMapLayerRegistry.instance().removeMapLayer(points_layer) + QgsProject.instance().removeMapLayer(points_layer) def testQgsSimpleFillSymbolLayer(self): """Create a new style from a .sld file and match test. diff --git a/tests/src/python/test_qgsvectorlayer.py b/tests/src/python/test_qgsvectorlayer.py index 441c328739b..e5bf47b75a0 100644 --- a/tests/src/python/test_qgsvectorlayer.py +++ b/tests/src/python/test_qgsvectorlayer.py @@ -31,7 +31,6 @@ from qgis.core import (Qgis, QgsField, QgsFieldConstraints, QgsFields, - QgsMapLayerRegistry, QgsVectorJoinInfo, QgsSymbol, QgsSingleSymbolRenderer, @@ -1194,7 +1193,7 @@ class TestQgsVectorLayer(unittest.TestCase): joinLayer = createJoinLayer() joinLayer2 = createJoinLayer() - QgsMapLayerRegistry.instance().addMapLayers([joinLayer, joinLayer2]) + QgsProject.instance().addMapLayers([joinLayer, joinLayer2]) layer = createLayerWithOnePoint() @@ -1248,7 +1247,7 @@ class TestQgsVectorLayer(unittest.TestCase): """ test calculating min/max/uniqueValues on joined field """ joinLayer = createJoinLayer() layer = createLayerWithTwoPoints() - QgsMapLayerRegistry.instance().addMapLayers([joinLayer, layer]) + QgsProject.instance().addMapLayers([joinLayer, layer]) join = QgsVectorJoinInfo() join.targetFieldName = "fldint" diff --git a/tests/src/python/test_qgsvectorlayereditbuffer.py b/tests/src/python/test_qgsvectorlayereditbuffer.py index 40ecc1076fb..5d8c512a1df 100644 --- a/tests/src/python/test_qgsvectorlayereditbuffer.py +++ b/tests/src/python/test_qgsvectorlayereditbuffer.py @@ -29,7 +29,6 @@ from qgis.core import (Qgis, QgsPoint, QgsField, QgsFields, - QgsMapLayerRegistry, QgsVectorJoinInfo, QgsSymbol, QgsSingleSymbolRenderer, diff --git a/tests/src/python/test_qgsvectorlayertools.py b/tests/src/python/test_qgsvectorlayertools.py index 2fcd4612897..2ce3f47ce7f 100644 --- a/tests/src/python/test_qgsvectorlayertools.py +++ b/tests/src/python/test_qgsvectorlayertools.py @@ -15,7 +15,7 @@ __copyright__ = 'Copyright 2015, The QGIS Project' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' -from qgis.core import QgsFeatureRequest, QgsVectorLayer, QgsMapLayerRegistry, QgsVectorLayerTools +from qgis.core import QgsFeatureRequest, QgsVectorLayer, QgsProject, QgsVectorLayerTools from qgis.testing import start_app, unittest import os @@ -55,7 +55,7 @@ class TestQgsVectorLayerTools(unittest.TestCase): # Create test layer cls.vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' table="qgis_test"."someData" (geom) sql=', 'layer', 'postgres') - QgsMapLayerRegistry.instance().addMapLayer(cls.vl) + QgsProject.instance().addMapLayer(cls.vl) cls.vltools = SubQgsVectorLayerTools() diff --git a/tests/src/python/utilities.py b/tests/src/python/utilities.py index 20caf949f2a..a1a86023357 100644 --- a/tests/src/python/utilities.py +++ b/tests/src/python/utilities.py @@ -29,7 +29,7 @@ from qgis.PyQt.QtCore import QDir from qgis.core import ( QgsCoordinateReferenceSystem, QgsVectorFileWriter, - QgsMapLayerRegistry, + QgsProject, QgsMapSettings, QgsMapRendererParallelJob, QgsMapRendererSequentialJob, @@ -241,7 +241,7 @@ def mapSettingsString(ms): s = 'MapSettings...\n' s += ' layers(): {0}\n'.format( - [QgsMapLayerRegistry.instance().mapLayer(i).name() + [QgsProject.instance().mapLayer(i).name() for i in ms.layers()]) s += ' backgroundColor(): rgba {0},{1},{2},{3}\n'.format( ms.backgroundColor().red(), ms.backgroundColor().green(),