mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-08 06:52:28 +12:00
Merge pull request #777 from siliconserf/Issue-324-NoID-Fix
Update abstractModel.py
This commit is contained in:
commit
653357d2e9
|
@ -39,6 +39,9 @@ class abstractModel(QAbstractItemModel):
|
|||
- XML Import / Export
|
||||
- Drag'n'drop
|
||||
|
||||
Row => item/abstractModel/etc.
|
||||
Col => data sub-element. Col 1 (second counting) is ID for all model types.
|
||||
|
||||
"""
|
||||
def __init__(self, parent):
|
||||
QAbstractItemModel.__init__(self, parent)
|
||||
|
@ -426,21 +429,32 @@ class abstractModel(QAbstractItemModel):
|
|||
# In case of copy actions, items might be duplicates, so we need new IDs.
|
||||
# But they might not be, if we cut, then paste. Paste is a Copy Action.
|
||||
# The first paste would not need new IDs. But subsequent ones will.
|
||||
|
||||
# Recursively change the existing IDs to new, unique values. No need to strip out the old
|
||||
# even if they are not duplicated in pasting. There is no practical need for ID conservation.
|
||||
|
||||
if action == Qt.CopyAction:
|
||||
IDs = self.rootItem.listAllIDs()
|
||||
|
||||
for item in items:
|
||||
if item.ID() in IDs:
|
||||
# Recursively remove ID. So will get a new one when inserted.
|
||||
def stripID(item):
|
||||
item.setData(Outline.ID, None)
|
||||
def makeNewID(item):
|
||||
k = 1
|
||||
while True: # Python doesn't have "Do...While"
|
||||
ks = str(k)
|
||||
if ks not in IDs:
|
||||
item.setData(Outline.ID,ks)
|
||||
IDs.append(ks) #Keep track of new IDs allocated.
|
||||
for c in item.children():
|
||||
stripID(c)
|
||||
|
||||
stripID(item)
|
||||
makeNewID(c)
|
||||
break # Actual Loop Exit
|
||||
else:
|
||||
k = k+1 # Try the next candidate ID
|
||||
|
||||
makeNewID(item)
|
||||
r = self.insertItems(items, beginRow, parent)
|
||||
|
||||
|
||||
return r
|
||||
|
||||
################# ADDING AND REMOVING #################
|
||||
|
@ -459,7 +473,7 @@ class abstractModel(QAbstractItemModel):
|
|||
|
||||
# Insert only if parent is folder
|
||||
if parentItem.isFolder():
|
||||
self.beginInsertRows(parent, row, row + len(items) - 1)
|
||||
self.beginInsertRows(parent, row, row + len(items) - 1) # Create space.
|
||||
|
||||
for i in items:
|
||||
parentItem.insertChild(row + items.index(i), i)
|
||||
|
@ -518,7 +532,8 @@ class abstractModel(QAbstractItemModel):
|
|||
else:
|
||||
parentItem = parent.internalPointer()
|
||||
|
||||
self._removingRows = True # Views that are updating can easily know
|
||||
self._removingRows = True
|
||||
# Views that are updating can easily know
|
||||
# if this is due to row removal.
|
||||
self.beginRemoveRows(parent, row, row + count - 1)
|
||||
for i in range(count):
|
||||
|
|
Loading…
Reference in a new issue