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

ossia / score / 45070253512

22 Nov 2026 09:06PM UTC coverage: 62.137% (+0.3%) from 61.818%
45070253512

Pull #2409

github

web-flow
Merge 74d2d6e4b into ef0dd3ce5
Pull Request #2409: Snippets, a keyboard-driven process picker, node copy and paste, musical snapping in the piano roll

269268 of 804435 branches covered (33.47%)

2227 of 2815 new or added lines in 90 files covered. (79.11%)

108 existing lines in 24 files now uncovered.

274840 of 442315 relevant lines covered (62.14%)

763452.11 hits per line

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

20.27
/src/plugins/score-plugin-library/Library/ProcessTreeView.cpp
1
#include "ProcessTreeView.hpp"
2

3

4
#include <score/widgets/CursorTheme.hpp>
5
#include <score/widgets/Pixmap.hpp>
6
#if defined(__EMSCRIPTEN__)
7
#include <score/widgets/ItemViewDrag.hpp>
8

9
#include <QStyleOptionViewItem>
10
#endif
11

12
#include <QContextMenuEvent>
13
#include <QDrag>
14
#include <QMenu>
15
#include <QGuiApplication>
16
#include <QMimeData>
17
#include <QMouseEvent>
18
#include <QSortFilterProxyModel>
19

20
#include <wobjectimpl.h>
21

22
W_OBJECT_IMPL(Library::ProcessTreeView)
55,850 !
23
namespace Library
24
{
25
Library::ProcessData* ProcessTreeView::dataFromViewIndex(QModelIndex idx)
17 ✔
26
{
27
  SCORE_ASSERT(idx.isValid());
17 !
28
  auto proxy = (QSortFilterProxyModel*)this->model();
17 ✔
29
  auto model_idx = proxy->mapToSource(idx);
17 ✔
30
  auto data = reinterpret_cast<TreeNode<ProcessData>*>(model_idx.internalPointer());
17 ✔
31
  return data;
17 ✔
32
}
33

34
void ProcessTreeView::reselect()
×
35
{
36
  if(auto* sm = selectionModel(); sm && !sm->selectedIndexes().isEmpty())
×
37
  {
38
    if(auto* data = dataFromViewIndex(sm->selectedIndexes().front()))
×
39
    {
40
      selected(*data);
×
41
      return;
×
42
    }
43
  }
×
44
  selected({});
×
45
}
×
46

47
void ProcessTreeView::selectionChanged(
3,369 ✔
48
    const QItemSelection& sel, const QItemSelection& desel)
49
{
50
  setDropIndicatorShown(true);
3,369 ✔
51

52
  if(!sel.isEmpty())
3,369 ✔
53
  {
54
    // guard against transient null internalPointer from async scan rebuild
55
    if(auto* data = dataFromViewIndex(sel.indexes().front()))
17 !
56
      selected(*data);
17 !
57
  }
17 ✔
58
  else if(desel.size() > 0)
3,352 !
59
  {
60
    selected({});
×
61
  }
×
62
}
3,369 ✔
63

64
QModelIndexList ProcessTreeView::selectedDraggableIndexes() const
×
65
{
66
  QModelIndexList indexes = selectedIndexes();
×
67
  auto m = QTreeView::model();
×
68
  auto isNotDragEnabled = [m](const QModelIndex& index) {
×
69
    return !(m->flags(index) & Qt::ItemIsDragEnabled);
×
70
  };
71
  indexes.erase(
×
72
      std::remove_if(indexes.begin(), indexes.end(), isNotDragEnabled), indexes.end());
×
73
  return indexes;
×
74
}
×
75

76
void ProcessTreeView::startDrag(Qt::DropActions)
×
77
{
78
  QModelIndexList indexes = selectedDraggableIndexes();
×
79
  if(indexes.count() == 1)
×
80
  {
81
    // auto proxy = (QSortFilterProxyModel*)this->model();
82
    // auto model_idx = proxy->mapFromSource(indexes.first());
83

84
    // QMimeData* data = proxy->mimeData(QModelIndexList{model_idx});
85
    QMimeData* data = QTreeView::model()->mimeData(indexes);
×
86
    if(!data)
×
87
      return;
×
88

89
    QDrag* drag = new QDrag(this);
×
90
    drag->setMimeData(data);
×
91
    score::CursorTheme::instance().setDragCursors(*drag);
×
92
#if defined(__EMSCRIPTEN__)
93
    QStyleOptionViewItem opt;
94
    initViewItemOption(&opt);
95
    score::setItemViewDragPixmap(*drag, *this, opt, indexes);
96
#endif
97
    drag->exec();
×
98
  }
×
99
}
×
100

NEW
101
void ProcessTreeView::contextMenuEvent(QContextMenuEvent* event)
×
102
{
103
  // What can be renamed: the snippets of the user's library. A double-click
104
  // adds them to the score, so this and F2 are how they are renamed.
NEW
105
  const auto index = indexAt(event->pos());
×
NEW
106
  if(!index.isValid() || !(model()->flags(index) & Qt::ItemIsEditable))
×
107
  {
NEW
108
    QTreeView::contextMenuEvent(event);
×
NEW
109
    return;
×
110
  }
111
  // Rows may come and go while the menu is open: the library is scanned
NEW
112
  QMenu menu{this};
×
NEW
113
  connect(
×
NEW
114
      menu.addAction(tr("Rename")), &QAction::triggered, this,
×
NEW
115
      [this, index = QPersistentModelIndex{index}] {
×
NEW
116
    if(!index.isValid())
×
NEW
117
      return;
×
NEW
118
    setCurrentIndex(index);
×
NEW
119
    edit(index);
×
NEW
120
  });
×
NEW
121
  menu.exec(event->globalPos());
×
NEW
122
  event->accept();
×
NEW
123
}
×
124

UNCOV
125
void ProcessTreeView::mouseDoubleClickEvent(QMouseEvent* event)
×
126
{
127
  auto index = indexAt(event->pos());
×
128
  if(index.isValid())
×
129
  {
130
    // guard against transient null internalPointer from async scan rebuild
131
    auto data = dataFromViewIndex(index);
×
132
    if(data && data->key != UuidKey<Process::ProcessModel>{})
×
133
    {
134
      doubleClicked(*data);
×
135
      event->accept();
×
136
      return;
×
137
    }
138
  }
×
139
  QTreeView::mouseDoubleClickEvent(event);
×
140
}
×
141

142
}
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