manuskript/src/ui/chkOutlineCompile.py

45 lines
1.4 KiB
Python
Raw Normal View History

2015-06-05 06:22:37 +12:00
#!/usr/bin/env python
#--!-- coding: utf8 --!--
2015-06-08 08:06:57 +12:00
2015-06-05 06:22:37 +12:00
from qt import *
from enums import *
# Because I have trouble with QDataWidgetMapper and the checkbox, I don't know why.
class chkOutlineCompile(QCheckBox):
def __init__(self, parent=None):
QCheckBox.__init__(self, parent)
self.stateChanged.connect(self.changed)
self.currentModelIndex = None
def setModel(self, mdlOutline):
self.mdlOutline = mdlOutline
self.mdlOutline.dataChanged.connect(self.updateSelectedItem)
def setCurrentModelIndex(self, idx):
self.currentModelIndex = idx
self.updateSelectedItem()
def updateSelectedItem(self, idx1=None, idx2=None):
2015-06-06 11:32:52 +12:00
if not self.currentModelIndex or not self.currentModelIndex.isValid():
2015-06-05 06:22:37 +12:00
self.setChecked(False)
self.setEnabled(False)
else:
self.setEnabled(True)
item = self.currentModelIndex.internalPointer()
c = item.data(Outline.compile)
if c:
c = int(c)
else:
c = Qt.Unchecked
self.setCheckState(c)
def changed(self, state):
2015-06-06 11:32:52 +12:00
if self.currentModelIndex and self.currentModelIndex.isValid():
2015-06-05 06:22:37 +12:00
mdl = self.currentModelIndex.model()
modelIndex = mdl.index(self.currentModelIndex.row(), Outline.compile.value, self.currentModelIndex.parent())
mdl.setData(modelIndex, state)