Beispiel #1
0
    def dropEvent(self, theEvent):
        """Overload the drop item event to ensure relevant data has been
        updated.
        """
        sHandle = self.getSelectedHandle()
        if sHandle is None:
            logger.error("Invalid drag and drop event")
            return

        logger.debug("Drag'n'drop of item '%s' accepted", sHandle)

        sItem = self._getTreeItem(sHandle)
        isExpanded = False
        if sItem is not None:
            isExpanded = sItem.isExpanded()

        pItem = sItem.parent()
        pIndex = 0
        if pItem is not None:
            pIndex = pItem.indexOfChild(sItem)

        wCount = self._getItemWordCount(sHandle)
        self.propagateCount(sHandle, 0)

        QTreeWidget.dropEvent(self, theEvent)
        self._postItemMove(sHandle, wCount)
        self._recordLastMove(sItem, pItem, pIndex)
        self._alertTreeChange(tHandle=sHandle, flush=True)
        sItem.setExpanded(isExpanded)

        return
Beispiel #2
0
    def dropEvent(self, theEvent):
        """Overload the drop of dragged item event to check whether the
        drop is allowed or not. Disallowed drops are cancelled.
        """
        sHandle = self.getSelectedHandle()
        if sHandle is None:
            logger.error("No handle selected")
            return

        dIndex = self.indexAt(theEvent.pos())
        if not dIndex.isValid():
            logger.error("Invalid drop index")
            return

        sItem = self._getTreeItem(sHandle)
        dItem = self.itemFromIndex(dIndex)
        dHandle = dItem.data(self.C_NAME, Qt.UserRole)
        snItem = self.theProject.projTree[sHandle]
        dnItem = self.theProject.projTree[dHandle]
        if dnItem is None:
            self.theParent.makeAlert(
                self.tr("The item cannot be moved to that location."),
                nwAlert.ERROR)
            return

        pItem = sItem.parent()
        pIndex = 0
        if pItem is not None:
            pIndex = pItem.indexOfChild(sItem)

        wCount = int(sItem.data(self.C_COUNT, Qt.UserRole))
        isFile = snItem.itemType == nwItemType.FILE
        isRoot = snItem.itemType == nwItemType.ROOT
        onFile = dnItem.itemType == nwItemType.FILE

        isSame = snItem.itemClass == dnItem.itemClass
        isNone = snItem.itemClass == nwItemClass.NO_CLASS
        isNote = snItem.itemLayout == nwItemLayout.NOTE
        onFree = dnItem.itemClass in nwLists.FREE_CLASS and isFile

        allowDrop = isSame or isNone or isNote or onFree
        allowDrop &= not (self.dropIndicatorPosition()
                          == QAbstractItemView.OnItem and onFile)

        if allowDrop and not isRoot:
            logger.debug("Drag'n'drop of item '%s' accepted", sHandle)
            self.propagateCount(sHandle, 0)
            QTreeWidget.dropEvent(self, theEvent)
            self._postItemMove(sHandle, snItem, dnItem, wCount)
            self._recordLastMove(sItem, pItem, pIndex)

        else:
            theEvent.ignore()
            logger.debug("Drag'n'drop of item '%s' not accepted", sHandle)
            self.theParent.makeAlert(
                self.tr("The item cannot be moved to that location."),
                nwAlert.ERROR)

        return
