优化操作逻辑
This commit is contained in:
parent
2605103b9f
commit
cd47994617
@ -55,8 +55,11 @@ class DrEngine(object):
|
|||||||
"""保存设置"""
|
"""保存设置"""
|
||||||
setting['working'] = self.working
|
setting['working'] = self.working
|
||||||
with open(self.settingFileName, 'w') as f:
|
with open(self.settingFileName, 'w') as f:
|
||||||
str = json.dumps(setting)
|
try:
|
||||||
f.write(str)
|
str = json.dumps(setting)
|
||||||
|
f.write(str)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
@ -12,7 +12,7 @@ from PyQt4.QtGui import QTreeView
|
|||||||
from dataRecorder.drEngine import DrEngine
|
from dataRecorder.drEngine import DrEngine
|
||||||
from eventEngine import *
|
from eventEngine import *
|
||||||
from uiBasicWidget import QtGui, QtCore
|
from uiBasicWidget import QtGui, QtCore
|
||||||
from util.UiUtil import CheckBoxDelegate, GateWayListItemEditorCreator
|
from util.UiUtil import CheckBoxDelegate, ComboDelegate
|
||||||
|
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding("utf8")
|
sys.setdefaultencoding("utf8")
|
||||||
@ -81,16 +81,27 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||||||
return self.rootItem.columnCount()
|
return self.rootItem.columnCount()
|
||||||
|
|
||||||
def setData(self, index, value, role=None):
|
def setData(self, index, value, role=None):
|
||||||
|
item = index.internalPointer()
|
||||||
|
if item is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if index.column() == 5:
|
||||||
|
result = item.setData(index.column(), value)
|
||||||
|
if result:
|
||||||
|
self.dataChanged.emit(index, index)
|
||||||
|
# 如果第一条
|
||||||
|
if item.parentItem == self.rootItem:
|
||||||
|
for row in range(item.childCount()):
|
||||||
|
childIndex = self.index(row, index.column(), index)
|
||||||
|
self.setData(childIndex, value, QtCore.Qt.DisplayRole)
|
||||||
|
|
||||||
if index.column() in [1, 2, 3] and role == QtCore.Qt.CheckStateRole:
|
if index.column() in [1, 2, 3] and role == QtCore.Qt.CheckStateRole:
|
||||||
item = index.internalPointer()
|
|
||||||
if item is None:
|
|
||||||
return False
|
|
||||||
result = item.setData(index.column(), True if value == QtCore.Qt.Checked else False)
|
result = item.setData(index.column(), True if value == QtCore.Qt.Checked else False)
|
||||||
if result:
|
if result:
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
|
|
||||||
# 如果第一条
|
# 如果第一条
|
||||||
if item.parentItem == self.rootItem:
|
if item.parentItem == self.rootItem and index.column() in [1, 2]:
|
||||||
for row in range(item.childCount()):
|
for row in range(item.childCount()):
|
||||||
childIndex = self.index(row, index.column(), index)
|
childIndex = self.index(row, index.column(), index)
|
||||||
self.setData(childIndex, value, QtCore.Qt.CheckStateRole)
|
self.setData(childIndex, value, QtCore.Qt.CheckStateRole)
|
||||||
@ -109,6 +120,9 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||||||
|
|
||||||
item = index.internalPointer()
|
item = index.internalPointer()
|
||||||
|
|
||||||
|
if role == QtCore.Qt.TextAlignmentRole:
|
||||||
|
return QtCore.Qt.AlignCenter
|
||||||
|
|
||||||
if role == QtCore.Qt.CheckStateRole and (
|
if role == QtCore.Qt.CheckStateRole and (
|
||||||
index.column() in [1, 2] or index.column() == 3 and item.parentItem != self.rootItem):
|
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
|
return QtCore.Qt.Checked if item.data(index.column()) == True else QtCore.Qt.Unchecked
|
||||||
@ -230,13 +244,12 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
self.qTreeView = QTreeView()
|
self.qTreeView = QTreeView()
|
||||||
self.model = TreeModel()
|
self.model = TreeModel()
|
||||||
self.qTreeView.setModel(self.model)
|
self.qTreeView.setModel(self.model)
|
||||||
|
self.qTreeView.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
|
||||||
self.qTreeView.setItemDelegateForColumn(1, CheckBoxDelegate(self))
|
self.qTreeView.setItemDelegateForColumn(1, CheckBoxDelegate(self))
|
||||||
self.qTreeView.setItemDelegateForColumn(2, CheckBoxDelegate(self))
|
self.qTreeView.setItemDelegateForColumn(2, CheckBoxDelegate(self))
|
||||||
self.qTreeView.setItemDelegateForColumn(3, CheckBoxDelegate(self))
|
self.qTreeView.setItemDelegateForColumn(3, CheckBoxDelegate(self))
|
||||||
|
self.qTreeView.setItemDelegateForColumn(5, ComboDelegate(self, ["CTP", "LTS", "XTP", "FEMAS", "XSPEED", "QDP",
|
||||||
factory = QtGui.QItemEditorFactory()
|
"KSOTP", "KSGOLD", "SGIT"]))
|
||||||
factory.registerEditor(QtCore.QVariant.Line, GateWayListItemEditorCreator())
|
|
||||||
QtGui.QItemEditorFactory.setDefaultFactory(factory)
|
|
||||||
|
|
||||||
vbox.addWidget(self.qTreeView)
|
vbox.addWidget(self.qTreeView)
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
@ -279,10 +292,14 @@ class DrEditWidget(QtGui.QWidget):
|
|||||||
contracts = self.mainEngine.getAllContracts()
|
contracts = self.mainEngine.getAllContracts()
|
||||||
for contract in contracts:
|
for contract in contracts:
|
||||||
contractName = self.getContractChineseName(contract.name)
|
contractName = self.getContractChineseName(contract.name)
|
||||||
gateWayName = contract.gatewayName
|
gateWayName = u"CTP"
|
||||||
hasTick = tick.has_key(contract.symbol)
|
hasTick = tick.has_key(contract.symbol)
|
||||||
hasBar = bar.has_key(contract.symbol)
|
hasBar = bar.has_key(contract.symbol)
|
||||||
hasActive = contract.symbol in active
|
hasActive = contract.symbol in active
|
||||||
|
if hasTick:
|
||||||
|
gateWayName = tick[contract.symbol]
|
||||||
|
elif hasBar:
|
||||||
|
gateWayName = bar[contract.symbol]
|
||||||
if contractDict.has_key(contractName):
|
if contractDict.has_key(contractName):
|
||||||
parentItem = contractDict[contractName]
|
parentItem = contractDict[contractName]
|
||||||
item = TreeItem([contract.symbol, hasTick, hasBar, hasActive, contract.exchange, gateWayName],
|
item = TreeItem([contract.symbol, hasTick, hasBar, hasActive, contract.exchange, gateWayName],
|
||||||
|
@ -104,7 +104,7 @@ class ComboDelegate(QItemDelegate):
|
|||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
combo = QComboBox(parent)
|
combo = QComboBox(parent)
|
||||||
|
combo.addItems(self.dataList)
|
||||||
return combo
|
return combo
|
||||||
|
|
||||||
def setEditorData(self, editor, index):
|
def setEditorData(self, editor, index):
|
||||||
@ -113,7 +113,7 @@ class ComboDelegate(QItemDelegate):
|
|||||||
editor.setCurrentIndex(index)
|
editor.setCurrentIndex(index)
|
||||||
|
|
||||||
def setModelData(self, editor, model, index):
|
def setModelData(self, editor, model, index):
|
||||||
model.setData(index, editor.itemText(editor.currentIndex()))
|
model.setData(index, str(editor.itemText(editor.currentIndex())))
|
||||||
|
|
||||||
def updateEditorGeometry(self, editor, option, index):
|
def updateEditorGeometry(self, editor, option, index):
|
||||||
print option, option.rect
|
print option, option.rect
|
||||||
|
Loading…
Reference in New Issue
Block a user