38 CMatrix::operator=(mp);
45 for (
int i=0; i<getnumrows(); i++)
48 for (
int j=0; j<getnumcols(); j++)
52 QJsonArray Row_Labels;
53 for (
unsigned int i=0; i<
rowlabels.size(); i++)
55 Row_Labels.append(QString::fromStdString(
rowlabels[i]));
57 QJsonArray Column_Labels;
60 Column_Labels.append(QString::fromStdString(
columnlabels[i]));
63 out[
"RowLabels"] = Row_Labels;
64 out[
"ColumnLabels"] = Column_Labels;
69 QJsonArray array = jsonobject[
"Matrix"].toArray();
70 QJsonArray Row_Labels = jsonobject[
"RowLabels"].toArray();
71 QJsonArray Column_Labels = jsonobject[
"ColumnLabels"].toArray();
75 Resize(array.size(), array[0].toArray().size());
79 for (
unsigned int i=0; i<array.size(); i++)
81 for (
unsigned int j=0; j<array[i].toArray().size(); j++)
83 matr[i][j] = array[i].toArray()[j].toDouble();
87 for (
unsigned int i=0; i<Row_Labels.size(); i++)
88 rowlabels[i] = Row_Labels[i].toString().toStdString();
90 for (
unsigned int i=0; i<Column_Labels.size(); i++)
91 columnlabels[i] = Column_Labels[i].toString().toStdString();
98 file->write(QString::fromStdString(
ToString()).toUtf8());
104 for (
int j=0; j<getnumcols(); j++)
109 for (
int i=0; i<getnumrows(); i++)
113 for (
int j=0; j<getnumcols(); j++)
116 out+=QString::number(
valueAt(i,j)).toStdString();
124 QTableWidget *tablewidget =
new QTableWidget();
125 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
126 tablewidget->setColumnCount(getnumcols());
127 tablewidget->setRowCount(getnumrows());
128 QStringList rowheaders;
129 QStringList colheaders;
131 for (
int j=0; j<getnumcols(); j++)
134 for (
int i = 0; i < getnumrows(); i++)
135 rowheaders << QString::fromStdString(
rowlabels[i]);
137 tablewidget->setHorizontalHeaderLabels(colheaders);
138 tablewidget->setVerticalHeaderLabels(rowheaders);
140 for (
int i = 0; i < getnumrows(); i++)
142 for (
int j = 0; j < getnumcols(); j++)
144 QTableWidgetItem* item;
148 item =
new QTableWidgetItem(matr[i][j] == 1 ?
"Fail" :
"Pass");
151 item->setBackground(QBrush(Qt::red));
156 item =
new QTableWidgetItem(QString::number(matr[i][j]));
162 tablewidget->verticalHeaderItem(i)->setForeground(QBrush(Qt::red));
164 item->setBackground(QBrush(Qt::red));
168 item->setForeground(QBrush(Qt::black));
173 tablewidget->setItem(i, j, item);
174 tablewidget->item(i, j)->setTextAlignment(Qt::AlignCenter);
186 return CMatrix::operator[](i).at(j);
199 CMatrix out(getnumrows(), getnumcols());
207 for (
unsigned int i=0; i<
rowlabels.size(); i++)
211 for (
unsigned int j=0; j<getnumcols(); j++)
225 for (
unsigned int j=0; j<getnumrows(); j++)
236 for (
unsigned int i=0; i<
rowlabels.size(); i++)
238 if (!out.contains(QString::fromStdString(
rowlabels[i])))
239 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.
Abstract base class providing common serialization and visualization interface.
double lowlimit
Lower threshold for value highlighting (when enabled)
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.