Ejemplo n.º 1
0
 def __init__(self, ert):
     """
     @type ert: res.enkf.EnKFMain
     """
     QAbstractItemModel.__init__(self)
     self.__ert = ert
     self.__icon = resourceIcon("ide/small/bullet_star")
Ejemplo n.º 2
0
    def editorEvent(
        self,
        event: QtCore.QEvent,
        model: QtCore.QAbstractItemModel,
        option: QStyleOptionViewItem,
        index: QtCore.QModelIndex,
    ) -> bool:
        """Called when an event has occured in the editor.

        This can be used to customize how the delegate handles mouse/key events
        """
        if (event.type() == event.MouseButtonRelease
                and event.button() == Qt.RightButton):
            self.show_context_menu(index, model, event.globalPos(),
                                   option.widget)

        # if the user clicks quickly on the visibility checkbox, we *don't*
        # want it to be interpreted as a double-click.  We want the visibilty
        # to simply be toggled.
        if event.type() == event.MouseButtonDblClick:
            self.initStyleOption(option, index)
            style = option.widget.style()
            check_rect = style.subElementRect(
                style.SE_ItemViewItemCheckIndicator, option, option.widget)
            if check_rect.contains(event.pos()):
                cur_state = index.data(Qt.CheckStateRole)
                if model.flags(index) & Qt.ItemIsUserTristate:
                    state = Qt.CheckState((cur_state + 1) % 3)
                else:
                    state = Qt.Unchecked if cur_state else Qt.Checked
                return model.setData(index, state, Qt.CheckStateRole)
        # refer all other events to the QStyledItemDelegate
        return super().editorEvent(event, model, option, index)
Ejemplo n.º 3
0
 def __init__(self, keys):
     """
     @type ert: res.enkf.EnKFMain
     """
     QAbstractItemModel.__init__(self)
     self._keys = keys
     self.__icon = resourceIcon("star_filled.svg")
Ejemplo n.º 4
0
def index_of(model: QAbstractItemModel, obj: ItemType) -> QModelIndex:
    """Find the `QModelIndex` for a given object in the model."""
    fl = Qt.MatchExactly | Qt.MatchRecursive
    hits = model.match(model.index(0, 0, QModelIndex()),
                       Qt.UserRole,
                       obj,
                       hits=1,
                       flags=fl)
    return hits[0] if hits else QModelIndex()
Ejemplo n.º 5
0
    def setModelData(self, editor: QWidget, model: QAbstractItemModel,
                     index: QModelIndex):

        text = editor.text()
        if text == "":
            text = editor.placeholderText()
        # Update the "default" text to the previous value edited in
        self._default_text = text
        model.setData(index, text, Qt.DisplayRole)
Ejemplo n.º 6
0
 def __init__(self, parent=None):
     """Constructor."""
     QAbstractItemModel.__init__(self, parent)
     self.abbreviator = Abbreviator()
     self.testresults = []
     try:
         self.monospace_font = parent.window().editor.get_plugin_font()
     except AttributeError:  # If run standalone for testing
         self.monospace_font = QFont("Courier New")
         self.monospace_font.setPointSize(10)
Ejemplo n.º 7
0
    def setModelData(self, editor: QWidget, model: QAbstractItemModel,
                     index: QModelIndex) -> None:
        editor: QFileDialog
        result: int = editor.result()
        if result == QDialog.Accepted:
            # if accepted, this means that the user also wanted to overwrite the file
            dstPath: str = editor.selectedFiles()[0]
            dstPath: Path = Path(dstPath)

            model.setData(index, dstPath, Qt.EditRole)
Ejemplo n.º 8
0
    def editorEvent(self, event: QtCore.QEvent,
                    model: QtCore.QAbstractItemModel,
                    option: 'QStyleOptionViewItem',
                    index: QtCore.QModelIndex) -> bool:
        decorationRect = option.rect

        if event.type() == QEvent.MouseButtonPress and calculate_middle_rect(
                decorationRect, 20, 20).contains(event.pos()):
            item = index.model().data(index, Qt.UserRole)

            if isinstance(item, QVariant):
                return QStyledItemDelegate.editorEvent(self, event, model,
                                                       option, index)

            value = item['value']
            type = item['type']
            if type == 'checkbox':
                # 数据转换
                value = 1 if value == 0 else 0
                model.setData(index, value, Qt.DisplayRole)

        return QStyledItemDelegate.editorEvent(self, event, model, option,
                                               index)
Ejemplo n.º 9
0
 def __init__(self):
     QAbstractItemModel.__init__(self)
     self.__data = None
Ejemplo n.º 10
0
    def flags(self, index):
        """Read-only."""
        if not index.isValid():
            return 0

        return QAbstractItemModel.flags(self, index)
Ejemplo n.º 11
0
 def __init__(self, cases):
     QAbstractItemModel.__init__(self)
     self.__data = cases
Ejemplo n.º 12
0
 def __init__(self, source_model: QAbstractItemModel, parent=None) -> None:
     QAbstractItemModel.__init__(self, parent)
     self._source_model = source_model
     self._progress = None
     self._connect()
Ejemplo n.º 13
0
 def __init__(self, facade: LibresFacade):
     self.facade = facade
     QAbstractItemModel.__init__(self)
     self.__data = []
Ejemplo n.º 14
0
 def flags(self, index):
     """Override to make cells editable."""
     if not index.isValid():
         return Qt.ItemIsEnabled
     return QAbstractItemModel.flags(self, index)
Ejemplo n.º 15
0
    def __init__(self, tree_root, parent=None):
        QAbstractItemModel.__init__(self, parent)

        self.__root = tree_root