mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-14 18:02:23 +12:00
Outline Tab: drag n drop enabled
This commit is contained in:
parent
6607e1938e
commit
3fe177aa8a
|
@ -393,6 +393,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.mdlFlatData.dataChanged.connect(self.startTimerNoChanges)
|
||||
self.mdlOutline.dataChanged.connect(self.startTimerNoChanges)
|
||||
self.mdlPersos.dataChanged.connect(self.startTimerNoChanges)
|
||||
self.mdlPlots.dataChanged.connect(self.startTimerNoChanges)
|
||||
#self.mdlPersosInfos.dataChanged.connect(self.startTimerNoChanges)
|
||||
self.mdlStatus.dataChanged.connect(self.startTimerNoChanges)
|
||||
self.mdlLabels.dataChanged.connect(self.startTimerNoChanges)
|
||||
|
|
|
@ -14,9 +14,9 @@ class plotModel(QStandardItemModel):
|
|||
|
||||
self.updatePlotPersoButton()
|
||||
|
||||
####################################################################################################
|
||||
# QUERIES #
|
||||
####################################################################################################
|
||||
###############################################################################
|
||||
# QUERIES
|
||||
###############################################################################
|
||||
|
||||
def getPlotsByImportance(self):
|
||||
plots = [[], [], []]
|
||||
|
@ -36,7 +36,8 @@ class plotModel(QStandardItemModel):
|
|||
for i in range(item.rowCount()):
|
||||
_ID = item.child(i, Plot.ID.value).text()
|
||||
name = item.child(i, Plot.name.value).text()
|
||||
lst.append((_ID, name))
|
||||
summary = item.child(i, 3).text()
|
||||
lst.append((_ID, name, summary))
|
||||
return lst
|
||||
|
||||
def getPlotNameByID(self, ID):
|
||||
|
@ -47,6 +48,15 @@ class plotModel(QStandardItemModel):
|
|||
return name
|
||||
return None
|
||||
|
||||
def getSubPlotTextsByID(self, plotID, subplotRaw):
|
||||
"""Returns a tuple (name, summary) for the suplot whose raw in the model
|
||||
is ``subplotRaw``, of plot whose ID is ``plotID``.
|
||||
"""
|
||||
plotIndex = self.getIndexFromID(plotID)
|
||||
name = plotIndex.child(subplotRaw, Plot.name.value).data()
|
||||
summary = plotIndex.child(subplotRaw, 3).data() # 3 is for summary
|
||||
return (name, summary)
|
||||
|
||||
def getIndexFromID(self, ID):
|
||||
for i in range(self.rowCount()):
|
||||
_ID = self.item(i, Plot.ID.value).text()
|
||||
|
@ -60,10 +70,10 @@ class plotModel(QStandardItemModel):
|
|||
return i
|
||||
else:
|
||||
return None
|
||||
|
||||
####################################################################################################
|
||||
# ADDING / REMOVING #
|
||||
####################################################################################################
|
||||
|
||||
###############################################################################
|
||||
# ADDING / REMOVING
|
||||
###############################################################################
|
||||
|
||||
def addPlot(self):
|
||||
p = QStandardItem(self.tr("New plot"))
|
||||
|
@ -88,11 +98,11 @@ class plotModel(QStandardItemModel):
|
|||
|
||||
def removePlot(self, index):
|
||||
self.takeRow(index.row())
|
||||
|
||||
####################################################################################################
|
||||
# SUBPLOTS #
|
||||
####################################################################################################
|
||||
|
||||
###############################################################################
|
||||
# SUBPLOTS
|
||||
###############################################################################
|
||||
|
||||
def addSubPlot(self):
|
||||
index = self.mw.lstPlots.currentPlotIndex()
|
||||
if not index.isValid():
|
||||
|
@ -128,11 +138,11 @@ class plotModel(QStandardItemModel):
|
|||
return Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled
|
||||
else:
|
||||
return QStandardItemModel.flags(self, index)
|
||||
|
||||
####################################################################################################
|
||||
# PLOT PERSOS #
|
||||
####################################################################################################
|
||||
|
||||
|
||||
###############################################################################
|
||||
# PLOT PERSOS
|
||||
###############################################################################
|
||||
|
||||
def addPlotPerso(self, v):
|
||||
index = self.mw.lstPlots.currentPlotIndex()
|
||||
if index.isValid():
|
||||
|
|
|
@ -1047,7 +1047,7 @@ class Ui_MainWindow(object):
|
|||
|
||||
self.retranslateUi(MainWindow)
|
||||
self.stack.setCurrentIndex(1)
|
||||
self.tabMain.setCurrentIndex(6)
|
||||
self.tabMain.setCurrentIndex(5)
|
||||
self.tabSummary.setCurrentIndex(0)
|
||||
self.tabPersos.setCurrentIndex(0)
|
||||
self.tabPlot.setCurrentIndex(0)
|
||||
|
@ -1175,17 +1175,17 @@ class Ui_MainWindow(object):
|
|||
self.actCompile.setText(_translate("MainWindow", "Compile"))
|
||||
self.actCompile.setShortcut(_translate("MainWindow", "F6"))
|
||||
|
||||
from ui.views.treeView import treeView
|
||||
from ui.editors.mainEditor import mainEditor
|
||||
from ui.welcome import welcome
|
||||
from ui.sldImportance import sldImportance
|
||||
from ui.views.persoTreeView import persoTreeView
|
||||
from ui.cheatSheet import cheatSheet
|
||||
from ui.search import search
|
||||
from ui.views.outlineView import outlineView
|
||||
from ui.views.lineEditView import lineEditView
|
||||
from ui.sldImportance import sldImportance
|
||||
from ui.views.plotTreeView import plotTreeView
|
||||
from ui.editors.mainEditor import mainEditor
|
||||
from ui.collapsibleGroupBox2 import collapsibleGroupBox2
|
||||
from ui.welcome import welcome
|
||||
from ui.views.basicItemView import basicItemView
|
||||
from ui.views.plotTreeView import plotTreeView
|
||||
from ui.views.metadataView import metadataView
|
||||
from ui.views.treeView import treeView
|
||||
from ui.views.outlineView import outlineView
|
||||
from ui.collapsibleGroupBox2 import collapsibleGroupBox2
|
||||
from ui.views.lineEditView import lineEditView
|
||||
from ui.views.textEditView import textEditView
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
<item>
|
||||
<widget class="QTabWidget" name="tabMain">
|
||||
<property name="currentIndex">
|
||||
<number>6</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>true</bool>
|
||||
|
|
|
@ -5,6 +5,8 @@ from qt import *
|
|||
from enums import *
|
||||
from functions import *
|
||||
import settings
|
||||
from lxml import etree as ET
|
||||
import models.references as Ref
|
||||
|
||||
class plotTreeView(QTreeWidget):
|
||||
|
||||
|
@ -23,7 +25,11 @@ class plotTreeView(QTreeWidget):
|
|||
self._rootItem = QTreeWidgetItem()
|
||||
self.insertTopLevelItem(0, self._rootItem)
|
||||
#self.currentItemChanged.connect(self._currentItemChanged)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# SETTERS
|
||||
###############################################################################
|
||||
|
||||
def setShowSubPlot(self, v):
|
||||
self._showSubPlot = v
|
||||
self.updateItems()
|
||||
|
@ -38,7 +44,28 @@ class plotTreeView(QTreeWidget):
|
|||
def setFilter(self, text):
|
||||
self._filter = text
|
||||
self.updateItems()
|
||||
|
||||
###############################################################################
|
||||
# GETTERS
|
||||
###############################################################################
|
||||
|
||||
def getItemByID(self, ID):
|
||||
for i in range(self.topLevelItemCount()):
|
||||
if self.topLevelItem(i).data(0, Qt.UserRole) == ID:
|
||||
return self.topLevelItem(i)
|
||||
|
||||
def currentPlotIndex(self):
|
||||
"Returns index of the current item in plot model."
|
||||
ID = None
|
||||
if self.currentItem():
|
||||
ID = self.currentItem().data(0, Qt.UserRole)
|
||||
|
||||
return self._model.getIndexFromID(ID)
|
||||
|
||||
###############################################################################
|
||||
# UPDATES
|
||||
###############################################################################
|
||||
|
||||
def updateMaybe(self, topLeft, bottomRight):
|
||||
if topLeft.parent() != QModelIndex():
|
||||
return
|
||||
|
@ -90,6 +117,7 @@ class plotTreeView(QTreeWidget):
|
|||
f = cat.font(0)
|
||||
f.setBold(True)
|
||||
cat.setFont(0, f)
|
||||
cat.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
|
||||
self.addTopLevelItem(cat)
|
||||
#cat.setChildIndicatorPolicy(cat.DontShowIndicator)
|
||||
|
||||
|
@ -99,6 +127,7 @@ class plotTreeView(QTreeWidget):
|
|||
continue
|
||||
item = QTreeWidgetItem(cat, [name])
|
||||
item.setData(0, Qt.UserRole, ID)
|
||||
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
|
||||
|
||||
if self._showSubPlot:
|
||||
|
||||
|
@ -106,31 +135,55 @@ class plotTreeView(QTreeWidget):
|
|||
f.setBold(True)
|
||||
item.setFont(0, f)
|
||||
|
||||
for subID, name in self._model.getSubPlotsByID(ID):
|
||||
for subID, name, summary in self._model.getSubPlotsByID(ID):
|
||||
sub = QTreeWidgetItem(item, [name])
|
||||
sub.setData(0, Qt.UserRole, "{}:{}".format(ID, subID))
|
||||
#sub.setData(0, Qt.UserRole, "{}:{}".format(ID, subID))
|
||||
sub.setData(0, Qt.UserRole, ID)
|
||||
|
||||
if ID == self._lastID:
|
||||
self.setCurrentItem(item)
|
||||
|
||||
self.expandAll()
|
||||
self._updating = False
|
||||
|
||||
def getItemByID(self, ID):
|
||||
for i in range(self.topLevelItemCount()):
|
||||
if self.topLevelItem(i).data(0, Qt.UserRole) == ID:
|
||||
return self.topLevelItem(i)
|
||||
|
||||
def currentPlotIndex(self):
|
||||
ID = None
|
||||
if self.currentItem():
|
||||
ID = self.currentItem().data(0, Qt.UserRole)
|
||||
|
||||
return self._model.getIndexFromID(ID)
|
||||
|
||||
###############################################################################
|
||||
# DRAG N DROP
|
||||
###############################################################################
|
||||
|
||||
def mimeTypes(self):
|
||||
return ["application/xml"]
|
||||
|
||||
def mimeData(self, items):
|
||||
mimeData = QMimeData()
|
||||
encodedData = ""
|
||||
|
||||
root = ET.Element("outlineItems")
|
||||
|
||||
for item in items:
|
||||
plotID = item.data(0, Qt.UserRole)
|
||||
subplotRaw = item.parent().indexOfChild(item)
|
||||
|
||||
_id, name, summary = self._model.getSubPlotsByID(plotID)[subplotRaw]
|
||||
sub = ET.Element("outlineItem")
|
||||
sub.set(Outline.title.name, name)
|
||||
sub.set(Outline.type.name, settings.defaultTextType)
|
||||
sub.set(Outline.summaryFull.name, name)
|
||||
sub.set(Outline.notes.name, self.tr("**Plot:** {}").format(
|
||||
Ref.plotReference(plotID)))
|
||||
|
||||
root.append(sub)
|
||||
|
||||
encodedData = ET.tostring(root)
|
||||
|
||||
mimeData.setData("application/xml", encodedData)
|
||||
return mimeData
|
||||
|
||||
###############################################################################
|
||||
# EVENTS
|
||||
###############################################################################
|
||||
|
||||
def mouseDoubleClickEvent(self, event):
|
||||
item = self.currentItem()
|
||||
# Catching double clicks to forbid collapsing of toplevel items
|
||||
if item.parent():
|
||||
QTreeWidget.mouseDoubleClickEvent(self, event)
|
||||
|
||||
QTreeWidget.mouseDoubleClickEvent(self, event)
|
Loading…
Reference in a new issue