コード例 #1
0
    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
コード例 #2
0
    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
コード例 #3
0
 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
コード例 #4
0
 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
コード例 #5
0
 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()
コード例 #6
0
 def flags(self, ix: QtCore.QModelIndex) -> int:
     if ix.column() in self.query_manager.editable_fields_indices:
         return (
             QtCore.Qt.ItemIsEditable
             | QtCore.Qt.ItemIsEnabled
             | QtCore.Qt.ItemIsSelectable
         )
     return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
コード例 #7
0
ファイル: tree_model.py プロジェクト: Ensembles/ert
    def rowCount(self, parent):
        if parent is None:
            parent = QModelIndex()

        if parent.column() > 0:
            return 0

        if not parent.isValid():
            return len(self.__root)
        else:
            return len(parent.internalPointer())
コード例 #8
0
    def rowCount(self, parent):
        if parent is None:
            parent = QModelIndex()

        if parent.column() > 0:
            return 0

        if not parent.isValid():
            return len(self.__root)
        else:
            return len(parent.internalPointer())
コード例 #9
0
 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))
コード例 #10
0
 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))
コード例 #11
0
 def flags(self, ix: QtCore.QModelIndex) -> int:
     if ix.column() in self.query_manager.editable_fields_indices:
         return (QtCore.Qt.ItemIsEditable
                 | QtCore.Qt.ItemIsEnabled
                 | QtCore.Qt.ItemIsSelectable)
     return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable