示例#1
0
    def read_finished(self, data: KnData):
        if self._abort:
            return

        self.data = data
        models = self.models_root_item.copy()
        pr_fam = self.pr_root_item.copy()

        # Populate models tree
        for idx, t in enumerate(self.data.models):
            models.insertChildren(
                models.childCount(), 1, (f'{idx:01d}', t.model, t.market, t.model_text, '', '', t.gearbox),
                fixed_userType=Kg.dialog_item
                )
        # Populate PR Family tree
        for idx, p in enumerate(self.data.pr_families):
            pr_fam.insertChildren(
                pr_fam.childCount(), 1, (f'{idx:01d}', p.name, p.desc),
                fixed_userType=Kg.dialog_item
                )

        # Update View Models
        update_models = UpdateModel(self.treeView_Models)
        update_models.finished.connect(self._data_ready)
        update_models.update(KnechtModel(models, checkable_columns=[self.ModelColumn.code]))

        update_pr = UpdateModel(self.treeView_PrFam)
        update_pr.finished.connect(self._data_ready)
        update_pr.update(KnechtModel(pr_fam, checkable_columns=[self.PrColumn.code]))
示例#2
0
    def load_preset_page_content(self, model_code: str, fakom: str) -> KnechtModel:
        xml_data = self.preset_page_content.get(model_code + fakom)
        if not xml_data:
            return KnechtModel()

        root_item, error = KnechtOpenXml.read_xml(xml_data)
        LOGGER.debug('Loading Preset Page %s content with %s items', model_code + fakom, root_item.childCount())
        return KnechtModel(root_item)
示例#3
0
    def insert_child(cls, model: KnechtModel, parent, child: KnechtItem):
        position = child.childNumber()
        model.insertRows(position, 1, parent)
        new_index = model.index(position, 0, parent)

        cls.update_columns(model, new_index, parent, child.data_list())

        return new_index
示例#4
0
    def _build_material_tree(self, use_config: bool = False):
        material_root_item = KnechtItem(data=('', 'Material Name', 'PR-Tags',
                                              'Desc'))

        for idx, (name,
                  target) in enumerate(self.plmxml.look_lib.materials.items()):
            child_idx = material_root_item.childCount()

            material_root_item.insertChildren(child_idx, 1,
                                              (f'{idx:03d}', name, '', ''))
            target_item = material_root_item.child(child_idx)
            KnechtItemStyle.style_column(target_item, 'fakom_option')

            # -- Create Material Variants
            for c_idx, v in enumerate(target.variants):
                # -- Skip invisible variants in Config Display
                if use_config:
                    if v != target.visible_variant:
                        continue
                target_child_idx = target_item.childCount()
                target_item.insertChildren(
                    target_child_idx, 1,
                    (f'{c_idx:03d}', v.name, v.pr_tags, v.desc))
                if use_config:
                    variant_item = target_item.child(target_child_idx)
                    variant_item.style_bg_green()

        update_material_tree = UpdateModel(self.material_tree)
        update_material_tree.update(KnechtModel(material_root_item))
示例#5
0
    def xlsx_conversion_finished(self, file: Path, root_item: KnechtItem):
        # Move item to main thread
        _root_item = SaveLoadController.copy_item_to_main_thread(root_item)

        # Emit new model
        new_model = KnechtModel(_root_item)
        self.new_model_ready.emit(new_model, file.with_suffix('.xml'), True)
示例#6
0
    def _collect(self, index: QModelIndex, src_model: KnechtModel, collect_reset: bool=True
                 ) -> KnechtVariantList:
        variants = KnechtVariantList()
        current_item = src_model.get_item(index)
        reset_found = False

        if not current_item:
            return variants

        if KnechtSettings.dg['reset'] and collect_reset and current_item.userType != Kg.camera_item:
            reset_found = self._collect_reset_preset(variants, src_model)

        if current_item.userType == Kg.reference:
            # Current item is reference, use referenced item instead
            ref_id = current_item.reference
            current_item = src_model.id_mgr.get_preset_from_id(ref_id)

            if not current_item:
                return variants

        if current_item.userType in (Kg.variant, Kg.output_item):
            self._add_variant(current_item, variants, src_model)
            return variants

        variants.preset_name = current_item.data(Kg.NAME)
        variants.preset_id = current_item.preset_id
        self._collect_preset_variants(current_item, variants, src_model)

        if not reset_found and collect_reset and variants.plm_xml_path is None:
            self.reset_missing.emit()

        return variants
