Use ListModel.count instead of rowCount

The .count property properly updates when the model is changed.

Contributes to issue CURA-5876.
This commit is contained in:
Ghostkeeper 2018-12-03 11:13:26 +01:00
parent db05d7853a
commit f3af5a72ad
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
14 changed files with 49 additions and 36 deletions

View file

@ -165,7 +165,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
def __updateExtruders(self): def __updateExtruders(self):
extruders_changed = False extruders_changed = False
if self.rowCount() != 0: if self.count != 0:
extruders_changed = True extruders_changed = True
items = [] items = []

View file

@ -1540,7 +1540,7 @@ class MachineManager(QObject):
elif word.isdigit(): elif word.isdigit():
abbr_machine += word abbr_machine += word
else: else:
stripped_word = ''.join(char for char in unicodedata.normalize('NFD', word.upper()) if unicodedata.category(char) != 'Mn') stripped_word = "".join(char for char in unicodedata.normalize("NFD", word.upper()) if unicodedata.category(char) != "Mn")
# - use only the first character if the word is too long (> 3 characters) # - use only the first character if the word is too long (> 3 characters)
# - use the whole word if it's not too long (<= 3 characters) # - use the whole word if it's not too long (<= 3 characters)
if len(stripped_word) > 3: if len(stripped_word) > 3:

View file

@ -1,4 +1,4 @@
// Copyright (c) 2016 Ultimaker B.V. // Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2 import QtQuick 2.2
@ -23,7 +23,7 @@ Cura.MachineAction
target: base.extrudersModel target: base.extrudersModel
onModelChanged: onModelChanged:
{ {
var extruderCount = base.extrudersModel.rowCount(); var extruderCount = base.extrudersModel.count;
base.extruderTabsCount = extruderCount; base.extruderTabsCount = extruderCount;
} }
} }

View file

