HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
comment_entry.cpp
Go to the documentation of this file.
2 #include <QTextStream>
3 #include <QIODevice>
4 
5 namespace hal
6 {
7 
8  CommentEntry::CommentEntry(Node n, QString text, QString header) : mNode(n), mHeader(header), mText(text), mDirty(false)
9  {
10  mCreated = QDateTime::currentDateTime().toUTC();
11  mLastModified = mCreated;
12  }
13 
15  {
16  if (!jsonObj.contains("node") || !jsonObj["node"].isObject()
17  || !jsonObj.contains("header")
18  || !jsonObj.contains("created")
19  || !jsonObj.contains("modified")
20  || !jsonObj.contains("text")
21  )
22  return;
23  const QJsonObject& nodeObj = jsonObj["node"].toObject();
24  if (!nodeObj.contains("id") || !nodeObj.contains("type"))
25  return;
26  mNode = Node(nodeObj["id"].toInt(),(Node::NodeType)nodeObj["type"].toInt());
27  mHeader = jsonObj["header"].toString();
28  mCreated = QDateTime::fromString(jsonObj["created"].toString(), Qt::ISODate);
29  mLastModified = QDateTime::fromString(jsonObj["modified"].toString(), Qt::ISODate);
30  mText = jsonObj["text"].toString();
31  }
32 
34  {
35  mHeader = newHeader;
36  mLastModified = QDateTime::currentDateTime().toUTC();
37  mDirty = true;
38  }
39 
41  {
42  mText = newText;
43  mLastModified = QDateTime::currentDateTime().toUTC();
44  mDirty = true;
45  }
46 
47  void CommentEntry::setDirty(bool dirty)
48  {
49  mDirty = dirty;
50  }
51 
53  {
54  return mHeader;
55  }
56 
58  {
59  return mText;
60  }
61 
63  {
64  return mNode;
65  }
66 
68  {
69  return mCreated;
70  }
71 
73  {
74  return mLastModified;
75  }
76 
78  {
79  QJsonObject retval;
80  QJsonObject node;
81  node["id"] = (int) mNode.id();
82  node["type"] = (int) mNode.type();
83  retval["node"] = node;
84  retval["header"] = mHeader;
85  retval["created"] = mCreated.toString(Qt::ISODate);
86  retval["modified"] = mLastModified.toString(Qt::ISODate);
87  retval["text"] = mText;
88  return retval;
89  }
90 
92  {
93  return mNode.isNull();
94  }
95 
96  void CommentEntry::dump() const
97  {
98  QTextStream xout(stdout, QIODevice::WriteOnly);
99  xout << (mNode.isGate() ? "Gate" : "Module") << " " << mNode.id() << "\n";
100  xout << " header: <" << mHeader << ">\n";
101  xout << " created: " << mCreated.toString("dd.MM.yyyy hh:mm:ss") << "\n";
102  xout << " modified: " << mLastModified.toString("dd.MM.yyyy hh:mm:ss") << "\n";
103  xout << " text: <" << mText.left(35) << ">\n";
104  }
105 
107  {
108  return QString("dd.MM.yy hh:mm");
109  }
110 
111 }
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
Definition: defines.h:45
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