mirror of
https://github.com/shizand/statapp.git
synced 2025-10-21 00:57:28 +03:00
feat: добавлена генерация данных (#13)
Closes #2 --------- Co-authored-by: MisterMLiL <99662459+MisterMLiL@users.noreply.github.com>
This commit is contained in:
35
statapp/models/combobox_model.py
Normal file
35
statapp/models/combobox_model.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from PySide2.QtCore import QAbstractListModel, Qt
|
||||
|
||||
|
||||
class ComboBoxModel(QAbstractListModel):
|
||||
|
||||
def __init__(self, data):
|
||||
super().__init__()
|
||||
self._data = data
|
||||
|
||||
def updateAllData(self, data: list):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self._data = data
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def rawData(self, index: int):
|
||||
return self._data[index]
|
||||
|
||||
def findById(self, oid: int):
|
||||
for i, x in enumerate(self._data):
|
||||
if x[0] == oid:
|
||||
return i
|
||||
|
||||
return -1
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.DisplayRole:
|
||||
return self._data[index.row()][1]
|
||||
|
||||
if role == Qt.UserRole:
|
||||
return self._data[index.row()]
|
||||
|
||||
return None
|
||||
|
||||
def rowCount(self, index):
|
||||
return len(self._data)
|
59
statapp/models/data_model.py
Normal file
59
statapp/models/data_model.py
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
Reference in New Issue
Block a user