示例#7
0
    def _init_tree_view(self, tree_view: QTreeView) -> KnechtTreeView:
        """ Replace the UI Designer placeholder tree views """
        parent = tree_view.parent()
        new_view = KnechtTreeView(parent, None)
        replace_widget(tree_view, new_view)

        # DeltaGenResult wizard specific
        new_view.setEditTriggers(QTreeView.NoEditTriggers)
        new_view.setDragDropMode(QTreeView.NoDragDrop)
        new_view.supports_drag_move = False
        new_view.supports_drop = False

        # Setup filter widget
        new_view.filter_text_widget = self.filter_edit
        # Setup keyboard shortcuts
        new_view.shortcuts = KnechtTreeViewShortcuts(new_view)
        # Override Edit Shotcuts
        new_view.shortcut_overrides = PresetTreeViewShortcutOverrides(new_view)

        # Update with placeholder Model to avoid access to unset attributes
        UpdateModel(new_view).update(KnechtModel())

        for column in (Kg.VALUE, Kg.TYPE, Kg.REF, Kg.ID):
            new_view.hideColumn(column)

        return new_view
    def replace_view(self, old_view):
        """ Replace an existing placeholder view """
        replace_widget(old_view, self)

        # Update with placeholder Model to avoid access to unset attributes
        UpdateModel(self).update(KnechtModel())

        # most Dialogs do not require a column description
        self.setHeaderHidden(True)
示例#9
0
 def _add_variant(item: KnechtItem, variants: KnechtVariantList, src_model: KnechtModel) -> None:
     if item.userType == Kg.variant:
         index = src_model.get_index_from_item(item)
         variants.add(index, item.data(Kg.NAME), item.data(Kg.VALUE), item.data(Kg.TYPE))
     elif item.userType == Kg.output_item:
         variants.output_path = item.data(Kg.VALUE)
         LOGGER.debug('Collected output path: %s', item.data(Kg.VALUE))
     elif item.userType == Kg.plmxml_item:
         variants.plm_xml_path = item.data(Kg.VALUE)
         LOGGER.debug('Collected PlmXml path: %s', item.data(Kg.VALUE))
示例#10
0
    def _build_scene_tree(self, use_config: bool):
        scene_root_item = KnechtItem(data=('', 'Name', 'PR-Tags',
                                           'Trigger Rules'))

        for idx, node in enumerate(self.plmxml.iterate_root_nodes()):
            self._iterate_scene_children(idx, node, scene_root_item,
                                         use_config)

        update_scene_tree = UpdateModel(self.scene_tree)
        update_scene_tree.update(KnechtModel(scene_root_item))
示例#11
0
    def update(self, new_model: KnechtModel):
        """
            Creates a QSortFilterProxyModel for the provided model and updates the view model with the
            proxy model instead of the actual model.

            If the previous model contained data, it will create an Undo command.
        """
        view_undo = _ViewReplaceModelUndo(self.view)

        self.view.progress_msg.msg(_('Daten werden eingerichtet.'))
        self.view.progress_msg.show_progress()

        new_model.silent = False
        new_model.initial_item_id_connection()

        proxy_model = KnechtSortFilterProxyModel(self.view)
        proxy_model.setSourceModel(new_model)

        if not view_undo.change_model(proxy_model):
            # Previous model was empty, no undo created
            # We need to update the model without undo
            self.view.setModel(proxy_model)

        QTimer.singleShot(1, self.setup_header)
