2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Nicolas Arnaud-Cormos
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
#include "macroevent.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QDataStream>
|
2011-01-20 14:03:07 +01:00
|
|
|
|
2014-11-05 09:06:09 +01:00
|
|
|
namespace Macros {
|
|
|
|
|
namespace Internal {
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Macros::MacroEvent
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The MacroEvent class represents an event in a macro.
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2011-04-19 15:42:14 +02:00
|
|
|
An event stores information so it can be replayed. An event can be:
|
2010-12-20 10:35:30 +01:00
|
|
|
\list
|
2013-02-06 08:50:23 +01:00
|
|
|
\li menu action
|
|
|
|
|
\li key event on an editor
|
|
|
|
|
\li find/replace usage
|
2010-12-20 10:35:30 +01:00
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The information are stored in a map of QVariants (using quint8 for keys).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
QVariant MacroEvent::value(quint8 id) const
|
|
|
|
|
{
|
2014-11-05 09:06:09 +01:00
|
|
|
return m_values.value(id);
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroEvent::setValue(quint8 id, const QVariant &value)
|
|
|
|
|
{
|
2014-11-05 09:06:09 +01:00
|
|
|
m_values[id] = value;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroEvent::load(QDataStream &stream)
|
|
|
|
|
{
|
2013-01-15 13:52:34 +01:00
|
|
|
QByteArray ba;
|
|
|
|
|
stream >> ba;
|
2020-06-26 13:59:38 +02:00
|
|
|
m_id = Utils::Id::fromName(ba);
|
2010-12-20 10:35:30 +01:00
|
|
|
int count;
|
|
|
|
|
stream >> count;
|
|
|
|
|
quint8 id;
|
|
|
|
|
QVariant value;
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
stream >> id;
|
|
|
|
|
stream >> value;
|
2014-11-05 09:06:09 +01:00
|
|
|
m_values[id] = value;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroEvent::save(QDataStream &stream) const
|
|
|
|
|
{
|
2014-11-05 09:06:09 +01:00
|
|
|
stream << m_id.name();
|
2022-05-19 10:26:48 +02:00
|
|
|
stream << int(m_values.count());
|
2019-07-24 13:43:54 +02:00
|
|
|
for (auto i = m_values.cbegin(), end = m_values.cend(); i != end; ++i)
|
2010-12-20 10:35:30 +01:00
|
|
|
stream << i.key() << i.value();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id MacroEvent::id() const
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2014-11-05 09:06:09 +01:00
|
|
|
return m_id;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
void MacroEvent::setId(Utils::Id id)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2014-11-05 09:06:09 +01:00
|
|
|
m_id = id;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
2014-11-05 09:06:09 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Macro
|