25
25
#include " engraving/dom/score.h"
26
26
#include " engraving/dom/system.h"
27
27
#include " engraving/dom/undo.h"
28
+ #include " engraving/rendering/score/systemlayout.h"
28
29
29
30
using namespace mu ::inspector;
30
31
using namespace mu ::notation;
31
32
using namespace mu ::engraving;
33
+ using mu::engraving::rendering::score::SystemLayout;
32
34
33
35
EmptyStavesVisibilitySettingsModel::EmptyStavesVisibilitySettingsModel (QObject* parent, IElementRepositoryService* repository)
34
36
: AbstractInspectorModel(parent, repository)
@@ -43,6 +45,37 @@ bool EmptyStavesVisibilitySettingsModel::isEmpty() const
43
45
return !selection || !selection->isRange ();
44
46
}
45
47
48
+ void EmptyStavesVisibilitySettingsModel::loadProperties ()
49
+ {
50
+ updateCanHideEmptyStavesInSelection ();
51
+ updateCanShowAllEmptyStaves ();
52
+ updateCanResetEmptyStavesVisibility ();
53
+ }
54
+
55
+ void EmptyStavesVisibilitySettingsModel::onCurrentNotationChanged ()
56
+ {
57
+ INotationPtr notation = currentNotation ();
58
+ if (!notation) {
59
+ return ;
60
+ }
61
+
62
+ notation->undoStack ()->changesChannel ().onReceive (this , [this ](const ScoreChanges& changes) {
63
+ if (changes.isTextEditing ) {
64
+ return ;
65
+ }
66
+
67
+ if (changes.changedPropertyIdSet .empty () && changes.changedStyleIdSet .empty ()) {
68
+ // In this specific case, it's not done by InspectorListModel::listenScoreChanges()
69
+ onNotationChanged ({}, {});
70
+ }
71
+ });
72
+ }
73
+
74
+ void EmptyStavesVisibilitySettingsModel::onNotationChanged (const mu::engraving::PropertyIdSet&, const mu::engraving::StyleIdSet&)
75
+ {
76
+ loadProperties ();
77
+ }
78
+
46
79
void EmptyStavesVisibilitySettingsModel::hideEmptyStavesInSelection ()
47
80
{
48
81
if (isEmpty ()) {
@@ -58,7 +91,7 @@ void EmptyStavesVisibilitySettingsModel::hideEmptyStavesInSelection()
58
91
const staff_idx_t staffStart = range->startStaffIndex ();
59
92
const staff_idx_t staffEnd = range->endStaffIndex ();
60
93
61
- beginCommand (muse::TranslatableString (" undoableAction" , " Hide empty staves in selection " ));
94
+ beginCommand (muse::TranslatableString (" undoableAction" , " Hide empty staves" ));
62
95
63
96
for (System* system : systems) {
64
97
for (staff_idx_t staffIdx = staffStart; staffIdx < staffEnd; ++staffIdx) {
@@ -80,7 +113,7 @@ void EmptyStavesVisibilitySettingsModel::showAllEmptyStaves()
80
113
const INotationSelectionPtr sel = selection ();
81
114
const std::vector<System*> systems = sel->selectedSystems ();
82
115
83
- beginCommand (muse::TranslatableString (" undoableAction" , " Show all empty staves" ));
116
+ beginCommand (muse::TranslatableString (" undoableAction" , " Show empty staves" ));
84
117
85
118
for (System* system : systems) {
86
119
for (staff_idx_t staffIdx = 0 ; staffIdx < score->nstaves (); ++staffIdx) {
@@ -113,3 +146,108 @@ void EmptyStavesVisibilitySettingsModel::resetEmptyStavesVisibility()
113
146
114
147
endCommand ();
115
148
}
149
+
150
+ void EmptyStavesVisibilitySettingsModel::updateCanHideEmptyStavesInSelection ()
151
+ {
152
+ auto set = [this ] (bool can) {
153
+ if (m_canHideEmptyStavesInSelection == can) {
154
+ return ;
155
+ }
156
+ m_canHideEmptyStavesInSelection = can;
157
+ emit canHideEmptyStavesInSelectionChanged ();
158
+ };
159
+
160
+ if (isEmpty ()) {
161
+ set (false );
162
+ return ;
163
+ }
164
+
165
+ const INotationSelectionPtr sel = selection ();
166
+ const std::vector<System*> systems = sel->selectedSystems ();
167
+
168
+ const INotationSelectionRangePtr range = sel->range ();
169
+ const staff_idx_t staffStart = range->startStaffIndex ();
170
+ const staff_idx_t staffEnd = range->endStaffIndex ();
171
+
172
+ for (const System* system : systems) {
173
+ for (staff_idx_t staffIdx = staffStart; staffIdx < staffEnd; ++staffIdx) {
174
+ if (system->staff (staffIdx)->show ()
175
+ && SystemLayout::canChangeSysStaffVisibility (system, staffIdx)) {
176
+ set (true );
177
+ return ;
178
+ }
179
+ }
180
+ }
181
+
182
+ set (false );
183
+ }
184
+
185
+ void EmptyStavesVisibilitySettingsModel::updateCanShowAllEmptyStaves ()
186
+ {
187
+ auto set = [this ] (bool can) {
188
+ if (m_canShowAllEmptyStaves == can) {
189
+ return ;
190
+ }
191
+ m_canShowAllEmptyStaves = can;
192
+ emit canShowAllEmptyStavesChanged ();
193
+ };
194
+
195
+ if (isEmpty ()) {
196
+ set (false );
197
+ return ;
198
+ }
199
+
200
+ Score* score = currentNotation ()->elements ()->msScore ();
201
+
202
+ const INotationSelectionPtr sel = selection ();
203
+ const std::vector<System*> systems = sel->selectedSystems ();
204
+
205
+ for (const System* system : systems) {
206
+ for (staff_idx_t staffIdx = 0 ; staffIdx < score->nstaves (); ++staffIdx) {
207
+ if (!system->staff (staffIdx)->show ()
208
+ && SystemLayout::canChangeSysStaffVisibility (system, staffIdx)) {
209
+ set (true );
210
+ return ;
211
+ }
212
+ }
213
+ }
214
+
215
+ set (false );
216
+ }
217
+
218
+ void EmptyStavesVisibilitySettingsModel::updateCanResetEmptyStavesVisibility ()
219
+ {
220
+ auto set = [this ] (bool can) {
221
+ if (m_canResetEmptyStavesVisibility == can) {
222
+ return ;
223
+ }
224
+ m_canResetEmptyStavesVisibility = can;
225
+ emit canResetEmptyStavesVisibilityChanged ();
226
+ };
227
+
228
+ if (isEmpty ()) {
229
+ set (false );
230
+ return ;
231
+ }
232
+
233
+ Score* score = currentNotation ()->elements ()->msScore ();
234
+
235
+ const INotationSelectionPtr sel = selection ();
236
+ const std::vector<System*> systems = sel->selectedSystems ();
237
+
238
+ for (const System* system : systems) {
239
+ for (const MeasureBase* mb : system->measures ()) {
240
+ if (!mb->isMeasure ()) {
241
+ continue ;
242
+ }
243
+ for (staff_idx_t staffIdx = 0 ; staffIdx < score->nstaves (); ++staffIdx) {
244
+ if (toMeasure (mb)->hideStaffIfEmpty (staffIdx) != engraving::AutoOnOff::AUTO) {
245
+ set (true );
246
+ return ;
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ set (false );
253
+ }
0 commit comments