2015-06-04 17:08:49 +12:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#--!-- coding: utf8 --!--
|
|
|
|
|
2015-06-08 08:06:57 +12:00
|
|
|
|
|
|
|
|
2015-06-04 17:08:49 +12:00
|
|
|
|
|
|
|
from qt import *
|
|
|
|
from enums import *
|
|
|
|
|
|
|
|
class cmbOutlineStatusChoser(QComboBox):
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
QComboBox.__init__(self, parent)
|
|
|
|
self.activated[int].connect(self.changed)
|
|
|
|
self.currentModelIndex = None
|
|
|
|
|
2015-06-11 01:57:44 +12:00
|
|
|
def setModels(self, mdlStatus, mdlOutline):
|
|
|
|
self.mdlStatus = mdlStatus
|
|
|
|
self.mdlStatus.dataChanged.connect(self.updateItems) # Not emiting?
|
2015-06-04 17:08:49 +12:00
|
|
|
self.mdlOutline = mdlOutline
|
|
|
|
self.mdlOutline.dataChanged.connect(self.updateSelectedItem)
|
|
|
|
self.updateItems()
|
|
|
|
|
|
|
|
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-04 17:08:49 +12:00
|
|
|
self.setCurrentIndex(0)
|
|
|
|
else:
|
2015-06-11 01:57:44 +12:00
|
|
|
val = self.currentModelIndex.internalPointer().data(Outline.status.value)
|
|
|
|
if not val: val = 0
|
|
|
|
try:
|
|
|
|
self.setCurrentIndex(int(val))
|
|
|
|
except:
|
|
|
|
pass
|
2015-06-04 17:08:49 +12:00
|
|
|
|
|
|
|
def changed(self, idx):
|
|
|
|
if self.currentModelIndex:
|
|
|
|
modelIndex = self.mdlOutline.index(self.currentModelIndex.row(), Outline.status.value, self.currentModelIndex.parent())
|
2015-06-11 01:57:44 +12:00
|
|
|
self.mdlOutline.setData(modelIndex, self.currentIndex())
|
2015-06-04 17:08:49 +12:00
|
|
|
|
|
|
|
def setCurrentModelIndex(self, idx):
|
|
|
|
self.currentModelIndex = idx
|
2015-06-11 01:57:44 +12:00
|
|
|
self.updateItems()
|
2015-06-04 17:08:49 +12:00
|
|
|
self.updateSelectedItem()
|
|
|
|
|
2015-06-11 01:57:44 +12:00
|
|
|
def updateItems(self, topLeft=None, bottomRight=None, roles=None):
|
2015-06-04 17:08:49 +12:00
|
|
|
self.clear()
|
2015-06-11 01:57:44 +12:00
|
|
|
for i in range(self.mdlStatus.rowCount()):
|
|
|
|
item = self.mdlStatus.item(i, 0)
|
|
|
|
if item:
|
|
|
|
self.addItem(item.text())
|
2015-06-04 17:08:49 +12:00
|
|
|
|
|
|
|
if self.currentModelIndex:
|
|
|
|
self.updateSelectedItem()
|