示例#12
0
    def current_view(self) -> KnechtTreeView:
        """ Guarantees to return a KnechtTreeView even if the current tab is a non-document widget """
        current_tab = self.tab.currentWidget()

        if not hasattr(current_tab, 'user_view'):
            # Look for existing tab with tree view
            for i in range(self.tab.count() - 1, -1, -1):
                if hasattr(self.tab.widget(i), 'user_view'):
                    self.tab.setCurrentIndex(i)
                    return self.tab.widget(i).user_view

            # Create a tab with a view if necessary
            model = KnechtModel()
            return self.create_view(model,
                                    Path('New_Document_View.xml'),
                                    new_page=True)
        return current_tab.user_view
示例#13
0
    def create_presets(self):
        root_item = KnechtItem()

        for (src_index,
             item) in self.image_view.editor.iterator.iterate_view():
            if item.data(self.check_column, Qt.CheckStateRole) == Qt.Unchecked:
                continue

            name = item.data(Kg.NAME)
            data = (f'{root_item.childCount():03d}', name, '', 'preset', '',
                    Kid.convert_id(f'{root_item.childCount()}'))
            root_item.insertChildren(root_item.childCount(), 1, data)

        date = datetime.datetime.now().strftime('%Y%m%d')
        project = self._current_project_name.replace(' ', '_')
        self.finished.emit(KnechtModel(root_item),
                           Path(f'{date}_{project}.xml'))
示例#14
0
    def _add_camera_variants(item: KnechtItem, variants: KnechtVariantList, src_model: KnechtModel) -> None:
        """ Convert Camera Preset items to camera command variants """
        for child in item.iter_children():
            camera_tag, camera_value = child.data(Kg.NAME), child.data(Kg.VALUE)

            if camera_tag in KnechtImageCameraInfo.rtt_camera_cmds:
                index = src_model.get_index_from_item(child)
                camera_cmd = KnechtImageCameraInfo.rtt_camera_cmds.get(camera_tag)
                camera_value = camera_value.replace(' ', '')

                try:
                    camera_cmd = camera_cmd.format(*camera_value.split(','))
                except Exception as e:
                    LOGGER.warning('Camera Info Tag Value does not match %s\n%s', camera_value, e)

                variants.add(index, camera_tag, camera_cmd, 'camera_command')

                LOGGER.debug('Collecting Camera Command %s: %s', camera_tag, camera_cmd)
示例#15
0
    def update_project_view(self, projects: dict):
        """ (Name, ModelYear, 'JobNo) """
        if not projects:
            return

        root_item = KnechtItem(
            None,
            ('', _('Bezeichnung'), _('Modelljahr'), _('Job'), '', _('Id')))

        for num_idx, (_id, project_data) in enumerate(projects.items()):
            data = (f'{num_idx:03d}', *project_data, '', str(_id))
            p_item = KnechtItem(root_item, data)
            KnechtItemStyle.style_column(p_item,
                                         'render_preset',
                                         column=Kg.NAME)
            root_item.append_item_child(p_item)

        update_model = UpdateModel(self.project_view)
        update_model.update(KnechtModel(root_item))

        self.toggle_view_columns(self.details_btn.isChecked())
        self.project_view.setHeaderHidden(False)
示例#16
0
    def setup_tree_view(self,
                        tree_view: KnechtTreeView,
                        model: Union[KnechtModel, None] = None,
                        file: Path = Path('New_Document.xml'),
                        filter_widget: QLineEdit = None):
        # Setup TreeView model
        if not model:
            # Use empty model if none provided
            model = KnechtModel()

        # Setup model
        update_model = UpdateModel(tree_view)
        update_model.update(model)
        tree_view.progress.hide()

        # Setup keyboard shortcuts
        shortcuts = KnechtTreeViewShortcuts(tree_view)
        tree_view.shortcuts = shortcuts

        # Setup filter text widget
        if filter_widget:
            tree_view.filter_text_widget = filter_widget

        # Set Tree object name
        tree_view.setObjectName(file.name)

        # Set focus to the just created view
        # otherwise menus may try to access already deleted views
        tree_view.setFocus(Qt.OtherFocusReason)

        # Connect view clean status change
        tree_view.clean_changed.connect(self.view_clean_changed)

        LOGGER.debug('View manager basic tree setup for %s %s',
                     tree_view.objectName(), file.name)
        self.view_updated.emit(tree_view)

        self.additional_tree_setup(tree_view)
