Commit 3607866a authored by hjk's avatar hjk
Browse files

De-pimpl Macros::Internal::MacroEvent



Less code, less cycles.

Change-Id: I1bbc2d5050fd29f199c12120d183f84c686953fe
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent f80e5800
......@@ -34,7 +34,8 @@
#include <QVariant>
#include <QDataStream>
using namespace Macros::Internal;
namespace Macros {
namespace Internal {
/*!
\class Macros::MacroEvent
......@@ -50,57 +51,21 @@ using namespace Macros::Internal;
The information are stored in a map of QVariants (using quint8 for keys).
*/
class MacroEvent::MacroEventPrivate
{
public:
Core::Id id;
QMap<quint8, QVariant> values;
};
// ---------- MacroEvent ------------
MacroEvent::MacroEvent():
d(new MacroEventPrivate)
{
}
MacroEvent::MacroEvent(const MacroEvent &other):
d(new MacroEventPrivate)
{
d->id = other.d->id;
d->values = other.d->values;
}
MacroEvent::~MacroEvent()
{
delete d;
}
MacroEvent& MacroEvent::operator=(const MacroEvent &other)
{
if (this == &other)
return *this;
d->id = other.d->id;
d->values = other.d->values;
return *this;
}
QVariant MacroEvent::value(quint8 id) const
{
return d->values.value(id);
return m_values.value(id);
}
void MacroEvent::setValue(quint8 id, const QVariant &value)
{
d->values[id] = value;
m_values[id] = value;
}
void MacroEvent::load(QDataStream &stream)
{
QByteArray ba;
stream >> ba;
d->id = Core::Id::fromName(ba);
m_id = Core::Id::fromName(ba);
int count;
stream >> count;
quint8 id;
......@@ -108,15 +73,15 @@ void MacroEvent::load(QDataStream &stream)
for (int i = 0; i < count; ++i) {
stream >> id;
stream >> value;
d->values[id] = value;
m_values[id] = value;
}
}
void MacroEvent::save(QDataStream &stream) const
{
stream << d->id.name();
stream << d->values.count();
QMapIterator<quint8, QVariant> i(d->values);
stream << m_id.name();
stream << m_values.count();
QMapIterator<quint8, QVariant> i(m_values);
while (i.hasNext()) {
i.next();
stream << i.key() << i.value();
......@@ -125,10 +90,13 @@ void MacroEvent::save(QDataStream &stream) const
Core::Id MacroEvent::id() const
{
return d->id;
return m_id;
}
void MacroEvent::setId(Core::Id id)
{
d->id = id;
m_id = id;
}
} // namespace Internal
} // namespace Macro
......@@ -47,10 +47,7 @@ namespace Internal {
class MacroEvent
{
public:
MacroEvent();
MacroEvent(const MacroEvent &other);
virtual ~MacroEvent();
MacroEvent& operator=(const MacroEvent &other);
MacroEvent() {}
Core::Id id() const;
void setId(Core::Id id);
......@@ -62,8 +59,8 @@ public:
void save(QDataStream &stream) const;
private:
class MacroEventPrivate;
MacroEventPrivate* d;
Core::Id m_id;
QMap<quint8, QVariant> m_values;
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment