def dropOn(self, event): if event.isAccepted(): return False, None, None, None index = QModelIndex() row = -1 col = -1 if self.viewport().rect().contains(event.pos()): index = self.indexAt(event.pos()) if not index.isValid() or not self.visualRect(index).contains( event.pos()): index = self.rootIndex() if self.model().supportedDropActions() & event.dropAction(): if index != self.rootIndex(): dropIndicatorPosition = self.position(event.pos(), self.visualRect(index), index) if dropIndicatorPosition == QAbstractItemView.AboveItem: row = index.row() col = index.column() elif dropIndicatorPosition == QAbstractItemView.BelowItem: row = index.row() + 1 col = index.column() else: row = index.row() col = index.column() if not self.droppingOnItself(event, index): return True, row, col, index return False, None, None, None
def updateSentence(self, QModelIndex): self.sentenceInCorrectionIndex = QModelIndex self.sentenceInCorrection = self.packedSentences[QModelIndex.row()] sentenceModel = sentenceCorrectionModel(self.sentenceInCorrection.getTokens()) self.ui.sentenceCorrectionView.setModel(sentenceModel) self.ui.sentenceList.scrollTo(QModelIndex) self.ui.sentenceIndex.setText(QString(str(QModelIndex.row())))
def apply(self): if not self.__dialog: self.createDialog() self.__datasource.applied = False sourceType = unicode(self.__dialog.ui.typeComboBox.currentText()) self.__datasource.dataSourceName = unicode( self.__dialog.ui.nameLineEdit.text()) if sourceType in self.__dialog.imp.keys(): self.__dialog.imp[sourceType].fromForm(self.__datasource) self.__datasource.dataSourceType = sourceType self.__datasource.doc = unicode( self.__dialog.ui.docTextEdit.toPlainText()).strip() index = QModelIndex() if hasattr(self.__dialog, "view") and self.__dialog.view \ and self.__dialog.view.model(): if hasattr(self.__dialog.view, "currentIndex"): index = self.__dialog.view.currentIndex() finalIndex = self.__dialog.view.model().createIndex( index.row(), 2, index.parent().internalPointer()) self.__dialog.view.expand(index) row = index.row() column = index.column() parent = index.parent() if self.__dialog.root: self.updateNode(index) if index.isValid(): index = self.__dialog.view.model().index(row, column, parent) self.__dialog.view.setCurrentIndex(index) self.__dialog.view.expand(index) if hasattr(self.__dialog, "view") and self.__dialog.view \ and self.__dialog.view.model(): self.__dialog.view.model().emit( SIGNAL("dataChanged(const QModelIndex &," " const QModelIndex &)"), index.parent(), index.parent()) if index.column() != 0: index = self.__dialog.view.model().index( index.row(), 0, index.parent()) self.__dialog.view.model().emit( SIGNAL("dataChanged(const QModelIndex &," " const QModelIndex &)"), index, finalIndex) self.__dialog.view.expand(index) if not self.__datasource.tree: self.createNodes() self.__datasource.applied = True return True
def setData(self, ix: QtCore.QModelIndex, value: SqlDataType, role: int=QtCore.Qt.EditRole) -> bool: try: pk = self.visible_data[ix.row()][self.query_manager.table.primary_key_index] row = next( i for i, row in enumerate(self.modified_data) if row[self.query_manager.table.primary_key_index] == pk ) self.visible_data[ix.row()][ix.column()] = value self.modified_data[row][ix.column()] = value self.dataChanged.emit(ix, ix) return True except: return False
def data(self, QModelIndex, int_role = None): """ For initial role out, assume http://qt-project.org/doc/qt-4.8/qt.html#ItemDataRole-enum :param QModelIndex: :param int_role: :return: Qt::DisplayRole 0 The key data to be rendered in the form of text. (QString) Qt::DecorationRole 1 The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap) Qt::EditRole 2 The data in a form suitable for editing in an editor. (QString) Qt::ToolTipRole 3 The data displayed in the item's tooltip. (QString) Qt::StatusTipRole 4 The data displayed in the status bar. (QString) Qt::WhatsThisRole 5 The data displayed for the item in "What's This?" mode. (QString) Qt::SizeHintRole 13 The size hint for the item that will be supplied to views. (QSize) Roles describing appearance and meta data (with associated types): Constant Value Description Qt::FontRole 6 The font used for items rendered with the default delegate. (QFont) Qt::TextAlignmentRole 7 The alignment of the text for items rendered with the default delegate. (Qt::AlignmentFlag) Qt::BackgroundRole 8 The background brush used for items rendered with the default delegate. (QBrush) Qt::BackgroundColorRole 8 This role is obsolete. Use BackgroundRole instead. Qt::ForegroundRole 9 The foreground brush (text color, typically) used for items rendered with the default delegate. (QBrush) Qt::TextColorRole 9 This role is obsolete. Use ForegroundRole instead. Qt::CheckStateRole 10 This role is used to obtain the checked state of an item. (Qt::CheckState) Qt::InitialSortOrderRole 14 This role is used to obtain the initial sort order of a header view section. (Qt::SortOrder). This role was introduced in Qt 4.8. """ if int_role == 0: if QModelIndex.isValid(): i = QModelIndex.row() j = QModelIndex.column() return QString(str(self.DataFrame.ix[i, j])) else: return QVariant() else: return QVariant()
def setData(self, ix: QtCore.QModelIndex, value: SqlDataType, role: int = QtCore.Qt.EditRole) -> bool: try: pk = self.visible_data[ix.row()][ self.query_manager.table.primary_key_index] row = next( i for i, row in enumerate(self.modified_data) if row[self.query_manager.table.primary_key_index] == pk) self.visible_data[ix.row()][ix.column()] = value self.modified_data[row][ix.column()] = value self.dataChanged.emit(ix, ix) return True except: return False
def sizeHint(self, option: QStyleOptionViewItem, index: QModelIndex): pz = self.layer_prez(index.row()) # if pz.kind == KIND.RGB: # LOG.debug('triple-sizing composite layer') # return QSize(CELL_WIDTH, CELL_HEIGHT*3) # else: return QSize(CELL_WIDTH, CELL_HEIGHT)
def delete_row(self, ix: QtCore.QModelIndex) -> None: row = ix.row() pk = self.visible_data[row][self.query_manager.table.primary_key_index] mod_row = next(i for i, r in enumerate(self.modified_data) if r[self.query_manager.table.primary_key_index] == pk) del self.visible_data[row] del self.modified_data[mod_row] self.dataChanged.emit(ix, ix)
def delete_row(self, ix: QtCore.QModelIndex) -> None: row = ix.row() pk = self.visible_data[row][self.query_manager.table.primary_key_index] mod_row = next( i for i, r in enumerate(self.modified_data) if r[self.query_manager.table.primary_key_index] == pk ) del self.visible_data[row] del self.modified_data[mod_row] self.dataChanged.emit(ix, ix)
def setData(self, index: QModelIndex, data, role: int = None): LOG.debug('setData {0!r:s}'.format(data)) if not index.isValid(): return False if role == Qt.EditRole: if isinstance(data, str): LOG.debug("changing row {0:d} name to {1!r:s}".format( index.row(), data)) self.doc.change_layer_name(index.row(), data) self.dataChanged.emit(index, index) return True else: LOG.debug("data type is {0!r:s}".format(type(data))) elif role == Qt.CheckStateRole: newvalue = True if data == Qt.Checked else False LOG.debug('toggle layer visibility for row {} to {}'.format( index.row(), newvalue)) self.doc.toggle_layer_visibility(index.row(), newvalue) self.dataChanged.emit(index, index) return True elif role == Qt.ItemDataRole: LOG.warning('attempting to change layer') # self.doc.replace_layer() # FIXME implement this self.dataChanged.emit(index, index) return True elif role == Qt.DisplayRole: if index.isValid(): LOG.debug("changing row {} name to {0!r:s}".format( index.row(), data)) self.doc.change_layer_name(index.row(), data) return True return False
def data(self, index: QModelIndex, role: int = None): if not index.isValid(): return None row = index.row() # LOG.debug("getting data for row %d" % row) # col = index.column() el = self.listing info = el[row] if row < len(self.doc) else None if not info: return None # pass auxiliary info about the layer through the Qt.UserRole for use when displaying eq_content = self._last_equalizer_values.get(info[INFO.UUID], None) if role == Qt.UserRole: # get the animation order also animation_order = self.doc.layer_animation_order(row) return (eq_content, animation_order) elif role == Qt.EditRole: return self.doc.current_layer_set[ index.row()] if index.row() < len(self.doc) else None elif role == Qt.CheckStateRole: check = Qt.Checked if self.doc.is_layer_visible( row) else Qt.Unchecked return check elif role == Qt.ToolTipRole: if not eq_content: return None value, normalized = eq_content[:2] return str(value) elif role == Qt.DisplayRole: # lao = self.doc.layer_animation_order(row) name = info[INFO.DISPLAY_NAME] # return ('[-] ' if lao is None else '[{}]'.format(lao+1)) + el[row]['name'] # if leroy: # data = '[%.2f] ' % leroy[0] # return data + name return name return None
def add_row(self, ix: QtCore.QModelIndex) -> None: dummies = { FieldType.bool: True , FieldType.int: 0 , FieldType.float: 0.0 , FieldType.str: '' , FieldType.date: '1900-01-01' } dummy_row = [] # type: List for fld in self.query_manager.table.fields: dummy_row.append(dummies[fld.dtype]) for k, v in self.query_manager.table.foreign_keys.items(): dummy_row[k] = next(fk for fk in self.foreign_keys[k]) dummy_row[self.query_manager.table.primary_key_index] = uuid.uuid4().int self.visible_data.insert(ix.row(), dummy_row) self.modified_data.insert(0, dummy_row) self.dataChanged.emit(ix, ix)
def add_row(self, ix: QtCore.QModelIndex) -> None: dummies = { FieldType.bool: True, FieldType.int: 0, FieldType.float: 0.0, FieldType.str: '', FieldType.date: '1900-01-01' } dummy_row = [] # type: List for fld in self.query_manager.table.fields: dummy_row.append(dummies[fld.dtype]) for k, v in self.query_manager.table.foreign_keys.items(): dummy_row[k] = next(fk for fk in self.foreign_keys[k]) dummy_row[ self.query_manager.table.primary_key_index] = uuid.uuid4().int self.visible_data.insert(ix.row(), dummy_row) self.modified_data.insert(0, dummy_row) self.dataChanged.emit(ix, ix)
def data(self, index: QtCore.QModelIndex, role: int=QtCore.Qt.DisplayRole): alignment = { FieldType.bool: QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, FieldType.date: QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, FieldType.int: QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, FieldType.float: QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter, FieldType.str: QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, } col = index.column() fld = self.query_manager.table.fields[col] val = self.visible_data[index.row()][col] try: if not index.isValid(): return elif role == QtCore.Qt.TextAlignmentRole: return alignment[fld.dtype] elif role == QtCore.Qt.DisplayRole: if col in self.foreign_keys.keys(): return self.foreign_keys[col][val] return fld.format_value(val) except Exception as e: self.error_signal.emit('Error modeling data: {}'.format(e))
def data(self, index: QtCore.QModelIndex, role: int = QtCore.Qt.DisplayRole): alignment = { FieldType.bool: QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, FieldType.date: QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, FieldType.int: QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, FieldType.float: QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter, FieldType.str: QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, } col = index.column() fld = self.query_manager.table.fields[col] val = self.visible_data[index.row()][col] try: if not index.isValid(): return elif role == QtCore.Qt.TextAlignmentRole: return alignment[fld.dtype] elif role == QtCore.Qt.DisplayRole: if col in self.foreign_keys.keys(): return self.foreign_keys[col][val] return fld.format_value(val) except Exception as e: self.error_signal.emit('Error modeling data: {}'.format(e))
def itemFromIndex(self, index): index = QModelIndex( index) # explicitly convert from QPersistentModelIndex if index.isValid(): return index.internalPointer().childAt(index.row()) return self._root
def itemFromIndex(self, index): index = QModelIndex(index) # explicitly convert from QPersistentModelIndex if index.isValid(): return index.internalPointer().childAt(index.row()) return self._root