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

ossia / score / 30712175708

01 Aug 2026 06:17PM UTC coverage: 15.231% (-0.03%) from 15.263%
30712175708

Pull #2169

github

web-flow
Merge c60ea2870 into 3ceec338e
Pull Request #2169: 3rdparty: stop vendored xtensor/xtl/xsimd from polluting score's install

30395 of 199565 relevant lines covered (15.23%)

1075.35 hits per line

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

31.08
/src/plugins/score-plugin-scenario/Scenario/Document/Interval/IntervalView.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 <Process/Dataflow/CableItem.hpp>
4
#include <Process/ProcessMimeSerialization.hpp>
5
#include <Process/Style/ScenarioStyle.hpp>
6

7
#include <Scenario/Application/Menus/ScenarioCopy.hpp>
8
#include <Scenario/Document/Interval/IntervalHeader.hpp>
9
#include <Scenario/Document/Interval/IntervalModel.hpp>
10
#include <Scenario/Document/Interval/IntervalPixmaps.hpp>
11
#include <Scenario/Document/Interval/IntervalPresenter.hpp>
12
#include <Scenario/Document/Interval/IntervalView.hpp>
13
#include <Scenario/Process/ScenarioInterface.hpp>
14
#include <Scenario/Process/ScenarioModel.hpp>
15

16
#include <score/widgets/MimeData.hpp>
17

18
#include <QCursor>
19
#include <QDrag>
20
#include <QMimeData>
21

