def _initialize_configuration_model(self, configuration): data = DataStorage() configurations = data.get_configurations() configurations_order = data.get_configurations_order() for name in configurations_order: if name == configuration.get_name(): continue EditView._add_configuration(configurations[name], self._configurationTreeWidget) EditView._configuration_model = self._configurationTreeWidget material_print_amounts = configuration.get_material_print_amounts() for material in configuration.get_materials(): item = get_item(self._materialTreeWidget.invisibleRootItem(), material.get_name()) check_item(item) if item is not None: print_amount = material_print_amounts[material.get_name()] item.setText(1, str(print_amount)) configuration_print_amounts = configuration.get_config_print_amounts() for configuration in configuration.get_configurations(): item = get_item(self._configurationTreeWidget.invisibleRootItem(), configuration.get_name()) check_item(item) if item is not None: print_amount = configuration_print_amounts[configuration.get_name()] item.setText(1, str(print_amount))
def _saved(self): name = self._nameField.text() self._configuration = Configuration(name) data = DataStorage() data.add_configuration(self._configuration) data.persist() self.accept()
def _initialize_model(self): data = DataStorage() materials = data.get_materials() materials_order = data.get_materials_order() for name in materials_order: MaterialView._add_material(materials[name], self._treeWidget) if MaterialView._material_model is None: MaterialView._material_model = self._treeWidget
def _get_config_model(): data = DataStorage() configurations_order = data.get_configurations_order() model = QStandardItemModel() for name in configurations_order: item = create_new_list_item(name) model.appendRow(item) return model
def _initialize_material_model(self): data = DataStorage() materials = data.get_materials() materials_order = data.get_materials_order() for name in materials_order: EditView._add_material(materials[name], self._materialTreeWidget) if EditView._material_model is None: EditView._material_model = self._materialTreeWidget
def _save(self): # update sub configurations config_print_amounts = self._calculate_print_amounts(self._configurationTreeWidget.invisibleRootItem()) for config in self._currentConfiguration.get_configurations(): # type: Configuration if config.get_name() not in config_print_amounts: self._currentConfiguration.remove_configuration(config) else: self._currentConfiguration.set_config_print_amount(config, config_print_amounts[config.get_name()]) del config_print_amounts[config.get_name()] data = DataStorage() for config_name in config_print_amounts: config = data.get_configuration(config_name) self._currentConfiguration.add_configuration(config, config_print_amounts[config_name]) # update material configurations material_print_amounts = self._calculate_print_amounts(self._materialTreeWidget.invisibleRootItem()) for material in self._currentConfiguration.get_materials(): # type: Material if material.get_name() not in material_print_amounts: self._currentConfiguration.remove_material(material) else: self._currentConfiguration.set_material_print_amount( material, material_print_amounts[material.get_name()] ) del material_print_amounts[material.get_name()] for material_name in material_print_amounts: material = data.get_material(material_name) self._currentConfiguration.add_material(material, material_print_amounts[material_name]) data.update_configuration(self._currentConfiguration.get_name(), self._currentConfiguration) data.persist() self.done(QDialog.Accepted)
def _on_selection_change(self, model_index): """ Called on selecting a new item in the listView. :param model_index: index of selected item :type model_index: QModelIndex """ data = DataStorage() configurations = data.get_configurations() selected_item = self._configuration_model.itemFromIndex(model_index) # type: QStandardItem current_config_name = selected_item.text() current_config = configurations[current_config_name] # type: Configuration self._show_detail_view(current_config) config_wide_print_amount = self._config_wide_print_amounts[current_config_name] material_print_amounts = current_config.get_effective_material_print_amounts( config_wide_print_amount, self._recalculateEffectivePrintAmounts ) self._recalculateEffectivePrintAmounts = False if self._selected_counter == 0: MaterialView.reset_check_state_and_print_amount() for material in current_config.get_materials(): item = get_item(MaterialView.get_model().invisibleRootItem(), material.get_name()) if item is not None: print_amount = material_print_amounts[material.get_name()] if is_checked(selected_item): check_item(item) if current_config_name not in self._selected_configs: print_amount += int(item.text(1)) else: print_amount = int(item.text(1)) item.setText(1, str(print_amount)) if is_checked(selected_item) and current_config_name not in self._selected_configs: self._selected_configs[current_config_name] = True self._selected_counter += 1 if not is_checked(selected_item) and current_config_name in self._selected_configs: self._selected_configs.pop(current_config_name) self._selected_counter -= 1 self._currentConfiguration = current_config
def _on_selection_change(self, model_index): """ Called on selecting a new item in the treeView. :param model_index: index of selected item :type model_index: QModelIndex """ data = DataStorage() materials = data.get_materials() selected_item = self._treeWidget.itemFromIndex(model_index) # type: QTreeWidgetItem current_material_name = selected_item.text(0) parent_item = selected_item.parent() current_material = None if parent_item is not None: parent_material = data.get_material(parent_item.text(0)) sub_materials = parent_material.get_materials() for sub_material in sub_materials: if sub_material.get_name() == selected_item.text(0): current_material = sub_material break else: current_material = materials[current_material_name] self._show_detail_view(current_material)