diff --git a/src/notation/inotationinteraction.h b/src/notation/inotationinteraction.h index 88e119c6a4592..ba43beeed3b39 100644 --- a/src/notation/inotationinteraction.h +++ b/src/notation/inotationinteraction.h @@ -333,6 +333,7 @@ class INotationInteraction virtual muse::async::Channel showItemRequested() const = 0; virtual void setGetViewRectFunc(const std::function& func) = 0; + virtual void checkAndShowError() = 0; }; using INotationInteractionPtr = std::shared_ptr; diff --git a/src/notation/internal/notationinteraction.cpp b/src/notation/internal/notationinteraction.cpp index d03333aaed979..3e5c6b1d271b3 100644 --- a/src/notation/internal/notationinteraction.cpp +++ b/src/notation/internal/notationinteraction.cpp @@ -93,7 +93,6 @@ #include "engraving/rw/xmlreader.h" #include "engraving/rw/rwregister.h" -#include "mscoreerrorscontroller.h" #include "notationerrors.h" #include "notation.h" #include "notationnoteinput.h" @@ -234,6 +233,8 @@ NotationInteraction::NotationInteraction(Notation* notation, INotationUndoStackP notifyAboutSelectionChangedIfNeed(); }); + m_errorsController = std::make_shared(iocContext()); + m_noteInput->stateChanged().onNotify(this, [this]() { if (!m_noteInput->isNoteInputMode()) { hideShadowNote(); @@ -1342,8 +1343,7 @@ void NotationInteraction::endDrag() } notifyAboutDragChanged(); - - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); } muse::async::Notification NotationInteraction::dragChanged() const @@ -2047,7 +2047,7 @@ bool NotationInteraction::dropSingle(const PointF& pos, Qt::KeyboardModifiers mo notifyAboutDropChanged(); } - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); return accepted; } @@ -2172,7 +2172,7 @@ bool NotationInteraction::dropRange(const QByteArray& data, const PointF& pos, b endDrop(); notifyAboutDropChanged(); //MScore::setError(MsError::DEST_TUPLET); - //MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + // checkAndShowError(); // NOTE: if we show the error popup here it seems that the mouse-release event is missed // so the dragged region stays sticked to the mouse and move around. Don't know how to fix it. [M.S.] return false; @@ -2207,7 +2207,7 @@ bool NotationInteraction::dropRange(const QByteArray& data, const PointF& pos, b endDrop(); apply(); - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); return true; } @@ -2336,7 +2336,7 @@ bool NotationInteraction::applyPaletteElement(mu::engraving::EngravingItem* elem setDropTarget(nullptr); - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); return true; } @@ -4909,7 +4909,7 @@ void NotationInteraction::splitSelectedMeasure() score()->cmdSplitMeasure(chordRest); apply(); - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); } void NotationInteraction::joinSelectedMeasures() @@ -4924,7 +4924,7 @@ void NotationInteraction::joinSelectedMeasures() score()->cmdJoinMeasure(measureRange.startMeasure, measureRange.endMeasure); apply(); - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); } Ret NotationInteraction::canAddBoxes() const @@ -5116,6 +5116,7 @@ void NotationInteraction::addBoxes(BoxType boxType, int count, int beforeBoxInde void NotationInteraction::copySelection() { if (!selection()->canCopy()) { + checkAndShowError(); return; } @@ -5241,7 +5242,7 @@ void NotationInteraction::pasteSelection(const Fraction& scale) selectAndStartEditIfNeeded(pastedElement); } - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); } void NotationInteraction::swapSelection() @@ -5284,7 +5285,7 @@ void NotationInteraction::deleteSelection() score()->cmdDeleteSelection(); } - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); apply(); resetHitElementContext(); } @@ -5889,7 +5890,7 @@ void NotationInteraction::addIntervalToSelectedNotes(int interval) if (notes.empty()) { MScore::setError(MsError::NO_NOTE_SELECTED); - MScoreErrorsController(iocContext()).checkAndShowMScoreError(); + checkAndShowError(); return; } @@ -8201,3 +8202,11 @@ void NotationInteraction::setGetViewRectFunc(const std::function& func) { static_cast(m_noteInput.get())->setGetViewRectFunc(func); } + +void NotationInteraction::checkAndShowError() +{ + IF_ASSERT_FAILED(m_errorsController) { + return; + } + m_errorsController->checkAndShowMScoreError(); +} diff --git a/src/notation/internal/notationinteraction.h b/src/notation/internal/notationinteraction.h index d802eb677ca76..dd22b2ada49db 100644 --- a/src/notation/internal/notationinteraction.h +++ b/src/notation/internal/notationinteraction.h @@ -35,6 +35,8 @@ #include "../iselectinstrumentscenario.h" #include "inotationundostack.h" +#include "mscoreerrorscontroller.h" + #include "engraving/dom/engravingitem.h" #include "engraving/dom/elementgroup.h" #include "engraving/types/symid.h" @@ -333,6 +335,7 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable muse::async::Channel showItemRequested() const override; void setGetViewRectFunc(const std::function& func) override; + void checkAndShowError() override; private: mu::engraving::Score* score() const; @@ -520,6 +523,8 @@ class NotationInteraction : public INotationInteraction, public muse::Injectable std::shared_ptr m_selectionFilter = nullptr; + std::shared_ptr m_errorsController = nullptr; + DragData m_dragData; muse::async::Notification m_dragChanged; std::vector m_anchorLines; diff --git a/src/notation/tests/mocks/notationinteractionmock.h b/src/notation/tests/mocks/notationinteractionmock.h index d44709f99643b..cd4bc3ce50b7e 100644 --- a/src/notation/tests/mocks/notationinteractionmock.h +++ b/src/notation/tests/mocks/notationinteractionmock.h @@ -286,5 +286,6 @@ class NotationInteractionMock : public INotationInteraction MOCK_METHOD(muse::async::Channel, showItemRequested, (), (const, override)); MOCK_METHOD(void, setGetViewRectFunc, (const std::function&), (override)); + MOCK_METHOD(void, checkAndShowError, (), (override)); }; }