mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 10:17:52 -06:00
Sync currently selected preset between visibility-page and -menu
This commit is contained in:
parent
4c1002bf47
commit
74fe281e1d
7 changed files with 82 additions and 61 deletions
|
@ -362,13 +362,8 @@ class CuraApplication(QtApplication):
|
|||
|
||||
default_visibility_profile = SettingVisibilityPresetsModel.getInstance().getItem(0)
|
||||
|
||||
preferences.addPreference("general/preset_setting_visibility_choice", default_visibility_profile["id"])
|
||||
preferences.setDefault("general/visible_settings", ";".join(default_visibility_profile["settings"]))
|
||||
|
||||
preset_setting_visibility_choice = Preferences.getInstance().getValue("general/preset_setting_visibility_choice")
|
||||
if not SettingVisibilityPresetsModel.getInstance().find("id", preset_setting_visibility_choice):
|
||||
Preferences.getInstance().setValue("general/preset_setting_visibility_choice", default_visibility_profile["id"])
|
||||
|
||||
self.applicationShuttingDown.connect(self.saveSettings)
|
||||
self.engineCreatedSignal.connect(self._onEngineCreated)
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot, QUrl
|
|||
|
||||
from UM.Logger import Logger
|
||||
from UM.Qt.ListModel import ListModel
|
||||
|
||||
from UM.Preferences import Preferences
|
||||
from UM.Resources import Resources
|
||||
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError
|
||||
|
||||
|
@ -27,11 +27,18 @@ class SettingVisibilityPresetsModel(ListModel):
|
|||
self.addRoleName(self.NameRole, "name")
|
||||
self.addRoleName(self.SettingsRole, "settings")
|
||||
|
||||
self._container_ids = []
|
||||
self._containers = []
|
||||
|
||||
self._populate()
|
||||
|
||||
preferences = Preferences.getInstance()
|
||||
preferences.addPreference("cura/active_setting_visibility_preset", "custom")
|
||||
|
||||
self._active_preset = Preferences.getInstance().getValue("cura/active_setting_visibility_preset")
|
||||
if self.find("id", self._active_preset) < 0:
|
||||
self._active_preset = "custom"
|
||||
|
||||
self.activePresetChanged.emit()
|
||||
|
||||
|
||||
def _populate(self):
|
||||
items = []
|
||||
for item in Resources.getAllResourcesOfType(cura.CuraApplication.CuraApplication.ResourceTypes.SettingVisibilityPreset):
|
||||
|
@ -77,6 +84,23 @@ class SettingVisibilityPresetsModel(ListModel):
|
|||
items.sort(key = lambda k: (k["weight"], k["id"]))
|
||||
self.setItems(items)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setActivePreset(self, preset_id):
|
||||
if preset_id != "custom" and self.find("id", preset_id) == -1:
|
||||
Logger.log("w", "Tried to set active preset to unknown id %s", preset_id)
|
||||
return
|
||||
|
||||
Preferences.getInstance().setValue("cura/active_setting_visibility_preset", preset_id);
|
||||
|
||||
self._active_preset = preset_id
|
||||
self.activePresetChanged.emit()
|
||||
|
||||
activePresetChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty(str, notify = activePresetChanged)
|
||||
def activePreset(self):
|
||||
return self._active_preset
|
||||
|
||||
# Factory function, used by QML
|
||||
@staticmethod
|
||||
def createSettingVisibilityPresetsModel(engine, js_engine):
|
||||
|
|
|
@ -453,7 +453,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
Logger.log("w", "Workspace did not contain visible settings. Leaving visibility unchanged")
|
||||
else:
|
||||
global_preferences.setValue("general/visible_settings", visible_settings)
|
||||
global_preferences.setValue("general/preset_setting_visibility_choice", "Custom")
|
||||
global_preferences.setValue("cura/active_setting_visibility_preset", "custom")
|
||||
|
||||
categories_expanded = temp_preferences.getValue("cura/categories_expanded")
|
||||
if categories_expanded is None:
|
||||
|
|
|
@ -625,9 +625,12 @@ UM.MainWindow
|
|||
{
|
||||
preferences.visible = true;
|
||||
preferences.setPage(1);
|
||||
if(source && source.key)
|
||||
{
|
||||
preferences.getCurrentItem().scrollToSection(source.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// show the installed plugins page in the preferences dialog
|
||||
Connections
|
||||
|
|
|
@ -32,9 +32,13 @@ Menu
|
|||
{
|
||||
text: catalog.i18nc("@action:inmenu", "Custom selection")
|
||||
checkable: true
|
||||
checked: !showingSearchResults && !showingAllSettings
|
||||
checked: !showingSearchResults && !showingAllSettings && Cura.SettingVisibilityPresetsModel.activePreset == "custom"
|
||||
exclusiveGroup: group
|
||||
onTriggered: showSettingVisibilityProfile("Custom")
|
||||
onTriggered:
|
||||
{
|
||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
||||
showSettingVisibilityProfile();
|
||||
}
|
||||
}
|
||||
MenuSeparator { }
|
||||
|
||||
|
@ -46,12 +50,13 @@ Menu
|
|||
{
|
||||
text: model.name
|
||||
checkable: true
|
||||
checked: false
|
||||
checked: model.id == Cura.SettingVisibilityPresetsModel.activePreset
|
||||
exclusiveGroup: group
|
||||
onTriggered:
|
||||
{
|
||||
Cura.SettingVisibilityPresetsModel.setActivePreset(model.id);
|
||||
|
||||
UM.Preferences.setValue("general/visible_settings", model.settings.join(";"));
|
||||
UM.Preferences.setValue("general/preset_setting_visibility_choice", model.id);
|
||||
|
||||
showSettingVisibilityProfile();
|
||||
}
|
||||
|
@ -61,27 +66,6 @@ Menu
|
|||
onObjectRemoved: menu.removeItem(object)
|
||||
}
|
||||
|
||||
MenuSeparator { visible: false }
|
||||
MenuItem
|
||||
{
|
||||
text: catalog.i18nc("@action:inmenu", "Changed settings")
|
||||
visible: false
|
||||
enabled: true
|
||||
checkable: true
|
||||
checked: showingAllSettings
|
||||
exclusiveGroup: group
|
||||
onTriggered: showAllSettings()
|
||||
}
|
||||
MenuItem
|
||||
{
|
||||
text: catalog.i18nc("@action:inmenu", "Settings in profile")
|
||||
visible: false
|
||||
enabled: true
|
||||
checkable: true
|
||||
checked: showingAllSettings
|
||||
exclusiveGroup: group
|
||||
onTriggered: showAllSettings()
|
||||
}
|
||||
MenuSeparator {}
|
||||
MenuItem
|
||||
{
|
||||
|
@ -89,7 +73,11 @@ Menu
|
|||
checkable: true
|
||||
checked: showingAllSettings
|
||||
exclusiveGroup: group
|
||||
onTriggered: showAllSettings()
|
||||
onTriggered:
|
||||
{
|
||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
||||
showAllSettings();
|
||||
}
|
||||
}
|
||||
MenuSeparator {}
|
||||
MenuItem
|
||||
|
|
|
@ -37,6 +37,8 @@ UM.PreferencesPage
|
|||
id: base;
|
||||
anchors.fill: parent;
|
||||
|
||||
property bool inhibitSwitchToCustom: false
|
||||
|
||||
CheckBox
|
||||
{
|
||||
id: toggleVisibleSettings
|
||||
|
@ -84,7 +86,7 @@ UM.PreferencesPage
|
|||
if (visibilityPreset.currentIndex != visibilityPreset.model.count - 1)
|
||||
{
|
||||
visibilityPreset.currentIndex = visibilityPreset.model.count - 1
|
||||
UM.Preferences.setValue("general/preset_setting_visibility_choice", visibilityPreset.model.getItem(visibilityPreset.currentIndex).id)
|
||||
UM.Preferences.setValue("cura/active_setting_visibility_preset", visibilityPreset.model.getItem(visibilityPreset.currentIndex).id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +131,7 @@ UM.PreferencesPage
|
|||
currentIndex:
|
||||
{
|
||||
// Load previously selected preset.
|
||||
var index = model.find("id", UM.Preferences.getValue("general/preset_setting_visibility_choice"));
|
||||
var index = model.find("id", model.activePreset);
|
||||
if(index == -1)
|
||||
{
|
||||
index = 0;
|
||||
|
@ -140,14 +142,12 @@ UM.PreferencesPage
|
|||
|
||||
onActivated:
|
||||
{
|
||||
// TODO What to do if user is selected "Custom from Combobox" ?
|
||||
if (model.getItem(index).id == "custom"){
|
||||
UM.Preferences.setValue("general/preset_setting_visibility_choice", model.get(index).id)
|
||||
return
|
||||
}
|
||||
base.inhibitSwitchToCustom = true;
|
||||
model.setActivePreset(model.getItem(index).id);
|
||||
|
||||
UM.Preferences.setValue("general/visible_settings", model.getItem(index).settings.join(";"))
|
||||
UM.Preferences.setValue("general/preset_setting_visibility_choice", model.getItem(index).id)
|
||||
UM.Preferences.setValue("general/visible_settings", model.getItem(index).settings.join(";"));
|
||||
UM.Preferences.setValue("cura/active_setting_visibility_preset", model.getItem(index).id);
|
||||
base.inhibitSwitchToCustom = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,16 @@ UM.PreferencesPage
|
|||
exclude: ["machine_settings", "command_line_settings"]
|
||||
showAncestors: true
|
||||
expanded: ["*"]
|
||||
visibilityHandler: UM.SettingPreferenceVisibilityHandler { }
|
||||
visibilityHandler: UM.SettingPreferenceVisibilityHandler
|
||||
{
|
||||
onVisibilityChanged:
|
||||
{
|
||||
if(Cura.SettingVisibilityPresetsModel.activePreset != "" && !base.inhibitSwitchToCustom)
|
||||
{
|
||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Loader
|
||||
|
@ -220,19 +229,7 @@ UM.PreferencesPage
|
|||
{
|
||||
id: settingVisibilityItem;
|
||||
|
||||
UM.SettingVisibilityItem {
|
||||
|
||||
// after changing any visibility of settings, set the preset to the "Custom" option
|
||||
visibilityChangeCallback : function()
|
||||
{
|
||||
// If already "Custom" then don't do nothing
|
||||
if (visibilityPreset.currentIndex != visibilityPreset.model.count - 1)
|
||||
{
|
||||
visibilityPreset.currentIndex = visibilityPreset.model.count - 1
|
||||
UM.Preferences.setValue("general/preset_setting_visibility_choice", visibilityPreset.model.getItem(visibilityPreset.currentIndex).id)
|
||||
}
|
||||
}
|
||||
}
|
||||
UM.SettingVisibilityItem { }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ Item
|
|||
property Action configureSettings
|
||||
property bool findingSettings
|
||||
property bool showingAllSettings
|
||||
property bool inhibitSwitchToCustom: false
|
||||
signal showTooltip(Item item, point location, string text)
|
||||
signal hideTooltip()
|
||||
|
||||
|
@ -559,7 +560,15 @@ Item
|
|||
//: Settings context menu action
|
||||
visible: !findingSettings;
|
||||
text: catalog.i18nc("@action:menu", "Hide this setting");
|
||||
onTriggered: definitionsModel.hide(contextMenu.key);
|
||||
onTriggered:
|
||||
{
|
||||
definitionsModel.hide(contextMenu.key);
|
||||
// visible settings have changed, so we're no longer showing a preset
|
||||
if (Cura.SettingVisibilityPresetsModel.activePreset != "")
|
||||
{
|
||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
||||
}
|
||||
}
|
||||
}
|
||||
MenuItem
|
||||
{
|
||||
|
@ -586,6 +595,11 @@ Item
|
|||
{
|
||||
definitionsModel.show(contextMenu.key);
|
||||
}
|
||||
// visible settings have changed, so we're no longer showing a preset
|
||||
if (Cura.SettingVisibilityPresetsModel.activePreset != "")
|
||||
{
|
||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
||||
}
|
||||
}
|
||||
}
|
||||
MenuItem
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue