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