-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
propertyitem.cpp
156 lines (126 loc) · 3.17 KB
/
propertyitem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "propertyitem.h"
#include "property.h"
using namespace mu::inspector;
using namespace mu::engraving;
PropertyItem::PropertyItem(const Ms::Pid propertyId, QObject* parent)
: QObject(parent), m_isVisible(true)
{
m_propertyId = propertyId;
}
void PropertyItem::fillValues(const QVariant& currentValue, const QVariant& defaultValue)
{
updateCurrentValue(currentValue);
setDefaultValue(defaultValue);
emit isModifiedChanged(isModified());
}
void PropertyItem::updateCurrentValue(const QVariant& currentValue)
{
if (m_currentValue == currentValue) {
return;
}
m_currentValue = currentValue;
emit isUndefinedChanged(isUndefined());
emit valueChanged(m_currentValue);
}
void PropertyItem::resetToDefault()
{
setValue(m_defaultValue);
}
void PropertyItem::applyToStyle()
{
emit applyToStyleRequested(m_styleId, m_currentValue);
}
Ms::Pid PropertyItem::propertyId() const
{
return m_propertyId;
}
QVariant PropertyItem::value() const
{
return m_currentValue;
}
QVariant PropertyItem::defaultValue() const
{
return m_defaultValue;
}
bool PropertyItem::isUndefined() const
{
return !m_currentValue.isValid();
}
bool PropertyItem::isEnabled() const
{
return m_isEnabled;
}
bool PropertyItem::isVisible() const
{
return m_isVisible;
}
bool PropertyItem::isStyled() const
{
return m_styleId != Ms::Sid::NOSTYLE;
}
bool PropertyItem::isModified() const
{
return m_currentValue != m_defaultValue;
}
void PropertyItem::setStyleId(const Ms::Sid styleId)
{
if (m_styleId == styleId) {
return;
}
m_styleId = styleId;
emit isStyledChanged();
}
void PropertyItem::setValue(const QVariant& value)
{
if (m_currentValue == value) {
return;
}
updateCurrentValue(value);
emit propertyModified(m_propertyId, m_currentValue);
emit isModifiedChanged(isModified());
}
void PropertyItem::setDefaultValue(const QVariant& defaultValue)
{
if (m_defaultValue == defaultValue) {
return;
}
m_defaultValue = defaultValue;
emit defaultValueChanged(m_defaultValue);
}
void PropertyItem::setIsEnabled(bool isEnabled)
{
if (m_isEnabled == isEnabled) {
return;
}
m_isEnabled = isEnabled;
emit isEnabledChanged(m_isEnabled);
}
void PropertyItem::setIsVisible(bool isVisible)
{
if (m_isVisible == isVisible) {
return;
}
m_isVisible = isVisible;
emit isVisibleChanged(isVisible);
}