mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -06:00
Add sidebar views menu item and expose model to QML
This commit is contained in:
parent
713055e320
commit
4ef39ca313
5 changed files with 37 additions and 8 deletions
|
@ -38,6 +38,7 @@ from cura.ShapeArray import ShapeArray
|
||||||
from cura.ConvexHullDecorator import ConvexHullDecorator
|
from cura.ConvexHullDecorator import ConvexHullDecorator
|
||||||
from cura.SetParentOperation import SetParentOperation
|
from cura.SetParentOperation import SetParentOperation
|
||||||
from cura.Sidebar.SidebarController import SidebarController
|
from cura.Sidebar.SidebarController import SidebarController
|
||||||
|
from cura.Sidebar.SidebarViewModel import SidebarViewModel
|
||||||
from cura.SliceableObjectDecorator import SliceableObjectDecorator
|
from cura.SliceableObjectDecorator import SliceableObjectDecorator
|
||||||
from cura.BlockSlicingDecorator import BlockSlicingDecorator
|
from cura.BlockSlicingDecorator import BlockSlicingDecorator
|
||||||
|
|
||||||
|
@ -819,6 +820,7 @@ class CuraApplication(QtApplication):
|
||||||
qmlRegisterType(UserChangesModel, "Cura", 1, 1, "UserChangesModel")
|
qmlRegisterType(UserChangesModel, "Cura", 1, 1, "UserChangesModel")
|
||||||
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
|
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
|
||||||
qmlRegisterSingletonType(SidebarController, "Cura", 1, 0, "SidebarController", self.getSidebarController)
|
qmlRegisterSingletonType(SidebarController, "Cura", 1, 0, "SidebarController", self.getSidebarController)
|
||||||
|
qmlRegisterType(SidebarViewModel, "Cura", 1, 0, "SidebarViewModel")
|
||||||
|
|
||||||
# As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
|
# 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")))
|
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
|
||||||
|
|
|
@ -9,6 +9,10 @@ class SettingsSidebarView(QObject, SidebarView):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
## As the default sidebar is not a plugin, we have a get plugin ID method to allow the sidebar view model to get the needed data.
|
||||||
|
def getPluginId(self):
|
||||||
|
return "default"
|
||||||
|
|
||||||
## As the default sidebar is not a plugin, we have a get meta data method here to allow the sidebar view model to get the needed data.
|
## As the default sidebar is not a plugin, we have a get meta data method here to allow the sidebar view model to get the needed data.
|
||||||
def getMetaData(self):
|
def getMetaData(self):
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -46,6 +46,7 @@ class SidebarController:
|
||||||
## Change the active sidebar view to one of the registered views.
|
## Change the active sidebar view to one of the registered views.
|
||||||
def setActiveSidebarView(self, name: str):
|
def setActiveSidebarView(self, name: str):
|
||||||
print("setting active sidebar view")
|
print("setting active sidebar view")
|
||||||
|
self.activeSidebarViewChanged.emit()
|
||||||
|
|
||||||
## Get all sidebar views registered in this controller.
|
## Get all sidebar views registered in this controller.
|
||||||
def getAllSidebarViews(self) -> Dict[SidebarView]:
|
def getAllSidebarViews(self) -> Dict[SidebarView]:
|
||||||
|
|
|
@ -13,7 +13,10 @@ class SidebarViewModel(ListModel):
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
# connect views changed signals
|
||||||
self._controller = Application.getInstance().getSidebarController()
|
self._controller = Application.getInstance().getSidebarController()
|
||||||
|
self._controller.sidebarViewsChanged.connect(self._onSidebarViewsChanged)
|
||||||
|
self._controller.activeSidebarViewChanged.connect(self._onSidebarViewsChanged)
|
||||||
|
|
||||||
# register Qt list roles
|
# register Qt list roles
|
||||||
self.addRoleName(self.IdRole, "id")
|
self.addRoleName(self.IdRole, "id")
|
||||||
|
@ -39,7 +42,7 @@ class SidebarViewModel(ListModel):
|
||||||
if "visible" in sidebar_view_metadata and not sidebar_view_metadata["visible"]:
|
if "visible" in sidebar_view_metadata and not sidebar_view_metadata["visible"]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = sidebar_view_metadata.get("name", id)
|
name = sidebar_view_metadata.get("name", sidebar_view_id)
|
||||||
weight = sidebar_view_metadata.get("weight", 0)
|
weight = sidebar_view_metadata.get("weight", 0)
|
||||||
|
|
||||||
items.append({
|
items.append({
|
||||||
|
|
|
@ -12,21 +12,40 @@ Menu
|
||||||
title: catalog.i18nc("@title:menu menubar:toplevel", "&View");
|
title: catalog.i18nc("@title:menu menubar:toplevel", "&View");
|
||||||
id: menu
|
id: menu
|
||||||
enabled: !PrintInformation.preSliced
|
enabled: !PrintInformation.preSliced
|
||||||
|
|
||||||
|
// main views
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: UM.ViewModel{}
|
model: UM.ViewModel{}
|
||||||
MenuItem
|
MenuItem
|
||||||
{
|
{
|
||||||
text: model.name;
|
text: model.name
|
||||||
checkable: true;
|
checkable: true
|
||||||
checked: model.active;
|
checked: model.active
|
||||||
exclusiveGroup: group;
|
exclusiveGroup: group
|
||||||
onTriggered: UM.Controller.setActiveView(model.id);
|
onTriggered: UM.Controller.setActiveView(model.id)
|
||||||
}
|
}
|
||||||
onObjectAdded: menu.insertItem(index, object)
|
onObjectAdded: menu.insertItem(index, object)
|
||||||
onObjectRemoved: menu.removeItem(object)
|
onObjectRemoved: menu.removeItem(object)
|
||||||
}
|
}
|
||||||
ExclusiveGroup { id: group; }
|
ExclusiveGroup { id: group }
|
||||||
|
|
||||||
|
// sidebar views
|
||||||
|
Instantiator
|
||||||
|
{
|
||||||
|
model: Cura.SidebarViewModel{}
|
||||||
|
MenuItem
|
||||||
|
{
|
||||||
|
text: model.name
|
||||||
|
checkable: true
|
||||||
|
checked: model.active
|
||||||
|
exclusiveGroup: sidebarGroup
|
||||||
|
onTriggered: Cura.SidebarController.setActiveSidebarView(model.id)
|
||||||
|
}
|
||||||
|
onObjectAdded: menu.insertItem(index, object)
|
||||||
|
onObjectRemoved: menu.removeItem(object)
|
||||||
|
}
|
||||||
|
ExclusiveGroup { id: sidebarGroup }
|
||||||
|
|
||||||
MenuSeparator {}
|
MenuSeparator {}
|
||||||
MenuItem { action: Cura.Actions.homeCamera; }
|
MenuItem { action: Cura.Actions.homeCamera; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue