优化复选框的显示
This commit is contained in:
parent
1e2799933f
commit
2605103b9f
@ -3,6 +3,7 @@
|
||||
'''
|
||||
行情记录模块相关的GUI控制组件
|
||||
'''
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
@ -11,7 +12,7 @@ from PyQt4.QtGui import QTreeView
|
||||
from dataRecorder.drEngine import DrEngine
|
||||
from eventEngine import *
|
||||
from uiBasicWidget import QtGui, QtCore
|
||||
from util.UiUtil import CheckBoxDelegate
|
||||
from util.UiUtil import CheckBoxDelegate, GateWayListItemEditorCreator
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding("utf8")
|
||||
@ -112,7 +113,7 @@ class TreeModel(QtCore.QAbstractItemModel):
|
||||
index.column() in [1, 2] or index.column() == 3 and item.parentItem != self.rootItem):
|
||||
return QtCore.Qt.Checked if item.data(index.column()) == True else QtCore.Qt.Unchecked
|
||||
|
||||
if role != QtCore.Qt.DisplayRole or index.column() == 3 and item.parentItem == self.rootItem:
|
||||
if role != QtCore.Qt.DisplayRole or index.column() in [3, 4] and item.parentItem == self.rootItem:
|
||||
return None
|
||||
|
||||
return item.data(index.column())
|
||||
@ -121,9 +122,12 @@ class TreeModel(QtCore.QAbstractItemModel):
|
||||
if not index.isValid():
|
||||
return QtCore.Qt.NoItemFlags
|
||||
|
||||
if index.column() in [0, 4, 5]:
|
||||
if index.column() in [0, 4]:
|
||||
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
|
||||
|
||||
if index.column() in [5]:
|
||||
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
|
||||
|
||||
item = index.internalPointer()
|
||||
if index.column() == 3 and item.parentItem == self.rootItem:
|
||||
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
|
||||
@ -210,9 +214,9 @@ class DrEditWidget(QtGui.QWidget):
|
||||
|
||||
vline = QtGui.QHBoxLayout()
|
||||
vline.setSpacing(2)
|
||||
btnTickAll = QtGui.QPushButton(u"全部记录tick", self)
|
||||
btnBarAll = QtGui.QPushButton(u'全部记录bar', self)
|
||||
btnSaveAll = QtGui.QPushButton(u'保存设置', self)
|
||||
btnTickAll = QtGui.QPushButton(u"全部记录Tick", self)
|
||||
btnBarAll = QtGui.QPushButton(u'全部记录Bar', self)
|
||||
btnSaveAll = QtGui.QPushButton(u'保存设置(重启后生效)', self)
|
||||
btnTickAll.clicked.connect(self.selectAllTick)
|
||||
btnBarAll.clicked.connect(self.selectAllBar)
|
||||
btnSaveAll.clicked.connect(self.saveSetting)
|
||||
@ -230,6 +234,10 @@ class DrEditWidget(QtGui.QWidget):
|
||||
self.qTreeView.setItemDelegateForColumn(2, CheckBoxDelegate(self))
|
||||
self.qTreeView.setItemDelegateForColumn(3, CheckBoxDelegate(self))
|
||||
|
||||
factory = QtGui.QItemEditorFactory()
|
||||
factory.registerEditor(QtCore.QVariant.Line, GateWayListItemEditorCreator())
|
||||
QtGui.QItemEditorFactory.setDefaultFactory(factory)
|
||||
|
||||
vbox.addWidget(self.qTreeView)
|
||||
self.setLayout(vbox)
|
||||
|
||||
@ -244,19 +252,48 @@ class DrEditWidget(QtGui.QWidget):
|
||||
def loadData(self):
|
||||
child = []
|
||||
|
||||
tick = {}
|
||||
bar = {}
|
||||
active = []
|
||||
with open(self.mainEngine.drEngine.settingFileName) as f:
|
||||
drSetting = json.load(f)
|
||||
if 'tick' in drSetting:
|
||||
l = drSetting['tick']
|
||||
|
||||
for setting in l:
|
||||
tick[setting[0]] = setting[1]
|
||||
|
||||
if 'bar' in drSetting:
|
||||
l = drSetting['bar']
|
||||
|
||||
for setting in l:
|
||||
bar[setting[0]] = setting[1]
|
||||
|
||||
if 'active' in drSetting:
|
||||
d = drSetting['active']
|
||||
|
||||
for activeSymbol, symbol in d.items():
|
||||
active.append(symbol)
|
||||
|
||||
contractDict = {}
|
||||
contracts = self.mainEngine.getAllContracts()
|
||||
for contract in contracts:
|
||||
contractName = self.getContractChineseName(contract.name)
|
||||
gateWayName = contract.gatewayName
|
||||
hasTick = tick.has_key(contract.symbol)
|
||||
hasBar = bar.has_key(contract.symbol)
|
||||
hasActive = contract.symbol in active
|
||||
if contractDict.has_key(contractName):
|
||||
parentItem = contractDict[contractName]
|
||||
item = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], parentItem)
|
||||
item = TreeItem([contract.symbol, hasTick, hasBar, hasActive, contract.exchange, gateWayName],
|
||||
parentItem)
|
||||
parentItem.appendChild(item)
|
||||
else:
|
||||
item = TreeItem([contractName, False, False, False, contract.exchange, "CTP"], self.model.rootItem)
|
||||
item = TreeItem([contractName, False, False, False, contract.exchange, gateWayName],
|
||||
self.model.rootItem)
|
||||
contractDict[contractName] = item
|
||||
child.append(item)
|
||||
subItem = TreeItem([contract.symbol, False, False, False, contract.exchange, "CTP"], item)
|
||||
subItem = TreeItem([contract.symbol, hasTick, hasBar, hasActive, contract.exchange, gateWayName], item)
|
||||
item.appendChild(subItem)
|
||||
|
||||
# yumi = TreeItem([u"玉米", False, False, False, "SH", "CTP"], self.model.rootItem)
|
||||
|
@ -6,9 +6,6 @@
|
||||
|
||||
import json
|
||||
|
||||
from PyQt4.QtCore import QObject
|
||||
|
||||
from dataRecorder.drEngine import DrEngine
|
||||
from dataRecorder.uiDrEdit import DrEditWidget
|
||||
from eventEngine import *
|
||||
from uiBasicWidget import QtGui, QtCore
|
||||
@ -178,6 +175,7 @@ class DrEngineManager(QtGui.QWidget):
|
||||
self.mDrEditWidget.show()
|
||||
|
||||
def restart(self):
|
||||
self.drEngine.stop()
|
||||
self.updateSetting()
|
||||
self.mainEngine.drEngine = DrEngine(self.mainEngine, self.mainEngine.eventEngine)
|
||||
pass
|
||||
# self.drEngine.stop()
|
||||
# self.updateSetting()
|
||||
# self.mainEngine.drEngine = DrEngine(self.mainEngine, self.mainEngine.eventEngine)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from PyQt4 import QtCore
|
||||
from PyQt4.QtGui import QStyle, QStyledItemDelegate, QStyleOptionButton, QApplication, QItemDelegate
|
||||
from PyQt4.QtGui import QStyle, QStyledItemDelegate, QStyleOptionButton, QApplication, QItemDelegate, QComboBox, \
|
||||
QItemEditorCreatorBase
|
||||
|
||||
|
||||
class CheckBoxDelegate(QStyledItemDelegate):
|
||||
@ -94,3 +95,50 @@ class CheckBoxDelegate(QStyledItemDelegate):
|
||||
option.rect.height() / 2 -
|
||||
check_box_rect.height() / 2)
|
||||
return QtCore.QRect(check_box_point, check_box_rect.size())
|
||||
|
||||
|
||||
class ComboDelegate(QItemDelegate):
|
||||
def __init__(self, parent, dataList=[]):
|
||||
QItemDelegate.__init__(self, parent)
|
||||
self.dataList = dataList
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
combo = QComboBox(parent)
|
||||
|
||||
return combo
|
||||
|
||||
def setEditorData(self, editor, index):
|
||||
text = index.data().toString()
|
||||
index = editor.findText(text)
|
||||
editor.setCurrentIndex(index)
|
||||
|
||||
def setModelData(self, editor, model, index):
|
||||
model.setData(index, editor.itemText(editor.currentIndex()))
|
||||
|
||||
def updateEditorGeometry(self, editor, option, index):
|
||||
print option, option.rect
|
||||
editor.setGeometry(option.rect)
|
||||
|
||||
|
||||
class GateWayListEditor(QComboBox):
|
||||
def __init__(self, widget=None, dataList=[]):
|
||||
super(GateWayListEditor, self).__init__(widget)
|
||||
self.dataList = dataList
|
||||
self.populateList()
|
||||
|
||||
def getGateWay(self):
|
||||
gateWay = self.itemData(self.currentIndex(), QtCore.Qt.DisplayRole)
|
||||
return gateWay
|
||||
|
||||
def setGateWay(self, gateWay):
|
||||
self.setCurrentIndex(self.findData(gateWay, QtCore.Qt.DisplayRole))
|
||||
|
||||
def populateList(self):
|
||||
for i, gateWayName in enumerate(self.dataList):
|
||||
self.insertItem(i, gateWayName)
|
||||
self.setItemData(i, gateWayName, QtCore.Qt.DisplayRole)
|
||||
|
||||
|
||||
class GateWayListItemEditorCreator(QItemEditorCreatorBase):
|
||||
def createWidget(self, parent):
|
||||
return GateWayListEditor(parent, ["CTP", "LTS", "XTP", "FEMAS", "XSPEED", "QDP", "KSOTP", "KSGOLD", "SGIT"])
|
||||
|
Loading…
Reference in New Issue
Block a user