diff --git a/statapp/main_window.py b/statapp/main_window.py index 3fadbdc..38c0fa1 100644 --- a/statapp/main_window.py +++ b/statapp/main_window.py @@ -4,7 +4,7 @@ from PySide2.QtGui import QIcon from PySide2.QtWidgets import QMainWindow, QMessageBox, QApplication from statapp.generate_factor_window import GenerateFactorWindow, INDIRECT_LINK -from statapp.models.data_model import DataModel +from statapp.models.input_values_model import InputValuesModel from statapp.generate_window import GenerateWindow from statapp.about_window import AboutWindow from statapp.models.fileslc_model import FileSLCModel @@ -25,7 +25,7 @@ class MainWindow(QMainWindow): self.setWindowIcon(icon) self.isDataChanged = False - self.model = DataModel() + self.model = InputValuesModel() self.fileModel = FileSLCModel() self.ui.tableView.setModel(self.model) diff --git a/statapp/models/data_model.py b/statapp/models/data_model.py deleted file mode 100644 index c9ade7d..0000000 --- a/statapp/models/data_model.py +++ /dev/null @@ -1,59 +0,0 @@ -import numpy as np -from PySide2 import QtCore -from PySide2.QtCore import Qt - - -class DataModel(QtCore.QAbstractTableModel): - def __init__(self, data=np.array([[]], dtype=np.float32)): - super().__init__() - - self._data = data - - def updateAllData(self, data): - self.layoutAboutToBeChanged.emit() - self._data = data - self.layoutChanged.emit() - - def rowCount(self, index): - return self._data.shape[0] - - def columnCount(self, index): - return self._data.shape[1] - - def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...): - if role == Qt.DisplayRole: - # if orientation == Qt.Orientation.Horizontal: - - if section == 0: - return 'Y' - - return f'X{section}' - - return None - - def flags(self, index): - return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable - - def setData(self, index, value, role): - if role == Qt.EditRole: - try: - value = float(value) - except ValueError: - return False - self._data[index.row(), index.column()] = value - return True - return False - - def getData(self): - return self._data - - def getY(self): - return self._data[:, 0] - - - def data(self, index, role): - if role == Qt.DisplayRole or role == Qt.EditRole: - # ? - return float(self._data[index.row(), index.column()]) - - return None \ No newline at end of file diff --git a/statapp/models/editable_table_model.py b/statapp/models/editable_table_model.py new file mode 100644 index 0000000..e2328e6 --- /dev/null +++ b/statapp/models/editable_table_model.py @@ -0,0 +1,30 @@ +import numpy as np +from PySide2.QtCore import Qt + +from statapp.models.ro_table_model import ROTableModel + + +class EditableTableModel(ROTableModel): + def __init__(self, data=np.array([[]], dtype=np.float32)): + super().__init__() + + self._data = data + + def flags(self, index): + return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable + + def setData(self, index, value, role): + if role == Qt.EditRole: + try: + value = float(value) + except ValueError: + return False + self._data[index.row(), index.column()] = value + return True + return False + + def data(self, index, role): + if role == Qt.DisplayRole or role == Qt.EditRole: + return float(self._data[index.row(), index.column()]) + + return None diff --git a/statapp/models/input_values_model.py b/statapp/models/input_values_model.py new file mode 100644 index 0000000..6f5629c --- /dev/null +++ b/statapp/models/input_values_model.py @@ -0,0 +1,16 @@ +import numpy as np +from PySide2.QtCore import Qt, QModelIndex + +from statapp.models.editable_table_model import EditableTableModel +from statapp.models.utils import yx_header + + +class InputValuesModel(EditableTableModel): + def __init__(self, data=np.array([[]], dtype=np.float32)): + super().__init__(data) + + def getHorizontalHeader(self): + return yx_header(self.rowCount(QModelIndex())) + + def getY(self): + return self._data[:, 0] diff --git a/statapp/models/ro_table_model.py b/statapp/models/ro_table_model.py index cb67ee9..aad69aa 100644 --- a/statapp/models/ro_table_model.py +++ b/statapp/models/ro_table_model.py @@ -43,10 +43,6 @@ class ROTableModel(QtCore.QAbstractTableModel): def getData(self): return self._data - def getY(self): - return self._data[:, 0] - - def data(self, index, role): if role == Qt.DisplayRole: return float(self._data[index.row(), index.column()]) diff --git a/statapp/models/utils.py b/statapp/models/utils.py new file mode 100644 index 0000000..6f8b3ba --- /dev/null +++ b/statapp/models/utils.py @@ -0,0 +1,2 @@ +def yx_header(count): + return ['Y'] + [f'X{i}' for i in range(1, count)] diff --git a/statapp/models/variance_analysis_model.py b/statapp/models/variance_analysis_model.py index 8a57895..fc37522 100644 --- a/statapp/models/variance_analysis_model.py +++ b/statapp/models/variance_analysis_model.py @@ -1,6 +1,7 @@ from PySide2.QtCore import QModelIndex from statapp.models.ro_table_model import ROTableModel +from statapp.models.utils import yx_header class VarianceAnalysisModel(ROTableModel): @@ -11,4 +12,4 @@ class VarianceAnalysisModel(ROTableModel): return ['Мат. ожидание', 'Среднекв. отклонение', 'Минимум', 'Максимум'] def getVerticalHeader(self): - return ['Y'] + [f'X{i}' for i in range(1, self.rowCount(QModelIndex()))] + return yx_header(self.rowCount(QModelIndex()))