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// SedSAT3 – Sediment Source Assessment Tool, version 3
2// U.S. Geological Survey. See LICENSE.md and DISCLAIMER.md in the repository root.
3
4#include "rangeset.h"
5#include <QFile>
6
11
13{
14 // (This used to construct an empty set instead of copying rhs)
15
16}
18{
20 map<string,Range>::operator=(rhs);
21 return *this;
22}
23QJsonObject RangeSet::toJsonObject() const
24{
25 QJsonObject out;
26 for (map<string,Range>::const_iterator it=cbegin(); it!=cend(); it++)
27 {
28 out[QString::fromStdString(it->first)] = it->second.toJsonObject();
29 }
30 return out;
31}
32bool RangeSet::ReadFromJsonObject(const QJsonObject &jsonobject)
33{
34 for (const QString& key: jsonobject.keys())
35 {
36 Range range;
37 range.ReadFromJsonObject(jsonobject[key].toObject());
38 this->operator[](key.toStdString()) = range;
39 }
40 return true;
41}
42string RangeSet::ToString() const
43{
44 string out;
45 for (map<string,Range>::const_iterator it=cbegin(); it!=cend(); it++)
46 {
47 out.append(it->first + ":" + it->second.ToString());
48 }
49 return out;
50}
51
52bool RangeSet::writetofile(QFile* file)
53{
54 file->write(QString::fromStdString(ToString()).toUtf8());
55 return true;
56
57}
58bool RangeSet::Read(const QStringList &/*strlist*/)
59{
60 return true;
61}
62
64{
65 double out = -1e24;
66 for (map<string,Range>::iterator it=begin(); it!=end(); it++)
67 {
68 out = max(out,it->second.Get(_range::high));
69 if (it->second.GetValue()!=0)
70 out = max(out,it->second.GetValue());
71 }
72 return out;
73}
75{
76 double out = 1e24;
77 for (map<string,Range>::iterator it=begin(); it!=end(); it++)
78 {
79 out = min(out,it->second.Get(_range::low));
80 if (it->second.GetValue()!=0)
81 out = min(out,it->second.GetValue());
82 }
83 return out;
84}
85
86QTableWidget *RangeSet::ToTable()
87{
88 QTableWidget *tablewidget = new QTableWidget();
89 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
90 tablewidget->setColumnCount(4);
91 tablewidget->setRowCount(size());
92 QStringList headers;
93 headers<<"Low"<<"High"<<"Median"<<"Mean";
94 QStringList constituents;
95 int row = 0;
96 for (map<string,Range>::iterator it=begin(); it!=end(); it++ )
97 {
98 tablewidget->setItem(row,0, new QTableWidgetItem(QString::number(it->second.Get(_range::low))));
99 tablewidget->setItem(row,1, new QTableWidgetItem(QString::number(it->second.Get(_range::high))));
100 tablewidget->setItem(row,2, new QTableWidgetItem(QString::number(it->second.Median())));
101 tablewidget->setItem(row,3, new QTableWidgetItem(QString::number(it->second.Mean())));
102 row++;
103 constituents << QString::fromStdString(it->first);
104 }
105
106 tablewidget->setHorizontalHeaderLabels(headers);
107 tablewidget->setVerticalHeaderLabels(constituents);
108 return tablewidget;
109}
Interface()
Default constructor.
Definition interface.cpp:6
Interface & operator=(const Interface &intf)
Assignment operator.
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserialize object from JSON format.
Definition rangeset.cpp:32
bool writetofile(QFile *) override
Write object data to a file.
Definition rangeset.cpp:52
double minval()
Definition rangeset.cpp:74
double maxval()
Definition rangeset.cpp:63
RangeSet & operator=(const RangeSet &rhs)
Definition rangeset.cpp:17
QTableWidget * ToTable() override
Create a Qt table widget representation of the data.
Definition rangeset.cpp:86
QJsonObject toJsonObject() const override
Serialize object to JSON format.
Definition rangeset.cpp:23
bool Read(const QStringList &strlist) override
Parse object data from a string list.
Definition rangeset.cpp:58
string ToString() const override
Convert object to string representation.
Definition rangeset.cpp:42
Definition range.h:11
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserialize object from JSON format.
Definition range.cpp:43
STL class.
@ low
Lower bound of the parameter range.
Definition parameter.h:17
@ high
Upper bound of the parameter range.
Definition parameter.h:18