2015-06-05 06:22:37 +12:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#--!-- coding: utf8 --!--
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
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)
|