Skip to content

Commit

Permalink
Merge pull request #21774 from mathesoncalum/20513-bends_copydrag_crash
Browse files Browse the repository at this point in the history
Fix #20513: Disable copy-dragging for bends (Master)
  • Loading branch information
RomanPudashkin committed Mar 4, 2024
2 parents 92dc6e2 + 6136168 commit eeee31f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/engraving/rendering/single/singlelayout.cpp
Expand Up @@ -978,6 +978,7 @@ void SingleLayout::layout(GradualTempoChangeSegment* item, const Context& ctx)
void SingleLayout::layout(GuitarBend*, const Context&)
{
NOT_IMPLEMENTED;
//! NOTE: Bends can be removed from disallowed elements in NotationInteraction::dragCopyAllowed once this has been implemented
}

void SingleLayout::layout(GuitarBendSegment*, const Context&)
Expand Down
1 change: 1 addition & 0 deletions src/notation/inotationinteraction.h
Expand Up @@ -95,6 +95,7 @@ class INotationInteraction
virtual async::Notification dragChanged() const = 0;

virtual bool isDragCopyStarted() const = 0;
virtual bool dragCopyAllowed(const EngravingItem* element) const = 0;
virtual void startDragCopy(const EngravingItem* element, QObject* dragSource) = 0;
virtual void endDragCopy() = 0;

Expand Down
23 changes: 18 additions & 5 deletions src/notation/internal/notationinteraction.cpp
Expand Up @@ -1131,17 +1131,30 @@ bool NotationInteraction::isDragCopyStarted() const
return m_drag != nullptr;
}

//! NOTE: Copied from ScoreView::cloneElement
void NotationInteraction::startDragCopy(const EngravingItem* element, QObject* dragSource)
bool NotationInteraction::dragCopyAllowed(const EngravingItem* element) const
{
if (!element) {
return;
return false;
}

if (element->isMeasure() || element->isNote() || element->isVBox()) {
return;
switch (element->type()) {
case ElementType::MEASURE:
case ElementType::NOTE:
case ElementType::VBOX:
// TODO: Bends can't be copy-dragged until corresponding SingleLayout::layout and SingleDraw::draw methods have been implemented
case ElementType::GUITAR_BEND:
case ElementType::GUITAR_BEND_SEGMENT:
case ElementType::GUITAR_BEND_HOLD:
case ElementType::GUITAR_BEND_HOLD_SEGMENT:
case ElementType::GUITAR_BEND_TEXT:
return false;
default: return true;
}
}

//! NOTE: Copied from ScoreView::cloneElement
void NotationInteraction::startDragCopy(const EngravingItem* element, QObject* dragSource)
{
if (isDragStarted()) {
endDragCopy();
}
Expand Down
1 change: 1 addition & 0 deletions src/notation/internal/notationinteraction.h
Expand Up @@ -103,6 +103,7 @@ class NotationInteraction : public INotationInteraction, public async::Asyncable
async::Notification dragChanged() const override;

bool isDragCopyStarted() const override;
bool dragCopyAllowed(const EngravingItem* element) const override;
void startDragCopy(const EngravingItem* element, QObject* dragSource) override;
void endDragCopy() override;

Expand Down
1 change: 1 addition & 0 deletions src/notation/tests/mocks/notationinteractionmock.h
Expand Up @@ -65,6 +65,7 @@ class NotationInteractionMock : public INotationInteraction
MOCK_METHOD(async::Notification, dragChanged, (), (const, override));

MOCK_METHOD(bool, isDragCopyStarted, (), (const, override));
MOCK_METHOD(bool, dragCopyAllowed, (const EngravingItem*), (const, override));
MOCK_METHOD(void, startDragCopy, (const EngravingItem*, QObject*), (override));
MOCK_METHOD(void, endDragCopy, (), (override));

Expand Down
4 changes: 3 additions & 1 deletion src/notation/view/notationviewinputcontroller.cpp
Expand Up @@ -605,7 +605,9 @@ void NotationViewInputController::mousePressEvent(QMouseEvent* event)
}

if (keyState == (Qt::ShiftModifier | Qt::ControlModifier)) {
viewInteraction()->startDragCopy(hitElement, m_view->asItem());
if (viewInteraction()->dragCopyAllowed(hitElement)) {
viewInteraction()->startDragCopy(hitElement, m_view->asItem());
}
return;
}

Expand Down

0 comments on commit eeee31f

Please sign in to comment.