Beispiel #3
0
    def dropEvent(self, theEvent):
        """Overload the drop of dragged item event to check whether the
        drop is allowed or not. Disallowed drops are cancelled.
        """
        sHandle = self.getSelectedHandle()
        if sHandle is None:
            logger.error("No handle selected")
            return

        dIndex = self.indexAt(theEvent.pos())
        if not dIndex.isValid():
            logger.error("Invalid drop index")
            return

        dItem = self.itemFromIndex(dIndex)
        dHandle = dItem.text(self.C_HANDLE)
        snItem = self.theProject.getItem(sHandle)
        dnItem = self.theProject.getItem(dHandle)
        if dnItem is None:
            self.makeAlert("The item cannot be moved to that location.",
                           nwAlert.ERROR)
            return

        isSame = snItem.itemClass == dnItem.itemClass
        isNone = snItem.itemClass == nwItemClass.NO_CLASS
        isNote = snItem.itemLayout == nwItemLayout.NOTE
        onFile = dnItem.itemType == nwItemType.FILE
        isRoot = snItem.itemType == nwItemType.ROOT
        onRoot = dnItem.itemType == nwItemType.ROOT
        isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
        if (isSame or isNone
                or isNote) and not (onFile and isOnTop) and not isRoot:
            logger.debug("Drag'n'drop of item %s accepted" % sHandle)
            QTreeWidget.dropEvent(self, theEvent)
            if isNone:
                self._moveOrphanedItem(sHandle, dHandle)
                self._cleanOrphanedRoot()
            else:
                self._updateItemParent(sHandle)
            if not isSame:
                logger.debug(
                    "Item %s class has been changed from %s to %s" %
                    (sHandle, snItem.itemClass.name, dnItem.itemClass.name))
                snItem.setClass(dnItem.itemClass)
                self.setTreeItemValues(sHandle)
        else:
            logger.debug("Drag'n'drop of item %s not accepted" % sHandle)
            self.makeAlert("The item cannot be moved to that location.",
                           nwAlert.ERROR)

        return
    def dropEvent(self, event: QDropEvent):
        """custom drop event to prevent reparenting
        """
        # data = event.mimeData()
        # if data.hasFormat('application/x-qabstractitemmodeldatalist'):
        #     the_bytearray = data.data('application/x-qabstractitemmodeldatalist')
        #     data_item = self.decodeMimeData(the_bytearray)
        #     print("got a drop event", data_item)

        # item Drop above
        pos = event.pos()
        dest_item = self.itemAt(pos)
        if dest_item is None:
            return
        dest_parent = dest_item.parent()
        selected_items = self.selectedItems()
        for x in selected_items:
            if x.parent() != dest_parent:
                return

        res = QTreeWidget.dropEvent(self, event)
        if isinstance(dest_item, OutlineVirtualHelixItem):
            part = dest_item.part()
            vhi_list = [dest_parent.child(i) for i in range(dest_parent.childCount())]
            part.setImportedVHelixOrder([vhi.idNum() for vhi in vhi_list], check_batch=False)
    def dropEvent(self, event: QDropEvent):
        """custom drop event to prevent reparenting
        """
        # data = event.mimeData()
        # if data.hasFormat('application/x-qabstractitemmodeldatalist'):
        #     the_bytearray = data.data('application/x-qabstractitemmodeldatalist')
        #     data_item = self.decodeMimeData(the_bytearray)
        #     print("got a drop event", data_item)

        # item Drop above
        pos = event.pos()
        dest_item = self.itemAt(pos)
        if dest_item is None:
            return
        dest_parent = dest_item.parent()
        selected_items = self.selectedItems()
        for x in selected_items:
            if x.parent() != dest_parent:
                return

        res = QTreeWidget.dropEvent(self, event)
        if isinstance(dest_item, OutlineVirtualHelixItem):
            part = dest_item.part()
            vhi_list = [dest_parent.child(i) for i in range(dest_parent.childCount())]
            part.setImportedVHelixOrder([vhi.idNum() for vhi in vhi_list], check_batch=False)
