Relax moving restrictions in project tree, and improve test coverage of NWItem class

This commit is contained in:
Veronica Berglyd Olsen
2022-04-17 18:32:22 +02:00
parent 50db7fcddb
commit 3f4356467e
3 changed files with 130 additions and 12 deletions
+6 -3
View File
@@ -259,7 +259,7 @@ class NWItem():
return
##
# Methods
# Lookup Methods
##
def describeMe(self, hLevel=None):
@@ -296,8 +296,7 @@ class NWItem():
return self._class in (nwItemClass.NOVEL, nwItemClass.ARCHIVE, nwItemClass.TRASH)
def isInactive(self):
"""Returns true if the item is in the inactive parts of the
project.
"""Returns true if the item is in an inactive class.
"""
return self._class in (nwItemClass.NO_CLASS, nwItemClass.ARCHIVE, nwItemClass.TRASH)
@@ -313,6 +312,10 @@ class NWItem():
stIcon = self.theProject.importItems.icon(self._import)
return stName, stIcon
##
# Special Setters
##
def setImportStatus(self, value):
"""Update the importance or status value based on class. This is
a wrapper setter for setStatus and setImport.
+10 -8
View File
@@ -37,7 +37,7 @@ from PyQt5.QtWidgets import (
from novelwriter.core import NWDoc
from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
from novelwriter.constants import trConst, nwLists, nwLabels
from novelwriter.constants import trConst, nwLabels
logger = logging.getLogger(__name__)
@@ -790,21 +790,23 @@ class GuiProjectTree(QTreeWidget):
if pItem is not None:
pIndex = pItem.indexOfChild(sItem)
wCount = int(sItem.data(self.C_COUNT, Qt.UserRole))
# Determine if the drag and drop is allowed:
# - Files can be moved anywhere
# - Folders can only be moved within the same root folder
# - Root folders cannot be moved at all
# - Items cannot be dropped on top of a file (moved inside)
isFile = snItem.itemType == nwItemType.FILE
isRoot = snItem.itemType == nwItemType.ROOT
onFile = dnItem.itemType == nwItemType.FILE
inSame = snItem.itemRoot == dnItem.itemRoot
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 = inSame or isFile
allowDrop &= not (self.dropIndicatorPosition() == QAbstractItemView.OnItem and onFile)
if allowDrop and not isRoot:
logger.debug("Drag'n'drop of item '%s' accepted", sHandle)
wCount = int(sItem.data(self.C_COUNT, Qt.UserRole))
self.propagateCount(sHandle, 0)
QTreeWidget.dropEvent(self, theEvent)
self._postItemMove(sHandle, wCount)