diff --git a/GUI/Model/BaseItem/SessionItem.h b/GUI/Model/BaseItem/SessionItem.h index 114d989bfa44bfacdacda695dee72d571fbe5fc0..e2abe50a776105c04ca48b35a3e8d6e25eefe891 100644 --- a/GUI/Model/BaseItem/SessionItem.h +++ b/GUI/Model/BaseItem/SessionItem.h @@ -201,6 +201,7 @@ class GroupInfo; //! //! This code part again shows the (highly error-prone) string-based type checking. //#define USE_MAPPERS +#include class BA_CORE_API_ SessionItem { friend class SessionModel; diff --git a/GUI/Model/Data/DataItem.cpp b/GUI/Model/Data/DataItem.cpp index 14a00f8e6a2cb530f8877bfbee39bc1b359e1093..df4832af96cffc2292b4cd7986cbb2bd0e4e2a5d 100644 --- a/GUI/Model/Data/DataItem.cpp +++ b/GUI/Model/Data/DataItem.cpp @@ -23,7 +23,7 @@ void DataItem::setDatafield(Datafield* data) m_data.reset(data); setLastModified(QDateTime::currentDateTime()); - emit datafieldChanged(data); + emit datafieldChanged(); #ifdef USE_MAPPERS emitDataChanged(); #endif diff --git a/GUI/Model/Data/DataItem.h b/GUI/Model/Data/DataItem.h index a5dda13c826ab1e12646440a59ddf8bee691a2b9..7ad4f7ca37e4db70baf016cedcc22209448000f2 100644 --- a/GUI/Model/Data/DataItem.h +++ b/GUI/Model/Data/DataItem.h @@ -76,7 +76,7 @@ public: virtual void reset(ImportDataInfo data) = 0; signals: - void datafieldChanged(Datafield* data); + void datafieldChanged(); void rawDataVectorChanged(const std::vector& data); void fileNameChanged(const QString& filename); void axesUnitsChanged(); diff --git a/GUI/Model/Data/IntensityDataItem.cpp b/GUI/Model/Data/IntensityDataItem.cpp index 99d4882bb309bd3ce14a66aa553de9b141c712dc..48403c5165ffa97757d5d2ec6f22d39c47ea35a3 100644 --- a/GUI/Model/Data/IntensityDataItem.cpp +++ b/GUI/Model/Data/IntensityDataItem.cpp @@ -331,7 +331,7 @@ void IntensityDataItem::setLogz(bool logz) void IntensityDataItem::setInterpolated(bool interp) { setItemValue(P_IS_INTERPOLATED, interp); - emit interpolationChanged(); + emit interpolationChanged(interp); } //! Sets zoom range of X,Y axes, if it was not yet defined. diff --git a/GUI/Model/Data/IntensityDataItem.h b/GUI/Model/Data/IntensityDataItem.h index 7b1c329eca053a33b9b38492c5d39cef1b45d9d2..f49cfa755be248349534f6729dd0ca7b7ed40174 100644 --- a/GUI/Model/Data/IntensityDataItem.h +++ b/GUI/Model/Data/IntensityDataItem.h @@ -26,6 +26,7 @@ class ProjectionContainerItem; class BA_CORE_API_ IntensityDataItem : public DataItem { Q_OBJECT private: +// using DataItem::mapper; static constexpr auto P_PROJECTIONS{"Projections"}; static constexpr auto P_TITLE{"Title"}; static constexpr auto P_IS_INTERPOLATED{"Interpolation"}; @@ -123,7 +124,7 @@ public: signals: void gradientChanged(); - void interpolationChanged(); + void interpolationChanged(bool isInterpol); void axesRangeChangedFromPlot(); void updateOtherPlots(); void updateThisPlot(); diff --git a/GUI/Model/Device/AxesItems.cpp b/GUI/Model/Device/AxesItems.cpp index e4845490fc18bb9ee87bd8d1c55d4e04e2484265..3fa213675e93552705392e521f37f1665dd54a24 100644 --- a/GUI/Model/Device/AxesItems.cpp +++ b/GUI/Model/Device/AxesItems.cpp @@ -195,7 +195,7 @@ bool AmplitudeAxisItem::isLogScale() const void AmplitudeAxisItem::setLogScale(bool value) { setItemValue(P_IS_LOGSCALE, value); - emit logScaleChanged(); + emit logScaleChanged(value); } SessionItem* AmplitudeAxisItem::logScaleItem() const diff --git a/GUI/Model/Device/AxesItems.h b/GUI/Model/Device/AxesItems.h index f17244c1c0b5d2ba1352d75279fb4b30822e9add..cb100e772a544df00639ed3cdd016cea43c9cfa8 100644 --- a/GUI/Model/Device/AxesItems.h +++ b/GUI/Model/Device/AxesItems.h @@ -99,7 +99,7 @@ public: void setLocked(bool locked); signals: - void logScaleChanged(); + void logScaleChanged(bool isLog); }; diff --git a/GUI/Model/Model/JobFunctions.cpp b/GUI/Model/Model/JobFunctions.cpp index fde7b61c058590eda02d56932c55a23af5da08e7..5b122c3f7e1f81d4b68d8bfdef38b5ec73ce2f5f 100644 --- a/GUI/Model/Model/JobFunctions.cpp +++ b/GUI/Model/Model/JobFunctions.cpp @@ -112,6 +112,7 @@ void GUI::Model::JobFunctions::initDataView(JobItem* job_item) // also triggers Data1DViewItem::setAxesRangeToData and // GUI::Model::DataViewUtils::updateAxesTitle by setting new value of P_AXES_UNITS. auto* converter = job_item->instrumentItem()->createCoordSystem(); + view_item->setAxesUnits(GUI::Model::JobItemUtils::availableUnits(*converter)); } diff --git a/GUI/Model/Model/JobModel.cpp b/GUI/Model/Model/JobModel.cpp index fcaede6d5a9f0ad4fcc5349d9e92dd6a40ba476a..782fe82ee69caa2a398a6659e26158afbdfedd4b 100644 --- a/GUI/Model/Model/JobModel.cpp +++ b/GUI/Model/Model/JobModel.cpp @@ -55,7 +55,8 @@ JobItem* JobModel::addJob(const MultiLayerItem* sampleItem, const InstrumentItem ASSERT(sampleItem); ASSERT(instrumentItem); - auto* jobItem = insertItem(); + JobItem* jobItem = insertItem(); + emit jobAdded(); jobItem->setItemName(generateJobName()); jobItem->setIdentifier(QUuid::createUuid().toString()); diff --git a/GUI/Model/Model/JobModel.h b/GUI/Model/Model/JobModel.h index 27bcc68fbf2b92f6157be95edd6ce32ee64a4f0c..70877ed61aa7a9d792e83bc1269a75015e470bd0 100644 --- a/GUI/Model/Model/JobModel.h +++ b/GUI/Model/Model/JobModel.h @@ -53,6 +53,7 @@ public: signals: void focusRequest(JobItem* item); void globalProgress(int); + void jobAdded(); private: //! generates numbered job name with new/unused number diff --git a/GUI/View/Job/JobListModel.cpp b/GUI/View/Job/JobListModel.cpp index b5af7038faf6449e36592e9e1921c5f50178c332..cdae3c976382d656b5a4e1ee007beb1cde637114 100644 --- a/GUI/View/Job/JobListModel.cpp +++ b/GUI/View/Job/JobListModel.cpp @@ -28,19 +28,16 @@ JobListModel::JobListModel(JobModel* jobs, QObject* parent) : QAbstractListModel(parent) , m_jobs(jobs) { - for (JobItem* job : m_jobs->jobItems()) + for (JobItem* job : m_jobs->jobItems()) { enableJobNotification(job); - - connect(jobs, &QAbstractItemModel::rowsAboutToBeInserted, this, - &JobListModel::onRowsAboutToBeInserted); - connect(jobs, &QAbstractItemModel::rowsInserted, this, &JobListModel::onRowsInserted); + } + connect(jobs, &JobModel::jobAdded, this, &JobListModel::onJobAdded, Qt::UniqueConnection); } JobListModel::~JobListModel() { - for (JobItem* job : m_jobs->jobItems()) { + for (JobItem* job : m_jobs->jobItems()) disableJobNotification(job); - } } int JobListModel::rowCount(const QModelIndex&) const @@ -111,20 +108,10 @@ void JobListModel::emitJobListModelChanged(JobItem* job) // private slots //-------------------------------------------------------------------------------------------------- -void JobListModel::onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end) +void JobListModel::onJobAdded() { - if (!parent.isValid()) - beginInsertRows(QModelIndex(), start, end); -} - -void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end) -{ - if (!parent.isValid()) { - endInsertRows(); - QVector jobs = m_jobs->jobItems(); - for (int i = start; i <= end; i++) - enableJobNotification(jobs.at(i)); - } + for (JobItem* job : m_jobs->jobItems()) + enableJobNotification(job); } //-------------------------------------------------------------------------------------------------- @@ -134,15 +121,13 @@ void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end) void JobListModel::enableJobNotification(JobItem* job) { // name - connect(job, &JobItem::jobNameChanged, this, - [=](const QString&) { emitJobListModelChanged(job); }); + connect(job, &JobItem::jobNameChanged, this, [=]() { emitJobListModelChanged(job); }); // status - connect(job, &JobItem::jobStatusChanged, this, - [=](const JobStatus) { emitJobListModelChanged(job); }); + connect(job, &JobItem::jobStatusChanged, this, [=]() { emitJobListModelChanged(job); }); // progress - connect(job, &JobItem::jobProgressChanged, this, [=](int) { emitJobListModelChanged(job); }); + connect(job, &JobItem::jobProgressChanged, this, [=]() { emitJobListModelChanged(job); }); } void JobListModel::disableJobNotification(JobItem* job) diff --git a/GUI/View/Job/JobListModel.h b/GUI/View/Job/JobListModel.h index 202ab4203d2f830a8c54d44a86fd6dab3d1bd9bd..19cedddd7435a1070608988a2821362a987027f7 100644 --- a/GUI/View/Job/JobListModel.h +++ b/GUI/View/Job/JobListModel.h @@ -40,8 +40,7 @@ public: private slots: void emitJobListModelChanged(JobItem* job); - void onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end); - void onRowsInserted(const QModelIndex& parent, int start, int end); + void onJobAdded(); private: void enableJobNotification(JobItem* job); diff --git a/GUI/View/PlotComparison/FitComparisonController.cpp b/GUI/View/PlotComparison/FitComparisonController.cpp index 3a23142b7e2eec12fabdc7ef19bc71b6f1731f04..748850d1ec4903b5fe030bf3020ac3e9e81317bf 100644 --- a/GUI/View/PlotComparison/FitComparisonController.cpp +++ b/GUI/View/PlotComparison/FitComparisonController.cpp @@ -177,7 +177,7 @@ void DiffItemController::subscribe() m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this); #else connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this, - [=](Datafield*) { updateDiffData(); }); + &DiffItemController::updateDiffData, Qt::UniqueConnection); #endif // on diff item units change diff --git a/GUI/View/PlotComparison/FitComparisonViewController.cpp b/GUI/View/PlotComparison/FitComparisonViewController.cpp index c865c740a37a26e84381d3915afc2458bc6ba921..edcf973169040d651aa6c5b8fc606079f20f9955 100644 --- a/GUI/View/PlotComparison/FitComparisonViewController.cpp +++ b/GUI/View/PlotComparison/FitComparisonViewController.cpp @@ -168,23 +168,20 @@ void DiffItemController::subscribe() m_current_item->dataItem()->mapper()->setOnValueChange([this]() { updateDiffData(); }, this); #else connect(m_current_item->dataItem(), &DataItem::datafieldChanged, this, - [=](Datafield*) { updateDiffData(); }); + &DiffItemController::updateDiffData, Qt::UniqueConnection); #endif } void DiffItemController::unsubscribe() { -#ifdef USE_MAPPERS - m_diff_item->mapper()->unsubscribe(this); -#else - disconnect(m_diff_item, nullptr, this, nullptr); -#endif if (!m_current_item) return; #ifdef USE_MAPPERS m_current_item->dataItem()->mapper()->unsubscribe(this); + m_diff_item->mapper()->unsubscribe(this); #else disconnect(m_current_item->dataItem(), nullptr, this, nullptr); + disconnect(m_diff_item, nullptr, this, nullptr); #endif m_current_item = nullptr; } diff --git a/GUI/View/PlotComparison/Plot1D.cpp b/GUI/View/PlotComparison/Plot1D.cpp index c7d9acb45ecc9d906374d0bcf80781ad5789f9db..834b7751639c01043f4c85607a208b366bbd2686 100644 --- a/GUI/View/PlotComparison/Plot1D.cpp +++ b/GUI/View/PlotComparison/Plot1D.cpp @@ -134,7 +134,7 @@ void Plot1D::subscribeToItem() #else DataItem* dataItem = pair.first->dataItem(); connect(dataItem, &DataItem::datafieldChanged, caller, - [caller](Datafield*) { caller->refreshPlotData(); }); + [caller]() { caller->refreshPlotData(); }); #endif }); setConnected(true); diff --git a/GUI/View/PlotUtil/ColorMap.cpp b/GUI/View/PlotUtil/ColorMap.cpp index afe6b6f7e16fd9dac0abfa5dd55064a5892c8628..9393941ec03c92702c8315c5161cd365b7b7bd5b 100644 --- a/GUI/View/PlotUtil/ColorMap.cpp +++ b/GUI/View/PlotUtil/ColorMap.cpp @@ -225,9 +225,8 @@ void ColorMap::subscribeToItem() intensityItem()->mapper()->setOnValueChange([this]() { onIntensityModified(); }, this); #else // datafield - connect(intensityItem(), &IntensityDataItem::datafieldChanged, this, [=]() { - onIntensityModified(); - }); + connect(intensityItem(), &IntensityDataItem::datafieldChanged, this, + &ColorMap::onIntensityModified, Qt::UniqueConnection); // units connect(intensityItem(), &IntensityDataItem::axesUnitsReplotRequested, this, [=]() { setAxesRangeFromItem(intensityItem()); diff --git a/GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp b/GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp index 53ca1596d924f4926d4e95784498f985eef14786..34c30ba65ad4c2614edfe4903cbc24d8cdd1aaad 100644 --- a/GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp +++ b/GUI/View/PlotUtil/IntensityDataPropertyWidget.cpp @@ -28,7 +28,7 @@ #include #define FOR_EACH_ITEM \ - for(IntensityDataItem* item : m_items_vec) \ + for(IntensityDataItem*& item : m_items_vec) \ if(item) IntensityDataPropertyWidget::IntensityDataPropertyWidget(QWidget* parent) @@ -141,14 +141,12 @@ void IntensityDataPropertyWidget::setItem(QVector itemsVec) updateUIValues(); - // react on external changes (e.g. zooming in customplot shall update the axis values) - - - // update coordinates on axes units change #ifdef USE_MAPPERS + // react on external changes (e.g. zooming in customplot shall update the axis values) first_item->mapper()->setOnChildPropertyChange( [=](SessionItem*, const QString&) { updateUIValues(); }, this); + // update coordinates on axes units change first_item->mapper()->setOnPropertyChange( [this](SessionItem* item, const QString& name) { if(jobItem()) @@ -160,7 +158,7 @@ void IntensityDataPropertyWidget::setItem(QVector itemsVec) [&](SessionItem*) { item = nullptr; }, this); #else - // update values on panel + // react on external changes (e.g. zooming in customplot shall update the axis values) FOR_EACH_ITEM connect(item, &IntensityDataItem::axesRangeChangedFromPlot, this, [=](){ updateUIValues(); diff --git a/GUI/View/Projection/ProjectionsEditor.cpp b/GUI/View/Projection/ProjectionsEditor.cpp index e8cb68749eadaf12551d7397f460f73fb8f349f4..6e93d5b5c1871b0ae7ca8d4ab74d2b2da693a78f 100644 --- a/GUI/View/Projection/ProjectionsEditor.cpp +++ b/GUI/View/Projection/ProjectionsEditor.cpp @@ -101,7 +101,10 @@ JobItem* ProjectionsEditor::jobItem() IntensityDataItem* ProjectionsEditor::simulatedIntensity() { - return dynamic_cast(jobItem()->dataItem()); + if(jobItem()) + return dynamic_cast(jobItem()->dataItem()); + else + return nullptr; } IntensityDataItem* ProjectionsEditor::realIntensityDataItem() diff --git a/GUI/View/Projection/ProjectionsPlot.cpp b/GUI/View/Projection/ProjectionsPlot.cpp index 810cc383afaaea9a1560d5fbead99cc455fd262b..ad6524a68580a6fccd284f094b374d57b2a47120 100644 --- a/GUI/View/Projection/ProjectionsPlot.cpp +++ b/GUI/View/Projection/ProjectionsPlot.cpp @@ -81,25 +81,63 @@ void ProjectionsPlot::subscribeToItem() this); // Values of intensity changed, regenerate everything. - intensityItem()->mapper()->setOnValueChange( - [this]() { +#ifdef USE_MAPPERS +// intensityItem()->mapper()->setOnValueChange( +// [this]() { +// updateProjectionsData(); +// updateProjections(); +// }, +// this); +#else + connect(intensityItem(), &IntensityDataItem::datafieldChanged, this, [=]() { updateProjectionsData(); updateProjections(); - }, - this); + }); +#endif - // IntensityItem property (e.g. interpolation changed) + // interpolation changed +#ifdef USE_MAPPERS intensityItem()->mapper()->setOnPropertyChange( [this](const QString& name) { onIntensityItemPropertyChanged(name); }, this); +#else + connect(intensityItem(), &IntensityDataItem::interpolationChanged, this, + &ProjectionsPlot::setInterpolate, Qt::UniqueConnection); +#endif - // Update to changed IntensityDataItem axes + // AXES +#ifdef USE_MAPPERS intensityItem()->mapper()->setOnChildPropertyChange( [this](SessionItem* item, const QString name) { if (item->modelType() == BasicAxisItem::M_TYPE - || item->modelType() == AmplitudeAxisItem::M_TYPE) + || item->modelType() == AmplitudeAxisItem::M_TYPE) { onAxisPropertyChanged(item->itemName(), name); + } }, this); +#else + // if the colormap is zoomed or dragged: + connect(intensityItem(), &IntensityDataItem::updateOtherPlots, this, + &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); + + // if axes are changed externally, from the properties panel: + // axes range + connect(intensityItem()->xAxisItem(), &BasicAxisItem::axisRangeChanged, this, + &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); + connect(intensityItem()->yAxisItem(), &BasicAxisItem::axisRangeChanged, this, + &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); + connect(intensityItem()->zAxisItem(), &BasicAxisItem::axisRangeChanged, this, + &ProjectionsPlot::updateAxesRange, Qt::UniqueConnection); + + // axes title + connect(intensityItem()->xAxisItem(), &BasicAxisItem::axisTitleChanged, this, + &ProjectionsPlot::updateAxesTitle, Qt::UniqueConnection); + connect(intensityItem()->yAxisItem(), &BasicAxisItem::axisTitleChanged, this, + &ProjectionsPlot::updateAxesTitle, Qt::UniqueConnection); + + // z log scale + connect(intensityItem()->zAxisItem(), &AmplitudeAxisItem::logScaleChanged, this, + &ProjectionsPlot::setLogz, Qt::UniqueConnection); +#endif updateProjectionsData(); updateProjections(); diff --git a/GUI/View/Toplevel/SimulationView.cpp b/GUI/View/Toplevel/SimulationView.cpp index 3d0879fd33554804b526167e4a653ca81c467c95..bca752e6bb46d5c660ee5311e5aea82920527515 100644 --- a/GUI/View/Toplevel/SimulationView.cpp +++ b/GUI/View/Toplevel/SimulationView.cpp @@ -194,7 +194,8 @@ void SimulationView::updateSelection(QComboBox* comboBox, QStringList itemList, } if (allowNone) - itemList.insert(-1, "None"); + itemList.prepend("None"); + comboBox->addItems(itemList); if (itemList.contains(previousItem)) comboBox->setCurrentIndex(itemList.indexOf(previousItem));