Beispiel #6
0
    def dropEvent(self, theEvent):
        """Overload the drop of dragged item event to check whether the drop is allowed
        or not. Disallowed drops are cancelled.
        """
        sHandle = self.getSelectedHandle()
        if sHandle is None:
            return

        dIndex = self.indexAt(theEvent.pos())
        if not dIndex.isValid():
            return

        dItem = self.itemFromIndex(dIndex)
        dHandle = dItem.text(self.C_HANDLE)
        snItem = self.theProject.getItem(sHandle)
        dnItem = self.theProject.getItem(dHandle)
        isSame = snItem.itemClass == dnItem.itemClass
        isNone = snItem.itemClass == nwItemClass.NO_CLASS
        onFile = dnItem.itemType == nwItemType.FILE
        isRoot = snItem.itemType == nwItemType.ROOT
        onRoot = dnItem.itemType == nwItemType.ROOT
        isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
        isAbove = self.dropIndicatorPosition() == QAbstractItemView.AboveItem
        isBelow = self.dropIndicatorPosition() == QAbstractItemView.BelowItem
        if (isSame or isNone) and not (onFile and isOnTop) and not isRoot:
            logger.verbose("Drag'n'drop of item %s accepted" % sHandle)
            QTreeWidget.dropEvent(self, theEvent)
            if isNone:
                self._moveOrphanedItem(sHandle, dHandle)
                self._cleanOrphanedRoot()
            else:
                self._updateItemParent(sHandle)
        elif isRoot and (isAbove or isBelow) and onRoot:
            logger.verbose("Drag'n'drop of item %s accepted" % sHandle)
            QTreeWidget.dropEvent(self, theEvent)
        else:
            logger.verbose("Drag'n'drop of item %s not accepted" % sHandle)

        return
Beispiel #7
0
    def dropEvent(self, theEvent):
        """Overload the drop of dragged item event to check whether the
        drop is allowed or not. Disallowed drops are cancelled.
        """
        sHandle = self.getSelectedHandle()
        if sHandle is None:
            logger.error("No handle selected")
            return

        dIndex = self.indexAt(theEvent.pos())
        if not dIndex.isValid():
            logger.error("Invalid drop index")
            return

        sItem = self._getTreeItem(sHandle)
        dItem = self.itemFromIndex(dIndex)
        dHandle = dItem.data(self.C_NAME, Qt.UserRole)
        snItem = self.theProject.projTree[sHandle]
        dnItem = self.theProject.projTree[dHandle]
        if dnItem is None:
            self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR)
            return

        wCount = int(sItem.data(self.C_COUNT, Qt.UserRole))
        isSame = snItem.itemClass == dnItem.itemClass
        isNone = snItem.itemClass == nwItemClass.NO_CLASS
        isNote = snItem.itemLayout == nwItemLayout.NOTE
        onFile = dnItem.itemType == nwItemType.FILE
        isRoot = snItem.itemType == nwItemType.ROOT
        onFree = dnItem.itemClass == nwItemClass.ARCHIVE
        onFree |= dnItem.itemClass == nwItemClass.TRASH
        onFree &= snItem.itemType == nwItemType.FILE
        isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
        if (isSame or isNone or isNote or onFree) and not (onFile and isOnTop) and not isRoot:
            logger.debug("Drag'n'drop of item %s accepted" % sHandle)
            self.propagateCount(sHandle, 0)
            QTreeWidget.dropEvent(self, theEvent)
            self._updateItemParent(sHandle)

            # If the item does not have the same class as the target,
            # and the target is not a free root folder, update its class
            if not (isSame or onFree):
                logger.debug("Item %s class has been changed from %s to %s" % (
                    sHandle,
                    snItem.itemClass.name,
                    dnItem.itemClass.name
                ))
                snItem.setClass(dnItem.itemClass)
                self.setTreeItemValues(sHandle)

            self.propagateCount(sHandle, wCount)

            # The items dropped into archive or trash should be removed
            # from the project index, for all other items, we rescan the
            # file to ensure the index is up to date.
            if onFree:
                self.theIndex.deleteHandle(sHandle)
            else:
                self.theIndex.reIndexHandle(sHandle)

        else:
            theEvent.ignore()
            logger.debug("Drag'n'drop of item %s not accepted" % sHandle)
            self.makeAlert("The item cannot be moved to that location.", nwAlert.ERROR)

        return
Beispiel #8
0
 def dropEvent(self, e):
     QTreeWidget.dropEvent(self, e)
     self.expandAll()
     e.accept()
Beispiel #9
0
 def dropEvent(self, event):
     self.root.sortChildren(0, Qt.AscendingOrder)
     QTreeWidget.dropEvent(self, event)