2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Nicolas Arnaud-Cormos
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-20 11:10:30 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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();
|
|
|
|
|
stream << 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
|