def mimeData(self, indexes): mimeData = QMimeData() encodedData = QByteArray() stream = QDataStream(encodedData, QIODevice.WriteOnly) for index in indexes: if not index.isValid(): continue if not isinstance(index.internalPointer(), TableItem): continue table = self.getItem(index) stream.writeQString(table.mimeUri()) mimeData.setData(self.QGIS_URI_MIME, encodedData) return mimeData
def _dropEvent(event): if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'): data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid') stream = QDataStream(data, QIODevice.ReadOnly) algorithm_id = stream.readQString() alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id) if alg is not None: self._addAlgorithm(alg, event.pos()) else: assert False, algorithm_id elif event.mimeData().hasText(): itemId = event.mimeData().text() if itemId in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]: self.addInputOfType(itemId, event.pos()) event.accept() else: event.ignore()
def _dropEvent(event): def alg_dropped(algorithm_id, pos): alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id) if alg is not None: self._addAlgorithm(alg, pos) else: assert False, algorithm_id def input_dropped(id, pos): if id in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]: self.addInputOfType(itemId, pos) if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'): data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid') stream = QDataStream(data, QIODevice.ReadOnly) algorithm_id = stream.readQString() QTimer.singleShot(0, lambda id=algorithm_id, pos=self.view.mapToScene(event.pos()): alg_dropped(id, pos)) event.accept() elif event.mimeData().hasText(): itemId = event.mimeData().text() QTimer.singleShot(0, lambda id=itemId, pos=self.view.mapToScene(event.pos()): input_dropped(id, pos)) event.accept() else: event.ignore()
def mimeData( self, indices: Union[QModelIndex, List[QModelIndex]], mimeType: str = mime_types['list']) -> QMimeData: """ MIME data. """ mimeData = QMimeData() data = QByteArray() stream = QDataStream(data, QIODevice.WriteOnly) for index in indices: row = index.row() stream.writeBytes(self.tab[row][0].encode('utf-8')) stream.writeBytes(self.tab[row][1].encode('utf-8')) stream.writeInt16(self.tab[row][2]) mimeData.setData(mimeType, data) return mimeData
def dropMimeData( self, mimeData: QMimeData, action: Qt.DropAction, row: int, column: int, index: QModelIndex) -> bool: """ Drop MIME data. """ # pylint: disable=W0613 if mimeData.hasFormat(mime_types['list']): mime_type = mime_types['list'] elif mimeData.hasFormat(mime_types['colrow']): mime_type = mime_types['colrow'] elif mimeData.hasFormat(mime_types['value']): mime_type = mime_types['value'] else: return False data = mimeData.data(mime_type) stream = QDataStream(data, QIODevice.ReadOnly) data_set = [] while not stream.atEnd(): stream_type = stream.readBytes().decode('utf-8') name = stream.readBytes().decode('utf-8') id = stream.readInt16() # pylint: disable=W0622 field = (stream_type, name, id) modelRCV = self.modelRC + self.modelValue if stream_type == 'calculation' and \ stream_type in [x[0] for x in modelRCV] and \ mime_type == mime_types['list']: self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'Function can be droped in only one area.' ), 15000) return False elif (field in self.modelRC or field in self.tab) and \ mime_type in [mime_types['list'], mime_types['value']]: self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'This field has already been droped.' ), 15000) return False elif stream_type == 'calculation' and \ id not in self.calculation.listText and \ 'text' in [x[0] for x in self.modelValue]: self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'For the text value, function can only be one of ' '{}.'.format(self.calculation.textName) ), 15000) return False data_set.append(field) self.insertRows(row, len(data_set), index, data_set) return True
def dropMimeData( self, mimeData: QMimeData, action: Qt.DropAction, row: int, column: int, index: QModelIndex) -> bool: """ Drop MIME data. """ # pylint: disable=W0613 if mimeData.hasFormat(mime_types['list']): mime_type = mime_types['list'] elif mimeData.hasFormat(mime_types['colrow']): mime_type = mime_types['colrow'] elif mimeData.hasFormat(mime_types['value']): mime_type = mime_types['value'] else: return False data = mimeData.data(mime_type) stream = QDataStream(data, QIODevice.ReadOnly) data_set = [] while not stream.atEnd(): stream_type = stream.readBytes().decode('utf-8') name = stream.readBytes().decode('utf-8') id = stream.readInt16() # pylint: disable=W0622 field = (stream_type, name, id) dataRC = self.modelRows + self.modelColumns all_data = dataRC + self.tab if len(self.tab) >= 2: self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'Value field may contain a maximum of two entries.' ), 15000) return False elif stream_type == 'calculation' and \ stream_type in [x[0] for x in all_data] and \ mime_type == mime_types['list']: self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'Function can be droped in only one area.' ), 15000) return False elif len(self.tab) == 1 and stream_type != 'calculation' and \ self.tab[0][0] != 'calculation': self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'One of the items in the Value field must be a ' 'function.' ), 15000) return False elif len(self.tab) == 1 and \ ((stream_type == 'text' and self.tab[0][2] not in self.calculation.listText) or (id not in self.calculation.listText and self.tab[0][0] == 'text')): self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'For the text value, function can only be one of ' '{}.'.format(self.calculation.textName) ), 15000) return False elif stream_type == 'text' and \ [x for x in dataRC if x[0] == 'calculation' and x[2] not in self.calculation.listText]: self.main_window.statusBar() \ .showMessage(QCoreApplication.translate( 'GroupStats', 'For the text value function can only be one of ' '{}.'.format(self.calculation.textName) ), 15000) return False data_set.append(field) self.insertRows(row, len(data_set), index, data_set) return True