Пример #1
0
    def dropMimeData(
        self,
        data: QtCore.QMimeData,
        action: Qt.DropAction,
        row: int,
        column: int,
        parent: QModelIndex,
    ) -> bool:

        if action == Qt.IgnoreAction:
            return True

        if not data.hasFormat("application/json/table") and not data.hasFormat(
                "application/json/list"):
            return False

        if row != -1:
            begin_row = row
        elif parent.isValid():
            begin_row = parent.row()
        else:
            begin_row = len(self._data)

        if data.hasFormat("application/json/list"):
            data_json = data.data("application/json/list").data().decode()
        else:
            data_json = data.data("application/json/table").data().decode()
        new_data = json.loads(data_json)

        if len(new_data) == 0 or len(new_data[0]) != 4:
            return False

        self.insertEntries(begin_row, new_data)

        return True
Пример #2
0
    def dropMimeData(self, mime: QMimeData, action, row: int, column: int,
                     parent: QModelIndex):
        LOG.debug('dropMimeData at row {}'.format(row))
        if action == Qt.IgnoreAction:
            return True

        if mime.hasFormat('text/uri-list'):
            if mime.hasUrls():
                LOG.debug('found urls in drop!')
                paths = [
                    qurl.path() for qurl in mime.urls() if qurl.isLocalFile()
                ]
                self.doc.import_files(paths)  # FIXME: replace with a signal
                return True
        elif mime.hasFormat(self._mimetype):
            # unpickle the presentation information and re-insert it
            # b = base64.decodebytes(mime.text())
            b = mime.data(self._mimetype)
            layer_set_len, insertion_info = pkl.loads(b)
            LOG.debug('dropped: {0!r:s}'.format(insertion_info))
            count = len(insertion_info)
            if row == -1:
                row = len(self.doc)  # append
                # FIXME: row=col=-1 implies drop-on-parent
                #  which may mean replace or may mean append for composite layers
            # self.insertRows(row, count)
            # for i, presentation in enumerate(l):
            #     self.setData(self.index(row+i, 0), presentation)
            order = list(range(layer_set_len))
            inserted_row_numbers = []
            # inserted_presentations = []
            # delete_these_rows = []
            insertion_point = row
            uuids = []
            for old_row, presentation in reversed(sorted(insertion_info)):
                del order[old_row]
                if old_row < insertion_point:
                    insertion_point -= 1
                inserted_row_numbers.insert(0, old_row)
                uuids.append(presentation.uuid)
                # delete_these_rows.append(old_row if old_row<row else old_row+count)
                # inserted_presentations.append(presentation)
            order = order[:insertion_point] + inserted_row_numbers + order[
                insertion_point:]
            LOG.debug('new order after drop {0!r:s}'.format(order))
            self.select([])
            self.doc.reorder_by_indices(order)
            # self.doc.insert_layer_prez(row, inserted_presentations)
            # LOG.debug('after insertion removing rows {0!r:s}'.format(delete_these_rows))
            # for exrow in delete_these_rows:
            #     self.doc.remove_layer_prez(exrow)
            # self.doc.didReorderLayers.emit(order)  # FUTURE: not our business to be emitting on behalf of the document
            assert (count == len(insertion_info))
            return True
        return False
    def dropMimeData(
        self,
        data: QtCore.QMimeData,
        action: Qt.DropAction,
        row: int,
        column: int,
        parent: QModelIndex,
    ) -> bool:
        if action == Qt.IgnoreAction:
            return True

        if not data.hasFormat("application/json/list"):
            return False

        data_json = data.data("application/json/list").data().decode()
        new_data = json.loads(data_json)

        if len(new_data) == 0 or len(new_data[0]) != 4:
            return False

        for d in new_data:
            self._selected[d[0]] = False

        self.dataChanged.emit(
            self.index(0, 0), self.index(len(self._data), len(self._data))
        )

        return True
Пример #4
0
    def dropMimeData(
            self,
            data: QMimeData,
            action: Qt.DropAction,
            row: int = -1,
            col: int = -1,
            parent: QModelIndex = QModelIndex(),
    ):
        if action == Qt.IgnoreAction or not data or not data.hasFormat(
                DEFAULT_MIME_FORMAT):
            return True

        if row < 0 or row > len(self._selected):
            position = len(self._selected)
        else:
            position = self._plugins[row].pluginOrder

        encoded = data.data(DEFAULT_MIME_FORMAT)
        stream = QDataStream(encoded, QIODevice.ReadOnly)

        indexes = []
        while not stream.atEnd():
            srcRow = stream.readInt32()
            stream.readInt32()  # src column
            mapItems = stream.readInt32()  # role data map
            for i in range(mapItems):
                stream.readInt32()  # map role ID
                stream.readQVariant()  # map role value
            indexes.append(self.index(srcRow, 0))

        self.setPluginsOrder(indexes, position)
        return False
Пример #5
0
    def hasCustomData(self, type):
        """ Has custom data.

			Args:
				type: str

			Returns:
				bool
	    """
        return QMimeData.hasFormat(self.getMimeFormatForType(type))
Пример #6
0
 def isMimeAccepted(self, mime: QMimeData) -> bool:
     return mime.hasFormat(
         self.DRAG_POSITION) or super().isMimeAccepted(mime)