示例#17
0
    def update_image_view(self, images: dict):
        if not images:
            return

        root_item = KnechtItem(None, ('', _('Name'), _('Priorität'),
                                      _('Erstellt'), '', _('wagenbauteil Id')))

        for num_idx, (img_id, image_data) in enumerate(images.items()):
            """ (name, priority, created, pr_string, opt_id, produced_image_id) """
            name, priority, created, pr_string, opt_id, produced_image_id = image_data
            img_item = KnechtItem(
                root_item,
                (f'{num_idx:03d}', name, priority, created, '', str(opt_id)))
            KnechtItemStyle.style_column(img_item, 'preset', Kg.NAME)
            root_item.append_item_child(img_item)

        update_model = UpdateModel(self.image_view)
        update_model.update(
            KnechtModel(root_item, checkable_columns=[self.check_column]))

        self.toggle_view_columns(self.details_btn.isChecked())
        self.image_view.setHeaderHidden(False)
        self.image_view.check_items([], Kg.NAME, check_all=True)
示例#18
0
    def _xml_items_loaded(self, root_item: KnechtItem, error: str, file: Path):
        if not root_item.childCount():
            LOGGER.info('Could not load Xml. KnechtXml returned %s', error)
            self.load_aborted.emit(error, file)
            return

        # Transfer root_item to new_model
        new_model = KnechtModel(root_item)

        # Add recent file entry
        if self.create_recent_entries:
            KnechtSettings.add_recent_file(file.as_posix(), 'xml')
            KnechtSettings.app['current_path'] = file.parent.as_posix()

        # Output load info
        self.last_progress_time = time.time() - self.load_start_time

        LOGGER.info(
            f'Xml file {file.name} took {self.last_progress_time:.4}s to parse. {root_item.thread()}'
        )

        # Transfer model
        self.model_loaded.emit(new_model, file)
示例#19
0
    def initializePage(self):
        data = self.wizard.session.data.import_data
        item_creator = KnechtDataToModel(data)

        # -- Populate Preset Tree --
        for trim in data.models:
            if trim.model not in data.selected_models:
                continue

            item_data = (f'{item_creator.root_item.childCount():03d}', trim.model_text, trim.model, 'trim_setup')
            trim_item = KnechtItem(item_creator.root_item, item_data)
            trim_item.fixed_userType = Kg.group_item
            item_creator.create_fakom(trim, is_preset_wizard=True, parent_item=trim_item)
            item_creator.root_item.append_item_child(trim_item)

        fakom_model = KnechtModel(item_creator.root_item)
        for column in (Kg.VALUE, Kg.DESC, Kg.TYPE, Kg.REF, Kg.ID):
            self.fakom_tree.hideColumn(column)
        UpdateModel(self.fakom_tree).update(fakom_model)

        QTimer.singleShot(50, self.load_fakom_selection)

        LOGGER.info('FaKom Wizard Page initialized.')
示例#20
0
    def _create_options_knecht_model(model_code, import_data: KnData, is_pr_options=True):
        """ Create Knecht Item Model with either available PR-Options or Packages """
        converter = KnechtDataToModel(import_data)
        opt_item_model = KnechtModel()

        trim = [t for t in import_data.models if t.model == model_code]
        if not trim:
            return opt_item_model
        else:
            trim = trim[0]

        if is_pr_options:
            if import_data.options_text_filter:
                # Create PR-Options matching E
                converter.create_pr_options(trim.iterate_optional_filtered_pr(), opt_item_model.root_item,
                                            ignore_pr_family=False)
            else:
                # Create PR-Options not matching L
                converter.create_pr_options(trim.iterate_optional_pr(), opt_item_model.root_item,
                                            ignore_pr_family=False)
        else:
            converter.create_packages(trim, opt_item_model.root_item, filter_pkg_by_pr_family=False)

        return opt_item_model
示例#21
0
    def _init_tree_view(self, tree_view: QTreeView,
                        item_model: KnechtModel) -> KnechtTreeView:
        """ Replace the UI Designer placeholder tree views """
        parent = tree_view.parent()
        new_view = KnechtTreeView(parent, self.wizard.ui.app.undo_grp)
        replace_widget(tree_view, new_view)

        # Preset wizard specific
        new_view.setEditTriggers(QTreeView.NoEditTriggers)
        new_view.supports_drag_move = False
        new_view.supports_drop = False

        # Setup filter widget
        new_view.filter_text_widget = self.line_edit_preset
        # Setup keyboard shortcuts
        new_view.shortcuts = KnechtTreeViewShortcuts(new_view)

        # Update with placeholder Model to avoid access to unset attributes
        UpdateModel(new_view).update(item_model or KnechtModel())

        for column in self.hidden_columns_a:
            new_view.hideColumn(column)

        return new_view
示例#22
0
    def _init_tree_view(self, tree_view: QTreeView) -> KnechtTreeView:
        """ Replace the UI Designer placeholder tree views """
        parent = tree_view.parent()
        new_view = KnechtTreeView(parent, None)
        replace_widget(tree_view, new_view)

        # Fakom wizard specific
        new_view.setSelectionMode(QTreeView.NoSelection)
        new_view.setSelectionBehavior(QTreeView.SelectRows)
        new_view.setEditTriggers(QTreeView.NoEditTriggers)
        new_view.setDragDropMode(QTreeView.NoDragDrop)
        new_view.supports_drag_move = False
        new_view.setIndentation(15)

        # Setup filter widget
        new_view.filter_text_widget = self.filter_edit
        # Setup keyboard shortcuts
        new_view.shortcuts = KnechtTreeViewShortcuts(new_view)

        # Update with placeholder Model to avoid access to unset attributes
        UpdateModel(new_view).update(KnechtModel())
        new_view.clicked.connect(self._fakom_item_pressed)

        return new_view
示例#23
0
    def _create_document_from_transfer(self, data):
        self.ui.main_menu.file_menu.load_save_mgr.load_start_time = time.time()
        new_file = Path(create_file_safe_name(f"{data.get('label', '')}_Transfer.xml"))
        preset_ls: List[KnechtVariantList] = data.get('presets', list())

        # -- Create Item Model
        root_item = KnechtItem()
        plmxml_path = preset_ls[0].plm_xml_path

        plmxml_item = self._create_top_level_item(root_item, ItemTemplates.plmxml)
        plmxml_item.setData(Kg.VALUE, plmxml_path)
        plmxml_item.setData(Kg.NAME, Path(plmxml_path).name)

        root_item.append_item_child(plmxml_item)
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)

        preset_item_ls = list()
        for idx, variant_ls in enumerate(preset_ls, start=1):
            variants = variant_ls.variants
            name = variant_ls.preset_name

            model = ''
            if len(variants) > 1:
                model = variants[1].value

            preset_item = self._create_top_level_item(root_item, ItemTemplates.preset)
            preset_item.setData(Kg.NAME, name)
            preset_item.setData(Kg.VALUE, model)
            preset_item.setData(Kg.ID, Kid.create_id())
            plmxml_ref = plmxml_item.copy(new_parent=preset_item)
            plmxml_ref.convert_to_reference()
            preset_item.append_item_child(plmxml_ref)

            for variant in variants:
                pr_item = KnechtItem(preset_item,
                                     (f'{preset_item.childCount():03d}', variant.value, 'on'))
                preset_item.append_item_child(pr_item)

            preset_item_ls.append(preset_item)
            root_item.append_item_child(preset_item)

        # -- Create some sugar template
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)

        #  - Viewsets -
        views = list()
        for shot in ('Shot-05', 'Shot-06'):
            view = self._create_top_level_item(root_item, ItemTemplates.viewset)
            view.setData(Kg.NAME, f'Viewset_{shot}')
            view.child(0).setData(Kg.VALUE, shot)
            root_item.append_item_child(view)
            views.append(view)

        #  - Output -
        out = self._create_top_level_item(root_item, ItemTemplates.output)
        out.setData(Kg.VALUE, os.path.expanduser('~'))
        root_item.append_item_child(out)

        #  - RenderPreset -
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)
        ren = self._create_top_level_item(root_item, ItemTemplates.render)
        ren.setData(Kg.NAME, f"Render_{data.get('label')}")
        out_ref = out.copy(new_parent=ren)
        out_ref.convert_to_reference()
        out_ref.setData(Kg.ORDER, f'{ren.childCount():03d}')
        ren.append_item_child(out_ref)

        for item in views + preset_item_ls:
            ref_item = item.copy()
            ref_item.removeChildren(0, ref_item.childCount())
            ref_item.convert_to_reference()
            ref_item.setData(Kg.ORDER, f'{ren.childCount():03d}')
            ren.append_item_child(ref_item)

        root_item.append_item_child(ren)
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)

        self.model_loaded.emit(KnechtModel(root_item), new_file)
