HAL
comment_entry.cpp
Go to the documentation of this file.
2 #include <QTextStream>
3 
4 namespace hal
5 {
6 
7  CommentEntry::CommentEntry(Node n, QString text, QString header) : mNode(n), mHeader(header), mText(text), mDirty(false)
8  {
9  mCreated = QDateTime::currentDateTime().toUTC();
10  mLastModified = mCreated;
11  }
12 
14  {
15  if (!jsonObj.contains("node") || !jsonObj["node"].isObject()
16  || !jsonObj.contains("header")
17  || !jsonObj.contains("created")
18  || !jsonObj.contains("modified")
19  || !jsonObj.contains("text")
20  )
21  return;
22  const QJsonObject& nodeObj = jsonObj["node"].toObject();
23  if (!nodeObj.contains("id") || !nodeObj.contains("type"))
24  return;
25  mNode = Node(nodeObj["id"].toInt(),(Node::NodeType)nodeObj["type"].toInt());
26  mHeader = jsonObj["header"].toString();
27  mCreated = QDateTime::fromString(jsonObj["created"].toString(), Qt::ISODate);
28  mLastModified = QDateTime::fromString(jsonObj["modified"].toString(), Qt::ISODate);
29  mText = jsonObj["text"].toString();
30  }
31 
33  {
34  mHeader = newHeader;
35  mLastModified = QDateTime::currentDateTime().toUTC();
36  mDirty = true;
37  }
38 
40  {
41  mText = newText;
42  mLastModified = QDateTime::currentDateTime().toUTC();
43  mDirty = true;
44  }
45 
46  void CommentEntry::setDirty(bool dirty)
47  {
48  mDirty = dirty;
49  }
50 
52  {
53  return mHeader;
54  }
55 
57  {
58  return mText;
59  }
60 
62  {
63  return mNode;
64  }
65 
67  {
68  return mCreated;
69  }
70 
72  {
73  return mLastModified;
74  }
75 
77  {
78  QJsonObject retval;
79  QJsonObject node;
80  node["id"] = (int) mNode.id();
81  node["type"] = (int) mNode.type();
82  retval["node"] = node;
83  retval["header"] = mHeader;
84  retval["created"] = mCreated.toString(Qt::ISODate);
85  retval["modified"] = mLastModified.toString(Qt::ISODate);
86  retval["text"] = mText;
87  return retval;
88  }
89 
91  {
92  return mNode.isNull();
93  }
94 
95  void CommentEntry::dump() const
96  {
97  QTextStream xout(stdout, QIODevice::WriteOnly);
98  xout << (mNode.isGate() ? "Gate" : "Module") << " " << mNode.id() << "\n";
99  xout << " header: <" << mHeader << ">\n";
100  xout << " created: " << mCreated.toString("dd.MM.yyyy hh:mm:ss") << "\n";
101  xout << " modified: " << mLastModified.toString("dd.MM.yyyy hh:mm:ss") << "\n";
102  xout << " text: <" << mText.left(35) << ">\n";
103  }
104 
106  {
107  return QString("dd.MM.yy hh:mm");
108  }
109 
110 }
bool isInvalid() const
QDateTime getCreationTime() const
QDateTime getLastModifiedTime() const
QString getHeader() const
QJsonObject toJson() const
CommentEntry(Node n, QString text=QString(), QString header=QString())
void setDirty(bool dirty)
Node getNode() const
QString getText() const
void setText(QString newText)
QString getDateFormatString() const
void setHeader(QString newHeader)
void dump() const
The Node class object represents a module or a gate.
Definition: gui_def.h:61
NodeType type() const
type getter for type information
Definition: gui_def.h:71
bool isGate() const
isGate test whether node is a gate
Definition: gui_def.h:89
bool isNull() const
isNull test for null-Node object typically returned from functions
Definition: gui_def.h:83
u32 id() const
id getter for ID information
Definition: gui_def.h:77
n
Definition: test.py:6
QDateTime currentDateTime()
QDateTime fromString(const QString &string, Qt::DateFormat format)
QString toString(Qt::DateFormat format) const const
QDateTime toUTC() const const
bool contains(const QString &key) const const
QString left(int n) const const