22
#include <wobjectimpl.h>
23
W_OBJECT_IMPL(Scenario::IntervalView)
6✔
24
namespace Scenario
25
{
26
IntervalView::IntervalView(IntervalPresenter& presenter, QGraphicsItem* parent)
12✔
27
    : QGraphicsItem{parent}
6✔
28
    , m_leftBrace{*this, this}
6✔
29
    , m_rightBrace{*this, this}
6✔
30
    , m_counterItem{score::Skin::instance().Light.main, this}
6✔
31
    , m_presenter{presenter}
6✔
32
    , m_selected{false}
33
    , m_infinite{false}
34
    , m_validInterval{true}
35
    , m_warning{false}
36
    , m_waiting{false}
37
    , m_dropTarget{false}
38
    , m_state{}
39
{
6✔
40
  this->setToolTip(QObject::tr("Interval\nA span of time which can contain processes."));
6✔
41
  setAcceptHoverEvents(true);
6✔
42
  setAcceptDrops(true);
6✔
43

44
  m_leftBrace.setX(minWidth());
6✔
45
  m_leftBrace.hide();
6✔
46

47
  m_rightBrace.setX(maxWidth());
6✔
48
  m_rightBrace.hide();
6✔
49

50
  const auto& skin = score::Skin::instance();
6✔
51

52
  m_counterItem.setFont(skin.Medium7Pt);
6✔
53
  m_counterItem.setAcceptedMouseButtons(Qt::MouseButton::NoButton);
6✔
54
  m_counterItem.setAcceptHoverEvents(false);
6✔
55
}
×
56

57
IntervalView::~IntervalView()
6✔
58
{
6✔
59
  for(auto item : childItems())
30✔
60
  {
61
    if(item->type() == Dataflow::CableItem::Type)
24✔
62
    {
63
      item->setParentItem(nullptr);
×
64
    }
×
65
  }
66
  // delete m_overlay;
67
}
6✔
68

69
void IntervalView::setInfinite(bool infinite)
×
70
{
71
  if(m_infinite != infinite)
×
72
  {
73
    prepareGeometryChange();
×
74

75
    m_infinite = infinite;
×
76
    updatePaths();
×
77
    updatePlayPaths();
×
78
    update();
×
79
  }
×
80
}
×
81

82
void IntervalView::setExecuting(bool e)
×
83
{
84
  if(m_waiting && !e)
×
85
  {
86
    m_execPing.start();
×
87
  }
×
88
  else if(e)
×
89
  {
90
    m_execPing.stop();
×
91
  }
×
92

93
  m_waiting = e;
×
94
  update();
×
95
}
×
96

97
void IntervalView::setDefaultWidth(double width)
40✔
98
{
99
  if(m_defaultWidth != width)
40✔
100
  {
101
    prepareGeometryChange();
17✔
102
    m_defaultWidth = width;
17✔
103
    updatePaths();
17✔
104
    updatePlayPaths();
17✔
105
    update();
17✔
106
  }
17✔
107
}
40✔
108

109
void IntervalView::setMaxWidth(bool infinite, double max)
17✔
110
{
111
  if(infinite != m_infinite || max != m_maxWidth)
17✔
112
  {
113
    prepareGeometryChange();
6✔
114

115
    m_infinite = infinite;
6✔
116
    m_maxWidth = max;
6✔
117

118
    updatePaths();
6✔
119
    updatePlayPaths();
6✔
120
    update();
6✔
121
  }
6✔
122
}
17✔
123

124
void IntervalView::setMinWidth(double min)
17✔
125
{
126
  if(min != m_minWidth)
17✔
127
  {
128
    prepareGeometryChange();
17✔
129
    m_minWidth = min;
17✔
130
    updatePaths();
17✔
131
    updatePlayPaths();
17✔
132
    update();
17✔
133
  }
17✔
134
}
17✔
135

136
void IntervalView::setRigid(bool r)
×
137
{
138
  m_rigid = r;
×
139
}
×
140

141
void IntervalView::setHeight(double height)
69✔
142
{
143
  if(m_height != height)
69✔
144
  {
145
    prepareGeometryChange();
23✔
146
    m_height = height;
23✔
147
    updatePaths();
23✔
148
    updatePlayPaths();
23✔
149
    update();
23✔
150
  }
23✔
151
}
69✔
152

153
double IntervalView::setPlayWidth(double width)
17✔
154
{
155
  const auto v = std::abs(m_playWidth - width);
17✔
156
  if(v > 1. || (width > 0 && (playedSolidPath.isEmpty())))
17✔
157
  {
158
    m_playWidth = width;
×
159
    updatePlayPaths();
×
160
    // Already called in
161
    // DisplayedElementsPresenter::on_intervalExecutionTimer() and
162
    // ScenarioPresenter::on_intervalExecutionTimer()
163
    // update();
164
    return v;
×
165
  }
166
  return 0.;
17✔
167
}
17✔
168

169
void IntervalView::setValid(bool val)
×
170
{
171
  m_validInterval = val;
×
172
}
×
173

174
void IntervalView::setGripCursor()
×
175
{
176
  auto& skin = score::Skin::instance();
×
177
  this->setCursor(skin.CursorClosedHand);
×
178
}
×
179

180
void IntervalView::setUngripCursor()
×
181
{
182
  auto& skin = score::Skin::instance();
×
183
  this->setCursor(skin.CursorOpenHand);
×
184
}
×
185

186
void IntervalView::mousePressEvent(QGraphicsSceneMouseEvent* event)
×
187
{
188
  if(event->pos().y() < 4)
×
189
    setGripCursor();
×
190
  else
191
    unsetCursor();
×
192

193
  if(contains(event->pos()))
×
194
  {
195
    m_presenter.pressed(event->scenePos());
×
196
    event->accept();
×
197
  }
×
198
  else
199
  {
200
    event->ignore();
×
201
  }
202
}
×
203

204
void IntervalView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
×
205
{
206
  if(event->modifiers() & Qt::ALT)
×
207
  {
208
    if(auto si
×
209
       = dynamic_cast<Scenario::ScenarioInterface*>(presenter().model().parent()))
×
210
    {
211
      JSONReader r;
×
212
      copySelectedElementsToJson(
×
213
          r, *const_cast<ScenarioInterface*>(si), m_presenter.context());
×
214

215
      if(!r.empty())
×
216
      {
217
        QDrag d{this};
×
218
        auto m = new QMimeData;
×
219
        m->setData(score::mime::scenariodata(), r.toByteArray());
×
220
        d.setMimeData(m);
×
221
        d.exec();
×
222
      }
×
223
    }
×
224
  }
×
225
  m_presenter.moved(event->scenePos());
×
226
}
×
227

228
void IntervalView::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
×
229
{
230
  m_presenter.released(event->scenePos());
×
231
  if(event->pos().y() < 4)
×
232
    setUngripCursor();
×
233
  else
234
    unsetCursor();
×
235
}
×
236

237
bool IntervalView::warning() const
×
238
{
239
  return m_warning;
×
240
}
241

242
void IntervalView::setWarning(bool warning)
×
243
{
244
  m_warning = warning;
×
245
}
×
246

247
const score::Brush& IntervalView::intervalColor(const Process::Style& skin) const
×
248
{
249
  if(Q_UNLIKELY(m_dropTarget))
×
250
  {
251
    return skin.IntervalDropTarget();
×
252
  }
253
  else if(Q_UNLIKELY(m_selected))
×
254
  {
255
    return skin.IntervalSelected();
×
256
  }
257
  else if(Q_UNLIKELY(m_warning))
×
258
  {
259
    return skin.IntervalWarning();
×
260
  }
261
  else if(Q_UNLIKELY(!m_validInterval || m_state == IntervalExecutionState::Disabled))
×
262
  {
263
    return skin.IntervalInvalid();
×
264
  }
265
  else if(Q_UNLIKELY(m_state == IntervalExecutionState::Muted))
×
266
  {
267
    return skin.IntervalMuted();
×
268
  }
269
  else
270
  {
271
    return skin.IntervalBase();
×
272
  }
273
}
×
274

275
const QPixmap& IntervalView::intervalDashedPixmap(const Process::Style& skin) const
×
276
{
277
  auto& pixmaps = intervalPixmaps(skin);
×
278
  if(Q_UNLIKELY(m_dropTarget))
×
279
  {
280
    return pixmaps.dashedDropTarget;
×
281
  }
282
  else if(Q_UNLIKELY(m_selected))
×
283
  {
284
    return pixmaps.dashedSelected;
×
285
  }
286
  else if(Q_UNLIKELY(m_warning))
×
287
  {
288
    return pixmaps.dashedWarning;
×
289
  }
290
  else if(Q_UNLIKELY(!m_validInterval || m_state == IntervalExecutionState::Disabled))
×
291
  {
292
    return pixmaps.dashedInvalid;
×
293
  }
294
  else if(Q_UNLIKELY(m_state == IntervalExecutionState::Muted))
×
295
  {
296
    return pixmaps.dashedMuted;
×
297
  }
298
  else
299
  {
300
    return pixmaps.dashed;
×
301
  }
302
}
×
303

304
void IntervalView::updateCounterPos()
40✔
305
{
306
  m_counterItem.setPos(defaultWidth() - m_counterItem.boundingRect().width() - 5, 5);
40✔
307
}
40✔
308

309
void IntervalView::setExecutionState(IntervalExecutionState s)
×
310
{
311
  m_state = s;
×
312
  update();
×
313
}
×
314

315
void IntervalView::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
×
316
{
317
  if(event->pos().x() <= this->m_defaultWidth && event->pos().y() <= 7.)
×
318
  {
319
    QGraphicsItem::dragEnterEvent(event);
×
320
    setDropTarget(true);
×
321
    event->accept();
×
322
  }
×
323
  else
324
  {
325
    event->ignore();
×
326
  }
327
}
×
328

329
void IntervalView::dragMoveEvent(QGraphicsSceneDragDropEvent* event)
×
330
{
331
  setDropTarget((event->pos().x() <= this->m_defaultWidth && event->pos().y() <= 12.));
×
332
  event->accept();
×
333
}
×
334

335
void IntervalView::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)
×
336
{
337
  QGraphicsItem::dragLeaveEvent(event);
×
338
  setDropTarget(false);
×
339
  event->accept();
×
340
}
×
341

