Skip to content

Commit 379a0a0

Browse files
committed
Selection filter - change behaviour of All button
1 parent d6b87fa commit 379a0a0

8 files changed

+45
-12
lines changed

src/engraving/dom/select.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,20 @@ int SelectionFilter::filteredTypes() const
9797

9898
bool SelectionFilter::isFiltered(SelectionFilterType type) const
9999
{
100-
if (type == SelectionFilterType::NONE || type == SelectionFilterType::ALL) {
101-
return m_filteredTypes == static_cast<unsigned int>(type);
100+
switch (type) {
101+
case SelectionFilterType::NONE:
102+
case SelectionFilterType::ALL:
103+
case SelectionFilterType::ALL_VOICES:
104+
case SelectionFilterType::ALL_NOTATION_ELEMENTS: {
105+
const unsigned int masked = m_filteredTypes & static_cast<unsigned int>(type);
106+
return masked == static_cast<unsigned int>(type);
107+
}
108+
default:
109+
return m_filteredTypes & static_cast<unsigned int>(type);
102110
}
103111

104-
return m_filteredTypes & static_cast<unsigned int>(type);
112+
UNREACHABLE;
113+
return false;
105114
}
106115

107116
void SelectionFilter::setFiltered(SelectionFilterType type, bool filtered)

src/engraving/dom/select.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ enum class SelState : char {
9292
static constexpr size_t NUMBER_OF_SELECTION_FILTER_TYPES = 23;
9393

9494
enum class SelectionFilterType : unsigned int {
95-
NONE = 0,
95+
// Voices...
9696
FIRST_VOICE = 1 << 0,
9797
SECOND_VOICE = 1 << 1,
9898
THIRD_VOICE = 1 << 2,
9999
FOURTH_VOICE = 1 << 3,
100+
101+
// Notation elements...
100102
DYNAMIC = 1 << 4,
101103
HAIRPIN = 1 << 5,
102104
FINGERING = 1 << 6,
@@ -116,7 +118,12 @@ enum class SelectionFilterType : unsigned int {
116118
BREATH = 1 << 20,
117119
TREMOLO = 1 << 21,
118120
GRACE_NOTE = 1 << 22,
119-
ALL = ~(~0u << NUMBER_OF_SELECTION_FILTER_TYPES)
121+
122+
// Masks...
123+
NONE = 0,
124+
ALL = ~(~0u << NUMBER_OF_SELECTION_FILTER_TYPES),
125+
ALL_VOICES = FIRST_VOICE | SECOND_VOICE | THIRD_VOICE | FOURTH_VOICE,
126+
ALL_NOTATION_ELEMENTS = ALL & ~ALL_VOICES
120127
};
121128

122129
//---------------------------------------------------------

src/notation/inotationinteraction.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class INotationInteraction
8484
virtual void selectTopOrBottomOfChord(MoveDirection d) = 0;
8585

8686
// SelectionFilter
87+
virtual unsigned int currentSelectionFilter() const = 0;
8788
virtual bool isSelectionTypeFiltered(SelectionFilterType type) const = 0;
8889
virtual void setSelectionTypeFiltered(SelectionFilterType type, bool filtered) = 0;
8990

src/notation/internal/notationinteraction.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,11 @@ muse::async::Notification NotationInteraction::selectionChanged() const
10251025
return m_selectionChanged;
10261026
}
10271027

1028+
unsigned int NotationInteraction::currentSelectionFilter() const
1029+
{
1030+
return score()->selectionFilter().filteredTypes();
1031+
}
1032+
10281033
bool NotationInteraction::isSelectionTypeFiltered(SelectionFilterType type) const
10291034
{
10301035
return score()->selectionFilter().isFiltered(type);

src/notation/internal/notationinteraction.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable
9595
void moveSegmentSelection(MoveDirection d) override;
9696

9797
// SelectionFilter
98+
unsigned int currentSelectionFilter() const override;
9899
bool isSelectionTypeFiltered(SelectionFilterType type) const override;
99100
void setSelectionTypeFiltered(SelectionFilterType type, bool filtered) override;
100101

src/notation/tests/mocks/notationinteractionmock.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class NotationInteractionMock : public INotationInteraction
5757
MOCK_METHOD(muse::async::Notification, selectionChanged, (), (const, override));
5858
MOCK_METHOD(void, selectTopOrBottomOfChord, (MoveDirection), (override));
5959

60+
MOCK_METHOD(unsigned int, currentSelectionFilter, (), (const, override));
6061
MOCK_METHOD(bool, isSelectionTypeFiltered, (SelectionFilterType), (const, override));
6162
MOCK_METHOD(void, setSelectionTypeFiltered, (SelectionFilterType, bool), (override));
6263

src/notation/view/selectionfiltermodel.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void SelectionFilterModel::load()
4040
beginResetModel();
4141

4242
m_types.clear();
43-
m_types << SelectionFilterType::ALL;
43+
m_types << SelectionFilterType::ALL_NOTATION_ELEMENTS;
4444

4545
for (size_t i = 0; i < mu::engraving::NUMBER_OF_SELECTION_FILTER_TYPES; i++) {
4646
m_types << static_cast<SelectionFilterType>(1 << i);
@@ -81,8 +81,12 @@ QVariant SelectionFilterModel::data(const QModelIndex& index, int role) const
8181
return isFiltered(type);
8282

8383
case IsIndeterminateRole:
84-
if (type == SelectionFilterType::ALL) {
85-
return !isFiltered(SelectionFilterType::ALL) && !isFiltered(SelectionFilterType::NONE);
84+
if (type == SelectionFilterType::ALL_NOTATION_ELEMENTS) {
85+
const unsigned int masked = filteredTypes() & static_cast<int>(SelectionFilterType::ALL_NOTATION_ELEMENTS);
86+
const bool hasNonZeroNotationElements = masked != static_cast<int>(SelectionFilterType::NONE);
87+
88+
// Indeterminate if some notation elements types are selected, but not all...
89+
return hasNonZeroNotationElements && !isFiltered(SelectionFilterType::ALL_NOTATION_ELEMENTS);
8690
}
8791

8892
return false;
@@ -110,7 +114,7 @@ bool SelectionFilterModel::setData(const QModelIndex& index, const QVariant& dat
110114
const bool filtered = data.toBool();
111115

112116
setFiltered(type, filtered);
113-
if (type == SelectionFilterType::ALL) {
117+
if (type == SelectionFilterType::ALL_NOTATION_ELEMENTS) {
114118
emit dataChanged(this->index(0), this->index(rowCount() - 1), { IsSelectedRole, IsIndeterminateRole });
115119
} else {
116120
emit dataChanged(this->index(0), this->index(0), { IsSelectedRole, IsIndeterminateRole });
@@ -157,6 +161,11 @@ INotationInteractionPtr SelectionFilterModel::currentNotationInteraction() const
157161
return currentNotation() ? currentNotation()->interaction() : nullptr;
158162
}
159163

164+
unsigned int SelectionFilterModel::filteredTypes() const
165+
{
166+
return currentNotationInteraction() ? currentNotationInteraction()->currentSelectionFilter() : 0;
167+
}
168+
160169
bool SelectionFilterModel::isFiltered(SelectionFilterType type) const
161170
{
162171
return currentNotationInteraction() ? currentNotationInteraction()->isSelectionTypeFiltered(type) : false;
@@ -172,7 +181,7 @@ void SelectionFilterModel::setFiltered(SelectionFilterType type, bool filtered)
172181
QString SelectionFilterModel::titleForType(SelectionFilterType type) const
173182
{
174183
switch (type) {
175-
case SelectionFilterType::ALL:
184+
case SelectionFilterType::ALL_NOTATION_ELEMENTS:
176185
return muse::qtrc("notation", "All");
177186
case SelectionFilterType::FIRST_VOICE:
178187
return muse::qtrc("notation", "Voice %1").arg(1);
@@ -220,8 +229,7 @@ QString SelectionFilterModel::titleForType(SelectionFilterType type) const
220229
return muse::qtrc("notation", "Tremolos");
221230
case SelectionFilterType::GRACE_NOTE:
222231
return muse::qtrc("notation", "Grace notes");
223-
case SelectionFilterType::NONE:
224-
break;
232+
default: break;
225233
}
226234

227235
return {};

src/notation/view/selectionfiltermodel.h

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SelectionFilterModel : public QAbstractListModel, public muse::Injectable,
7979
INotationPtr currentNotation() const;
8080
INotationInteractionPtr currentNotationInteraction() const;
8181

82+
unsigned int filteredTypes() const;
8283
bool isFiltered(SelectionFilterType type) const;
8384
void setFiltered(SelectionFilterType type, bool filtered);
8485

0 commit comments

Comments
 (0)