diff --git a/statapp/main_window.py b/statapp/main_window.py index 620a9df..a8ca582 100644 --- a/statapp/main_window.py +++ b/statapp/main_window.py @@ -19,8 +19,8 @@ # import numpy as np from PySide2 import QtCore -from PySide2.QtCore import Slot -from PySide2.QtWidgets import QMainWindow, QMessageBox +from PySide2.QtCore import Slot, Qt, QPoint +from PySide2.QtWidgets import QMainWindow, QMessageBox, QAction, QMenu from statapp.calculations import generateXValues, generateYValues from statapp.constants import NUMBERS_PRECISION @@ -79,6 +79,27 @@ class MainWindow(QMainWindow): # x1 = generateXValues(20, 2, 0, y) # x2 = generateXValues(10, 1, 0, y) # self.model.updateAllData(np.concatenate([y, x1, x2], axis=1)) + self.ui.tableView.horizontalHeader().setContextMenuPolicy(Qt.CustomContextMenu) + self.ui.tableView.horizontalHeader().customContextMenuRequested.connect(self.removeColumn) + + + def removeColumn(self, event: QPoint): + menu = QMenu(self) + + col = self.ui.tableView.columnAt(event.x()) + + if col == 0: + return + + def fun(): + self.model.removeCol(col) + self.isDataChanged = True + + selectAction = QAction("Удалить", self) + selectAction.triggered.connect(fun) + menu.addAction(selectAction) + menu.exec_(self.ui.tableView.mapToGlobal(event)) + def updateActionsEnabled(self): diff --git a/statapp/models/input_values_model.py b/statapp/models/input_values_model.py index 6360eb4..40f19c1 100644 --- a/statapp/models/input_values_model.py +++ b/statapp/models/input_values_model.py @@ -33,3 +33,6 @@ class InputValuesModel(EditableTableModel): def getY(self): return self._data[:, 0] + + def removeCol(self, index: int): + self.updateAllData(np.delete(self._data, index, axis=1))