Expose Account API to QML

This is done by adding the API as an SingletonType to Cura.

CURA-5744
This commit is contained in:
Jaime van Kessel 2018-09-21 17:23:30 +02:00
parent b54383e685
commit 081b2a28fe
4 changed files with 36 additions and 5 deletions

View file

@ -204,6 +204,7 @@ class CuraApplication(QtApplication):
self._quality_profile_drop_down_menu_model = None
self._custom_quality_profile_drop_down_menu_model = None
self._cura_API = None
self._physics = None
self._volume = None
@ -894,6 +895,12 @@ class CuraApplication(QtApplication):
self._custom_quality_profile_drop_down_menu_model = CustomQualityProfilesDropDownMenuModel(self)
return self._custom_quality_profile_drop_down_menu_model
def getCuraAPI(self, *args, **kwargs):
if self._cura_API is None:
from cura.API import CuraAPI
self._cura_API = CuraAPI()
return self._cura_API
## Registers objects for the QML engine to use.
#
# \param engine The QML engine.
@ -942,6 +949,9 @@ class CuraApplication(QtApplication):
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.getInstance)
qmlRegisterType(SidebarCustomMenuItemsModel, "Cura", 1, 0, "SidebarCustomMenuItemsModel")
from cura.API import CuraAPI
qmlRegisterSingletonType(CuraAPI, "Cura", 1, 1, "API", self.getCuraAPI)
# As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
qmlRegisterSingletonType(actions_url, "Cura", 1, 0, "Actions")