mirror of
https://github.com/shizand/statapp.git
synced 2025-04-03 16:13:44 +03:00
refactor: переписаны модели
This commit is contained in:
parent
c77ed6a82f
commit
6da0487500
@ -4,7 +4,7 @@ from PySide2.QtGui import QIcon
|
|||||||
from PySide2.QtWidgets import QMainWindow, QMessageBox, QApplication
|
from PySide2.QtWidgets import QMainWindow, QMessageBox, QApplication
|
||||||
|
|
||||||
from statapp.generate_factor_window import GenerateFactorWindow, INDIRECT_LINK
|
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.generate_window import GenerateWindow
|
||||||
from statapp.about_window import AboutWindow
|
from statapp.about_window import AboutWindow
|
||||||
from statapp.models.fileslc_model import FileSLCModel
|
from statapp.models.fileslc_model import FileSLCModel
|
||||||
@ -25,7 +25,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.setWindowIcon(icon)
|
self.setWindowIcon(icon)
|
||||||
|
|
||||||
self.isDataChanged = False
|
self.isDataChanged = False
|
||||||
self.model = DataModel()
|
self.model = InputValuesModel()
|
||||||
self.fileModel = FileSLCModel()
|
self.fileModel = FileSLCModel()
|
||||||
self.ui.tableView.setModel(self.model)
|
self.ui.tableView.setModel(self.model)
|
||||||
|
|
||||||
|
@ -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
|
|
30
statapp/models/editable_table_model.py
Normal file
30
statapp/models/editable_table_model.py
Normal file
@ -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
|
16
statapp/models/input_values_model.py
Normal file
16
statapp/models/input_values_model.py
Normal file
@ -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]
|
@ -43,10 +43,6 @@ class ROTableModel(QtCore.QAbstractTableModel):
|
|||||||
def getData(self):
|
def getData(self):
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
def getY(self):
|
|
||||||
return self._data[:, 0]
|
|
||||||
|
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
return float(self._data[index.row(), index.column()])
|
return float(self._data[index.row(), index.column()])
|
||||||
|
2
statapp/models/utils.py
Normal file
2
statapp/models/utils.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
def yx_header(count):
|
||||||
|
return ['Y'] + [f'X{i}' for i in range(1, count)]
|
@ -1,6 +1,7 @@
|
|||||||
from PySide2.QtCore import QModelIndex
|
from PySide2.QtCore import QModelIndex
|
||||||
|
|
||||||
from statapp.models.ro_table_model import ROTableModel
|
from statapp.models.ro_table_model import ROTableModel
|
||||||
|
from statapp.models.utils import yx_header
|
||||||
|
|
||||||
|
|
||||||
class VarianceAnalysisModel(ROTableModel):
|
class VarianceAnalysisModel(ROTableModel):
|
||||||
@ -11,4 +12,4 @@ class VarianceAnalysisModel(ROTableModel):
|
|||||||
return ['Мат. ожидание', 'Среднекв. отклонение', 'Минимум', 'Максимум']
|
return ['Мат. ожидание', 'Среднекв. отклонение', 'Минимум', 'Максимум']
|
||||||
|
|
||||||
def getVerticalHeader(self):
|
def getVerticalHeader(self):
|
||||||
return ['Y'] + [f'X{i}' for i in range(1, self.rowCount(QModelIndex()))]
|
return yx_header(self.rowCount(QModelIndex()))
|
||||||
|
Loading…
Reference in New Issue
Block a user