增加合约查询组件的过滤功能

This commit is contained in:
chenxy123 2017-03-15 23:33:52 +08:00
parent 1517117b8e
commit 531818ac5f
2 changed files with 58 additions and 3 deletions

View File

@ -1090,6 +1090,9 @@ class ContractMonitor(BasicMonitor):
#d['optionType'] = {'chinese':u'期权类型', 'cellType':BasicCell}
self.setHeaderDict(d)
# 过滤显示用的字符串
self.filterContent = EMPTY_STRING
self.initUi()
#----------------------------------------------------------------------
@ -1113,6 +1116,10 @@ class ContractMonitor(BasicMonitor):
row = 0
for key in l2:
# 如果设置了过滤信息且合约代码中不含过滤信息,则不显示
if self.filterContent and self.filterContent not in key:
continue
contract = d[key]
for n, header in enumerate(self.headerList):
@ -1149,4 +1156,52 @@ class ContractMonitor(BasicMonitor):
super(ContractMonitor, self).show()
self.refresh()
#----------------------------------------------------------------------
def setFilterContent(self, content):
"""设置过滤字符串"""
self.filterContent = content
########################################################################
class ContractManager(QtGui.QWidget):
"""合约管理组件"""
#----------------------------------------------------------------------
def __init__(self, mainEngine, parent=None):
"""Constructor"""
super(ContractManager, self).__init__(parent=parent)
self.mainEngine = mainEngine
self.initUi()
#----------------------------------------------------------------------
def initUi(self):
"""初始化界面"""
self.setWindowTitle(u'合约查询')
self.lineFilter = QtGui.QLineEdit()
self.buttonFilter = QtGui.QPushButton(u'查询')
self.buttonFilter.clicked.connect(self.filterContract)
self.monitor = ContractMonitor(self.mainEngine)
self.monitor.refresh()
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.lineFilter)
hbox.addWidget(self.buttonFilter)
hbox.addStretch()
vbox = QtGui.QVBoxLayout()
vbox.addLayout(hbox)
vbox.addWidget(self.monitor)
self.setLayout(vbox)
#----------------------------------------------------------------------
def filterContract(self):
"""显示过滤后的合约"""
content = str(self.lineFilter.text())
self.monitor.setFilterContent(content)
self.monitor.refresh()

View File

@ -179,7 +179,7 @@ class MainWindow(QtGui.QMainWindow):
try:
self.widgetDict['contractM'].show()
except KeyError:
self.widgetDict['contractM'] = ContractMonitor(self.mainEngine)
self.widgetDict['contractM'] = ContractManager(self.mainEngine)
self.widgetDict['contractM'].show()
#----------------------------------------------------------------------