diff --git a/manuskript/enums.py b/manuskript/enums.py index 591812e0..1368dfdc 100644 --- a/manuskript/enums.py +++ b/manuskript/enums.py @@ -26,7 +26,7 @@ class Plot(Enum): name = 0 ID = 1 importance = 2 - persos = 3 + characters = 3 description = 4 result = 5 subplots = 6 @@ -64,4 +64,3 @@ class Outline(Enum): # (sum of all sub-items' goals) textFormat = 15 revisions = 16 - diff --git a/manuskript/load_save/version_1.py b/manuskript/load_save/version_1.py index 095d5ae3..19b7e627 100644 --- a/manuskript/load_save/version_1.py +++ b/manuskript/load_save/version_1.py @@ -13,7 +13,7 @@ from PyQt5.QtCore import Qt, QModelIndex from PyQt5.QtGui import QColor from manuskript import settings -from manuskript.enums import Character, World +from manuskript.enums import Character, World, Plot from manuskript.functions import mainWindow, iconColor from lxml import etree as ET @@ -217,7 +217,15 @@ def saveProject(zip=None): # Either in XML or lots of plain texts? # More probably XML since there is not really a lot if writing to do (third-party) - # TODO + path = "plots.opml" + mdl = mw.mdlPlots + + root = ET.Element("opml") + root.attrib["version"] = "1.0" + body = ET.SubElement(root, "body") + addPlotItem(body, mdl) + content = ET.tostring(root, encoding="UTF-8", xml_declaration=True, pretty_print=True) + files.append((path, content)) # Settings # Saved in readable text (json) for easier versionning. But they mustn't be shared, it seems. @@ -301,6 +309,52 @@ def addWorldItem(root, mdl, parent=QModelIndex()): return root + +def addPlotItem(root, mdl, parent=QModelIndex()): + """ + Lists elements in a plot model and create an OPML xml file. + @param root: an Etree element + @param mdl: a plotModel + @param parent: the parent index in the plot model + @return: root, to which sub element have been added + """ + + # List every row (every plot item) + for x in range(mdl.rowCount(parent)): + + # For each row, create an outline item. + outline = ET.SubElement(root, "outline") + for y in range(mdl.columnCount(parent)): + + index = mdl.index(x, y, parent) + val = mdl.data(index) + + if not val: + continue + + for w in Plot: + if y == w.value: + outline.attrib[w.name] = val + + if y == Plot.characters.value: + if mdl.hasChildren(index): + characters = [] + for cX in range(mdl.rowCount(index)): + for cY in range(mdl.columnCount(index)): + cIndex = mdl.index(cX, cY, index) + characters.append(mdl.data(cIndex)) + outline.attrib[Plot.characters.name] = ",".join(characters) + else: + outline.attrib.pop(Plot.characters.name) + + elif y == Plot.subplots.value and mdl.hasChildren(index): + outline.attrib.pop(Plot.subplots.name) + + + # addWorldItem(outline, mdl, index) + + return root + def loadProject(project): """ Loads a project. diff --git a/manuskript/mainWindow.py b/manuskript/mainWindow.py index 630d6856..b01edd22 100644 --- a/manuskript/mainWindow.py +++ b/manuskript/mainWindow.py @@ -205,7 +205,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.txtPlotResult.setCurrentModelIndex(index) self.sldPlotImportance.setCurrentModelIndex(index) self.lstPlotPerso.setRootIndex(index.sibling(index.row(), - Plot.persos.value)) + Plot.characters.value)) subplotindex = index.sibling(index.row(), Plot.subplots.value) self.lstSubPlots.setRootIndex(subplotindex) if self.mdlPlots.rowCount(subplotindex): @@ -678,7 +678,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.tblDebugPlots.selectionModel().currentChanged.connect( lambda: self.tblDebugPlotsPersos.setRootIndex(self.mdlPlots.index( self.tblDebugPlots.selectionModel().currentIndex().row(), - Plot.persos.value)), AUC) + Plot.characters.value)), AUC) self.tblDebugPlots.selectionModel().currentChanged.connect( lambda: self.tblDebugSubPlots.setRootIndex(self.mdlPlots.index( self.tblDebugPlots.selectionModel().currentIndex().row(), diff --git a/manuskript/models/plotModel.py b/manuskript/models/plotModel.py index b7f4949f..6b272af8 100644 --- a/manuskript/models/plotModel.py +++ b/manuskript/models/plotModel.py @@ -182,10 +182,10 @@ class plotModel(QStandardItemModel): def addPlotPerso(self, v): index = self.mw.lstPlots.currentPlotIndex() if index.isValid(): - if not self.item(index.row(), Plot.persos.value): - self.setItem(index.row(), Plot.persos.value, QStandardItem()) + if not self.item(index.row(), Plot.characters.value): + self.setItem(index.row(), Plot.characters.value, QStandardItem()) - item = self.item(index.row(), Plot.persos.value) + item = self.item(index.row(), Plot.characters.value) # We check that the PersoID is not in the list yet for i in range(item.rowCount()): diff --git a/manuskript/models/references.py b/manuskript/models/references.py index 64261d7e..8c6b86a1 100644 --- a/manuskript/models/references.py +++ b/manuskript/models/references.py @@ -277,7 +277,7 @@ def infos(ref): # Characters pM = mainWindow().mdlCharacter - item = m.item(index.row(), Plot.persos.value) + item = m.item(index.row(), Plot.characters.value) characters = "" if item: for r in range(item.rowCount()):