Update _favorite_ids in BaseMaterialsModel._update

And make all subclasses run its super _update as well to make sure that this gets updated for them. It's necessary for the _createMaterialItem functionality because it needs to add an is_favorite role.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-21 17:30:12 +02:00
parent 5d76f96354
commit ea1c99b708
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
4 changed files with 7 additions and 10 deletions

View file

@ -4,6 +4,8 @@
from typing import Optional, Dict, Set from typing import Optional, Dict, Set
from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
from UM.Preferences import Preferences
from UM.Qt.ListModel import ListModel from UM.Qt.ListModel import ListModel
import cura.CuraApplication # Imported like this to prevent a circular reference. import cura.CuraApplication # Imported like this to prevent a circular reference.
@ -111,7 +113,7 @@ class BaseMaterialsModel(ListModel):
## This is an abstract method that needs to be implemented by the specific ## This is an abstract method that needs to be implemented by the specific
# models themselves. # models themselves.
def _update(self): def _update(self):
pass self._favorite_ids = set(Preferences.getInstance().getValue("cura/favorite_materials").split(";"))
## This method is used by all material models in the beginning of the ## This method is used by all material models in the beginning of the
# _update() method in order to prevent errors. It's the same in all models # _update() method in order to prevent errors. It's the same in all models

View file

@ -19,12 +19,10 @@ class FavoriteMaterialsModel(BaseMaterialsModel):
self._update() self._update()
def _update(self): def _update(self):
super()._update()
if not self._canUpdate(): if not self._canUpdate():
return return
# Get updated list of favorites
self._favorite_ids = self._material_manager.getFavorites()
item_list = [] item_list = []
for root_material_id, container_node in self._available_materials.items(): for root_material_id, container_node in self._available_materials.items():

View file

@ -10,12 +10,10 @@ class GenericMaterialsModel(BaseMaterialsModel):
self._update() self._update()
def _update(self): def _update(self):
super()._update()
if not self._canUpdate(): if not self._canUpdate():
return return
# Get updated list of favorites
self._favorite_ids = self._material_manager.getFavorites()
item_list = [] item_list = []
for root_material_id, container_node in self._available_materials.items(): for root_material_id, container_node in self._available_materials.items():

View file

@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2019 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.
from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtCore import Qt, pyqtSignal
@ -27,10 +27,9 @@ class MaterialBrandsModel(BaseMaterialsModel):
self._update() self._update()
def _update(self): def _update(self):
super()._update()
if not self._canUpdate(): if not self._canUpdate():
return return
# Get updated list of favorites
self._favorite_ids = self._material_manager.getFavorites()
brand_item_list = [] brand_item_list = []
brand_group_dict = {} brand_group_dict = {}