Akonadi

nodetree.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Daniel Vrátil <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "nodetree.h"
8 #include "cpphelper.h"
9 #include "typehelper.h"
10 
11 Node::Node(NodeType type, Node *parent)
12  : mParent(parent)
13  , mType(type)
14 {
15  if (parent) {
16  parent->appendNode(this);
17  }
18 }
19 
20 Node::~Node()
21 {
22  qDeleteAll(mChildren);
23 }
24 
25 Node::NodeType Node::type() const
26 {
27  return mType;
28 }
29 
30 Node *Node::parent() const
31 {
32  return mParent;
33 }
34 
35 void Node::appendNode(Node *child)
36 {
37  child->mParent = this;
38  mChildren.push_back(child);
39 }
40 
41 const QVector<Node const *> &Node::children() const
42 {
43  return mChildren;
44 }
45 
46 DocumentNode::DocumentNode(int version)
47  : Node(Document, nullptr)
48  , mVersion(version)
49 {
50 }
51 
52 int DocumentNode::version() const
53 {
54  return mVersion;
55 }
56 
57 ClassNode::ClassNode(const QString &name, ClassType type, DocumentNode *parent)
58  : Node(Node::Class, parent)
59  , mName(name)
60  , mClassType(type)
61 {
62 }
63 
64 QString ClassNode::name() const
65 {
66  return mName;
67 }
68 
69 ClassNode::ClassType ClassNode::classType() const
70 {
71  return mClassType;
72 }
73 
74 QString ClassNode::className() const
75 {
76  switch (mClassType) {
77  case Class:
78  return mName;
79  case Command:
80  return mName + QStringLiteral("Command");
81  case Response:
82  return mName + QStringLiteral("Response");
83  case Notification:
84  return mName + QStringLiteral("Notification");
85  default:
86  Q_ASSERT(false);
87  return QString();
88  }
89 }
90 
91 QString ClassNode::parentClassName() const
92 {
93  switch (mClassType) {
94  case Class:
95  return QString();
96  case Command:
97  return QStringLiteral("Command");
98  case Response:
99  return QStringLiteral("Response");
100  case Notification:
101  return QStringLiteral("ChangeNotification");
102  case Invalid:
103  Q_ASSERT(false);
104  return QString();
105  }
106  Q_UNREACHABLE();
107 }
108 
109 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
110 ClassNode::ClassType ClassNode::elementNameToType(const QStringRef &name)
111 #else
112 ClassNode::ClassType ClassNode::elementNameToType(QStringView name)
113 #endif
114 {
115  if (name == QLatin1String("class")) {
116  return Class;
117  } else if (name == QLatin1String("command")) {
118  return Command;
119  } else if (name == QLatin1String("response")) {
120  return Response;
121  } else if (name == QLatin1String("notification")) {
122  return Notification;
123  } else {
124  return Invalid;
125  }
126 }
127 
128 QVector<PropertyNode const *> ClassNode::properties() const
129 {
131  for (const auto node : std::as_const(mChildren)) {
132  if (node->type() == Node::Property) {
133  rv << static_cast<PropertyNode const *>(node);
134  }
135  }
136  CppHelper::sortMembers(rv);
137  return rv;
138 }
139 
140 CtorNode::CtorNode(const QVector<Argument> &args, ClassNode *parent)
141  : Node(Ctor, parent)
142  , mArgs(args)
143 {
144 }
145 
146 CtorNode::~CtorNode()
147 {
148 }
149 
150 QVector<CtorNode::Argument> CtorNode::arguments() const
151 {
152  return mArgs;
153 }
154 
155 void CtorNode::setArgumentType(const QString &name, const QString &type)
156 {
157  for (auto &arg : mArgs) {
158  if (arg.name == name) {
159  arg.type = type;
160  break;
161  }
162  }
163 }
164 
165 EnumNode::EnumNode(const QString &name, EnumType type, ClassNode *parent)
166  : Node(Enum, parent)
167  , mName(name)
168  , mEnumType(type)
169 {
170 }
171 
172 QString EnumNode::name() const
173 {
174  return mName;
175 }
176 
177 EnumNode::EnumType EnumNode::enumType() const
178 {
179  return mEnumType;
180 }
181 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
182 EnumNode::EnumType EnumNode::elementNameToType(const QStringRef &name)
183 #else
184 EnumNode::EnumType EnumNode::elementNameToType(QStringView name)
185 #endif
186 {
187  if (name == QLatin1String("enum")) {
188  return TypeEnum;
189  } else if (name == QLatin1String("flag")) {
190  return TypeFlag;
191  } else {
192  return TypeInvalid;
193  }
194 }
195 
196 EnumValueNode::EnumValueNode(const QString &name, EnumNode *parent)
197  : Node(EnumValue, parent)
198  , mName(name)
199  , mValue()
200 {
201 }
202 
203 QString EnumValueNode::name() const
204 {
205  return mName;
206 }
207 
208 void EnumValueNode::setValue(const QString &value)
209 {
210  mValue = value;
211 }
212 
213 QString EnumValueNode::value() const
214 {
215  return mValue;
216 }
217 
218 PropertyNode::PropertyNode(const QString &name, const QString &type, ClassNode *parent)
219  : Node(Property, parent)
220  , mName(name)
221  , mType(type)
222  , mSetter(nullptr)
223  , mReadOnly(false)
224  , mAsReference(false)
225 {
226 }
227 
228 PropertyNode::~PropertyNode()
229 {
230  delete mSetter;
231 }
232 
233 QString PropertyNode::type() const
234 {
235  return mType;
236 }
237 
238 QString PropertyNode::name() const
239 {
240  return mName;
241 }
242 
243 void PropertyNode::setDefaultValue(const QString &defaultValue)
244 {
245  mDefaultValue = defaultValue;
246 }
247 
248 QString PropertyNode::defaultValue() const
249 {
250  return mDefaultValue;
251 }
252 
253 bool PropertyNode::readOnly() const
254 {
255  return mReadOnly;
256 }
257 
258 void PropertyNode::setReadOnly(bool readOnly)
259 {
260  mReadOnly = readOnly;
261 }
262 
263 bool PropertyNode::asReference() const
264 {
265  return mAsReference;
266 }
267 
268 void PropertyNode::setAsReference(bool asReference)
269 {
270  mAsReference = asReference;
271 }
272 
273 bool PropertyNode::isPointer() const
274 {
275  return TypeHelper::isPointerType(mType);
276 }
277 
278 QMultiMap<QString, QString> PropertyNode::dependencies() const
279 {
280  return mDepends;
281 }
282 
283 void PropertyNode::addDependency(const QString &enumVar, const QString &enumValue)
284 {
285  mDepends.insert(enumVar, enumValue);
286 }
287 
288 void PropertyNode::setSetter(Setter *setter)
289 {
290  mSetter = setter;
291 }
292 
293 PropertyNode::Setter *PropertyNode::setter() const
294 {
295  return mSetter;
296 }
297 
298 QString PropertyNode::mVariableName() const
299 {
300  return QStringLiteral("m") + mName[0].toUpper() + QStringView(mName).mid(1);
301 }
302 
303 QString PropertyNode::setterName() const
304 {
305  return QStringLiteral("set") + mName[0].toUpper() + QStringView(mName).mid(1);
306 }
virtual QString type() const
Definition: nodetree.cpp:25
QString toUpper() const const
QStringView mid(qsizetype start) const const
Property
typename QMap< Key, T >::iterator insert(const Key &key, const T &value)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
Definition: nodetree.h:12
KDB_EXPORT KDbVersionInfo version()
QString name(StandardShortcut id)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jun 4 2023 03:52:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.