def createEditor (self, parent, option, index): try: content = index.model().data(index, Qt.EditRole) if content == None: return None except: return None column = index.column() row = index.row() parentNode = index.model().data(index.parent(), Qt.EditRole) self.currentIndex = index q_type = QVariant.nameToType(index.model().data(index.sibling(0,7), Qt.DisplayRole)) if column == 1 and parentNode: # combobox for field mapping currentLayer = self.iface.legendInterface().currentLayer() editorQWidget = QComboBox(parent) fieldItems = [] for field in self.iface.legendInterface().currentLayer().pendingFields(): fieldItems.append(field.name()) if not content in fieldItems: fieldItems.append(content) editorQWidget.addItems(fieldItems) editorQWidget.setCurrentIndex(editorQWidget.findText(content)) return editorQWidget if column == 3 and parentNode: # combobox for odk types editorQWidget = QComboBox(parent) #QVariantType = indexQModelIndex.model().item(row,7).data() if content in ['text','note','image','barcode','audio','video']: combobox_items = ['text','note','image','barcode','audio','video','select one'] elif content in ['date', 'datetime']: combobox_items = ['date', 'time', 'datetime'] elif content in ['geopoint','geoshape','geotrace']: combobox_items = ['geopoint','geoshape','geotrace'] elif content in ['select one']: combobox_items = ['select one', QVariantToODKtype(q_type)] elif content in ['select type']: combobox_items = ['text','decimal','integer','date','time','datetime','geopoint','geoshape','geotrace','image','barcode','audio','video','select one'] else: combobox_items = [content,'select one'] editorQWidget.addItems(combobox_items) editorQWidget.setCurrentIndex(editorQWidget.findText(content)) editorQWidget.currentIndexChanged.connect(self.changeAppearanceAccordingly) return editorQWidget elif column == 9 and parentNode: # qdialog for value/label map content = QgisODKChoices.getChoices(content, q_type, title = parentNode) index.model().setData(index,content, Qt.DisplayRole) QItemDelegate.createEditor(self, parent, option, index) elif column == 10 and parentNode: # combobox for appearance contentType = index.model().data(index.sibling(0,3), Qt.DisplayRole) if contentType == '' or not contentType in appearanceDef.keys(): return editorQWidget = QComboBox(parent) editorQWidget.addItems(appearanceDef[contentType]) #editorQWidget.setCurrentIndex(0) return editorQWidget else: return QItemDelegate.createEditor(self, parent, option, index)
def createEditor (self, parent, option, index): column = index.column() row = index.row() self.index = index content = index.model().data(index, Qt.EditRole) if column == 2: content = index.model().data(index, Qt.EditRole) label = index.model().data(index.model().index(row,1), Qt.EditRole) checkrowIndex = index.model().index(row,0) checkrowIndex = index.model().data(index.model().index(row,0), Qt.CheckStateRole) self.editorQWidget = QComboBox(parent) self.editorQWidget.setEditable(True) self.editorQWidget.addItems(self.module.fieldMapping.values()) self.editorQWidget.addItems(['GEOMETRY','ODKUUID']) if content in self.module.fieldMapping.values(): self.editorQWidget.setCurrentIndex(self.editorQWidget.findData(content)) #self.module.fieldTable.item(row,0).setCheckState(Qt.Checked) else: #self.editorQWidget.insertItem(0,label) self.editorQWidget.insertItem(0,'') #self.module.fieldTable.item(row,0).setCheckState(Qt.Unchecked) self.editorQWidget.setCurrentIndex(0) return self.editorQWidget else: return None return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): delegate = self.delegates.get(index.column()) if delegate is not None: return delegate.createEditor(parent, option, index) else: return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): """ Create the editor @param parent: @type parent: @param option: @type option: @param index: @type index: @return: @rtype: """ # get running probe from context self.items_ = ServerProbes.instance().getRunningProbes() self.items_ = sorted(self.items_) # sort agents list, new in v12.2 # load probs in combobox value = self.getValue(index) if index.column() == self.col_: editor = QComboBox(parent) editor.activated.connect(self.onItemActivated) editor.addItem(value) editor.insertSeparator(1) editor.addItems(self.items_) return editor return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): # special combobox for field type if index.column() == self.column: cbo = QComboBox(parent) for item in self.itemsDict: cbo.addItem(item, self.itemsDict[item]) return cbo return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): # special combobox for field type if index.column() == self.column: cbo = QComboBox(parent) for item in self.itemsDict: cbo.addItem(item, self.itemsDict[item]) return cbo return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): if index.parent().isValid(): # item has a parent -> no SimulationModule # TODO implement dropdown menu if property is a dict return QItemDelegate.createEditor(self, parent, option, index) else: # no parent -> top of hierarchy return self.comboDel.createEditor(parent, option, index)
def createEditor(self, parent, option, index): # special combobox for field type if index.column() == self.column: list = QListWidget(parent) for item in self.itemsDict: listItem = QListWidgetItem(item) listItem.setCheckState(Qt.Unchecked) list.addItem(listItem) return list return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): # special combobox for field type if index.column() == self.column: list = QListWidget(parent) for item in self.itemsDict: listItem = QListWidgetItem(item) listItem.setCheckState(Qt.Unchecked) list.addItem(listItem) return list return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): # special combobox for field type if index.column() == 1: cbo = QComboBox(parent) cbo.setEditable(True) cbo.setAutoCompletion(True) cbo.setFrame(False) for item in self.fieldTypes: cbo.addItem(item) return cbo return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): # special combobox for field type if index.column() == 1: cbo = QComboBox(parent) cbo.setEditable(True) cbo.setAutoCompletion(True) cbo.setFrame(False) for item in self.fieldTypes: cbo.addItem(item) return cbo return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): if index.column() in (MOD1, MOD2, MOD3): combobox = QComboBox(parent) combobox.addItems(self.modifiers) return combobox elif index.column() == KEY: combobox = QComboBox(parent) combobox.addItems(self.keys) return combobox else: return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self,parent,option,index): """create widgets to edit values""" if index.column() == 1: cbox = QComboBox(parent) cbox.setMaxVisibleItems(10) self.updateEditorGeometry(cbox, option,index ) for pos,value in enumerate([0,20,30,40,50,60,70,80,90,100]): icon = QPixmap(20,10) icon.fill(self._getColorForProgress(value)) cbox.insertItem(pos, QIcon(icon),"",value) cbox.showPopup() return cbox else: return QItemDelegate.createEditor(self,parent,option,index)
def createEditor (self, parent, option, index): column = index.column() self.index = index content = index.model().data(index, Qt.EditRole) if column == 2: self.content = index.model().data(index, Qt.EditRole) self.editorQWidget = QComboBox(parent) self.editorQWidget.setEditable(True) self.editorQWidget.addItems(self.module.fieldMapping.values()) if self.content in self.module.fieldMapping.values(): self.editorQWidget.setCurrentIndex(self.editorQWidget.findData(self.content)) else: self.editorQWidget.insertItem(0,'') self.editorQWidget.setCurrentIndex(0) return self.editorQWidget else: return None return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): """ Create the editor @param parent: @type parent: @param option: @type option: @param index: @type index: @return: @rtype: """ value = self.getValue(index) if index.column() == COL_VALUE: editor = QComboBox(parent) editor.activated.connect(self.onItemActivated) editor.addItem(value) editor.insertSeparator(1) # get running agents from context runningAgents = ServerAgents.instance().getRunningAgents() runningAgents = sorted( runningAgents) # sort agents list, new in v12.2 for i in xrange(len(runningAgents)): if len(runningAgents[i]) == 0: editor.insertSeparator(i + 2) else: editor.addItem(runningAgents[i]) editor.insertSeparator(len(runningAgents) + 2) # add alias params = [] for pr in self.parent.model.getData(): params.append(pr['name']) editor.addItems(params) return editor return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): model = index.model() if model.isColumn("name", index): textedit = QLineEdit(parent) return textedit elif model.isColumn("rating", index): spinbox = QSpinBox(parent) spinbox.setRange(0, 200) spinbox.setSingleStep(1) spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter) return spinbox elif model.isColumn("adjust", index): spinbox = QSpinBox(parent) spinbox.setRange(-10, 10) spinbox.setSingleStep(1) spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter) return spinbox else: return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): if len(self._view.selectedIndexes()) > 1: self._selected_indexes = self._view.selectedIndexes() columns = index.model().get_git_model().get_columns() field_name = columns[index.column()] if field_name in TEXT_FIELDS: editor = QTextEdit(parent) elif field_name in ACTOR_FIELDS: editor = QLineEdit(parent) elif field_name in TIME_FIELDS: editor = QDateTimeEdit(parent) editor.setDisplayFormat("yyyy-MM-dd hh:mm:ss") else: return QItemDelegate.createEditor(self, parent, option, index) self.connect(editor, SIGNAL("returnPressed()"), self.commitAndCloseEditor) return editor
def createEditor(self, parent, option, index): """ Create the editor @param parent: @type parent: @param option: @type option: @param index: @type index: @return: @rtype: """ value = self.getValue(index) if index.column() == self.col_: editor = QLineEdit(parent) return editor return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): """ Create the editor @param parent: @type parent: @param option: @type option: @param index: @type index: @return: @rtype: """ value = self.getValueRow(index) if index.column() == self.col_: if value['key'] == 'summary' or value['key'] == 'prerequisites': editorDialog = DescriptionDialog(value['value']) if editorDialog.exec_() == QDialog.Accepted: testDescr = editorDialog.getDescr() index.model().setData(index, q(testDescr)) return None if value['key'] == 'comments': editorDialog = CommentsDialog(value['value']) if editorDialog.exec_() == QDialog.Accepted: comments = editorDialog.getComments() index.model().setData(index, comments) return None elif value['key'] == 'date': # deprecated return None elif value['key'] == 'creation date': return None elif value['key'] == 'data mode': wdoc = index.model().getWdoc() if wdoc.extension != Workspace.TestData.TYPE: return None editorDialog = DataModeDialog() if editorDialog.exec_() == QDialog.Accepted: dataMode = editorDialog.getSelectedMode() # update lexer on editor if dataMode == 'Raw': wdoc.deactiveXmlLexer() else: wdoc.activeXmlLexer() # update table index.model().setData(index, dataMode) return None elif value['key'] == 'libraries': serverSutLibs = Settings.instance().serverContext['libraries'] editor = QComboBox(parent) editor.activated.connect(self.onItemActivated) editor.addItems(serverSutLibs.split(',')) return editor elif value['key'] == 'adapters': serverSutAdps = Settings.instance().serverContext['adapters'] editor = QComboBox(parent) editor.activated.connect(self.onItemActivated) editor.addItems(serverSutAdps.split(',')) return editor elif value['key'] == 'state': wdoc = index.model().getWdoc() if wdoc is None: return if not wdoc.isSaved(): return isTp = False isTs = False isTu = False isTg = False isTa = False if wdoc.extension == Workspace.TestUnit.TYPE: isTu = True if wdoc.extension == Workspace.TestAbstract.TYPE: isTa = True if wdoc.extension == Workspace.TestSuite.TYPE: isTs = True if wdoc.extension == Workspace.TestPlan.TYPE: isTp = True if wdoc.extension == Workspace.TestPlan.TYPE_GLOBAL: isTg = True editorDialog = StateDialog() if editorDialog.exec_() == QDialog.Accepted: stateTest = editorDialog.getSelectedState() if value['value'] != stateTest: # uci call if stateTest == 'Executing': duration = time.time() - float( wdoc.dataModel.testdev) # rest call RCI.instance().durationTestsWritingMetrics( duration=int(duration), projectId=wdoc.project, isTp=isTp, isTs=isTs, isTu=isTu, isTg=isTg, isTa=isTa) # update data model if stateTest == 'Writing': wdoc.dataModel.testdev = time.time() # update table index.model().setData(index, stateTest) return None else: editor = editor = QLineEdit(parent) return editor return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, QWidget, QStyleOptionViewItem, QModelIndex): return QItemDelegate.createEditor(self, QWidget, QStyleOptionViewItem, QModelIndex)
def createEditor(self, parent_view, option, index): ''' PyQt API Method -- See the PyQt documentation for a description ''' default_editor = QItemDelegate.createEditor(self, parent_view, option, index) if not index.isValid(): return default_editor item = index.internalPointer() node = item.node # editing of left hand columns is handled by dialogs etc, don't allow direct editing if index.column() == 0: pass elif index.column() == 1: # Combobox for multiple choices editor = default_editor # Create and prepare an editor for the node # Select database connection if node.get('choices') is not None: editor = QComboBox(parent_view) choices = [s.strip() for s in node.get('choices').split('|')] for item in choices: editor.addItem(item) # Select the current choice choice = node.text.strip() if node.text else '' if choice in choices: editor.setCurrentIndex(choices.index(choice)) elif node.get('type') == 'db_connection_hook': editor = QComboBox(parent_view) # Get connection names from database_server_connections.xml choices = get_db_connection_names() # Populate the editor with the choices for i in choices: editor.addItem(i) # Select files and folders elif node.get('type') in ('file_path', 'dir_path'): editor_file = QFileDialog() filter_str = QString("*.*") editor_file.setFilter(filter_str) editor_file.setAcceptMode(QFileDialog.AcceptOpen) current_value = \ index.model().data(index, Qt.DisplayRole).toString() if node.get('type') == 'file_path': method = editor_file.getOpenFileName title = 'Please select a file...' else: method = editor_file.getExistingDirectory title = 'Please select a directory...' fd = method(self.parent_view, title, current_value) # Check for cancel if len(fd) == 0: new_value = current_value else: new_value = QString(fd) editor = QItemDelegate.createEditor(self, self.parent_view, option, index) if type(editor) == QLineEdit: editor.setText(new_value) # Edit passwords elif node.get('type') == 'password': editor.setText(str(node.text or '')) editor.setStyleSheet('QLineEdit { background-color: red }') editor.setEchoMode(QLineEdit.PasswordEchoOnEdit) # Use default editor else: if type(editor) == QLineEdit: txt = index.model().data(index, Qt.DisplayRole).toString() editor.setText(txt) return editor
def createEditor(self, parent_view, option, index): """ PyQt API Method -- See the PyQt documentation for a description """ default_editor = QItemDelegate.createEditor(self, parent_view, option, index) if not index.isValid(): return default_editor item = index.internalPointer() node = item.node # editing of left hand columns is handled by dialogs etc, don't allow direct editing if index.column() == 0: pass elif index.column() == 1: # Combobox for multiple choices editor = default_editor # CK delete the following comment if the xml schema is complete and does'nt contain any 'choices' # if node.get('choices') is not None: # editor = QComboBox(parent_view) # choices = [s.strip() for s in node.get('choices').split('|')] # for item in choices: # editor.addItem(item) # # Select the current choice # choice = node.text.strip() if node.text else '' # if choice in choices: # editor.setCurrentIndex(choices.index(choice)) # Create and prepare an editor for the node # Select database connection if node.get("type") == "db_connection_hook": editor = QComboBox(parent_view) # Get connection names from database_server_connections.xml choices = get_db_connection_names() # Populate the editor with the choices for i in choices: editor.addItem(i) # Select files and folders elif node.get("type") in ("file_path", "dir_path"): editor_file = QFileDialog() filter_str = QString("*.*") editor_file.setFilter(filter_str) editor_file.setAcceptMode(QFileDialog.AcceptOpen) current_value = index.model().data(index, Qt.DisplayRole).toString() if node.get("type") == "file_path": method = editor_file.getOpenFileName title = "Please select a file..." else: method = editor_file.getExistingDirectory title = "Please select a directory..." fd = method(self.parent_view, title, current_value) # Check for cancel if len(fd) == 0: new_value = current_value else: new_value = QString(fd) editor = QItemDelegate.createEditor(self, self.parent_view, option, index) if type(editor) == QLineEdit: editor.setText(new_value) # Edit passwords elif node.get("type") == "password": editor.setText(str(node.text or "")) editor.setStyleSheet("QLineEdit { background-color: red }") editor.setEchoMode(QLineEdit.PasswordEchoOnEdit) # Use default editor else: if type(editor) == QLineEdit: txt = index.model().data(index, Qt.DisplayRole).toString() editor.setText(txt) return editor
def createEditor(self, QWidget, QStyleOptionViewItem, QModelIndex): return QItemDelegate.createEditor(self, QWidget, QStyleOptionViewItem, QModelIndex)