mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
Expose QgsProject::setInstance to API
Fixes #38755 Needs forward porting to all active branches
This commit is contained in:
parent
f018252023
commit
c80093c47a
@ -69,6 +69,20 @@ open within the main QGIS application.
|
|||||||
Returns the QgsProject singleton instance
|
Returns the QgsProject singleton instance
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
static void setInstance( QgsProject *project );
|
||||||
|
%Docstring
|
||||||
|
Set the current project instance to ``project``
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
this is used mainly by the server, which caches the projects and (potentially) needs to switch the current instance on every request
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`instance`
|
||||||
|
|
||||||
|
.. versionadded:: 3.10
|
||||||
|
%End
|
||||||
|
|
||||||
|
|
||||||
explicit QgsProject( QObject *parent /TransferThis/ = 0 );
|
explicit QgsProject( QObject *parent /TransferThis/ = 0 );
|
||||||
%Docstring
|
%Docstring
|
||||||
Create a new QgsProject.
|
Create a new QgsProject.
|
||||||
|
@ -165,6 +165,16 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
|
|||||||
//! Returns the QgsProject singleton instance
|
//! Returns the QgsProject singleton instance
|
||||||
static QgsProject *instance();
|
static QgsProject *instance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current project instance to \a project
|
||||||
|
*
|
||||||
|
* \note this is used mainly by the server, which caches the projects and (potentially) needs to switch the current instance on every request
|
||||||
|
* \see instance()
|
||||||
|
* \since QGIS 3.10.11
|
||||||
|
*/
|
||||||
|
static void setInstance( QgsProject *project ) ;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new QgsProject.
|
* Create a new QgsProject.
|
||||||
*
|
*
|
||||||
@ -1837,15 +1847,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
|
|||||||
|
|
||||||
static QgsProject *sProject;
|
static QgsProject *sProject;
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the current project instance to \a project
|
|
||||||
*
|
|
||||||
* \note this is used mainly by the server, which caches the projects and (potentially) needs to switch the current instance on every request
|
|
||||||
* \see instance()
|
|
||||||
* \note not available in Python bindings
|
|
||||||
* \since QGIS 3.2
|
|
||||||
*/
|
|
||||||
static void setInstance( QgsProject *project ) SIP_SKIP;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read map layers from project file.
|
* Read map layers from project file.
|
||||||
|
@ -1360,6 +1360,14 @@ class TestQgsProject(unittest.TestCase):
|
|||||||
p.setUseProjectScales(False)
|
p.setUseProjectScales(False)
|
||||||
self.assertEqual(len(spy), 4)
|
self.assertEqual(len(spy), 4)
|
||||||
|
|
||||||
|
def testSetInstance(self):
|
||||||
|
"""Test singleton API"""
|
||||||
|
|
||||||
|
p = QgsProject()
|
||||||
|
self.assertNotEqual(p, QgsProject.instance())
|
||||||
|
QgsProject.setInstance(p)
|
||||||
|
self.assertEqual(p, QgsProject.instance())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user