예제 #1
0
    def dropMimeData(
        self,
        data: QMimeData,
        action: Qt.DropAction,
        destRow: int,
        col: int,
        parent: QModelIndex,
    ) -> bool:
        """Handles `data` from a drag and drop operation ending with `action`.

        The specified row, column and parent indicate the location of an item
        in the model where the operation ended. It is the responsibility of the
        model to complete the action at the correct location.

        Returns
        -------
        bool ``True`` if the `data` and `action` were handled by the model;
            otherwise returns ``False``.
        """
        if not data or action != Qt.MoveAction:
            return False
        if not data.hasFormat(self.mimeTypes()[0]):
            return False

        if isinstance(data, ItemMimeData):
            moving_indices = data.indices

            logger.debug(f"dropMimeData: indices {moving_indices} ➡ {destRow}")

            if len(moving_indices) == 1:
                return self._root.move(moving_indices[0], destRow)
            else:
                return bool(self._root.move_multiple(moving_indices, destRow))
        return False
예제 #2
0
 def canDropMimeData(self, data: QMimeData, *args):
     if any([data.hasFormat(typ) for typ in self.mimeTypes()]):
         return True
     else:
         return False