SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
omsizecorrectiontablemodel.cpp
Go to the documentation of this file.
1// SedSAT3 – Sediment Source Assessment Tool, version 3
2// U.S. Geological Survey. See LICENSE.md and DISCLAIMER.md in the repository root.
3
5
6OmSizeCorrectionTableModel::OmSizeCorrectionTableModel(MultipleLinearRegressionSet *_mlrset, QObject *parent) : QAbstractTableModel(parent)
7{
8 MLRset = _mlrset;
9}
10int OmSizeCorrectionTableModel::rowCount(const QModelIndex &/*index*/) const
11{
12 return MLRset->size();
13}
14int OmSizeCorrectionTableModel::columnCount(const QModelIndex &/*index*/) const
15{
16 if (MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames().size()==2)
17 return 8;
18 else if (MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames().size()==1)
19 return 5;
20 return 0;
21}
22QVariant OmSizeCorrectionTableModel::data(const QModelIndex &index, int role) const
23{
24 MultipleLinearRegression *mlr = &MLRset->operator[](MLRset->Key(index.row()));
25 if (role == Qt::DisplayRole)
26 { if (index.column()==0)
27 {
28 return QString::fromStdString(MLRset->Key(index.row()));
29 }
30 if (index.column()==1)
31 {
32 return mlr->CoefficientsIntercept()[0];
33 }
34 if (index.column()==2)
35 {
36 return mlr->CoefficientsIntercept()[1];
37 }
38 if (index.column()==3)
39 {
40 return mlr->P_Value()[0];
41 }
42 if (index.column()==4)
43 {
44 if (mlr->Effective(0))
45 return "Yes";
46 else
47 return "No";
48 }
49 if (index.column()==5)
50 {
51 return mlr->CoefficientsIntercept()[2];
52 }
53 if (index.column()==6)
54 {
55 return mlr->P_Value()[1];
56 }
57 if (index.column()==7)
58 {
59 if (mlr->Effective(1))
60 return "Yes";
61 else
62 return "No";
63 }
64 }
65 if (role == Qt::ItemIsEnabled)
66 {
67 if (index.column()==7 || index.column()==4)
68 return true;
69 else
70 return false;
71 }
72
73 if (role == Qt::ForegroundRole)
74 {
75 // Significant coefficients are shown in red
76 if ((index.column()==3 && mlr->P_Value()[0]<mlr->PValueThreshold()) ||
77 (index.column()==6 && mlr->P_Value()[1]<mlr->PValueThreshold()))
78 return QVariant::fromValue(QColor(Qt::red));
79 else
80 return QVariant::fromValue(QColor(Qt::black));
81 }
82
83 return QVariant();
84
85}
86QVariant OmSizeCorrectionTableModel::headerData(int section, Qt::Orientation orientation, int role) const
87{
88 if (role == Qt::DisplayRole)
89 {
90 if (orientation == Qt::Horizontal)
91 { if (section==0)
92 {
93 return "Constituent";
94 }
95 if (section==1)
96 {
97 return "Intercept";
98 }
99 if (section==2)
100 {
101 return "Coefficient for " + QString::fromStdString(MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames()[0]);
102 }
103 if (section==3)
104 {
105 return "P-value for " + QString::fromStdString(MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames()[0]);
106 }
107 if (section==4)
108 {
109 return "Correct based on " + QString::fromStdString(MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames()[0]);
110 }
111 if (section==5)
112 {
113 return "Coefficient for " + QString::fromStdString(MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames()[1]);
114 }
115 if (section==6)
116 {
117 return "P-value for " + QString::fromStdString(MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames()[1]);
118 }
119 if (section==7)
120 {
121 return "Correct based on " + QString::fromStdString(MLRset->operator[](MLRset->Key(0)).GetIndependentVariableNames()[1]);
122 }
123 }
124 }
125 return QVariant();
126}
127bool OmSizeCorrectionTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
128{
129 MultipleLinearRegression *mlr = &MLRset->operator[](MLRset->Key(index.row()));
130 if (role==Qt::EditRole)
131 {
132 if (index.column()==4)
133 {
134 if (value.toString()=="Yes" || value.toBool())
135 mlr->SetEffective(0,true);
136 else
137 mlr->SetEffective(0,false);
138 }
139 if (index.column()==7)
140 {
141 if (value.toString()=="Yes" || value.toBool())
142 mlr->SetEffective(1,true);
143 else
144 mlr->SetEffective(1,false);
145 }
146
147 }
148 QString result = "Done";
149 emit editCompleted(result);
150 return true;
151}
152Qt::ItemFlags OmSizeCorrectionTableModel::flags(const QModelIndex & index) const
153{
154 if (index.column()!=4 && index.column()!=7)
155 return Qt::ItemIsSelectable | Qt::ItemIsEnabled ;
156 else
157 return Qt::ItemIsSelectable | Qt::ItemFlag::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsEditable ;
158
159}
160
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void editCompleted(const QString &)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
OmSizeCorrectionTableModel(MultipleLinearRegressionSet *MLRset, QObject *parent=nullptr)
MultipleLinearRegressionSet * MLRset
QVariant headerData(int section, Qt::Orientation orientation, int role) const override