• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 41569965004

03 Nov 2026 03:04AM UTC coverage: 53.588% (+1.9%) from 51.66%
41569965004

push

github

jcelerier
ci: build the documentation on Ubuntu 24.04, which its deps script targets

ubuntu-latest is now 26.04, where ubuntu.noble.deps.sh's Qt package names
(libqt6websockets6-dev and the like) no longer exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdPguhTJiZUHjuouE7tkj5

197270 of 368126 relevant lines covered (53.59%)

304198.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.52
/src/lib/core/command/CommandStack.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
#include <score/application/GUIApplicationContext.hpp>
4
#include <score/command/Command.hpp>
5
#include <score/command/Dispatchers/SendStrategy.hpp>
6
#include <score/command/Validity/ValidityCheckerList.hpp>
7
#include <score/document/DocumentContext.hpp>
8
#include <score/selection/SelectionStack.hpp>
9

10
#include <core/command/CommandStack.hpp>
11
#include <core/document/Document.hpp>
12

13
#include <wobjectimpl.h>
14
W_OBJECT_IMPL(score::CommandStack)
19,180 ✔
15
namespace score
16
{
17
CommandStack::CommandStack(const score::Document& ctx, QObject* parent)
3,060 ✔
18
    : m_checker{score::AppComponents().interfaces<ValidityCheckerList>(), ctx}
19
    , m_ctx{ctx.context()}
20
{
1,530 ✔
21
  this->setObjectName("CommandStack");
1,530 ✔
22
  this->setParent(parent);
1,530 ✔
23
}
×
24

25
CommandStack::~CommandStack()
1,530 ✔
26
{
×
27
  qDeleteAll(m_undoable);
1,530 ✔
28
  qDeleteAll(m_redoable);
1,530 ✔
29
}
1,530 ✔
30

31
void CommandStack::enableActions()
105 ✔
32
{
33
  canUndoChanged(canUndo());
105 ✔
34
  canRedoChanged(canRedo());
105 ✔
35
}
105 ✔
36

37
void CommandStack::disableActions()
125 ✔
38
{
39
  canUndoChanged(false);
125 ✔
40
  canRedoChanged(false);
125 ✔
41
}
125 ✔
42

43
bool CommandStack::canUndo() const
24,986 ✔
44
{
45
  return !m_undoable.empty();
24,986 ✔
46
}
47

48
bool CommandStack::canRedo() const
24,285 ✔
49
{
50
  return !m_redoable.empty();
24,285 ✔
51
}
52

53
QString CommandStack::undoText() const
931 ✔
54
{
55
  return canUndo() ? m_undoable.top()->description() : tr("Nothing to undo");
931 ✔
56
}
57

58
QString CommandStack::redoText() const
931 ✔
59
{
60
  return canRedo() ? m_redoable.top()->description() : tr("Nothing to redo");
931 ✔
61
}
62

63
int CommandStack::size() const
95,058 ✔
64
{
65
  return m_undoable.size() + m_redoable.size();
95,058 ✔
66
}
67

68
const Command* CommandStack::command(int index) const
89,607 ✔
69
{
70
  if(index < m_undoable.size())
89,607 ✔
71
  {
72
    return m_undoable[index];
88,707 ✔
73
  }
74
  else if((index - m_undoable.size()) < m_redoable.size())
900 ✔
75
  {
76
    return m_redoable[m_redoable.size() - (index - m_undoable.size()) - 1];
900 ✔
77
  }
78
  else
79
  {
80
    return nullptr;
×
81
  }
82
}
89,607 ✔
83

84
int CommandStack::currentIndex() const
1,808,614 ✔
85
{
86
  return m_undoable.size();
1,808,614 ✔
87
}
88

89
void CommandStack::markCurrentIndexAsSaved()
1,777 ✔
90
{
91
  // What pending edits changed is in the saved document
92
  m_pendingEdits = 0;
1,777 ✔
93
  setSavedIndex(currentIndex());
1,777 ✔
94
  saveIndexChanged(isAtSavedIndex());
1,777 ✔
95
}
1,777 ✔
96

97
bool CommandStack::isAtSavedIndex() const
217,052 ✔
98
{
99
  return m_pendingEdits == 0 && currentIndex() == m_savedIndex;
217,052 ✔
100
}
101

102
void CommandStack::beginPendingEdit()
34 ✔
103
{
104
  if(m_pendingEdits++ == 0)
34 ✔
105
    saveIndexChanged(isAtSavedIndex());
22 ✔
106
}
34 ✔
107

108
void CommandStack::endPendingEdit()
34 ✔
109
{
110
  if(m_pendingEdits > 0 && --m_pendingEdits == 0)
34 ✔
111
    saveIndexChanged(isAtSavedIndex());
20 ✔
112
}
34 ✔
113

114
void CommandStack::setIndexQuiet(int index)
2 ✔
115
{
116
  aboutToChange();
2 ✔
117
  while(index >= 0 && currentIndex() != index)
6 ✔
118
  {
119
    if(index < currentIndex())
4 ✔
120
      undoQuiet();
4 ✔
121
    else
122
      redoQuiet();
×
123
  }
124

125
  saveIndexChanged(isAtSavedIndex());
2 ✔
126
  sig_indexChanged();
2 ✔
127
}
2 ✔
128

129
void CommandStack::setIndex(int index)
2 ✔
130
{
131
  if(index != currentIndex())
2 ✔
132
  {
133
    setIndexQuiet(index);
2 ✔
134
    localIndexChanged(index);
2 ✔
135
  }
2 ✔
136
}
2 ✔
137

138
namespace
139
{
140
struct Replaying
141
{
142
  bool& flag;
143
  explicit Replaying(bool& f)
1,347 ✔
144
      : flag{f}
1,347 ✔
145
  {
146
    flag = true;
1,347 ✔
147
  }
1,347 ✔
148
  ~Replaying() { flag = false; }
1,347 ✔
149
};
150
}
151

152
void CommandStack::undoQuiet()
983 ✔
153
{
154
  aboutToChange();
983 ✔
155
  updateStack([&]() {
1,966 ✔
156
    auto cmd = m_undoable.pop();
983 ✔
157
    {
158
      Replaying r{m_replaying};
983 ✔
159
      SelectionStack::Batch b{m_ctx.selectionStack};
983 ✔
160
      cmd->undo(m_ctx);
983 ✔
161
    }
983 ✔
162
    m_redoable.push(cmd);
983 ✔
163

164
    saveIndexChanged(isAtSavedIndex());
983 ✔
165
    sig_undo();
983 ✔
166
  });
983 ✔
167
}
983 ✔
168

169
void CommandStack::redoQuiet()
364 ✔
170
{
171
  aboutToChange();
364 ✔
172
  updateStack([&]() {
728 ✔
173
    auto cmd = m_redoable.pop();
364 ✔
174
    {
175
      Replaying r{m_replaying};
364 ✔
176
      SelectionStack::Batch b{m_ctx.selectionStack};
364 ✔
177
      cmd->redo(m_ctx);
364 ✔
178
    }
364 ✔
179

180
    m_undoable.push(cmd);
364 ✔
181

182
    saveIndexChanged(isAtSavedIndex());
364 ✔
183
    sig_redo();
364 ✔
184
  });
364 ✔
185
}
364 ✔
186

187
void CommandStack::redoAndPush(Command* cmd)
4,133 ✔
188
{
189
  aboutToChange();
4,133 ✔
190
  {
191
    SelectionStack::Batch b{m_ctx.selectionStack};
4,133 ✔
192
    cmd->redo(m_ctx);
4,133 ✔
193
  }
4,133 ✔
194
  push(cmd);
4,133 ✔
195
}
4,133 ✔
196

197
void CommandStack::push(Command* cmd)
5,367 ✔
198
{
199
  aboutToChange();
5,367 ✔
200
  updateStack([&]() {
10,734 ✔
201
    localCommand(cmd);
5,367 ✔
202

203
    // We lose the state we saved
204
    if(currentIndex() < m_savedIndex)
5,367 ✔
205
      setSavedIndex(-1);
×
206

207
    // Push operation
208
    m_undoable.push(cmd);
5,367 ✔
209
    saveIndexChanged(isAtSavedIndex());
5,367 ✔
210

211
    if(!m_redoable.empty())
5,367 ✔
212
    {
213
      qDeleteAll(m_redoable);
474 ✔
214
      m_redoable.clear();
474 ✔
215
    }
474 ✔
216

217
    sig_push();
5,367 ✔
218
  });
5,367 ✔
219
}
5,367 ✔
220

221
void CommandStack::redoAndPushQuiet(Command* cmd)
×
222
{
223
  aboutToChange();
×
224
  {
225
    SelectionStack::Batch b{m_ctx.selectionStack};
×
226
    cmd->redo(m_ctx);
×
227
  }
×
228
  pushQuiet(cmd);
×
229
}
×
230

231
void CommandStack::pushQuiet(Command* cmd)
×
232
{
233
  aboutToChange();
×
234
  updateStack([&]() {
×
235
    // We lose the state we saved
236
    if(currentIndex() < m_savedIndex)
×
237
      setSavedIndex(-1);
×
238

239
    // Push operation
240
    m_undoable.push(cmd);
×
241
    saveIndexChanged(isAtSavedIndex());
×
242

243
    if(!m_redoable.empty())
×
244
    {
245
      qDeleteAll(m_redoable);
×
246
      m_redoable.clear();
×
247
    }
×
248

249
    sig_push();
×
250
  });
×
251
}
×
252

253
void CommandStack::setSavedIndex(int index)
1,780 ✔
254
{
255
  if(index != m_savedIndex)
1,780 ✔
256
  {
257
    m_savedIndex = index;
157 ✔
258
    saveIndexChanged(isAtSavedIndex());
157 ✔
259
  }
157 ✔
260
}
1,780 ✔
261

262
void CommandStack::validateDocument() const
×
263
{
264
  m_checker();
×
265
}
×
266

267
CommandStackFacade::CommandStackFacade(CommandStack& stack)
3,060 ✔
268
    : m_stack{stack}
3,060 ✔
269
{
270
}
3,060 ✔
271

272
const DocumentContext& CommandStackFacade::context() const
16,686 ✔
273
{
274
  return m_stack.context();
16,686 ✔
275
}
276

277
SelectionStack& CommandStackFacade::selectionStack() const
7,322 ✔
278
{
279
  return m_stack.context().selectionStack;
7,322 ✔
280
}
281

282
void CommandStackFacade::push(Command* cmd) const
1,229 ✔
283
{
284
  m_stack.push(cmd);
1,229 ✔
285
}
1,229 ✔
286

287
void CommandStackFacade::redoAndPush(Command* cmd) const
4,127 ✔
288
{
289
  m_stack.redoAndPush(cmd);
4,127 ✔
290
}
4,127 ✔
291

292
void CommandStackFacade::disableActions() const
125 ✔
293
{
294
  m_stack.disableActions();
125 ✔
295
}
125 ✔
296

297
void CommandStackFacade::enableActions() const
105 ✔
298
{
299
  m_stack.enableActions();
105 ✔
300
}
105 ✔
301

302
}
303

304
void SendStrategy::UndoRedo::send(
1 ✔
305
    const score::CommandStackFacade& stack, score::Command* other)
306
{
307
  {
308
    score::SelectionStack::Batch b{stack.selectionStack()};
1 ✔
309
    other->undo(stack.context());
1 ✔
310
  }
1 ✔
311
  stack.redoAndPush(other);
1 ✔
312
}
1 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc