Пример #1
0
        def create_reference(is_widget=True):
            # Reference target is item id
            reference_to_id = item.text(ItemColumn.ID)

            # Set reference values
            # ['order', 'name', 'value', 'type', 'reference', 'id']
            # the text_value msg.REFERENCE_NAME is only to inform the user
            # we will determine references later by UserType 1002
            value_list = [
                lead_zeros(order),
                item.text(ItemColumn.NAME), Msg.REFERENCE_NAME,
                item.text(ItemColumn.TYPE), reference_to_id, ''
            ]

            # Create reference
            new_reference = QTreeWidgetItem(destination_item, value_list)
            new_reference.UserType = 1002
            new_reference.setFlags(VAR_LEVEL_ITEM_FLAGS)
            new_undo_items.append(new_reference)

            # Visual indicator
            if is_widget:
                destination_item.overlay.ref_created()
            else:
                try:
                    destination_item.treeWidget().overlay.ref_created()
                except AttributeError:
                    # Case were destination item is not yet assigned to a tree widget
                    pass
Пример #2
0
    def create_tree_widget_item(node, parent=None):
        __values = XML.create_values_from_item_attrib(node.attrib)

        # Create tree widget item
        if parent:
            item = QTreeWidgetItem(parent, __values)
        else:
            item = QTreeWidgetItem(__values, XML.DEFAULT_TREE_WIDGET_TYPE)

        item.UserType = XML.xmlTagDict[node.tag]

        return item
Пример #3
0
    def item_changed(self, item: QtWidgets.QTreeWidgetItem, column: int):
        """ Signal itemChanged (QTreeWidgetItem *item, int column) """
        # TODO Dateiänderung anzeigen * _ *
        if column == ItemColumn.ORDER or self.ui.sort_tree_widget.work_timer.isActive(
        ):
            # Avoid calls from sorting
            self.set_unsaved_changes()
            return

        self.set_unsaved_changes()

        item.treeWidget().sortBtn.setEnabled(True)

        if column == ItemColumn.ORDER:
            # Re-write order with leading zeros for pretty sorting
            if str(item.text(column)).isdigit():
                item.setText(column, item.text(column).rjust(3, '0'))

        # Change Type based on input to reference column
        if column == ItemColumn.REF:
            # Reference column empty
            if item.text(column) == '':
                # Item is child
                if item.parent():
                    # Change to variant type
                    item.UserType = 1001
                    LOGGER.debug('Changed Type for %s to variant 1001.',
                                 item.text(1))
                else:
                    # Change to preset type
                    item.UserType = 1000
                    LOGGER.debug('Changed Type for %s to preset 1000.',
                                 item.text(1))
            else:
                # Change to reference type if reference entered
                item.UserType = 1002
                LOGGER.debug('Changed item type for %s to %s. Column text: %s',
                             item.text(1), item.UserType, item.text(column))

        # Changing preset name/value/type, updates references
        if item.UserType == 1000 and column in [
                ItemColumn.NAME, ItemColumn.VALUE, ItemColumn.TYPE
        ]:
            new_item_text = item.text(column)
            item_name = item.text(ItemColumn.NAME)
            item_id = item.text(ItemColumn.ID)

            # Update reference names
            if item_id:
                ref_items = item.treeWidget().findItems(
                    item_id, QtCore.Qt.MatchRecursive, ItemColumn.REF)

                # Make sure we don't compare names if name column has changed
                if column == ItemColumn.NAME:
                    ref_names = ref_items
                else:
                    ref_names = item.treeWidget().findItems(
                        item_id, QtCore.Qt.MatchRecursive, ItemColumn.REF)

                for ref_item in ref_items:
                    # Compare name
                    if ref_item in ref_names:
                        ref_item.setText(column, new_item_text)

                LOGGER.debug(
                    'Updated reference column %s from preset with value: %s',
                    column, new_item_text)

        # Changing reference name/value/type, updates preset
        # Disabled, leads to recursion on name check
        if item.UserType == 1002 and column in [
                ItemColumn.NAME, ItemColumn.VALUE, ItemColumn.TYPE
        ]:
            new_item_text = item.text(column)
            item_name = item.text(ItemColumn.NAME)
            item_id = item.text(ItemColumn.REF)

            if item_id:
                pre_items = item.treeWidget().findItems(
                    item_id, QtCore.Qt.MatchRecursive, ItemColumn.ID)

                # Make sure we don't compare names if name column has changed
                if column == ItemColumn.NAME:
                    pre_names = pre_items
                else:
                    pre_names = item.treeWidget().findItems(
                        item_id, QtCore.Qt.MatchRecursive, ItemColumn.ID)

                for pre_item in pre_items:
                    # Compare name
                    if pre_item in pre_names:
                        pre_item.setText(column, new_item_text)

                LOGGER.debug('Updated preset from reference: %s',
                             new_item_text)

        # Check if name is unipue
        if column == ItemColumn.NAME and item.UserType == 1000:
            self.ui.check_item_name(item, item.text(ItemColumn.NAME))

        if item.text(ItemColumn.TYPE) == 'seperator':
            if item.parent():
                # Sub seperator
                item.UserType = 1006
                LOGGER.debug('Updated item type to 1006 - sub seperator')
            else:
                item.UserType = 1005
                LOGGER.debug('Updated item type to 1005 - seperator')