@ -170,7 +170,7 @@ UM.Dialog
if (machineList.model.getItem(machineList.currentIndex).section != section) if (machineList.model.getItem(machineList.currentIndex).section != section)
{ {
// Find the first machine from this section // Find the first machine from this section
for(var i = 0; i < machineList.model.rowCount(); i++) for(var i = 0; i < machineList.model.count; i++)
{ {
var item = machineList.model.getItem(i); var item = machineList.model.getItem(i);
if (item.section == section) if (item.section == section)

View file

@ -44,7 +44,7 @@ Cura.ExpandableComponent
delegate: Item delegate: Item
{ {
height: parent.height height: parent.height
width: Math.round(ListView.view.width / extrudersModel.rowCount()) width: Math.round(ListView.view.width / extrudersModel.count)
// Extruder icon. Shows extruder index and has the same color as the active material. // Extruder icon. Shows extruder index and has the same color as the active material.
Cura.ExtruderIcon Cura.ExtruderIcon

View file

@ -34,7 +34,7 @@ Menu
MenuSeparator MenuSeparator
{ {
id: customSeparator id: customSeparator
visible: Cura.CustomQualityProfilesDropDownMenuModel.rowCount > 0 visible: Cura.CustomQualityProfilesDropDownMenuModel.count > 0
} }
Instantiator Instantiator
@ -45,7 +45,7 @@ Menu
Connections Connections
{ {
target: Cura.CustomQualityProfilesDropDownMenuModel target: Cura.CustomQualityProfilesDropDownMenuModel
onModelReset: customSeparator.visible = Cura.CustomQualityProfilesDropDownMenuModel.rowCount() > 0 onModelReset: customSeparator.visible = Cura.CustomQualityProfilesDropDownMenuModel.count > 0
} }
MenuItem MenuItem
@ -59,12 +59,12 @@ Menu
onObjectAdded: onObjectAdded:
{ {
customSeparator.visible = model.rowCount() > 0; customSeparator.visible = model.count > 0;
menu.insertItem(index, object); menu.insertItem(index, object);
} }
onObjectRemoved: onObjectRemoved:
{ {
customSeparator.visible = model.rowCount() > 0; customSeparator.visible = model.count > 0;
menu.removeItem(object); menu.removeItem(object);
} }
} }

View file

@ -21,8 +21,10 @@ UM.ManagementPage
function activeMachineIndex() function activeMachineIndex()
{ {
for(var i = 0; i < model.rowCount(); i++) { for(var i = 0; i < model.count; i++)
if (model.getItem(i).id == Cura.MachineManager.activeMachineId) { {
if (model.getItem(i).id == Cura.MachineManager.activeMachineId)
{
return i; return i;
} }
} }
@ -47,7 +49,7 @@ UM.ManagementPage
{ {
text: catalog.i18nc("@action:button", "Remove"); text: catalog.i18nc("@action:button", "Remove");
iconName: "list-remove"; iconName: "list-remove";
enabled: base.currentItem != null && model.rowCount() > 1 enabled: base.currentItem != null && model.count > 1
onClicked: confirmDialog.open(); onClicked: confirmDialog.open();
}, },
Button Button

View file

@ -57,7 +57,7 @@ Item
var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id
search_root_id = currentItemId search_root_id = currentItemId
} }
for (var material_idx = 0; material_idx < genericMaterialsModel.rowCount(); material_idx++) for (var material_idx = 0; material_idx < genericMaterialsModel.count; material_idx++)
{ {
var material = genericMaterialsModel.getItem(material_idx) var material = genericMaterialsModel.getItem(material_idx)
if (material.root_material_id == search_root_id) if (material.root_material_id == search_root_id)
@ -72,15 +72,15 @@ Item
return true return true
} }
} }
for (var brand_idx = 0; brand_idx < materialsModel.rowCount(); brand_idx++) for (var brand_idx = 0; brand_idx < materialsModel.count; brand_idx++)
{ {
var brand = materialsModel.getItem(brand_idx) var brand = materialsModel.getItem(brand_idx)
var types_model = brand.material_types var types_model = brand.material_types
for (var type_idx = 0; type_idx < types_model.rowCount(); type_idx++) for (var type_idx = 0; type_idx < types_model.count; type_idx++)
{ {
var type = types_model.getItem(type_idx) var type = types_model.getItem(type_idx)
var colors_model = type.colors var colors_model = type.colors
for (var material_idx = 0; material_idx < colors_model.rowCount(); material_idx++) for (var material_idx = 0; material_idx < colors_model.count; material_idx++)
{ {
var material = colors_model.getItem(material_idx) var material = colors_model.getItem(material_idx)
if (material.root_material_id == search_root_id) if (material.root_material_id == search_root_id)

View file

@ -188,21 +188,27 @@ Item
Connections Connections
{ {
target: qualitiesModel target: qualitiesModel
onItemsChanged: { onItemsChanged:
{
var toSelectItemName = base.currentItem == null ? "" : base.currentItem.name; var toSelectItemName = base.currentItem == null ? "" : base.currentItem.name;
if (newQualityNameToSelect != "") { if (newQualityNameToSelect != "")
{
toSelectItemName = newQualityNameToSelect; toSelectItemName = newQualityNameToSelect;
} }
var newIdx = -1; // Default to nothing if nothing can be found var newIdx = -1; // Default to nothing if nothing can be found
if (toSelectItemName != "") { if (toSelectItemName != "")
{
// Select the required quality name if given // Select the required quality name if given
for (var idx = 0; idx < qualitiesModel.rowCount(); ++idx) { for (var idx = 0; idx < qualitiesModel.count; ++idx)
{
var item = qualitiesModel.getItem(idx); var item = qualitiesModel.getItem(idx);
if (item.name == toSelectItemName) { if (item.name == toSelectItemName)
{
// Switch to the newly created profile if needed // Switch to the newly created profile if needed
newIdx = idx; newIdx = idx;
if (base.toActivateNewQuality) { if (base.toActivateNewQuality)
{
// Activate this custom quality if required // Activate this custom quality if required
Cura.MachineManager.setQualityChangesGroup(item.quality_changes_group); Cura.MachineManager.setQualityChangesGroup(item.quality_changes_group);
} }
@ -382,9 +388,11 @@ Item
var selectedItemName = Cura.MachineManager.activeQualityOrQualityChangesName; var selectedItemName = Cura.MachineManager.activeQualityOrQualityChangesName;
// Select the required quality name if given // Select the required quality name if given
for (var idx = 0; idx < qualitiesModel.rowCount(); idx++) { for (var idx = 0; idx < qualitiesModel.count; idx++)
{
var item = qualitiesModel.getItem(idx); var item = qualitiesModel.getItem(idx);
if (item.name == selectedItemName) { if (item.name == selectedItemName)
{
currentIndex = idx; currentIndex = idx;
break; break;
} }

View file

@ -54,7 +54,7 @@ UM.PreferencesPage
{ {
return Qt.Unchecked return Qt.Unchecked
} }
else if(definitionsModel.visibleCount == definitionsModel.rowCount(null)) else if(definitionsModel.visibleCount == definitionsModel.count)
{ {
return Qt.Checked return Qt.Checked
} }

View file

@ -1,5 +1,5 @@
// Copyright (c) 2016 Ultimaker B.V. // Copyright (c) 2018 Ultimaker B.V.
// Uranium is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
@ -31,12 +31,15 @@ SettingItem
{ {
forceActiveFocus(); forceActiveFocus();
propertyProvider.setPropertyValue("value", model.getItem(index).index); propertyProvider.setPropertyValue("value", model.getItem(index).index);
} else }
else
{ {
if (propertyProvider.properties.value == -1) if (propertyProvider.properties.value == -1)
{ {
control.currentIndex = model.rowCount() - 1; // we know the last item is "Not overriden" control.currentIndex = model.count - 1; // we know the last item is "Not overriden"
} else { }
else
{
control.currentIndex = propertyProvider.properties.value; // revert to the old value control.currentIndex = propertyProvider.properties.value; // revert to the old value
} }
} }

View file

@ -106,7 +106,7 @@ Item
var availableMin = -1 var availableMin = -1
var availableMax = -1 var availableMax = -1
for (var i = 0; i < Cura.QualityProfilesDropDownMenuModel.rowCount(); i++) for (var i = 0; i < Cura.QualityProfilesDropDownMenuModel.count; i++)
{ {
var qualityItem = Cura.QualityProfilesDropDownMenuModel.getItem(i) var qualityItem = Cura.QualityProfilesDropDownMenuModel.getItem(i)
@ -183,7 +183,7 @@ Item
qualityModel.existingQualityProfile = 0 qualityModel.existingQualityProfile = 0
// check, the ticks count cannot be less than zero // check, the ticks count cannot be less than zero
qualityModel.totalTicks = Math.max(0, Cura.QualityProfilesDropDownMenuModel.rowCount() - 1) qualityModel.totalTicks = Math.max(0, Cura.QualityProfilesDropDownMenuModel.count - 1)
} }
} }
@ -1156,7 +1156,7 @@ Item
function populateExtruderModel() function populateExtruderModel()
{ {
extruderModel.clear(); extruderModel.clear();
for(var extruderNumber = 0; extruderNumber < extruders.rowCount() ; extruderNumber++) for(var extruderNumber = 0; extruderNumber < extruders.count; extruderNumber++)
{ {
extruderModel.append({ extruderModel.append({
text: extruders.getItem(extruderNumber).name, text: extruders.getItem(extruderNumber).name,

View file

@ -65,7 +65,7 @@ Item
style: UM.Theme.styles.toolbar_button style: UM.Theme.styles.toolbar_button
property bool isFirstElement: toolsModel.getItem(0).id == model.id property bool isFirstElement: toolsModel.getItem(0).id == model.id
property bool isLastElement: toolsModel.getItem(toolsModel.rowCount() - 1).id == model.id property bool isLastElement: toolsModel.getItem(toolsModel.count - 1).id == model.id
onCheckedChanged: onCheckedChanged:
{ {

View file

@ -19,7 +19,7 @@ Cura.ExpandableComponent
property var activeView: property var activeView:
{ {
for (var i = 0; i < viewModel.rowCount(); i++) for (var i = 0; i < viewModel.count; i++)
{ {
if (viewModel.items[i].active) if (viewModel.items[i].active)
{ {