SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
contribution.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 "contribution.h"
5#include "Utilities.h"
6#include "qfile.h"
7
9{
10
11}
12
13Contribution::Contribution(const Contribution &rhs):map<string, double>(rhs),Interface(rhs)
14{
15
16}
18{
19 map<string,double>::operator=(rhs);
21 return *this;
22}
23
25{
26 string out;
27 for (map<string,double>::const_iterator it=cbegin(); it!=cend(); it++ )
28 {
29 out += it->first + ":" + aquiutils::numbertostring(it->second) + "\n";
30 }
31 return out;
32}
33
35{
36 file->write(QString::fromStdString(ToString()).toUtf8());
37 return true;
38}
39
40bool Contribution::Read(const QStringList &strlist)
41{
42 clear();
43 for (int i=0; i<strlist.size();i++)
44 {
45 if (strlist[i].split(":").size()>1)
46 {
47 operator[](strlist[i].split(":")[0].toStdString()) = strlist[i].split(":")[1].toDouble();
48 }
49 }
50 return true;
51}
52
53QJsonObject Contribution::toJsonObject() const
54{
55 QJsonObject out;
56 for (map<string,double>::const_iterator it=cbegin(); it!=cend(); it++ )
57 {
58 out[QString::fromStdString(it->first)] = it->second;
59 }
60 return out;
61}
62
63bool Contribution::ReadFromJsonObject(const QJsonObject &jsonobject)
64{
65 clear();
66 for (const QString& key: jsonobject.keys())
67 {
68 operator[](key.toStdString()) = jsonobject[key].toDouble();
69 }
70 return true;
71}
72
73QTableWidget *Contribution::ToTable()
74{
75 QTableWidget *tablewidget = new QTableWidget();
76 tablewidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
77 tablewidget->setColumnCount(1);
78 tablewidget->setRowCount(size());
79 QStringList headers;
80 QStringList sources;
81 int i=0;
82 for (map<string,double>::const_iterator it=cbegin(); it!=cend(); it++ )
83 {
84 sources<<QString::fromStdString(it->first);
85 tablewidget->setItem(i,0, new QTableWidgetItem(QString::number(it->second)));
86 i++;
87 }
88 headers << "Contribution";
89 tablewidget->setHorizontalHeaderLabels(headers);
90 tablewidget->setVerticalHeaderLabels(sources);
91 return tablewidget;
92}
QTableWidget * ToTable() override
Creates a QTableWidget for displaying contributions.
bool ReadFromJsonObject(const QJsonObject &jsonobject) override
Deserializes contributions from JSON format.
bool Read(const QStringList &strlist) override
Reads contributions from string list.
QJsonObject toJsonObject() const override
Serializes contributions to JSON format.
Contribution()
Default constructor - creates an empty contribution set.
string ToString() const override
Converts contributions to colon-separated string format.
bool writetofile(QFile *) override
Writes contributions to file.
Contribution & operator=(const Contribution &rhs)
Assignment operator.
Interface()
Default constructor.
Definition interface.cpp:6
Interface & operator=(const Interface &intf)
Assignment operator.
STL class.