1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Job/BatchInfo.cpp
//! @brief Implements class BatchInfo.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/Model/Job/BatchInfo.h"
#include "GUI/Model/Job/JobStatus.h"
#include "GUI/Model/Util/UtilXML.h"
namespace {
namespace Tag {
const QString BeginTime("Begin");
const QString Comments("Comments");
const QString Duration("Duration");
const QString EndTime("End");
const QString Name("Name");
const QString Progress("Progress");
const QString Status("Status");
} // namespace Tag
} // namespace
BatchInfo::BatchInfo()
: m_status(JobStatus::Idle)
{
}
void BatchInfo::setJobName(const QString& name)
{
m_name = name;
emit jobNameChanged(name);
}
void BatchInfo::setBeginTime(const QDateTime& begin_time)
{
m_begin_time = begin_time;
emit jobBeginTimeChanged(begin_time);
}
void BatchInfo::setEndTime(const QDateTime& end_time)
{
m_end_time = end_time;
emit jobEndTimeChanged(end_time);
}
std::optional<size_t> BatchInfo::duration() const
{
QDateTime begin_time = beginTime();
QDateTime end_time = endTime();
if (begin_time.isValid() && end_time.isValid() && begin_time < end_time)
return begin_time.msecsTo(end_time);
return std::nullopt;
}
void BatchInfo::setComments(const QString& comments)
{
m_comments = comments;
emit jobCommentsChanged(comments);
}
void BatchInfo::setProgress(int progress)
{
m_progress = progress;
emit jobProgressChanged(progress);
}
void BatchInfo::setStatus(JobStatus status)
{
m_status = status;
emit jobStatusChanged(status);
}
void BatchInfo::writeTo(QXmlStreamWriter* w) const
{
XML::writeTaggedValue(w, Tag::Name, m_name);
XML::writeTaggedValue(w, Tag::BeginTime, m_begin_time.toString(Qt::ISODateWithMs));
XML::writeTaggedValue(w, Tag::EndTime, m_end_time.toString(Qt::ISODateWithMs));
XML::writeTaggedValue(w, Tag::Progress, m_progress);
XML::writeTaggedValue(w, Tag::Comments, m_comments);
XML::writeTaggedValue(w, Tag::Status, jobStatusToString(m_status));
}
void BatchInfo::readFrom(QXmlStreamReader* r)
{
while (r->readNextStartElement()) {
QString tag = r->name().toString();
if (tag == Tag::Comments)
m_comments = XML::readTaggedString(r, tag);
else if (tag == Tag::Progress)
m_progress = XML::readTaggedString(r, tag).toInt();
else if (tag == Tag::BeginTime) {
QString s = XML::readTaggedString(r, tag);
m_begin_time = QDateTime::fromString(s, Qt::ISODateWithMs);
} else if (tag == Tag::EndTime) {
QString s = XML::readTaggedString(r, tag);
m_end_time = QDateTime::fromString(s, Qt::ISODateWithMs);
} else if (tag == Tag::Name)
m_name = XML::readTaggedString(r, tag);
else if (tag == Tag::Status) {
QString s = XML::readTaggedString(r, tag);
m_status = jobStatusFromString(s);
} else
r->skipCurrentElement();
}
}
|