Esempio n. 1
0
 def onSavePressed(self):
     tmp = tempfile.mkstemp(suffix=".json")[-1]
     file = QtCore.QFile(tmp)
     file.open(QtCore.QIODevice.WriteOnly)
     stream = QtCore.QDataStream(file)
     model = self.view.model()
     self.saveModel(model.invisibleRootItem(), stream)
     file.close()
     self.statusBar().showMessage("File saved: {}".format(tmp))
Esempio n. 2
0
 def mimeData(self, indexes):
     mimedata = QtCore.QMimeData()
     encoded_data = QtCore.QByteArray()
     stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.WriteOnly)
     for index in indexes:
         if index.isValid():
             text = self.data(index, 0)
     stream << QtCore.QByteArray(text.encode("utf-8"))
     mimedata.setData("application/vnd.treeviewdragdrop.list", encoded_data)
     return mimedata
Esempio n. 3
0
    def mimeData(self, indices):
        #print("Generate mime Data - len:"+str(len(indices)),flush=True)
        mimeData      = QtCore.QMimeData()
        encodedData = QtCore.QByteArray()

        if len(indices) != 1:
            return None

        stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.WriteOnly)
        index=indices[0]
        item = index.internalPointer()

        #data=str(id(item))#ukazatel
        data="AHOJ"
        self._dragFrom=index
        mimeData.setData("application/pou.cz", bytes(data, 'utf-8'))
        mimeData.setText(data)
        return mimeData
Esempio n. 4
0
    def dropMimeData(self, data, action, row, column, parent):
        if action == QtCore.Qt.IgnoreAction:
            return True
        if not data.hasFormat("application/vnd.treeviewdragdrop.list"):
            return False
        if column > 0:
            return False

        num_rows = self.rowCount(QtCore.QModelIndex())
        if num_rows <= 0:
            return False

        if row < 0:
            if parent.isValid():
                row = parent.row()
            else:
                return False

        encoded_data = data.data("application/vnd.treeviewdragdrop.list")
        stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.ReadOnly)

        new_items = []
        rows = 0
        while not stream.atEnd():
            text = QtCore.QByteArray()
            stream >> text
            text = bytes(text).decode("utf-8")
            index = self.nodes.index(text)
            new_items.append((text, index))
            rows += 1

        self.lastDroppedItems = []
        for (text, index) in new_items:
            target_row = row
            if index < row:
                target_row += 1
            self.beginInsertRows(QtCore.QModelIndex(), target_row, target_row)
            self.nodes.insert(target_row, text)
            self.endInsertRows()
            self.lastDroppedItems.append(text)
            row += 1

        self.pendingRemoveRowsAfterDrop = True
        return True