23#include <QtCore/QObject>
24#include <QtCore/QString>
25#include <QtCore/QVariantMap>
27#include "cc_tools_qt/Api.h"
28#include "cc_tools_qt/Message.h"
39template <
typename TValue>
43 typedef TValue ValueType;
45 PropBase(
const QString& name,
const QByteArray& propName)
52 void setTo(U&& val, QObject& obj)
const
54 obj.setProperty(m_propName, QVariant::fromValue(std::forward<U>(val)));
55 assert(obj.property(m_propName).template canConvert<ValueType>());
59 void setTo(U&& val, QVariantMap& map)
const
61 map.insert(m_name, QVariant::fromValue(std::forward<U>(val)));
62 assert(map.value(m_name).template canConvert<ValueType>());
65 ValueType getFrom(
const QObject& obj,
const ValueType& defaultVal = ValueType())
const
67 auto var = obj.property(m_propName.constData());
68 if ((!var.isValid()) || (!var.template canConvert<ValueType>())) {
72 return var.template value<ValueType>();
75 ValueType getFrom(
const QVariantMap& map,
const ValueType& defaultVal = ValueType())
const
77 auto var = map.value(m_name);
78 if ((!var.isValid()) || (!var.template canConvert<ValueType>())) {
82 return var.template value<ValueType>();
85 void copyFromTo(
const QObject& from, QObject& to)
const
87 auto var = from.property(m_propName);
89 to.setProperty(m_propName, std::move(var));
94 const QString& m_name;
95 const QByteArray& m_propName;
98class CC_API Type :
public PropBase<unsigned>
100 typedef PropBase<unsigned> Base;
102 typedef Message::Type ValueType;
104 Type() : Base(Name, PropName) {}
106 template <
typename TTo>
107 void setTo(ValueType val, TTo&& to)
109 Base::setTo(
static_cast<Base::ValueType
>(val), std::forward<TTo>(to));
112 template <
typename TFrom>
113 ValueType getFrom(TFrom&& from)
115 return static_cast<ValueType
>(Base::getFrom(std::forward<TFrom>(from)));
119 static const QString Name;
120 static const QByteArray PropName;
123class CC_API MsgIdx :
public PropBase<unsigned>
125 typedef PropBase<unsigned> Base;
127 MsgIdx() : Base(Name, PropName) {}
130 static const QString Name;
131 static const QByteArray PropName;
135class CC_API Timestamp :
public PropBase<unsigned long long>
137 typedef PropBase<unsigned long long> Base;
139 Timestamp() : Base(Name, PropName) {}
142 static const QString Name;
143 static const QByteArray PropName;
146class CC_API ProtocolName :
public PropBase<QString>
148 typedef PropBase<QString> Base;
150 ProtocolName() : Base(Name, PropName) {}
153 static const QString Name;
154 static const QByteArray PropName;
157class CC_API TransportMsg :
public PropBase<MessagePtr>
159 typedef PropBase<MessagePtr> Base;
161 TransportMsg() : Base(Name, PropName) {}
164 static const QString Name;
165 static const QByteArray PropName;
168class CC_API RawDataMsg :
public PropBase<MessagePtr>
170 typedef PropBase<MessagePtr> Base;
172 RawDataMsg() : Base(Name, PropName) {}
175 static const QString Name;
176 static const QByteArray PropName;
179class CC_API ExtraInfoMsg :
public PropBase<MessagePtr>
181 typedef PropBase<MessagePtr> Base;
183 ExtraInfoMsg() : Base(Name, PropName) {}
186 static const QString Name;
187 static const QByteArray PropName;
190class CC_API ExtraInfo :
public PropBase<QVariantMap>
192 typedef PropBase<QVariantMap> Base;
194 ExtraInfo() : Base(Name, PropName) {}
197 static const QString Name;
198 static const QByteArray PropName;
201class CC_API ForceExtraInfoExistence :
public PropBase<bool>
203 typedef PropBase<bool> Base;
205 ForceExtraInfoExistence() : Base(Name, PropName) {}
208 static const QString Name;
209 static const QByteArray PropName;
213class CC_API Delay :
public PropBase<unsigned long long>
215 typedef PropBase<unsigned long long> Base;
217 Delay() : Base(Name, PropName) {}
220 static const QString Name;
221 static const QByteArray PropName;
224class CC_API DelayUnits :
public PropBase<QString>
226 typedef PropBase<QString> Base;
228 DelayUnits() : Base(Name, PropName) {}
231 static const QString Name;
232 static const QByteArray PropName;
236class CC_API RepeatDuration :
public PropBase<unsigned long long>
238 typedef PropBase<unsigned long long> Base;
240 RepeatDuration() : Base(Name, PropName) {}
243 static const QString Name;
244 static const QByteArray PropName;
247class CC_API RepeatDurationUnits :
public PropBase<QString>
249 typedef PropBase<QString> Base;
251 RepeatDurationUnits() : Base(Name, PropName) {}
254 static const QString Name;
255 static const QByteArray PropName;
258class CC_API RepeatCount :
public PropBase<unsigned>
260 typedef PropBase<unsigned> Base;
262 RepeatCount() : Base(Name, PropName) {}
265 static const QString Name;
266 static const QByteArray PropName;
269class CC_API ScrollPos :
public PropBase<int>
271 typedef PropBase<int> Base;
273 ScrollPos() : Base(Name, PropName) {}
276 static const QString Name;
277 static const QByteArray PropName;
281class CC_API Comment :
public PropBase<QString>
283 typedef PropBase<QString> Base;
285 Comment() : Base(Name, PropName) {}
288 static const QString Name;
289 static const QByteArray PropName;