SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
rangeset.cpp
Go to the documentation of this file.
1#include "rangeset.h"
2#include <QFile>
3
8
10{
11
12}
14{
16 map<string,Range>::operator=(rhs);
17 return *this;
18}
19QJsonObject RangeSet::toJsonObject() const
20{
21 QJsonObject out;
22 for (map<string,Range>::const_iterator it=cbegin(); it!=cend(); it++)
23 {
24 out[QString::fromStdString(it->first)] = it->second.toJsonObject();
25 }
26 return out;
27}
28bool RangeSet::ReadFromJsonObject(const QJsonObject &jsonobject)
29{
30 for (QString key: jsonobject.keys())
31 {
32 Range range;
33 range.ReadFromJsonObject(jsonobject[key].toObject());
34 this->operator[](key.toStdString()) = range;
35 }
36 return true;
37}
38string RangeSet::ToString() const
39{
40 string out;
41 for (map<string,Range>::const_iterator it=cbegin(); it!=cend(); it++)
42 {
43 out.append(it->first + ":" + it->second.ToString());
44 }
45 return out;
46}
47
48bool RangeSet::writetofile(QFile* file)
49{
50 file->write(QString::fromStdString(ToString()).toUtf8());
51 return true;
52
53}
54bool RangeSet::Read(const QStringList &strlist)
55{
56 return true;
57}
58
60{
61 double out = -1e24;
62 for (map<string,Range>::iterator it=begin(); it!=end(); it++)
63 {
64 out = max(out,it->second.Get(_range::high));
65 if (it->second.GetValue()!=0)
66 out = max(out,it->second.GetValue());
67 }
68 return out;
69}
71{
72 double out = 1e24;
73 for (map<string,Range>::iterator it=begin(); it!=end(); it++)
74 {
75 out = min(out,it->second.Get(_range::low));
76 if (it->second.GetValue()!=0)
77 out = min(out,it->second.GetValue());
78 }
79 return out;
80}
81
82QTableWidget *RangeSet::ToTable()
83{
84 QTableWidget *tablewidget = new QTableWidget();
85 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
86 tablewidget->setColumnCount(4);
87 tablewidget->setRowCount(size());
88 QStringList headers;
89 headers<<"Low"<<"High"<<"Median"<<"Mean";
90 QStringList constituents;
91 int row = 0;
92 for (map<string,Range>::iterator it=begin(); it!=end(); it++ )
93 {
94 tablewidget->setItem(row,0, new QTableWidgetItem(QString::number(it->second.Get(_range::low))));
95 tablewidget->setItem(row,1, new QTableWidgetItem(QString::number(it->second.Get(_range::high))));
96 tablewidget->setItem(row,2, new QTableWidgetItem(QString::number(it->second.Median())));
97 tablewidget->setItem(row,3, new QTableWidgetItem(QString::number(it->second.Mean())));
98 row++;
99 constituents << QString::fromStdString(it->first);
100 }
101
102 tablewidget->setHorizontalHeaderLabels(headers);
103 tablewidget->setVerticalHeaderLabels(constituents);
104 return tablewidget;
105}
Abstract base class providing common serialization and visualization interface.
Definition interface.h:65
Interface & operator=(const Interface &intf)
Assignment operator.
Definition interface.cpp:14
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserialize object from JSON format.
Definition rangeset.cpp:28
bool writetofile(QFile *) override
Write object data to a file.
Definition rangeset.cpp:48
double minval()
Definition rangeset.cpp:70
double maxval()
Definition rangeset.cpp:59
RangeSet & operator=(const RangeSet &rhs)
Definition rangeset.cpp:13
QTableWidget * ToTable() override
Create a Qt table widget representation of the data.
Definition rangeset.cpp:82
QJsonObject toJsonObject() const override
Serialize object to JSON format.
Definition rangeset.cpp:19
bool Read(const QStringList &strlist) override
Parse object data from a string list.
Definition rangeset.cpp:54
string ToString() const override
Convert object to string representation.
Definition rangeset.cpp:38
Definition range.h:8
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserialize object from JSON format.
Definition range.cpp:40
@ low
Lower bound of the parameter range.
@ high
Upper bound of the parameter range.