Fixed updating instruments panel

This commit is contained in:
Eism 2021-06-23 13:52:35 +02:00
parent fc6b6dbce7
commit 733418ef50
8 changed files with 75 additions and 29 deletions

View file

@ -38,9 +38,11 @@ void MainWindowTitleProvider::load()
update();
IMasterNotationPtr masterNotation = context()->currentMasterNotation();
masterNotation->needSave().notification.onNotify(this, [this]() {
update();
});
if (masterNotation) {
masterNotation->needSave().notification.onNotify(this, [this]() {
update();
});
}
});
}

View file

@ -96,8 +96,6 @@ mu::Ret ConverterController::convertScoreParts(const mu::io::path& in, const mu:
{
TRACEFUNC;
LOGI() << "in: " << in << ", out: " << out;
auto masterNotation = notationCreator()->newMasterNotation();
IF_ASSERT_FAILED(masterNotation) {
return make_ret(Err::UnknownError);
@ -174,6 +172,8 @@ bool ConverterController::isConvertPageByPage(const std::string& suffix) const
mu::Ret ConverterController::convertPageByPage(notation::INotationWriterPtr writer, INotationPtr notation, const mu::io::path& out) const
{
TRACEFUNC;
for (size_t i = 0; i < notation->elements()->pages().size(); i++) {
const QString filePath = io::path(io::dirpath(out) + "/" + io::basename(out) + "-%1." + io::syffix(out)).toQString().arg(i + 1);
@ -219,6 +219,8 @@ mu::Ret ConverterController::convertFullNotation(notation::INotationWriterPtr wr
mu::Ret ConverterController::convertScorePartsToPdf(notation::INotationWriterPtr writer, IMasterNotationPtr masterNotation,
const io::path& out) const
{
TRACEFUNC;
INotationPtrList notations;
notations.push_back(masterNotation->notation());
@ -249,6 +251,8 @@ mu::Ret ConverterController::convertScorePartsToPdf(notation::INotationWriterPtr
mu::Ret ConverterController::convertScorePartsToPngs(notation::INotationWriterPtr writer, mu::notation::IMasterNotationPtr masterNotation,
const io::path& out) const
{
TRACEFUNC;
Ret ret = convertPageByPage(writer, masterNotation->notation(), out);
if (!ret) {
return ret;

View file

@ -47,11 +47,6 @@ InstrumentsPanelTreeModel::InstrumentsPanelTreeModel(QObject* parent)
if (masterNotation) {
m_masterNotationParts = masterNotation->parts();
m_masterNotationParts->partsChanged().onNotify(this, [this]() {
if (m_notationParts) {
load();
}
});
}
});

View file

@ -33,9 +33,11 @@ public:
virtual bool canUndo() const = 0;
virtual void undo() = 0;
virtual async::Notification undoNotification() const = 0;
virtual bool canRedo() const = 0;
virtual void redo() = 0;
virtual async::Notification redoNotification() const = 0;
virtual void prepareChanges() = 0;
virtual void rollbackChanges() = 0;

View file

@ -52,8 +52,12 @@ NotationParts::NotationParts(IGetScore* getScore, INotationInteractionPtr intera
updatePartTitles();
});
m_undoStack->stackChanged().onNotify(this, [this]() {
m_partsChanged.notify();
m_undoStack->undoNotification().onNotify(this, [this]() {
m_partsNotifier->changed();
});
m_undoStack->redoNotification().onNotify(this, [this]() {
m_partsNotifier->changed();
});
}
@ -183,7 +187,7 @@ void NotationParts::setPartVisible(const ID& partId, bool visible)
part->undoChangeProperty(Ms::Pid::VISIBLE, visible);
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(partId);
}
void NotationParts::setPartName(const ID& partId, const QString& name)
@ -196,7 +200,7 @@ void NotationParts::setPartName(const ID& partId, const QString& name)
doSetPartName(part, name);
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(partId);
}
void NotationParts::setPartSharpFlat(const ID& partId, const SharpFlat& sharpFlat)
@ -209,7 +213,7 @@ void NotationParts::setPartSharpFlat(const ID& partId, const SharpFlat& sharpFla
part->undoChangeProperty(Ms::Pid::PREFER_SHARP_FLAT, static_cast<int>(sharpFlat));
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(partId);
}
void NotationParts::setPartTransposition(const ID& partId, const instruments::Interval& transpose)
@ -222,7 +226,7 @@ void NotationParts::setPartTransposition(const ID& partId, const instruments::In
score()->transpositionChanged(part, transpose);
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(partId);
}
void NotationParts::setInstrumentVisible(const ID& instrumentId, const ID& fromPartId, bool visible)
@ -410,7 +414,7 @@ void NotationParts::setInstrumentName(const ID& instrumentId, const ID& fromPart
score()->undo(new Ms::ChangeInstrumentLong(instrumentInfo.fraction, part, { StaffName(name, 0) }));
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(fromPartId);
}
void NotationParts::setInstrumentAbbreviature(const ID& instrumentId, const ID& fromPartId, const QString& abbreviature)
@ -428,7 +432,7 @@ void NotationParts::setInstrumentAbbreviature(const ID& instrumentId, const ID&
score()->undo(new Ms::ChangeInstrumentShort(instrumentInfo.fraction, part, { StaffName(abbreviature, 0) }));
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(fromPartId);
}
void NotationParts::setStaffVisible(const ID& staffId, bool visible)
@ -642,7 +646,7 @@ void NotationParts::appendDoublingInstrument(const mu::instruments::Instrument&
ChangedNotifier<mu::instruments::Instrument>* notifier = partNotifier(destinationPartId);
notifier->itemAdded(instrument);
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(destinationPartId);
}
void NotationParts::appendStaff(Staff* staff, const ID& destinationPartId)
@ -707,7 +711,7 @@ void NotationParts::replaceInstrument(const ID& instrumentId, const ID& fromPart
ChangedNotifier<mu::instruments::Instrument>* notifier = partNotifier(part->id());
notifier->itemReplaced(InstrumentsConverter::convertInstrument(*oldInstrumentInfo.instrument), newInstrument);
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(fromPartId);
}
Notification NotationParts::partsChanged() const
@ -775,7 +779,7 @@ void NotationParts::removeInstruments(const IDList& instrumentIds, const ID& fro
doSetPartName(part, formatPartName(part));
updateScore();
m_partsNotifier->itemChanged(part);
notifyAboutPartChanged(fromPartId);
}
void NotationParts::doRemoveInstruments(const IDList& instrumentIds, Part* fromPart)
@ -883,11 +887,11 @@ void NotationParts::moveInstruments(const IDList& sourceInstrumentsIds, const ID
}
updateScore();
m_partsNotifier->itemChanged(fromPart);
notifyAboutPartChanged(sourcePartId);
notifyAboutInstrumentsChanged(fromPart->id());
if (fromPart != toPart) {
notifyAboutInstrumentsChanged(toPart->id());
m_partsNotifier->itemChanged(toPart);
notifyAboutPartChanged(destinationPartId);
}
}
@ -1412,6 +1416,16 @@ void NotationParts::initStaff(Staff* staff, const mu::instruments::Instrument& i
staff->setDefaultClefType(instrument.clefs[cleffIndex]);
}
void NotationParts::notifyAboutPartChanged(const ID& partId) const
{
Part* part = this->part(partId);
if (!part) {
return;
}
m_partsNotifier->itemChanged(part);
}
void NotationParts::notifyAboutStaffChanged(const ID& staffId) const
{
Staff* staff = this->staff(staffId);

View file

@ -160,6 +160,7 @@ private:
void initStaff(Staff* staff, const instruments::Instrument& instrument, const Ms::StaffType* staffType, int cleffIndex);
void notifyAboutPartChanged(const ID& partId) const;
void notifyAboutStaffChanged(const ID& staffId) const;
void notifyAboutInstrumentsChanged(const ID& partId) const;

View file

@ -54,7 +54,13 @@ void NotationUndoStack::undo()
masterScore()->setSaved(isStackClean());
notifyAboutNotationChanged();
notifyAboutStackStateChanged();
notifyAboutUndo();
notifyAboutStateChanged();
}
Notification NotationUndoStack::undoNotification() const
{
return m_undoNotification;
}
bool NotationUndoStack::canRedo() const
@ -76,7 +82,13 @@ void NotationUndoStack::redo()
masterScore()->setSaved(isStackClean());
notifyAboutNotationChanged();
notifyAboutStackStateChanged();
notifyAboutRedo();
notifyAboutStateChanged();
}
Notification NotationUndoStack::redoNotification() const
{
return m_redoNotification;
}
void NotationUndoStack::prepareChanges()
@ -97,7 +109,7 @@ void NotationUndoStack::rollbackChanges()
score()->endCmd(false, true);
masterScore()->setSaved(isStackClean());
notifyAboutStackStateChanged();
notifyAboutStateChanged();
}
void NotationUndoStack::commitChanges()
@ -109,7 +121,7 @@ void NotationUndoStack::commitChanges()
score()->endCmd();
masterScore()->setSaved(isStackClean());
notifyAboutStackStateChanged();
notifyAboutStateChanged();
}
mu::async::Notification NotationUndoStack::stackChanged() const
@ -137,11 +149,21 @@ void NotationUndoStack::notifyAboutNotationChanged()
m_notationChanged.notify();
}
void NotationUndoStack::notifyAboutStackStateChanged()
void NotationUndoStack::notifyAboutStateChanged()
{
m_stackStateChanged.notify();
}
void NotationUndoStack::notifyAboutUndo()
{
m_undoNotification.notify();
}
void NotationUndoStack::notifyAboutRedo()
{
m_redoNotification.notify();
}
bool NotationUndoStack::isStackClean() const
{
IF_ASSERT_FAILED(undoStack()) {

View file

@ -40,9 +40,11 @@ public:
bool canUndo() const override;
void undo() override;
async::Notification undoNotification() const override;
bool canRedo() const override;
void redo() override;
async::Notification redoNotification() const override;
void prepareChanges() override;
void rollbackChanges() override;
@ -52,7 +54,9 @@ public:
private:
void notifyAboutNotationChanged();
void notifyAboutStackStateChanged();
void notifyAboutStateChanged();
void notifyAboutUndo();
void notifyAboutRedo();
bool isStackClean() const;
@ -64,6 +68,8 @@ private:
async::Notification m_notationChanged;
async::Notification m_stackStateChanged;
async::Notification m_undoNotification;
async::Notification m_redoNotification;
};
}