示例#24
0
 def new_empty_model(view):
     empty_model = KnechtModel()
     update_model = UpdateModel(view)
     update_model.update(empty_model)
示例#25
0
 def _reset_view(self):
     UpdateModel(self.search_view).update(KnechtModel())
示例#26
0
    def __init__(self, wizard, model: str, fakom: str):
        """ Page for one Preset with available PR-Options and Packages tree's

        :param modules.gui.wizard.wizard.PresetWizard wizard: The parent wizard
        :param str model: model code
        :param str fakom: fakom code
        """
        super(PresetWizardPage, self).__init__()
        self.wizard = wizard
        self.model = model
        self.fakom = fakom

        trim = [
            x for x in wizard.session.data.import_data.models
            if x.model == model
        ][0]
        self.model_text = trim.model_text

        SetupWidget.from_ui_file(self, Resource.ui_paths['wizard_preset'])

        # -- Title --
        self.page_num = 1 + len(self.wizard.session.data.preset_page_ids)

        # -- Sub Title Update Timer --
        self.update_title_timer = QTimer()
        self.update_title_timer.setInterval(25)
        self.update_title_timer.setSingleShot(True)
        self.update_title_timer.timeout.connect(self.update_page_title)

        # -- Trigger filter update for all views ---
        self.update_filter_timer = QTimer()
        self.update_filter_timer.setInterval(5)
        self.update_filter_timer.setSingleShot(True)
        self.update_filter_timer.timeout.connect(self.update_filter_all_views)

        self.line_edit_preset: QLineEdit
        self.line_edit_preset.textChanged.connect(
            self.update_filter_timer.start)

        # -- Setup Page Ui --
        self.option_auto_btn: QPushButton
        self.option_auto_btn.setText(_('Preset auto&magisch befüllen'))
        self.option_auto_btn.setIcon(IconRsc.get_icon('qub_button'))
        self.option_auto_btn.setStatusTip(
            _('Aktuelles Preset automagisch mit nicht verwendeten Optionen befüllen. '
              'Bezugs-, Sitz-, Leder oder Fahrwerksoptionen werden ignoriert.')
        )
        self.option_auto_btn.released.connect(self.fill_automagically)

        self.option_hide_btn: QPushButton
        eye_icon = IconRsc.get_icon('eye')
        eye_icon.addPixmap(IconRsc.get_pixmap('eye-disabled'), QIcon.Normal,
                           QIcon.On)
        self.option_hide_btn.setIcon(eye_icon)
        self.option_hide_btn.setStatusTip(
            _('Bereits verwendete Optionen ein- oder ausblenden'))
        self.option_hide_btn.toggled.connect(self.update_available_options)

        self.option_lock_btn: QPushButton
        lock_icon = IconRsc.get_icon('lock_open')
        lock_icon.addPixmap(IconRsc.get_pixmap('lock'), QIcon.Normal, QIcon.On)
        self.option_lock_btn.setIcon(lock_icon)
        self.option_lock_btn.setStatusTip(
            _('Bereits verwendete Optionen für die Bearbeitung sperren'))
        self.option_lock_btn.toggled.connect(self.update_available_options)

        self.option_tree_btn: QPushButton
        opt_icon = QIcon(IconRsc.get_pixmap('options'))
        opt_icon.addPixmap(IconRsc.get_pixmap('options-neg'), QIcon.Normal,
                           QIcon.On)
        self.option_tree_btn.setIcon(opt_icon)
        self.option_tree_btn.setStatusTip(
            _('Spalte Beschreibung ein- oder ausblenden'))
        self.option_tree_btn.toggled.connect(self.update_view_headers)

        # -- Replace Placeholder TreeViews --
        self.pkg_tree = self._init_tree_view(
            self.pkg_tree, self.wizard.session.pkg_models.get(model))
        self.pkg_tree.permanent_type_filter_column = Kg.VALUE
        self.pkg_tree.context = OptionTreeContextMenu(self.pkg_tree, self)
        self.option_tree = self._init_tree_view(
            self.option_tree, self.wizard.session.opt_models.get(model))
        self.option_tree.permanent_type_filter_column = Kg.NAME
        self.option_tree.context = OptionTreeContextMenu(
            self.option_tree, self)

        # -- Setup Preset Tree --
        self.preset_tree = self._init_tree_view(self.preset_tree,
                                                KnechtModel())
        self.preset_tree.supports_drop = True
        self.preset_tree.supports_drag_move = True
        self.preset_tree.is_wizard_preset_view = True
        self.preset_tree.context = PresetTreeContextMenu(
            self.preset_tree, self.wizard)
        self.preset_tree.shortcut_override = PresetTreeViewShortcutOverrides(
            self.preset_tree)
        self.preset_tree.view_refreshed.connect(self.update_available_options)

        # Initial Tree sort
        QTimer.singleShot(50, self.update_view_headers)
