KDStateMachineEditor API Documentation 2.1
Loading...
Searching...
No Matches
modifypropertycommand.cpp
Go to the documentation of this file.
1/*
2 This file is part of the KDAB State Machine Editor Library.
3
4 SPDX-FileCopyrightText: 2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Kevin Funk <kevin.funk@kdab.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8
9 Licensees holding valid commercial KDAB State Machine Editor Library
10 licenses may use this file in accordance with the KDAB State Machine Editor
11 Library License Agreement provided with the Software.
12
13 Contact info@kdab.com if any conditions of this licensing are not clear to you.
14*/
15
17
18#include "debug.h"
19#include <QJsonObject>
20#include <QVariant>
21
22using namespace KDSME;
23
24ModifyPropertyCommand::ModifyPropertyCommand(QObject *object, const char *property,
25 const QVariant &value, const QString &text, QUndoCommand *parent)
26 : Command(text, parent)
27 , m_object(object)
28{
29 m_propertyMap.insert(property, value);
30 init();
31}
32
33ModifyPropertyCommand::ModifyPropertyCommand(QObject *object, const QJsonObject &propertyMap,
34 const QString &text, QUndoCommand *parent)
35 : Command(text, parent)
36 , m_object(object)
37{
38 auto it = propertyMap.constBegin();
39 while (it != propertyMap.constEnd()) {
40 m_propertyMap.insert(it.key().toLatin1(), it.value().toVariant());
41 ++it;
42 }
43 init();
44}
45
46void ModifyPropertyCommand::init()
47{
48 if (text().isEmpty() && !m_propertyMap.isEmpty()) {
49 if (m_propertyMap.size() == 1) {
50 setText(tr("Modify property '%1'").arg(m_propertyMap.begin().value().toString()));
51 } else {
52 setText(tr("Modify multiple properties"));
53 }
54 } else {
55 setText(tr("N/A"));
56 }
57}
58
60{
61 if (!m_object) {
62 qCDebug(KDSME_VIEW) << "Invalid object";
63 return;
64 }
65
66 auto it = m_propertyMap.constBegin();
67 while (it != m_propertyMap.constEnd()) {
68 m_oldPropertyMap.insert(it.key(), m_object->property(it.key().constData()));
69 if (!m_object->setProperty(it.key().constData(), it.value())) {
70 qCDebug(KDSME_VIEW) << "Failed to set property" << it.key();
71 }
72 ++it;
73 }
74}
75
77{
78 if (!m_object) {
79 qCDebug(KDSME_VIEW) << "Invalid object";
80 return;
81 }
82
83 auto it = m_oldPropertyMap.constBegin();
84 while (it != m_oldPropertyMap.constEnd()) {
85 if (!m_object->setProperty(it.key().constData(), it.value())) {
86 qCDebug(KDSME_VIEW) << "Failed to set property" << it.key();
87 }
88 ++it;
89 }
90 m_oldPropertyMap.clear();
91}
ModifyPropertyCommand(QObject *object, const char *property, const QVariant &value, const QString &text=QString(), QUndoCommand *parent=nullptr)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDStateMachineEditor
Create Qt State Machine metacode using a graphical user interface
https://github.com/KDAB/KDStateMachineEditor
Generated on Tue Jul 15 2025 15:21:47 for KDStateMachineEditor API Documentation by doxygen 1.9.8