Skip to content

Commit

Permalink
Merge pull request musescore#18383 from Eism/score_switch_parts_crash…
Browse files Browse the repository at this point in the history
…_fix

fixed musescore#18254: Crash when switching between score and part with different measures selected
  • Loading branch information
RomanPudashkin committed Jul 5, 2023
2 parents 317b708 + 5dbd72a commit e190d03
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/inspector/models/abstractinspectormodel.cpp
Expand Up @@ -121,19 +121,14 @@ AbstractInspectorModel::AbstractInspectorModel(QObject* parent, IElementReposito
return;
}

setupCurrentNotationChangedConnection();

connect(m_repository->getQObject(), SIGNAL(elementsUpdated(const QList<mu::engraving::EngravingItem*>&)), this,
SLOT(updateProperties()));
connect(this, &AbstractInspectorModel::requestReloadPropertyItems, this, &AbstractInspectorModel::updateProperties);
}

void AbstractInspectorModel::setupCurrentNotationChangedConnection()
void AbstractInspectorModel::init()
{
onCurrentNotationChanged();
currentNotationChanged().onNotify(this, [this]() {
onCurrentNotationChanged();
});
}

void AbstractInspectorModel::onCurrentNotationChanged()
Expand Down
7 changes: 4 additions & 3 deletions src/inspector/models/abstractinspectormodel.h
Expand Up @@ -131,6 +131,8 @@ class AbstractInspectorModel : public QObject, public async::Asyncable
explicit AbstractInspectorModel(QObject* parent, IElementRepositoryService* repository = nullptr,
mu::engraving::ElementType elementType = mu::engraving::ElementType::INVALID);

void init();

Q_INVOKABLE virtual void requestResetToDefaults();

QString title() const;
Expand All @@ -151,6 +153,8 @@ class AbstractInspectorModel : public QObject, public async::Asyncable

virtual void requestElements();

virtual void onCurrentNotationChanged();

public slots:
void setTitle(QString title);
void setIcon(ui::IconCode::Code icon);
Expand Down Expand Up @@ -201,7 +205,6 @@ public slots:

notation::INotationSelectionPtr selection() const;

virtual void onCurrentNotationChanged();
virtual void onNotationChanged(const mu::engraving::PropertyIdSet& changedPropertyIdSet,
const mu::engraving::StyleIdSet& changedStyleIdSet);

Expand All @@ -215,8 +218,6 @@ protected slots:
void updateProperties();

private:
void setupCurrentNotationChangedConnection();

void initPropertyItem(PropertyItem* propertyItem, std::function<void(const mu::engraving::Pid propertyId,
const QVariant& newValue)> onPropertyChangedCallBack = nullptr,
std::function<void(const mu::engraving::Sid styleId,
Expand Down
9 changes: 9 additions & 0 deletions src/inspector/models/abstractinspectorproxymodel.cpp
Expand Up @@ -134,6 +134,15 @@ void AbstractInspectorProxyModel::setModels(const QList<AbstractInspectorModel*>
emit modelsChanged();
}

void AbstractInspectorProxyModel::onCurrentNotationChanged()
{
for (AbstractInspectorModel* model : modelList()) {
model->onCurrentNotationChanged();
}

AbstractInspectorModel::onCurrentNotationChanged();
}

void AbstractInspectorProxyModel::updateModels(const ElementKeySet& newElementKeySet)
{
QList<AbstractInspectorModel*> models;
Expand Down
2 changes: 2 additions & 0 deletions src/inspector/models/abstractinspectorproxymodel.h
Expand Up @@ -74,6 +74,8 @@ public slots:
void setModels(const QList<AbstractInspectorModel*>& models);

private:
void onCurrentNotationChanged() override;

QHash<InspectorModelType, AbstractInspectorModel*> m_modelsHash;
InspectorModelType m_defaultSubModelType = InspectorModelType::TYPE_UNDEFINED;
};
Expand Down
30 changes: 24 additions & 6 deletions src/inspector/models/inspectorlistmodel.cpp
Expand Up @@ -44,6 +44,8 @@ InspectorListModel::InspectorListModel(QObject* parent)
listenSelectionChanged();
context()->currentNotationChanged().onNotify(this, [this]() {
listenSelectionChanged();

notifyModelsAboutNotationChanged();
});
}

Expand Down Expand Up @@ -157,29 +159,36 @@ void InspectorListModel::createModelsBySectionType(const QList<InspectorSectionT

beginInsertRows(QModelIndex(), rowCount(), rowCount());

AbstractInspectorModel* newModel = nullptr;

switch (sectionType) {
case InspectorSectionType::SECTION_GENERAL:
m_modelList << new GeneralSettingsModel(this, m_repository);
newModel = new GeneralSettingsModel(this, m_repository);
break;
case InspectorSectionType::SECTION_MEASURES:
m_modelList << new MeasuresSettingsModel(this, m_repository);
newModel = new MeasuresSettingsModel(this, m_repository);
break;
case InspectorSectionType::SECTION_NOTATION:
m_modelList << new NotationSettingsProxyModel(this, m_repository, selectedElementKeySet);
newModel = new NotationSettingsProxyModel(this, m_repository, selectedElementKeySet);
break;
case InspectorSectionType::SECTION_TEXT:
m_modelList << new TextSettingsModel(this, m_repository);
newModel = new TextSettingsModel(this, m_repository);
break;
case InspectorSectionType::SECTION_SCORE_DISPLAY:
m_modelList << new ScoreSettingsModel(this, m_repository);
newModel = new ScoreSettingsModel(this, m_repository);
break;
case InspectorSectionType::SECTION_SCORE_APPEARANCE:
m_modelList << new ScoreAppearanceSettingsModel(this, m_repository);
newModel = new ScoreAppearanceSettingsModel(this, m_repository);
break;
case AbstractInspectorModel::InspectorSectionType::SECTION_UNDEFINED:
break;
}

if (newModel) {
newModel->init();
m_modelList << newModel;
}

endInsertRows();
}
}
Expand Down Expand Up @@ -272,6 +281,15 @@ AbstractInspectorModel* InspectorListModel::modelBySectionType(InspectorSectionT
return nullptr;
}

void InspectorListModel::notifyModelsAboutNotationChanged()
{
TRACEFUNC;

for (AbstractInspectorModel* model : m_modelList) {
model->onCurrentNotationChanged();
}
}

void InspectorListModel::listenSelectionChanged()
{
auto updateElementList = [this]() {
Expand Down
2 changes: 2 additions & 0 deletions src/inspector/models/inspectorlistmodel.h
Expand Up @@ -72,6 +72,8 @@ class InspectorListModel : public QAbstractListModel, public mu::async::Asyncabl

AbstractInspectorModel* modelBySectionType(InspectorSectionType sectionType) const;

void notifyModelsAboutNotationChanged();

QList<AbstractInspectorModel*> m_modelList;

IElementRepositoryService* m_repository = nullptr;
Expand Down

0 comments on commit e190d03

Please sign in to comment.