User pyqtProperty instead of puqtSlot

CURA-4333
This commit is contained in:
A.Sasin 2017-10-13 16:34:49 +02:00
parent 16bd4430e4
commit 7f5aed7ead
3 changed files with 50 additions and 149 deletions

View file

@ -413,10 +413,6 @@ class CuraApplication(QtApplication):
global_stack.getTop().clear()
# event handler for SidebarSimple, which will update sliders view visibility (like:sliders..)
if str(Preferences.getInstance().getValue("cura/active_mode")) == '0':
self.getMachineManager().hasUserCustomSettings()
@pyqtSlot(int)
def messageBoxClosed(self, button):
if self._message_box_callback:

View file

@ -413,23 +413,17 @@ class MachineManager(QObject):
return False
## Check whether user containers have adjusted settings or not
# The skipped settings are predefined, because they are used on SideBarSimple to escape them while validation
# \param skip_keys \type{list} List of setting keys which will be not taken into account ("support_enable" , "infill_sparse_density"...)
# \return \type{boole} Return true if user containers have any of adjusted settings
def hasUserCustomSettings(self) -> bool:
skip_keys = ["support_enable", "infill_sparse_density", "gradual_infill_steps", "adhesion_type", "support_extruder_nr"]
if skip_keys is None:
skip_keys = []
def getAllActiveUserChanges(self, skip_keys = {}) -> bool:
user_setting_keys = []
try:
if not self._global_container_stack:
return False
for container in self._global_container_stack.getContainers():
allContainers = self._global_container_stack.getContainers()
for container in allContainers:
meta = container.getMetaData()
if meta and meta["type"] and meta["type"] == "user":
user_setting_keys.extend(container.getAllKeys())
@ -446,29 +440,14 @@ class MachineManager(QObject):
if skip_key in user_setting_keys:
user_setting_keys.remove(skip_key)
except:
Logger.log("e", "While checking user custom settings occured error. skip_keys: %s", skip_keys )
return False
if len(user_setting_keys) > 0:
self.userSettingsUpdated = True
else:
self.userSettingsUpdated = False
self.userCustomSettingsChanged.emit()
return len(user_setting_keys) > 0
userSettingsUpdated = False
userCustomSettingsChanged = pyqtSignal()
ignore_list = ["support_enable", "infill_sparse_density", "gradual_infill_steps", "adhesion_type", "support_extruder_nr"]
@pyqtSlot()
def checkWhetherUserContainersHaveSettings(self):
return self.hasUserCustomSettings()
#Property to show wheter user settings are updated or not
@pyqtProperty(bool, notify = userCustomSettingsChanged)
def userCustomSettingsProperty(self):
return self.userSettingsUpdated
@pyqtProperty(bool, notify = activeStackValueChanged)
def allActiveUserSettings(self):
return self.getAllActiveUserChanges(skip_keys = self.ignore_list)
@pyqtProperty(int, notify = activeStackValueChanged)
def numUserSettings(self) -> int:

View file

