Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #26507: Crash when revealing instruments in a custom part #26564

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,12 @@ Item {
flickable.contentY = contentYBackup
}

onVisibilityChanged: function(visible) {
treeModel.toggleVisibilityOfSelectedRows(visible);
onChangeVisibilityOfSelectedRowsRequested: function(visible) {
treeModel.changeVisibilityOfSelectedRows(visible);
}

onChangeVisibilityRequested: function(index, visible) {
treeModel.changeVisibility(index, visible)
}

onDragStarted: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ FocusableControl {
signal popupOpened(var popupX, var popupY, var popupHeight)
signal popupClosed()

signal visibilityChanged(bool visible)
signal changeVisibilityOfSelectedRowsRequested(bool visible)
signal changeVisibilityRequested(var index, bool visible)

signal dragStarted()
signal dropped()
Expand Down Expand Up @@ -231,9 +232,9 @@ FocusableControl {
}

if (root.isSelected) {
root.visibilityChanged(!isVisible)
root.changeVisibilityOfSelectedRowsRequested(!isVisible)
} else {
model.itemRole.isVisible = !isVisible
root.changeVisibilityRequested(styleData.index, !isVisible)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentsscene/view/abstractlayoutpaneltreeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AbstractLayoutPanelTreeItem : public QObject
Q_PROPERTY(QString id READ idStr CONSTANT)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(int type READ typeInt CONSTANT)
Q_PROPERTY(bool isVisible READ isVisible WRITE setIsVisible NOTIFY isVisibleChanged)
Q_PROPERTY(bool isVisible READ isVisible NOTIFY isVisibleChanged)
Q_PROPERTY(bool isExpandable READ isExpandable NOTIFY isExpandableChanged)
Q_PROPERTY(bool isRemovable READ isRemovable NOTIFY isRemovableChanged)
Q_PROPERTY(bool isSelectable READ isSelectable CONSTANT)
Expand Down
32 changes: 23 additions & 9 deletions src/instrumentsscene/view/layoutpaneltreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include "uicomponents/view/itemmultiselectionmodel.h"

#include "async/async.h"
#include "defer.h"
#include "log.h"

Expand Down Expand Up @@ -152,6 +151,8 @@ bool LayoutPanelTreeModel::removeRows(int row, int count, const QModelIndex& par

emit isEmptyChanged();

updateSystemObjectLayers();

return true;
}

Expand Down Expand Up @@ -223,10 +224,10 @@ void LayoutPanelTreeModel::setupPartsConnections()
});

m_notation->parts()->systemObjectStavesChanged().onNotify(this, [this]() {
// Wait until parts are fully loaded / updated
async::Async::call(this, [this]() {
m_shouldUpdateSystemObjectLayers = true;
if (!m_isLoadingBlocked) {
updateSystemObjectLayers();
});
}
});
}

Expand Down Expand Up @@ -521,6 +522,7 @@ bool LayoutPanelTreeModel::moveRows(const QModelIndex& sourceParent, int sourceR
endMoveRows();

updateRearrangementAvailability();
updateSystemObjectLayers();

return true;
}
Expand All @@ -543,17 +545,27 @@ void LayoutPanelTreeModel::endActiveDrag()
m_dragInProgress = false;

setLoadingBlocked(false);

updateSystemObjectLayers();
}

void LayoutPanelTreeModel::toggleVisibilityOfSelectedRows(bool visible)
void LayoutPanelTreeModel::changeVisibilityOfSelectedRows(bool visible)
{
for (const QModelIndex& index : m_selectionModel->selectedIndexes()) {
AbstractLayoutPanelTreeItem* item = modelIndexToItem(index);

item->setIsVisible(visible);
changeVisibility(index, visible);
}
}

void LayoutPanelTreeModel::changeVisibility(const QModelIndex& index, bool visible)
{
setLoadingBlocked(true);

AbstractLayoutPanelTreeItem* item = modelIndexToItem(index);
item->setIsVisible(visible);

setLoadingBlocked(false);
}

QItemSelectionModel* LayoutPanelTreeModel::selectionModel() const
{
return m_selectionModel;
Expand Down Expand Up @@ -928,10 +940,12 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
{
TRACEFUNC;

if (!m_masterNotation || !m_rootItem) {
if (!m_masterNotation || !m_rootItem || !m_shouldUpdateSystemObjectLayers) {
return;
}

m_shouldUpdateSystemObjectLayers = false;

// Create copy, because we're going to modify them
std::vector<Staff*> newSystemObjectStaves = m_masterNotation->notation()->parts()->systemObjectStaves();
QList<AbstractLayoutPanelTreeItem*> children = m_rootItem->childItems();
Expand Down
5 changes: 4 additions & 1 deletion src/instrumentsscene/view/layoutpaneltreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class LayoutPanelTreeModel : public QAbstractItemModel, public muse::async::Asyn
Q_INVOKABLE void moveSelectedRowsUp();
Q_INVOKABLE void moveSelectedRowsDown();
Q_INVOKABLE void removeSelectedRows();
Q_INVOKABLE void toggleVisibilityOfSelectedRows(bool visible);
Q_INVOKABLE void changeVisibilityOfSelectedRows(bool visible);
Q_INVOKABLE void changeVisibility(const QModelIndex& index, bool visible);

Q_INVOKABLE void startActiveDrag();
Q_INVOKABLE void endActiveDrag();
Expand Down Expand Up @@ -181,6 +182,8 @@ private slots:

bool m_layoutPanelVisible = true;

bool m_shouldUpdateSystemObjectLayers = false;

bool m_dragInProgress = false;
AbstractLayoutPanelTreeItem* m_dragSourceParentItem = nullptr;
MoveParams m_activeDragMoveParams;
Expand Down
Loading