// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include "JFJochViewerSidePanelChart.h" JFJochViewerSidePanelChart::JFJochViewerSidePanelChart(QWidget *parent) : QWidget(parent) { auto layout = new QVBoxLayout(this); combo_box = new QComboBox(this); combo_box->addItem("Azimuthal integration (1D)", 0); combo_box->addItem("Azimuthal integration (2D)", 3); combo_box->addItem("Wilson plot", 1); combo_box->addItem("I/sigma", 2); combo_box->addItem("X-ray fluorescence spectrum", 4); layout->addWidget(combo_box); connect(combo_box, &QComboBox::currentIndexChanged, this, &JFJochViewerSidePanelChart::comboBoxSelected); azint_plot = new JFJochSimpleChartView(this); azint_image = new JFJochAzIntImageView(this); stack = new QStackedWidget(this); stack->addWidget(azint_plot); // index 0 stack->addWidget(azint_image); // index 1 layout->addWidget(stack); setLayout(layout); } void JFJochViewerSidePanelChart::comboBoxSelected(int val) { // Switch between chart (options 0..2) and image (option 3) auto index = combo_box->currentIndex(); int mode = combo_box->itemData(index).toInt(); if (mode == 3) { stack->setCurrentWidget(azint_image); } else { stack->setCurrentWidget(azint_plot); } redrawPlot(); } void JFJochViewerSidePanelChart::redrawPlot() { std::vector x,y; if (image) { auto index = combo_box->currentIndex(); switch (combo_box->itemData(index).toInt()) { case 0: x = image->GetAzInt1D_BinToQ(); y = image->GetAzInt1D(); break; case 1: x = image->ImageData().integration_one_over_d; y = image->ImageData().integration_logI; break; case 2: x = image->ImageData().integration_one_over_d; y = image->ImageData().integration_Isigma; break; case 4: x = image->Dataset().experiment.GetFluorescenceSpectrum().GetEnergy_eV(); y = image->Dataset().experiment.GetFluorescenceSpectrum().GetData(); break; case 3: { // Render 2D azimuthal integration as an image const auto &profile = image->ImageData().az_int_profile; const auto &ds = image->Dataset(); int az_bins = ds.azimuthal_bins; int q_bins = ds.q_bins; if (az_bins > 1 && q_bins > 0 && profile.size() == static_cast(az_bins * q_bins)) { azint_image->SetData(profile, az_bins, q_bins); } else { azint_image->Clear(); } // Make sure we don't try to update the chart in this mode x.clear(); y.clear(); break; } } } if (!x.empty() && !y.empty()) { azint_plot->UpdateData(x,y); } else { azint_plot->ClearData(); } } void JFJochViewerSidePanelChart::loadImage(std::shared_ptr in_image) { image = in_image; redrawPlot(); }