Пример #4
0
    def drop_action(self, source_widget, src_item_list, dest_item):
        if self.no_internal_drag_drop:
            return False

        sort_items = self.ui.sort_tree_widget
        # SortTree(self.ui, source_widget)
        # just for visual indication
        copy = False

        # Dropped to empty area, create copy
        if dest_item is None:
            self.copy(source_widget, self.widget)
            source_widget.overlay.copy_created()
            return

        for src_item in src_item_list:
            # ---------------------
            # Destination and Source are var / ref
            if dest_item.UserType in [1001, 1002
                                      ] and src_item.UserType in [1001, 1002]:
                if src_item.parent() and dest_item.parent():
                    if src_item.parent() is dest_item.parent():
                        # Re-order
                        swap_item_order(src_item, dest_item)

                        # Re-Order all children
                        sort_items.sort_current_level(src_item)

                        LOGGER.debug('Variant %s moved to %s',
                                     src_item.text(ItemColumn.NAME),
                                     dest_item.text(ItemColumn.NAME))
                    else:
                        order = int(dest_item.text(ItemColumn.ORDER))

                        # Copy all selected items at once
                        self.copy(src_item_list,
                                  dest_item.parent(),
                                  src_is_itemlist=True,
                                  new_src_order=order)

                        # Cancel loop, copy worker started with item list
                        return

            # ---------------------
            # Destination is preset and Source is var / ref
            elif dest_item.UserType == 1000 and src_item.UserType in [
                    1001, 1002
            ]:
                if dest_item != src_item.parent():
                    # Destination is different preset, copy variant to top
                    value_list = get_column_values(src_item)
                    # Re-order to top
                    value_list[0] = lead_zeros(0)

                    # Create new item in destination
                    new_item = QTreeWidgetItem(dest_item, value_list)
                    new_item.UserType = src_item.UserType
                    new_item.setFlags(VAR_LEVEL_ITEM_FLAGS)

                    # Re-order
                    re_order_items(new_item, 0, dest_item)
                    sort_items.sort_current_level(new_item)

                    # Undo command
                    AddRemoveItemsCommand.add(self.widget, [new_item],
                                              txt='zu Preset hinzufügen')

                    # Visual indication
                    copy = True
                    LOGGER.debug('Variant %s copied to top of %s',
                                 src_item.text(ItemColumn.NAME),
                                 dest_item.text(ItemColumn.NAME))
                else:
                    # Destination is same preset put variant to top
                    re_order_items(src_item, 0, dest_item)

                    # Re-Order all children
                    sort_items.sort_current_level(src_item)
                    LOGGER.debug('Variant %s re-ordered to top of %s',
                                 src_item.text(ItemColumn.NAME),
                                 dest_item.text(ItemColumn.NAME))

            # ---------------------
            # Source is preset, create reference
            if src_item.UserType == 1000:
                # Create reference at top of preset
                if dest_item.UserType in [1000, 1003]:
                    new_items = self.ui.find_reference_items.check_reference(
                        0, src_item, dest_item)

                    # Undo command
                    if new_items:
                        # Re-order item position
                        re_order_items(new_items[0], 0, dest_item)

                        AddRemoveItemsCommand.add(self.widget,
                                                  new_items,
                                                  txt='Referenz erstellen')

                        # Re-order
                        sort_items.sort_current_level(new_items[0])

                    LOGGER.debug('Reference created %s at to top of %s',
                                 src_item.text(1), dest_item.text(1))

                # Create reference at variant position
                if dest_item.UserType in [1001, 1002]:
                    order = int(dest_item.text(ItemColumn.ORDER))
                    new_items = self.ui.find_reference_items.check_reference(
                        order, src_item, dest_item.parent())

                    if new_items:
                        # Swap order
                        swap_item_order(new_items[0], dest_item)

                        # Undo command
                        AddRemoveItemsCommand.add(
                            self.widget,
                            new_items,
                            txt='Referenz an Varianten Position erstellen')

                        # Re-order
                        sort_items.sort_current_level(new_items[0])

                    LOGGER.debug(
                        'Reference created %s at variant position %s in %s',
                        src_item.text(1), order,
                        dest_item.parent().text(1))

        if copy:
            source_widget.overlay.copy_created()