示例#27
0
    def collect_result(self):
        kn_data = self.session.data.import_data
        converter = KnechtDataToModel(kn_data)
        trim_items = dict()

        # --- Create Trim Setups ---
        for model_code in self.session.data.fakom_selection.keys():
            trim = self._get_trim_from_models(kn_data.models, model_code)
            trim_items[model_code] = dict()
            trim_item = converter.create_trim(trim)
            trim_item.refresh_id_data()
            trim_items[model_code]['trim_setup'] = trim_item
            trim_items[model_code][
                'trim_option'] = converter.create_trim_options(
                    trim, kn_data.options_text_filter)
            trim_items[model_code]['packages'] = list()
            trim_items[model_code]['fakom'] = dict()

        # -- Create FaKom Items --
        for preset_page in self.session.iterate_preset_pages():
            fakom_ls = preset_page.fakom.split('-')
            if len(fakom_ls) < 4:
                continue
            trim = self._get_trim_from_models(kn_data.models,
                                              preset_page.model)

            # Create lists of List[KnPr] for SIB/VOS/LUM families
            sib_pr_ls = [
                pr for pr in trim.iterate_available_pr()
                if pr.family.casefold() == 'sib'
            ]
            lum_pr_ls = [
                pr for pr in trim.iterate_available_pr()
                if pr.family.casefold() == 'lum'
            ]
            vos_pr_ls = [
                pr for pr in trim.iterate_available_pr()
                if pr.family.casefold() == 'vos'
            ]

            fa, sib, vos, lum = fakom_ls
            LOGGER.debug('Creating Fakom Item %s %s %s %s', fa, sib, vos, lum)
            sib_pr = self._get_pr_from_list(sib_pr_ls, sib)
            vos_pr = self._get_pr_from_list(vos_pr_ls, vos)
            lum_pr = self._get_pr_from_list(lum_pr_ls, lum)

            fakom_type = 'fakom_option'
            if not {sib_pr.value, vos_pr.value, lum_pr.value}.difference('L'):
                fakom_type = 'fakom_setup'

            fa_item = converter.create_fakom_item(None, trim.model,
                                                  trim.model_text, fa, sib,
                                                  vos, lum, sib_pr.desc,
                                                  vos_pr.desc, lum_pr.desc,
                                                  fakom_type, False)
            fa_item.refresh_id_data()
            trim_items[preset_page.model]['fakom'][preset_page.fakom] = fa_item

        # --- Prepare presets ---
        preset_items = list()
        for preset_page in self.session.iterate_preset_pages():
            # -- Create Preset item --
            preset_item = KnechtItem(
                None, ('000', preset_page.subTitle(), '',
                       Kg.type_keys[Kg.preset], '', Kid.create_id()))
            # -- Add reference to trim setup --
            trim_ref = trim_items[preset_page.model]['trim_setup'].copy(
                copy_children=False)
            trim_ref.convert_to_reference()
            trim_ref.setData(0, '000')
            preset_item.append_item_child(trim_ref)

            # -- Add reference to fakom item --
            fa_ref = trim_items[preset_page.model]['fakom'][
                preset_page.fakom].copy(copy_children=False)
            fa_ref.convert_to_reference()
            fa_ref.setData(0, '001')
            preset_item.append_item_child(fa_ref)

            # -- Collect preset content --
            for _, pr_item in preset_page.preset_tree.editor.iterator.iterate_view(
            ):
                if pr_item.userType == Kg.variant:
                    # --- Add PR-option ---
                    pr_item_copy = pr_item.copy()
                    pr_item_copy.setData(0, f'{preset_item.childCount():03d}')
                    preset_item.append_item_child(pr_item_copy)
                else:
                    # --- Add package reference ---
                    pkg_ref = pr_item.copy(copy_children=False)
                    pkg_ref.convert_to_reference()
                    pkg_ref.setData(0, f'{preset_item.childCount():03d}')
                    preset_item.append_item_child(pkg_ref)
                    # --- Add package ---
                    trim_items[preset_page.model]['packages'].append(
                        pr_item.copy())

            preset_items.append(preset_item)

        # --- Create trim, package and fakom items ---
        root_item = KnechtItem()

        for model_code in self.session.data.fakom_selection.keys():
            # -- Add trim setup --
            trim_item = trim_items[model_code]['trim_setup']
            trim_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
            root_item.append_item_child(trim_item)

            # -- Add trim options --
            trim_options = trim_items[model_code]['trim_option']
            trim_options.setData(Kg.ORDER, f'{root_item.childCount():03d}')
            root_item.append_item_child(trim_options)

            # -- Add Packages --
            for pkg_item in trim_items[model_code]['packages']:
                pkg_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
                root_item.append_item_child(pkg_item)

            # -- Add FaKom Items --
            for fa_item in trim_items[model_code]['fakom'].values():
                fa_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
                root_item.append_item_child(fa_item)

            # -- Add separator --
            root_item.append_item_child(
                KnechtItem(
                    None,
                    (f'{root_item.childCount():03d}', '', '', 'separator')))

        # -- Create default Reset --
        reset_item = create_reset_item(root_item.childCount())
        root_item.append_item_child(reset_item)

        # -- Add separator --
        root_item.append_item_child(
            KnechtItem(None,
                       (f'{root_item.childCount():03d}', '', '', 'separator')))

        # --- Create Preset items ---
        for preset_item in preset_items:
            preset_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
            root_item.append_item_child(preset_item)

        UpdateModel(self.result_tree).update(KnechtModel(root_item))