Fixed the crash occurring when 'NaN' has to be displayed in the 'Table of values' table of the 'Acoustic data' tab.
parent
ab66158a60
commit
127dcde098
|
|
@ -1,5 +1,5 @@
|
||||||
from PyQt5.QtCore import Qt, QAbstractTableModel
|
from PyQt5.QtCore import Qt, QAbstractTableModel
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
class TableModel(QAbstractTableModel):
|
class TableModel(QAbstractTableModel):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
|
@ -9,20 +9,17 @@ class TableModel(QAbstractTableModel):
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
value = self._data.iloc[index.row(), index.column()]
|
value = self._data.iloc[index.row(), index.column()]
|
||||||
# if role == Qt.TextAlignmentRole:
|
|
||||||
# value = self._data.iloc[index.row(), index.column()]
|
|
||||||
# if isinstance(value, int) or isinstance(value, float):
|
|
||||||
# return Qt.AlignVCenter + Qt.AlignRight
|
|
||||||
|
|
||||||
if isinstance(value, float):
|
if isinstance(value, float):
|
||||||
|
|
||||||
|
if np.isnan(value):
|
||||||
|
return "NaN"
|
||||||
|
|
||||||
# Render float to 2 dp
|
# Render float to 2 dp
|
||||||
if len(str(value).split(".")[1]) <= 3:
|
elif len(str(value).split(".")[1]) <= 3:
|
||||||
return "%.2f" % value
|
return "%.2f" % value
|
||||||
else:
|
else:
|
||||||
return "%.2e" % value
|
return "%.2e" % value
|
||||||
# if isinstance(value, str):
|
|
||||||
# # Render strings with quotes
|
|
||||||
# return '"%s"' % value
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
@ -41,4 +38,4 @@ class TableModel(QAbstractTableModel):
|
||||||
if orientation == Qt.Horizontal:
|
if orientation == Qt.Horizontal:
|
||||||
return str(self._data.columns[section])
|
return str(self._data.columns[section])
|
||||||
if orientation == Qt.Vertical:
|
if orientation == Qt.Vertical:
|
||||||
return str(self._data.index[section])
|
return str(self._data.index[section])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue