# Path: asammdf/gui/dialogs/range_editor.py
# class RangeEditor(Ui_RangeDialog, QtWidgets.QDialog):
#     def __init__(self, name, unit="", ranges=None, brush=False, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.setupUi(self)
# 
#         self.name = name
#         self.unit = unit
#         self.result = []
#         self.pressed_button = None
#         self._brush = brush
# 
#         if ranges:
#             for range_info in ranges:
#                 widget = RangeWidget(
#                     parent=self,
#                     name=self.name,
#                     brush=brush,
#                     **range_info,
#                 )
# 
#                 item = QtWidgets.QListWidgetItem()
#                 item.setSizeHint(widget.sizeHint())
#                 self.ranges.addItem(item)
#                 self.ranges.setItemWidget(item, widget)
# 
#         self.ranges.setUniformItemSizes(True)
# 
#         self.apply_btn.clicked.connect(self.apply)
#         self.insert_btn.clicked.connect(self.insert)
#         self.cancel_btn.clicked.connect(self.cancel)
#         self.reset_btn.clicked.connect(self.reset)
# 
#         self.setWindowTitle(f"Edit {self.name} range colors")
# 
#     def apply(self, event):
#         ranges = []
#         count = self.ranges.count()
#         for i in range(count):
#             item = self.ranges.item(i)
#             if item is None:
#                 continue
# 
#             widget = self.ranges.itemWidget(item)
#             ranges.append(widget.to_dict(brush=self._brush))
# 
#         self.result = ranges
#         self.pressed_button = "apply"
#         self.close()
# 
#     def insert(self, event):
#         widget = RangeWidget(self.name)
# 
#         item = QtWidgets.QListWidgetItem()
#         item.setSizeHint(widget.sizeHint())
#         self.ranges.addItem(item)
#         self.ranges.setItemWidget(item, widget)
# 
#     def reset(self, event):
#         self.ranges.clear()
#         self.result = []
# 
#     def cancel(self, event):
#         self.result = []
#         self.pressed_button = "cancel"
#         self.close()
# 
# Path: asammdf/gui/utils.py
# def extract_mime_names(data):
#     def fix_comparison_name(data):
#         for i, (
#             name,
#             group_index,
#             channel_index,
#             mdf_uuid,
#             item_type,
#             ranges,
#         ) in enumerate(data):
#             if item_type == "channel":
#                 if (group_index, channel_index) != (-1, -1):
#                     name = COMPARISON_NAME.match(name).group("name").strip()
#                     data[i][0] = name
#             else:
#                 fix_comparison_name(channel_index)
# 
#     names = []
#     if data.hasFormat("application/octet-stream-asammdf"):
#         data = bytes(data.data("application/octet-stream-asammdf")).decode("utf-8")
#         data = json.loads(data)
#         fix_comparison_name(data)
#         names = data
# 
#     return names


import json
from struct import pack
from PyQt5 import QtCore, QtGui, QtWidgets
from ..dialogs.range_editor import RangeEditor
from ..utils import extract_mime_names

            data.append(
                (
                    info,
                    *item.entry,
                    str(item.mdf_uuid),
                    "channel",
                    ranges,
                )
            )

        data = json.dumps(data).encode("utf-8")

        mimeData.setData("application/octet-stream-asammdf", QtCore.QByteArray(data))

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.exec(QtCore.Qt.CopyAction)

    def dragEnterEvent(self, e):
        e.accept()

    def dropEvent(self, e):

        if e.source() is self:
            super().dropEvent(e)
            self.items_rearranged.emit()
        else:
            data = e.mimeData()
            if data.hasFormat("application/octet-stream-asammdf"):

# Path: asammdf/gui/dialogs/range_editor.py
# class RangeEditor(Ui_RangeDialog, QtWidgets.QDialog):
#     def __init__(self, name, unit="", ranges=None, brush=False, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.setupUi(self)
# 
#         self.name = name
#         self.unit = unit
#         self.result = []
#         self.pressed_button = None
#         self._brush = brush
# 
#         if ranges:
#             for range_info in ranges:
#                 widget = RangeWidget(
#                     parent=self,
#                     name=self.name,
#                     brush=brush,
#                     **range_info,
#                 )
# 
#                 item = QtWidgets.QListWidgetItem()
#                 item.setSizeHint(widget.sizeHint())
#                 self.ranges.addItem(item)
#                 self.ranges.setItemWidget(item, widget)
# 
#         self.ranges.setUniformItemSizes(True)
# 
#         self.apply_btn.clicked.connect(self.apply)
#         self.insert_btn.clicked.connect(self.insert)
#         self.cancel_btn.clicked.connect(self.cancel)
#         self.reset_btn.clicked.connect(self.reset)
# 
#         self.setWindowTitle(f"Edit {self.name} range colors")
# 
#     def apply(self, event):
#         ranges = []
#         count = self.ranges.count()
#         for i in range(count):
#             item = self.ranges.item(i)
#             if item is None:
#                 continue
# 
#             widget = self.ranges.itemWidget(item)
#             ranges.append(widget.to_dict(brush=self._brush))
# 
#         self.result = ranges
#         self.pressed_button = "apply"
#         self.close()
# 
#     def insert(self, event):
#         widget = RangeWidget(self.name)
# 
#         item = QtWidgets.QListWidgetItem()
#         item.setSizeHint(widget.sizeHint())
#         self.ranges.addItem(item)
#         self.ranges.setItemWidget(item, widget)
# 
#     def reset(self, event):
#         self.ranges.clear()
#         self.result = []
# 
#     def cancel(self, event):
#         self.result = []
#         self.pressed_button = "cancel"
#         self.close()
# 
# Path: asammdf/gui/utils.py
# def extract_mime_names(data):
#     def fix_comparison_name(data):
#         for i, (
#             name,
#             group_index,
#             channel_index,
#             mdf_uuid,
#             item_type,
#             ranges,
#         ) in enumerate(data):
#             if item_type == "channel":
#                 if (group_index, channel_index) != (-1, -1):
#                     name = COMPARISON_NAME.match(name).group("name").strip()
#                     data[i][0] = name
#             else:
#                 fix_comparison_name(channel_index)
# 
#     names = []
#     if data.hasFormat("application/octet-stream-asammdf"):
#         data = bytes(data.data("application/octet-stream-asammdf")).decode("utf-8")
#         data = json.loads(data)
#         fix_comparison_name(data)
#         names = data
# 
#     return names


# Path: asammdf/gui/widgets/tree_numeric.py
import json
from struct import pack
from PyQt5 import QtCore, QtGui, QtWidgets
from ..dialogs.range_editor import RangeEditor
from ..utils import extract_mime_names


            data.append(
                (
                    info,
                    *item.entry,
                    str(item.mdf_uuid),
                    "channel",
                    ranges,
                )
            )

        data = json.dumps(data).encode("utf-8")

        mimeData.setData("application/octet-stream-asammdf", QtCore.QByteArray(data))

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.exec(QtCore.Qt.CopyAction)

    def dragEnterEvent(self, e):
        e.accept()

    def dropEvent(self, e):

        if e.source() is self:
            super().dropEvent(e)
            self.items_rearranged.emit()
        else:
            data = e.mimeData()
            if data.hasFormat("application/octet-stream-asammdf"):

                names = extract_mime_names(data)