Beispiel #1
0
    def on_press(self, event):
        if self.editing:
            self.stop_editing()

        if event.button != 1:
            return

        if event.xdata is None or event.ydata is None:
            return

        modifiers = QtWidgets.QApplication.keyboardModifiers()
        if (
            not modifiers & QtCore.Qt.ShiftModifier
            and not modifiers & QtCore.Qt.ControlModifier
            and self.line is not None
        ):
            ok, points = self.line.contains(event)
            del points
            if ok:
                self.start_edit(event.xdata, event.ydata)
                return

        # Search for the closest
        d = np.sqrt(
            (self.xdata - event.xdata) ** 2.0
            + (self.ydatas[self.column - 1] - event.ydata) ** 2.0
        )
        ind = np.argmin(d)
        if ind is None:
            return

        # Define considered points
        if (
            modifiers & QtCore.Qt.ShiftModifier
            and not modifiers & QtCore.Qt.ControlModifier
            and self.previous_point_index is not None
        ):
            selection = QtCore.QItemSelection(
                self.selection_model.model().index(
                    self.previous_point_index, self.column
                ),
                self.selection_model.model().index(ind, self.column),
            )
        else:
            selection = self.selection_model.model().index(ind, self.column)
            self.previous_point_index = ind

        # Alter selection
        if QtWidgets.QApplication.keyboardModifiers() & QtCore.Qt.ControlModifier:
            selection = self.selection_model.model().index(ind, self.column)
            self.selection_model.select(selection, QtCore.QItemSelectionModel.Toggle)
        else:
            self.selection_model.select(
                selection, QtCore.QItemSelectionModel.ClearAndSelect
            )

        self.refresh_selection()
Beispiel #2
0
 def test_apply_interpolation(self):
     self.dialog = self.create_dialog()
     self.dialog.leftSpinBox.setValue(-0.5)
     self.dialog.leftSpinBox.setValue(-0.6)
     model = self.dialog.pointsTableModel
     self.dialog.pointsTableView.selectionModel().select(
         QtCore.QItemSelection(model.index(1, 1), model.index(4, 2)),
         QtCore.QItemSelectionModel.ClearAndSelect,
     )
     self.dialog.apply_interpolation()