@ -20,34 +20,12 @@ Item
property variant minimumPrintTime: PrintInformation.minimumPrintTime;
property variant maximumPrintTime: PrintInformation.maximumPrintTime;
property bool settingsEnabled: ExtruderManager.activeExtruderStackId || machineExtruderCount.properties.value == 1
property bool hasUserSettings: Cura.MachineManager.userCustomSettingsProperty
property var tickClickedViaProfileSlider: undefined
property bool hasUserSettings: Cura.MachineManager.allActiveUserSettings
Component.onCompleted: PrintInformation.enabled = true
Component.onDestruction: PrintInformation.enabled = false
UM.I18nCatalog { id: catalog; name: "cura" }
onVisibleChanged:
{
if (visible)
{
base.checkUserSettings()
}
}
function checkUserSettings() {
Cura.MachineManager.checkWhetherUserContainersHaveSettings()
if (!hasUserSettings && tickClickedViaProfileSlider != undefined)
{
Cura.MachineManager.setActiveQuality(Cura.ProfilesModel.getItem(tickClickedViaProfileSlider).id);
}
tickClickedViaProfileSlider = undefined;
}
ScrollView
{
visible: Cura.MachineManager.activeMachineName != "" // If no printers added then the view is invisible
@ -198,7 +176,7 @@ Item
{
anchors.verticalCenter: parent.verticalCenter
anchors.top: parent.top
anchors.topMargin: Math.floor(UM.Theme.getSize("sidebar_margin").height / 2)
anchors.topMargin: parseInt(UM.Theme.getSize("sidebar_margin").height / 2)
color: (Cura.MachineManager.activeMachine != null && Cura.ProfilesModel.getItem(index).available) ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
text:
{
@ -217,13 +195,13 @@ Item
// Make sure the text aligns correctly with each tick
if (qualityModel.totalTicks == 0) {
// If there is only one tick, align it centrally
return Math.floor(((base.width * 0.55) - width) / 2)
return parseInt(((base.width * 0.55) - width) / 2)
} else if (index == 0) {
return (base.width * 0.55 / qualityModel.totalTicks) * index
} else if (index == qualityModel.totalTicks) {
return (base.width * 0.55 / qualityModel.totalTicks) * index - width
} else {
return Math.floor((base.width * 0.55 / qualityModel.totalTicks) * index - (width / 2))
return parseInt((base.width * 0.55 / qualityModel.totalTicks) * index - (width / 2))
}
}
}
@ -332,26 +310,6 @@ Item
}
}
}
//If any of settings were changed in custom mode then the Rectangle will
//overlap quality slider area. It is used to catch mouse click
MouseArea {
anchors.fill: qualitySlider
visible: hasUserSettings
enabled: hasUserSettings
onClicked: {
const offset = qualityModel.qualitySliderStepWidth / 2;
const mousePosition = mouseX + offset;
// save where it was clicked
base.tickClickedViaProfileSlider = Math.floor(mousePosition / qualityModel.qualitySliderStepWidth);
discardOrKeepProfileChangesDialog.show();
}
}
}
Label
@ -360,13 +318,10 @@ Item
anchors.top: speedSlider.bottom
anchors.left: parent.left
anchors.right: speedSlider.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width
text: catalog.i18nc("@label", "Print Speed")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
elide: Text.ElideRight
}
Label
@ -432,7 +387,7 @@ Item
anchors.topMargin: UM.Theme.getSize("sidebar_margin").height * 2
anchors.left: parent.left
width: Math.floor(UM.Theme.getSize("sidebar").width * .45 - UM.Theme.getSize("sidebar_margin").width)
width: UM.Theme.getSize("sidebar").width * .45 - UM.Theme.getSize("sidebar_margin").width
Label
{
@ -442,7 +397,7 @@ Item
color: UM.Theme.getColor("text")
anchors.top: parent.top
anchors.topMargin: Math.floor(UM.Theme.getSize("sidebar_margin").height * 1.7)
anchors.topMargin: UM.Theme.getSize("sidebar_margin").height * 1.7
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("sidebar_margin").width
}
@ -453,7 +408,7 @@ Item
id: infillCellRight
height: infillSlider.height + UM.Theme.getSize("sidebar_margin").height + enableGradualInfillCheckBox.visible * (enableGradualInfillCheckBox.height + UM.Theme.getSize("sidebar_margin").height)
width: Math.floor(UM.Theme.getSize("sidebar").width * .55)
width: UM.Theme.getSize("sidebar").width * .55
anchors.left: infillCellLeft.right
anchors.top: infillCellLeft.top
@ -464,10 +419,10 @@ Item
//anchors.top: parent.top
anchors.left: infillSlider.left
anchors.leftMargin: Math.floor((infillSlider.value / infillSlider.stepSize) * (infillSlider.width / (infillSlider.maximumValue / infillSlider.stepSize)) - 10 * screenScaleFactor)
anchors.leftMargin: (infillSlider.value / infillSlider.stepSize) * (infillSlider.width / (infillSlider.maximumValue / infillSlider.stepSize)) - 10 * screenScaleFactor
anchors.right: parent.right
text: Math.floor(infillDensity.properties.value) + "%"
text: parseInt(infillDensity.properties.value) + "%"
horizontalAlignment: Text.AlignLeft
color: infillSlider.enabled ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
@ -477,7 +432,7 @@ Item
Binding {
target: infillSlider
property: "value"
value: Math.floor(infillDensity.properties.value)
value: parseInt(infillDensity.properties.value)
}
Slider
@ -490,7 +445,7 @@ Item
anchors.rightMargin: UM.Theme.getSize("sidebar_margin").width
height: UM.Theme.getSize("sidebar_margin").height
width: Math.floor(infillCellRight.width - UM.Theme.getSize("sidebar_margin").width - style.handleWidth)
width: infillCellRight.width - UM.Theme.getSize("sidebar_margin").width - style.handleWidth
minimumValue: 0
maximumValue: 100
@ -498,15 +453,15 @@ Item
tickmarksEnabled: true
// disable slider when gradual support is enabled
enabled: Math.floor(infillSteps.properties.value) == 0
enabled: parseInt(infillSteps.properties.value) == 0
// set initial value from stack
value: Math.floor(infillDensity.properties.value)
value: parseInt(infillDensity.properties.value)
onValueChanged: {
// Don't round the value if it's already the same
if (Math.floor(infillDensity.properties.value) == infillSlider.value) {
if (parseInt(infillDensity.properties.value) == infillSlider.value) {
return
}
@ -575,7 +530,7 @@ Item
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: Math.floor(UM.Theme.getSize("sidebar_margin").height / 2)
anchors.topMargin: parseInt(UM.Theme.getSize("sidebar_margin").height / 2)
// we loop over all density icons and only show the one that has the current density and steps
Repeater
@ -586,8 +541,8 @@ Item
property int activeIndex: {
for (var i = 0; i < infillModel.count; i++) {
var density = Math.floor(infillDensity.properties.value)
var steps = Math.floor(infillSteps.properties.value)
var density = parseInt(infillDensity.properties.value)
var steps = parseInt(infillSteps.properties.value)
var infillModelItem = infillModel.get(i)
if (density >= infillModelItem.percentageMin
@ -626,13 +581,13 @@ Item
property alias _hovered: enableGradualInfillMouseArea.containsMouse
anchors.top: infillSlider.bottom
anchors.topMargin: Math.floor(UM.Theme.getSize("sidebar_margin").height / 2) // closer to slider since it belongs to the same category
anchors.topMargin: parseInt(UM.Theme.getSize("sidebar_margin").height / 2) // closer to slider since it belongs to the same category
anchors.left: infillCellRight.left
style: UM.Theme.styles.checkbox
enabled: base.settingsEnabled
visible: infillSteps.properties.enabled == "True"
checked: Math.floor(infillSteps.properties.value) > 0
checked: parseInt(infillSteps.properties.value) > 0
MouseArea {
id: enableGradualInfillMouseArea
@ -641,18 +596,18 @@ Item
hoverEnabled: true
enabled: true
property var previousInfillDensity: Math.floor(infillDensity.properties.value)
property var previousInfillDensity: parseInt(infillDensity.properties.value)
onClicked: {
// Set to 90% only when enabling gradual infill
if (Math.floor(infillSteps.properties.value) == 0) {
previousInfillDensity = Math.floor(infillDensity.properties.value)
if (parseInt(infillSteps.properties.value) == 0) {
previousInfillDensity = parseInt(infillDensity.properties.value)
infillDensity.setPropertyValue("value", String(90))
} else {
infillDensity.setPropertyValue("value", String(previousInfillDensity))
}
infillSteps.setPropertyValue("value", (Math.floor(infillSteps.properties.value) == 0) ? 5 : 0)
infillSteps.setPropertyValue("value", (parseInt(infillSteps.properties.value) == 0) ? 5 : 0)
}
onEntered: {
@ -668,7 +623,7 @@ Item
Label {
id: gradualInfillLabel
anchors.left: enableGradualInfillCheckBox.right
anchors.leftMargin: Math.floor(UM.Theme.getSize("sidebar_margin").width / 2)
anchors.leftMargin: parseInt(UM.Theme.getSize("sidebar_margin").width / 2)
text: catalog.i18nc("@label", "Enable gradual")
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
@ -729,7 +684,7 @@ Item
visible: enableSupportCheckBox.visible
anchors.top: infillCellRight.bottom
anchors.topMargin: Math.floor(UM.Theme.getSize("sidebar_margin").height * 1.5)
anchors.topMargin: parseInt(UM.Theme.getSize("sidebar_margin").height * 1.5)
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("sidebar_margin").width
anchors.verticalCenter: enableSupportCheckBox.verticalCenter
@ -938,7 +893,7 @@ Item
{
id: tipsCell
anchors.top: adhesionCheckBox.visible ? adhesionCheckBox.bottom : (enableSupportCheckBox.visible ? supportExtruderCombobox.bottom : infillCellRight.bottom)
anchors.topMargin: Math.floor(UM.Theme.getSize("sidebar_margin").height * 2)
anchors.topMargin: parseInt(UM.Theme.getSize("sidebar_margin").height * 2)
anchors.left: parent.left
width: parent.width
height: tipsText.contentHeight * tipsText.lineCount
@ -969,35 +924,6 @@ Item
storeIndex: 0
}
Binding
{
target: infillDensity
property: "containerStackId"
value: {
// not settable per extruder or there only is global, so we must pick global
if (machineExtruderCount.properties.value == 1) {
return Cura.MachineManager.activeStackId
}
// return the ID of the extruder when the infill is limited to an extruder
if (infillInheritStackProvider.properties.limit_to_extruder != null && infillInheritStackProvider.properties.limit_to_extruder >= 0) {
return ExtruderManager.extruderIds[String(infillInheritStackProvider.properties.limit_to_extruder)]
}
// default to the global stack
return Cura.MachineManager.activeStackId
}
}
UM.SettingPropertyProvider
{
id: infillInheritStackProvider
containerStackId: Cura.MachineManager.activeMachineId
key: "infill_sparse_density"
watchedProperties: [ "limit_to_extruder" ]
}
UM.SettingPropertyProvider
{
id: infillDensity