From 6082f0df675d32b2700f9e1d53732e5c5b25b1be Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Tue, 25 Jan 2022 14:50:01 +0100 Subject: [PATCH] forward change notifications from InstrumentView to the project document's InstrumentEditController --- GUI/View/Instrument/InstrumentView.cpp | 28 +++++++++++++++----------- GUI/View/Instrument/InstrumentView.h | 4 +--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/GUI/View/Instrument/InstrumentView.cpp b/GUI/View/Instrument/InstrumentView.cpp index 62bfaf1ce77..b037029c7b7 100644 --- a/GUI/View/Instrument/InstrumentView.cpp +++ b/GUI/View/Instrument/InstrumentView.cpp @@ -86,23 +86,23 @@ void InstrumentView::createWidgetsForCurrentInstrument() m_typeLabel->setText(currentInstrument->instrumentType()); if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) { auto* editor = new SpecularInstrumentEditor(m_scrollArea, sp); - connect(editor, &SpecularInstrumentEditor::dataChanged, - [=] { emit instrumentChanged(currentInstrument); }); + connect(editor, &SpecularInstrumentEditor::dataChanged, this, + &InstrumentView::onInstrumentChanged); m_scrollArea->setWidget(editor); } else if (auto* os = dynamic_cast<OffSpecularInstrumentItem*>(currentInstrument)) { auto* editor = new OffSpecularInstrumentEditor(m_scrollArea, os); - connect(editor, &OffSpecularInstrumentEditor::dataChanged, - [=] { emit instrumentChanged(currentInstrument); }); + connect(editor, &OffSpecularInstrumentEditor::dataChanged, this, + &InstrumentView::onInstrumentChanged); m_scrollArea->setWidget(editor); } else if (auto* gisas = dynamic_cast<GISASInstrumentItem*>(currentInstrument)) { auto* editor = new GISASInstrumentEditor(m_scrollArea, gisas); - connect(editor, &GISASInstrumentEditor::dataChanged, - [=] { emit instrumentChanged(currentInstrument); }); + connect(editor, &GISASInstrumentEditor::dataChanged, this, + &InstrumentView::onInstrumentChanged); m_scrollArea->setWidget(editor); } else if (auto* dp = dynamic_cast<DepthProbeInstrumentItem*>(currentInstrument)) { auto* editor = new DepthProbeInstrumentEditor(m_scrollArea, dp); - connect(editor, &DepthProbeInstrumentEditor::dataChanged, - [=] { emit instrumentChanged(currentInstrument); }); + connect(editor, &DepthProbeInstrumentEditor::dataChanged, this, + &InstrumentView::onInstrumentChanged); m_scrollArea->setWidget(editor); } else ASSERT(false); @@ -118,8 +118,12 @@ void InstrumentView::onInstrumentNameEditingFinished() { auto* currentInstrument = m_instrumentListView->currentInstrument(); auto newName = m_nameLineEdit->text(); - if (currentInstrument && currentInstrument->instrumentName() != newName) { - currentInstrument->setInstrumentName(newName); - emit instrumentChanged(currentInstrument); - } + if (currentInstrument && currentInstrument->instrumentName() != newName) + m_document->instrumentsEditController()->setInstrumentName(currentInstrument, newName); +} + +void InstrumentView::onInstrumentChanged() +{ + m_document->instrumentsEditController()->notifyInstrumentChanged( + m_instrumentListView->currentInstrument()); } diff --git a/GUI/View/Instrument/InstrumentView.h b/GUI/View/Instrument/InstrumentView.h index a57509d3bf3..1d26c40e55b 100644 --- a/GUI/View/Instrument/InstrumentView.h +++ b/GUI/View/Instrument/InstrumentView.h @@ -30,12 +30,10 @@ class InstrumentView : public QWidget { public: InstrumentView(QWidget* parent, ProjectDocument* document); -signals: - void instrumentChanged(InstrumentItem* instrument); - private: void createWidgetsForCurrentInstrument(); void onInstrumentNameEditingFinished(); + void onInstrumentChanged(); private: InstrumentListView* m_instrumentListView; -- GitLab