342
void IntervalView::dropEvent(QGraphicsSceneDragDropEvent* event)
×
343
{
344
  setDropTarget(false);
×
345
  if(event->pos().x() <= this->m_defaultWidth && event->pos().y() <= 12.)
×
346
  {
347
    dropReceived(event->pos(), *event->mimeData());
×
348
    update();
×
349

350
    event->accept();
×
351
  }
×
352
  else
353
  {
354
    event->ignore();
×
355
  }
356
}
×
357
}
358

359
QPainterPath Scenario::IntervalView::shape() const
×
360
{
361
  qreal x = std::min(0., minWidth());
×
362
  QPainterPath p;
×
363
  p.addRect({x, -5., defaultWidth() - x, intervalAndRackHeight() + 10.});
×
364
  if(!infinite())
×
365
    p.addRect({x, -5., maxWidth() - x, 10.});
×
366

367
  return p;
×
368
}
×
369

370
QPainterPath Scenario::IntervalView::opaqueArea() const
×
371
{
372
  return shape();
×
373
}
374

375
bool Scenario::IntervalView::contains(const QPointF& pt) const
×
376
{
377
  qreal x = std::min(0., minWidth());
×
378
  if(!QRectF{x, -5., defaultWidth() - x, intervalAndRackHeight() + 10.}.contains(pt))
×
379
    if(!infinite())
×
380
      if(!QRectF{x, -5., maxWidth() - x, 10.}.contains(pt))
×
381
        return false;
×
382
  return true;
×
383
}
×
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