def __init__(self, parent): CDBTreeModel.__init__(self, parent, 'rbJobType', 'id', 'group_id', 'name', order='code') # self.treeModel.setRootItem(CDBTreeItem(None, domain, rootItemId, self.treeModel)) self.setRootItemVisible(True) self.setLeavesVisible(True)
def preSetupUi(self): self.addModels( 'Tree', CDBTreeModel(self, 'OrgStructure', 'id', 'parent_id', 'name', self._orgStructureOrder, filters=self.getOrgStructureSectionFilter())) self.addModels('Table', COrgStructureAttachModel(self))
def __init__(self, parent): CComboBox.__init__(self, parent) self.SizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength) self.setModelColumn(0) self._model = CDBTreeModel(self, 'rbSocStatusClass', 'id', 'group_id', 'name', ['code', 'name', 'id']) self._model.setLeavesVisible(True) self._model.setOrder('code') self.setModel(self._model) self._popupView = CSocStatusTreeView(self) self._popupView.setObjectName('popupView') self._popupView.setModel(self._model) self.connect(self._popupView, QtCore.SIGNAL('hide()'), self.hidePopup) self.setView(self._popupView) self._popupView.installEventFilter(self) self._popupView.viewport().installEventFilter(self) QtCore.QObject.connect(self._popupView, QtCore.SIGNAL('activated(QModelIndex)'), self.on_ItemActivated) QtCore.QObject.connect(self._popupView, QtCore.SIGNAL('entered(QModelIndex)'), self.setCurrentIndex) self.prefferedWidth = 0
def __init__(self, parent=None): CDialogBase.__init__(self, parent) self.addModels( 'Tree', CDBTreeModel(self, 'rbSocStatusClass', 'id', 'group_id', 'name', ['code', 'name', 'id'])) self.modelTree.setLeavesVisible(True) self.modelTree.setOrder('code') self.setupUi(self) self.setModels(self.treeItems, self.modelTree, self.selectionModelTree) self.treeItems.header().hide() self.setTitle(u'Социальный статус') self.cmbOrgStructure.setOrgId(QtGui.qApp.currentOrgId()) self.cmbOrgStructure.setValue(QtGui.qApp.currentOrgStructureId()) self.lstItems.setTable('vrbSocStatusType', 'class_id=1')
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.cmbEventPurpose.setTable('rbEventTypePurpose', True, filter='code != \'0\'') self.cmbEventType.setTable('EventType', True, filter=getWorkEventTypeFilter()) self.cmbOrgStructure.setOrgId(QtGui.qApp.currentOrgId()) self.cmbOrgStructure.setValue(QtGui.qApp.currentOrgStructureId()) self.cmbVisitPayStatus.setCurrentIndex(0) treeModel = CDBTreeModel(self, 'rbSocStatusClass', 'id', 'group_id', 'name', ['code', 'name', 'id']) treeModel.setLeavesVisible(True) treeModel.setOrder('code') self.treeItems.setModel(treeModel) self.lstItems.setTable('vrbSocStatusType', 'class_id=1') self.socStatusClassId = 0
def __init__(self, parent): CDBTreeModel.__init__(self, parent, 'rbComplain', 'id', 'group_id', 'name', 'code') self.setRootItemVisible(False)
class CSocStatusComboBox(CComboBox): def __init__(self, parent): CComboBox.__init__(self, parent) self.SizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength) self.setModelColumn(0) self._model = CDBTreeModel(self, 'rbSocStatusClass', 'id', 'group_id', 'name', ['code', 'name', 'id']) self._model.setLeavesVisible(True) self._model.setOrder('code') self.setModel(self._model) self._popupView = CSocStatusTreeView(self) self._popupView.setObjectName('popupView') self._popupView.setModel(self._model) self.connect(self._popupView, QtCore.SIGNAL('hide()'), self.hidePopup) self.setView(self._popupView) self._popupView.installEventFilter(self) self._popupView.viewport().installEventFilter(self) QtCore.QObject.connect(self._popupView, QtCore.SIGNAL('activated(QModelIndex)'), self.on_ItemActivated) QtCore.QObject.connect(self._popupView, QtCore.SIGNAL('entered(QModelIndex)'), self.setCurrentIndex) self.prefferedWidth = 0 def setPrefferedWidth(self, prefferedWidth): self.prefferedWidth = prefferedWidth def update(self): self._model.update() def setValue(self, id): index = self._model.findItemId(id) self.setCurrentIndex(index) def value(self): modelIndex = self._model.index(self.currentIndex(), 0, self.rootModelIndex()) if modelIndex.isValid(): return self._model.itemId(modelIndex) return None def on_ItemActivated(self, index): if index.isValid(): if (int(index.flags()) & QtCore.Qt.ItemIsSelectable) != 0: self.hidePopup() self.emit(QtCore.SIGNAL('itemSelected(QModelIndex)'), index) else: self._popupView.setExpanded( index, not self._popupView.isExpanded(index)) def showPopup(self): # self.__searchString = '' # modelIndex = self._model.index(self.currentIndex(), 0, self.rootModelIndex()) self._popupView.setRealRootIndex(QtCore.QModelIndex()) self._popupView.expandAll() # prefferedWidth = self._popupView.sizeHint().width() prefferedWidth = max(self.prefferedWidth if self.prefferedWidth else 0, self._popupView.sizeHint().width()) if prefferedWidth: if self.width() < prefferedWidth: self._popupView.setFixedWidth(prefferedWidth) QtGui.QComboBox.showPopup(self) scrollBar = self._popupView.horizontalScrollBar() scrollBar.setValue(0) def setCurrentIndex(self, index): if not index: index = QtCore.QModelIndex() if index: self.setRootModelIndex(index.parent()) QtGui.QComboBox.setCurrentIndex(self, index.row()) # self.emit(QtCore.SIGNAL('codeSelected(QString)'), self._model.code(index)) def eventFilter(self, obj, event): if event.type( ) == QtCore.QEvent.KeyPress: # and obj == self.__popupView : if event.key() in [ QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return, QtCore.Qt.Key_Select ]: index = self._popupView.currentIndex() if index.isValid() and (int(index.flags()) & QtCore.Qt.ItemIsSelectable) != 0: self.hidePopup() self.setCurrentIndex(index) self.emit(QtCore.SIGNAL('itemSelected(QModelIndex)'), index) return True return False if event.type( ) == QtCore.QEvent.MouseButtonRelease and obj == self._popupView.viewport( ): self._popupView.mouseReleaseEvent( event ) # i1883.c12401 - нужна реакция на mouseRelease от QTreeView return True # return QtGui.QComboBox.eventFilter(self, obj, event) return False