mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Refactor code in AddLocalPrinterScrollView.qml
The commit simplifies the function for updating current items in the AddLocalPrinterScrollView.qml file. It also removes unnecessary properties and functions, streamlining the process for setting printer info. The changes improve code readability and efficiency CURA-11003
This commit is contained in:
parent
b810e63c60
commit
4c42ed7085
1 changed files with 16 additions and 31 deletions
|
@ -43,25 +43,22 @@ Item
|
||||||
const item = machineList.model.getItem(i);
|
const item = machineList.model.getItem(i);
|
||||||
if (item.section == section)
|
if (item.section == section)
|
||||||
{
|
{
|
||||||
machineList.currentIndex = i;
|
updateCurrentItem(i)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMachineName()
|
function updateCurrentItem(index)
|
||||||
{
|
{
|
||||||
return machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).name : "";
|
machineList.currentIndex = index;
|
||||||
|
currentItem = machineList.model.getItem(index);
|
||||||
|
if (currentItem != undefined)
|
||||||
|
{
|
||||||
|
machineName.text = currentItem.name
|
||||||
|
manufacturer.text = currentItem.metadata["manufacturer"]
|
||||||
|
author.text = currentItem.metadata["author"]
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMachineMetaDataEntry(key)
|
|
||||||
{
|
|
||||||
var metadata = machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).metadata : undefined;
|
|
||||||
if (metadata)
|
|
||||||
{
|
|
||||||
return metadata[key];
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer
|
Timer
|
||||||
|
@ -90,8 +87,6 @@ Item
|
||||||
placeholderText: catalog.i18nc("@label:textbox", "Search Printer")
|
placeholderText: catalog.i18nc("@label:textbox", "Search Printer")
|
||||||
font: UM.Theme.getFont("default_italic")
|
font: UM.Theme.getFont("default_italic")
|
||||||
leftPadding: searchIcon.width + UM.Theme.getSize("default_margin").width * 2
|
leftPadding: searchIcon.width + UM.Theme.getSize("default_margin").width * 2
|
||||||
property var expandedCategories
|
|
||||||
property bool lastFindingPrinters: false
|
|
||||||
|
|
||||||
UM.ColorImage
|
UM.ColorImage
|
||||||
{
|
{
|
||||||
|
@ -113,11 +108,7 @@ Item
|
||||||
{
|
{
|
||||||
machineDefinitionsModel.filter = {"id" : "*" + text.toLowerCase() + "*", "visible": true}
|
machineDefinitionsModel.filter = {"id" : "*" + text.toLowerCase() + "*", "visible": true}
|
||||||
base.findingPrinters = (text.length > 0)
|
base.findingPrinters = (text.length > 0)
|
||||||
if (base.findingPrinters != lastFindingPrinters)
|
|
||||||
{
|
|
||||||
updateDefinitionModel()
|
updateDefinitionModel()
|
||||||
lastFindingPrinters = base.findingPrinters
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onEscapePressed: filter.text = ""
|
Keys.onEscapePressed: filter.text = ""
|
||||||
|
@ -134,11 +125,10 @@ Item
|
||||||
base.currentSections.add(sectionexpanded);
|
base.currentSections.add(sectionexpanded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateCurrentItemUponSectionChange(base.currentSections[0]);
|
base.updateCurrentItem(0)
|
||||||
|
|
||||||
// Trigger update on base.currentSections
|
// Trigger update on base.currentSections
|
||||||
base.currentSections = base.currentSections;
|
base.currentSections = base.currentSections;
|
||||||
// Set the machineName to the first element of the list
|
|
||||||
machineList.currentIndex = 0
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -146,9 +136,9 @@ Item
|
||||||
base.currentSections.clear();
|
base.currentSections.clear();
|
||||||
base.currentSections.add(initialSection);
|
base.currentSections.add(initialSection);
|
||||||
updateCurrentItemUponSectionChange(initialSection);
|
updateCurrentItemUponSectionChange(initialSection);
|
||||||
|
updateCurrentItem(0)
|
||||||
// Trigger update on base.currentSections
|
// Trigger update on base.currentSections
|
||||||
base.currentSections = base.currentSections;
|
base.currentSections = base.currentSections;
|
||||||
machineList.currentIndex = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -241,11 +231,6 @@ Item
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
|
||||||
changeVisibility()
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeVisibility()
|
|
||||||
{
|
{
|
||||||
if (base.currentSections.has(section))
|
if (base.currentSections.has(section))
|
||||||
{
|
{
|
||||||
|
@ -277,7 +262,7 @@ Item
|
||||||
checked: machineList.currentIndex == index
|
checked: machineList.currentIndex == index
|
||||||
text: name
|
text: name
|
||||||
visible: base.currentSections.has(section)
|
visible: base.currentSections.has(section)
|
||||||
onClicked: machineList.currentIndex = index
|
onClicked: base.updateCurrentItem(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,8 +286,8 @@ Item
|
||||||
|
|
||||||
UM.Label
|
UM.Label
|
||||||
{
|
{
|
||||||
|
id: machineName
|
||||||
width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
|
width: parent.width - (2 * UM.Theme.getSize("default_margin").width)
|
||||||
text: base.getMachineName()
|
|
||||||
color: UM.Theme.getColor("primary_button")
|
color: UM.Theme.getColor("primary_button")
|
||||||
font: UM.Theme.getFont("huge")
|
font: UM.Theme.getFont("huge")
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
|
@ -323,7 +308,7 @@ Item
|
||||||
}
|
}
|
||||||
UM.Label
|
UM.Label
|
||||||
{
|
{
|
||||||
text: base.getMachineMetaDataEntry("manufacturer")
|
id: manufacturer
|
||||||
width: parent.width - manufacturerLabel.width
|
width: parent.width - manufacturerLabel.width
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
|
@ -334,7 +319,7 @@ Item
|
||||||
}
|
}
|
||||||
UM.Label
|
UM.Label
|
||||||
{
|
{
|
||||||
text: base.getMachineMetaDataEntry("author")
|
id: author
|
||||||
width: parent.width - profileAuthorLabel.width
|
width: parent.width - profileAuthorLabel.width
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue