Пример #1
0
 def editorEvent(self, event: QEvent, model: QAbstractItemModel, option: QStyleOptionViewItem, index: QModelIndex) -> bool:
     if index.column() == 3:
         if event.type() is QEvent.MouseButtonPress:
             v = bool(model.data(index, Qt.CheckStateRole))
             model.setData(index, not v, Qt.CheckStateRole)
             event.accept()
     elif index.column() == 2:
         if not self.cond["RESULT_DISPLAY_QUEST"]:
             if event.type() is QEvent.MouseButtonPress:
                 v = bool(model.data(index, Qt.CheckStateRole))
                 model.setData(index, not v, Qt.CheckStateRole)
                 event.accept()
     else:
         pass
     return super().editorEvent(event, model, option, index)
Пример #2
0
def _assert_model_rows_equal(
    model: QtCore.QAbstractItemModel,
    expected: List[Any],
    role: int = QtCore.Qt.DisplayRole,
):
    num_rows = model.rowCount()
    actual = [model.data(model.index(row, 0), role) for row in range(num_rows)]
    assert actual == expected
Пример #3
0
def _assert_model_data_equal(
    model: QtCore.QAbstractItemModel,
    expected: List[List[Any]],
    role: int = QtCore.Qt.DisplayRole,
):
    num_rows = model.rowCount()
    num_cols = model.columnCount()
    actual = [[
        model.data(model.index(row, column), role)
        for column in range(num_cols)
    ] for row in range(num_rows)]
    assert actual == expected
Пример #4
0
    def setModelData(self, editor: QtWidgets.QWidget,
                     model: QtCore.QAbstractItemModel,
                     index: QtCore.QModelIndex):
        """ Take the editor, read the given value and set it in the model.

        If the new formula is the same as the existing one, do not call setData
        """
        dialog = editor.findChild(FormulaDialog)
        if dialog.result() == QtWidgets.QDialog.Rejected:
            # Cancel was clicked, do not store anything.
            return
        if model.data(index, QtCore.Qt.DisplayRole) == dialog.formula:
            # The text in the dialog is the same as what is already there.
            return
        model.setData(index, dialog.formula, QtCore.Qt.EditRole)