Loading...
Searching...
No Matches
SelectionStack.hpp
1#pragma once
2#include <score/selection/Selection.hpp>
3
4#include <ossia/detail/hash_map.hpp>
5
6#include <QObject>
7#include <QStack>
8
9#include <verdigris>
10
12
13namespace score
14{
23class SCORE_LIB_BASE_EXPORT SelectionStack final : public QObject
24{
25 W_OBJECT(SelectionStack)
26public:
29
30 bool canUnselect() const;
31 bool canReselect() const;
32 void clear();
33 void clearAllButLast();
34
35 // Go to the previous set of selections
36 void unselect();
37
38 // Go to the next set of selections
39 void reselect();
40
41 // Push a new set of empty selection.
42 void deselect();
43
44 // Push a new selection without these objects
45 void deselectObjects(const Selection& toDeselect);
46
47 Selection currentSelection() const;
48
49 void pushNewSelection(const Selection& s)
50 E_SIGNAL(SCORE_LIB_BASE_EXPORT, pushNewSelection, s)
51
52 void currentSelectionChanged(const Selection& old, const Selection& current)
53 E_SIGNAL(SCORE_LIB_BASE_EXPORT, currentSelectionChanged, old, current)
54
55 void prune(IdentifiedObjectAbstract* p);
56 W_INVOKABLE(prune)
57
58 void pruneRecursively(IdentifiedObjectAbstract* p);
59 W_INVOKABLE(pruneRecursively)
60
61
71 class Batch
72 {
73 public:
74 explicit Batch(SelectionStack& s) noexcept
75 : m_stack{s}
76 {
77 ++m_stack.m_batchDepth;
78 }
79 ~Batch()
80 {
81 if(--m_stack.m_batchDepth == 0)
82 m_stack.sweepPruned();
83 }
84 Batch(const Batch&) = delete;
85 Batch& operator=(const Batch&) = delete;
86
87 private:
88 SelectionStack& m_stack;
89 };
90
91private:
92 // Select new objects
93 void push(const Selection& s);
94 void pruneConnections();
95 void sweepPruned();
96
97 // m_unselectable always contains the empty set at the beginning
98 QStack<Selection> m_unselectable;
99 QStack<Selection> m_reselectable;
100
101 ossia::hash_map<const IdentifiedObjectAbstract*, QMetaObject::Connection>
102 m_connections;
103
104 // Destroyed during the open batch and not swept yet
105 ossia::hash_set<const IdentifiedObjectAbstract*> m_pruned;
106 int m_batchDepth{};
107};
108}
Base class for IdentifiedObject.
Definition IdentifiedObjectAbstract.hpp:16
Definition Selection.hpp:12
Definition SelectionStack.hpp:72
The SelectionStack class.
Definition SelectionStack.hpp:24
Base toolkit upon which the software is built.
Definition Application.cpp:83