diff --git a/GUI/View/Setup/AxesPanel.cpp b/GUI/View/Setup/AxesPanel.cpp index 588183c9b55a4b9dc18088f3891eeb09d0632b50..d77087d08796fe748008869a398557976b59d3c0 100644 --- a/GUI/View/Setup/AxesPanel.cpp +++ b/GUI/View/Setup/AxesPanel.cpp @@ -17,6 +17,7 @@ #include "GUI/Model/Axis/AmplitudeAxisItem.h" #include "GUI/Model/Axis/BasicAxisItem.h" #include "GUI/Model/Data/Data2DItem.h" +#include "GUI/Model/Files/DatafilesSet.h" #include "GUI/Model/Job/DataSource.h" #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/Support/Data/ComboProperty.h" @@ -39,14 +40,6 @@ AxesPanel::AxesPanel(DataSource* ds) layout->setContentsMargins(8, 20, 8, 8); layout->setSpacing(5); - if (m_data_source->allData2DItems().empty()) - return; - - for (auto* item : m_data_source->allData2DItems()) - disconnect(item, nullptr, this, nullptr); - - m_updaters.clear(); - layout->addRow("Color scheme:", GUI::Util::createComboBox([this] { return *gApp->color_gradient_combo; }, [this](const QString& s) { @@ -186,17 +179,32 @@ AxesPanel::AxesPanel(DataSource* ds) layout->addRow(zGroup); - updateUIValues(); - - // react on external changes (e.g. zooming in customplot shall update the axis values) - connect(m_data_source->currentData2DItem(), &DataItem::itemAxesRangeChanged, this, - &AxesPanel::updateUIValues, Qt::UniqueConnection); + connect(gDoc->datafiles(), &DatafilesSet::setChanged, this, &AxesPanel::updatePanel); + updatePanel(); } AxesPanel::~AxesPanel() = default; +Data2DItem* AxesPanel::dataItem() +{ + return m_data_source->currentData2DItem(); +} + +void AxesPanel::updatePanel() +{ + if (dataItem()) { + // react on external changes (e.g. zooming in customplot shall update the axis values) + connect(m_data_source->currentData2DItem(), &DataItem::itemAxesRangeChanged, this, + &AxesPanel::updateUIValues, Qt::UniqueConnection); + updateUIValues(); + show(); + } else + hide(); +} + void AxesPanel::updateUIValues() { + ASSERT(dataItem()); for (const auto& updater : m_updaters) updater(); } diff --git a/GUI/View/Setup/AxesPanel.h b/GUI/View/Setup/AxesPanel.h index 82af2834865ebb38c54a4082a036012156f8b8ed..43af649339374a1544380c0a2e89131134928d74 100644 --- a/GUI/View/Setup/AxesPanel.h +++ b/GUI/View/Setup/AxesPanel.h @@ -17,6 +17,7 @@ #include <QWidget> +class Data2DItem; class DataSource; //! Widget to edit properties of a Data2DItem. @@ -27,6 +28,8 @@ public: ~AxesPanel(); private: + Data2DItem* dataItem(); + void updatePanel(); void updateUIValues(); QVector<std::function<void()>> m_updaters; diff --git a/GUI/View/Setup/AxisPanel.cpp b/GUI/View/Setup/AxisPanel.cpp index 9641faa1fa48d8dc32dc3817c614abe9398f9fb8..19e6719dceadfeb7d6e2eecfc63ebff8b09ad3b2 100644 --- a/GUI/View/Setup/AxisPanel.cpp +++ b/GUI/View/Setup/AxisPanel.cpp @@ -145,6 +145,7 @@ void AxisPanel::updatePanel() for (auto* item : m_data_source->allData1DItems()) connect(item, &DataItem::axesUnitsChanged, this, &AxisPanel::updateItemCoords, Qt::UniqueConnection); + updateUIValues(); show(); } else hide(); @@ -161,7 +162,7 @@ void AxisPanel::updateItemCoords(DataItem* item) void AxisPanel::updateUIValues() { - if (m_data_source->currentData1DItem()) - for (const auto& updater : m_updaters) - updater(); + ASSERT(dataItem()); + for (const auto& updater : m_updaters) + updater(); } diff --git a/GUI/View/Setup/AxisPanel.h b/GUI/View/Setup/AxisPanel.h index 1e1ada7665e7ee361787f6bb86b517f2edea0b72..7f0df3614d73b61212c1799e6957d03deda6f9f1 100644 --- a/GUI/View/Setup/AxisPanel.h +++ b/GUI/View/Setup/AxisPanel.h @@ -28,10 +28,9 @@ public: AxisPanel(DataSource*); ~AxisPanel(); +private: Data1DItem* dataItem(); void updatePanel(); - -private: void updateItemCoords(DataItem* item); void updateUIValues();