41 CMatrix::operator=(mp);
48 for (
int i=0; i<getnumrows(); i++)
51 for (
int j=0; j<getnumcols(); j++)
55 QJsonArray Row_Labels;
56 for (
unsigned int i=0; i<
rowlabels.size(); i++)
58 Row_Labels.append(QString::fromStdString(
rowlabels[i]));
60 QJsonArray Column_Labels;
63 Column_Labels.append(QString::fromStdString(
columnlabels[i]));
66 out[
"RowLabels"] = Row_Labels;
67 out[
"ColumnLabels"] = Column_Labels;
72 QJsonArray array = jsonobject[
"Matrix"].toArray();
73 QJsonArray Row_Labels = jsonobject[
"RowLabels"].toArray();
74 QJsonArray Column_Labels = jsonobject[
"ColumnLabels"].toArray();
78 Resize(array.size(), array[0].toArray().size());
82 for (
unsigned int i=0; i<array.size(); i++)
84 for (
unsigned int j=0; j<array[i].toArray().size(); j++)
86 matr[i][j] = array[i].toArray()[j].toDouble();
90 for (
unsigned int i=0; i<Row_Labels.size(); i++)
91 rowlabels[i] = Row_Labels[i].toString().toStdString();
93 for (
unsigned int i=0; i<Column_Labels.size(); i++)
94 columnlabels[i] = Column_Labels[i].toString().toStdString();
101 file->write(QString::fromStdString(
ToString()).toUtf8());
107 for (
int j=0; j<getnumcols(); j++)
112 for (
int i=0; i<getnumrows(); i++)
116 for (
int j=0; j<getnumcols(); j++)
119 out+=QString::number(
valueAt(i,j)).toStdString();
127 QTableWidget *tablewidget =
new QTableWidget();
128 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
129 tablewidget->setColumnCount(getnumcols());
130 tablewidget->setRowCount(getnumrows());
131 QStringList rowheaders;
132 QStringList colheaders;
134 for (
int j=0; j<getnumcols(); j++)
137 for (
int i = 0; i < getnumrows(); i++)
138 rowheaders << QString::fromStdString(
rowlabels[i]);
140 tablewidget->setHorizontalHeaderLabels(colheaders);
141 tablewidget->setVerticalHeaderLabels(rowheaders);
143 for (
int i = 0; i < getnumrows(); i++)
145 for (
int j = 0; j < getnumcols(); j++)
147 QTableWidgetItem* item =
nullptr;
151 item =
new QTableWidgetItem(matr[i][j] == 1 ?
"Fail" :
"Pass");
154 item->setBackground(QBrush(Qt::red));
159 item =
new QTableWidgetItem(QString::number(matr[i][j]));
165 tablewidget->verticalHeaderItem(i)->setForeground(QBrush(Qt::red));
167 item->setBackground(QBrush(Qt::red));
171 item->setForeground(QBrush(Qt::black));
176 tablewidget->setItem(i, j, item);
177 tablewidget->item(i, j)->setTextAlignment(Qt::AlignCenter);
189 return CMatrix::operator[](i).at(j);
202 CMatrix out(getnumrows(), getnumcols());
210 for (
unsigned int i=0; i<
rowlabels.size(); i++)
214 for (
unsigned int j=0; j<getnumcols(); j++)
228 for (
unsigned int j=0; j<getnumrows(); j++)
239 for (
unsigned int i=0; i<
rowlabels.size(); i++)
241 if (!out.contains(QString::fromStdString(
rowlabels[i])))
242 out<<QString::fromStdString(
rowlabels[i]);
Matrix class with labeled rows and columns for Chemical Mass Balance analysis.
CMBMatrix()
Default constructor - creates an empty matrix.
vector< string > ColumnLabels() const
Gets all column labels.
CMatrix toMatrix() const
Converts to base CMatrix type (without labels).
bool boolean_values
Display values as Pass/Fail instead of numbers.
string ToString() const override
Converts matrix to CSV-formatted string.
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserializes matrix from JSON format.
QJsonObject toJsonObject() const override
Serializes matrix to JSON format.
QTableWidget * ToTable() override
Creates a QTableWidget for displaying matrix data.
QStringList RowLabelCategories()
Gets unique row label categories.
CMBMatrix & operator=(const CMBMatrix &mp)
Assignment operator.
vector< string > columnlabels
Labels for each column.
double valueAt(int i, int j) const
Gets value at specified matrix position.
CMBVector GetColumn(const string &columnlabel)
Extracts a column by its label.
CMBVector GetRow(const string &rowlabel)
Extracts a row by its label.
vector< string > RowLabels() const
Gets all row labels.
bool writetofile(QFile *file) override
Writes matrix to file in CSV format.
vector< string > rowlabels
Labels for each row.
Vector class with string labels for Chemical Mass Balance analysis.
CVector toVector() const
Converts to base CVector type (without labels).
void SetLabels(const vector< string > &label)
Sets all element labels at once.
double lowlimit
Lower threshold for value highlighting (when enabled).
Interface()
Default constructor.
bool highlightoutsideoflimit
Flag indicating whether to highlight values outside defined limits.
double highlimit
Upper threshold for value highlighting (when enabled).
CMBVector operator*(const CMBMatrix &M, const CMBVector &V)
Matrix-vector multiplication operator.