From d7c963f71d365eca50541fe6d00afd12c425c3d5 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Wed, 14 Aug 2024 14:26:38 -0500 Subject: [PATCH] Added fit parameter presets as a combobox --- src/mvc/FitParamsTableModel.cpp | 19 +++++++++--- src/mvc/FitParamsTableModel.h | 7 +++-- src/mvc/FitSpectraWidget.cpp | 55 ++++++++++++++++++++++++++++----- src/mvc/FitSpectraWidget.h | 6 ++-- src/mvc/FittingDialog.cpp | 5 +-- src/mvc/MapsElementsWidget.cpp | 1 - src/mvc/SpectraWidget.cpp | 6 +++- src/mvc/SpectraWidget.h | 3 ++ 8 files changed, 83 insertions(+), 19 deletions(-) diff --git a/src/mvc/FitParamsTableModel.cpp b/src/mvc/FitParamsTableModel.cpp index d2abeb1..94dbdb6 100644 --- a/src/mvc/FitParamsTableModel.cpp +++ b/src/mvc/FitParamsTableModel.cpp @@ -4,7 +4,6 @@ *---------------------------------------------------------------------------*/ #include "FitParamsTableModel.h" -#include "fitting/models/gaussian_model.h" #include //--------------------------------------------------------------------------- @@ -18,7 +17,7 @@ FitParamsTableModel::FitParamsTableModel(QObject* parent) : QAbstractTableModel( m_headers[BOUND_TYPE] = tr("Is Fixed"); m_headers[MIN_VAL] = tr("Min Value"); m_headers[MAX_VAL] = tr("Max Value"); - m_headers[STEP_SIZE] = tr("Step Size"); + //m_headers[STEP_SIZE] = tr("Step Size"); _editable = true; _optimizer_supports_min_max = false; @@ -54,6 +53,16 @@ int FitParamsTableModel::columnCount(const QModelIndex &parent) const //--------------------------------------------------------------------------- +void FitParamsTableModel::setOptimizerPreset(fitting::models::Fit_Params_Preset preset) +{ + fitting::models::Gaussian_Model gmodel; + gmodel.update_fit_params_values(&_fit_parameters); + gmodel.set_fit_params_preset(preset); + updateFitParams(&gmodel.fit_parameters()); +} + +//--------------------------------------------------------------------------- + void FitParamsTableModel::setOptimizerSupportsMinMax(bool val) { _optimizer_supports_min_max = val; @@ -65,7 +74,7 @@ void FitParamsTableModel::setOptimizerSupportsMinMax(bool val) //--------------------------------------------------------------------------- -void FitParamsTableModel::updateFitParams(data_struct::Fit_Parameters* fit_params) +void FitParamsTableModel::updateFitParams(const data_struct::Fit_Parameters* fit_params) { if(fit_params != nullptr) { @@ -157,7 +166,7 @@ QVariant FitParamsTableModel::data(const QModelIndex &index, int role) const else if (index.column() == VALUE) return fitp.value; else if (index.column() == MIN_VAL) return fitp.min_val; else if (index.column() == MAX_VAL) return fitp.max_val; - else if (index.column() == STEP_SIZE) return fitp.step_size; + // else if (index.column() == STEP_SIZE) return fitp.step_size; else if (index.column() == BOUND_TYPE) { if (_optimizer_supports_min_max) @@ -403,6 +412,7 @@ bool FitParamsTableModel::setData(const QModelIndex &index, else return false; } + /* else if (column == STEP_SIZE) { if(ok) @@ -410,6 +420,7 @@ bool FitParamsTableModel::setData(const QModelIndex &index, else return false; } + */ else if (column == BOUND_TYPE) { _fit_parameters[fitp_name].bound_type = (data_struct::E_Bound_Type)value.toInt(); diff --git a/src/mvc/FitParamsTableModel.h b/src/mvc/FitParamsTableModel.h index 698d347..ccc2271 100644 --- a/src/mvc/FitParamsTableModel.h +++ b/src/mvc/FitParamsTableModel.h @@ -12,6 +12,7 @@ #include #include #include "data_struct/fit_parameters.h" +#include "fitting/models/gaussian_model.h" //--------------------------------------------------------------------------- @@ -36,7 +37,7 @@ class FitParamsTableModel BOUND_TYPE, MIN_VAL, MAX_VAL, - STEP_SIZE, + //STEP_SIZE, NUM_PROPS }; @@ -49,9 +50,11 @@ class FitParamsTableModel void setOptimizerSupportsMinMax(bool val); + void setOptimizerPreset(fitting::models::Fit_Params_Preset preset); + void setFitParams(data_struct::Fit_Parameters fit_params); - void updateFitParams(data_struct::Fit_Parameters* fit_params); + void updateFitParams(const data_struct::Fit_Parameters* fit_params); void only_keep_these_keys(data_struct::Fit_Parameters fit_params); diff --git a/src/mvc/FitSpectraWidget.cpp b/src/mvc/FitSpectraWidget.cpp index 882adb2..d749aa5 100644 --- a/src/mvc/FitSpectraWidget.cpp +++ b/src/mvc/FitSpectraWidget.cpp @@ -144,7 +144,6 @@ void FitSpectraWidget::createLayout() _fit_params_table->setItemDelegateForColumn(4, npDelegate); _fit_params_table->setItemDelegateForColumn(5, npDelegate); _fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - //_fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); _fit_params_table->setContextMenuPolicy(Qt::CustomContextMenu); connect(_fit_params_table, SIGNAL(customContextMenuRequested(QPoint)), @@ -160,7 +159,7 @@ void FitSpectraWidget::createLayout() _fit_elements_table->setModel(_fit_elements_table_model); _fit_elements_table->setItemDelegateForColumn(1, npDelegate); _fit_elements_table->sortByColumn(0, Qt::AscendingOrder); - //_fit_elements_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + //_fit_elements_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); QItemSelectionModel* mod = _fit_elements_table->selectionModel(); connect(mod, @@ -168,9 +167,7 @@ void FitSpectraWidget::createLayout() this, SLOT(element_selection_changed(QModelIndex,QModelIndex))); - _btnSsettings = new QPushButton(QIcon(":/images/gear.png"), "", this); - _btnSsettings->setMaximumWidth(64); - connect(_btnSsettings, &QPushButton::released, this, &FitSpectraWidget::onSettingsDialog); + connect(_spectra_widget, &SpectraWidget::onSettingsDialog, this, &FitSpectraWidget::onSettingsDialog); _btn_fit_spectra = new QPushButton("Fit Spectra"); connect(_btn_fit_spectra, &QPushButton::released, this, &FitSpectraWidget::Fit_Spectra_Click); @@ -226,6 +223,16 @@ void FitSpectraWidget::createLayout() _fit_params_tab_widget->addTab(_fit_params_table, "Fit Parameters"); _fit_params_tab_widget->addTab(element_widget, "Fit Elements"); + _cb_fitting_preset = new QComboBox(); + _cb_fitting_preset->addItem("User Defined"); + _cb_fitting_preset->addItem("Fit Amplitutes Only"); + _cb_fitting_preset->addItem("Fit No Tails"); + _cb_fitting_preset->addItem("Fit With Tails"); + _cb_fitting_preset->addItem("Fit With Free Energy"); + _cb_fitting_preset->addItem("Fit No Tails Energy Quadratic"); + connect(_cb_fitting_preset, &QComboBox::currentIndexChanged, this, &FitSpectraWidget::optimizer_preset_changed); + + _cb_opttimizer = new QComboBox(); _cb_opttimizer->addItem(STR_HYBRID_MP_FIT); _cb_opttimizer->addItem(STR_MP_FIT); @@ -247,7 +254,7 @@ void FitSpectraWidget::createLayout() { orient_layout = new QHBoxLayout(); //splitter->setOrientation(Qt::Horizontal); - grid_layout->addWidget(_btnSsettings, 0, 0); + grid_layout->addWidget(_cb_fitting_preset, 0, 0); grid_layout->addWidget(_cb_opttimizer, 0, 1); grid_layout->addWidget(_btn_fit_spectra, 1, 0); @@ -263,7 +270,7 @@ void FitSpectraWidget::createLayout() { orient_layout = new QVBoxLayout(); //splitter->setOrientation(Qt::Vertical); - grid_layout->addWidget(_btnSsettings, 0, 0); + grid_layout->addWidget(_cb_fitting_preset, 0, 0); grid_layout->addWidget(_cb_opttimizer, 0, 1); grid_layout->addWidget(_chk_auto_model, 0, 2); grid_layout->addWidget(_btn_export_csv, 0, 3); @@ -290,6 +297,8 @@ void FitSpectraWidget::createLayout() // splitter->setStretchFactor(0, 1); // splitter->addWidget(tab_and_buttons_widget); + _cb_fitting_preset->setCurrentIndex(2); + //optimizer_preset_changed(2); // batch with no tails optimizer_changed(STR_HYBRID_MP_FIT); QLayout* layout = new QVBoxLayout(); @@ -386,6 +395,8 @@ void FitSpectraWidget::onSettingsDialog() else { QString name = "Fitted_Int_" + QString(STR_FIT_GAUSS_MATRIX.c_str()); + _spectra_widget->remove_spectra(name); + name = "Fitted_Int_" + QString(STR_FIT_INT_BACKGROUND.c_str()); _spectra_widget->remove_spectra(name); } @@ -1237,6 +1248,36 @@ void FitSpectraWidget::element_selection_changed(int index) //--------------------------------------------------------------------------- +void FitSpectraWidget::optimizer_preset_changed(int val) +{ + switch (val) + { + case 0: + //_fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::NOT_SET); + break; + case 1: + _fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::MATRIX_BATCH_FIT); + break; + case 2: + _fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::BATCH_FIT_NO_TAILS); + break; + case 3: + _fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::BATCH_FIT_WITH_TAILS); + break; + case 4: + _fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::BATCH_FIT_WITH_FREE_ENERGY); + break; + case 5: + _fit_params_table_model->setOptimizerPreset(fitting::models::Fit_Params_Preset::BATCH_FIT_NO_TAILS_E_QUAD); + break; + default: + } + _fit_params_table->resizeColumnToContents(0); +} + +//--------------------------------------------------------------------------- + + void FitSpectraWidget::optimizer_changed(QString val) { if(val == STR_LM_FIT) diff --git a/src/mvc/FitSpectraWidget.h b/src/mvc/FitSpectraWidget.h index 9de29ca..d4fa471 100644 --- a/src/mvc/FitSpectraWidget.h +++ b/src/mvc/FitSpectraWidget.h @@ -109,6 +109,8 @@ public slots: void optimizer_changed(QString val); + void optimizer_preset_changed(int idx); + // void element_clicked(QModelIndex index); void Model_Spectra_Val_Change(QModelIndex,QModelIndex,QVector); @@ -186,6 +188,8 @@ private slots: QComboBox *_cb_opttimizer; + QComboBox *_cb_fitting_preset; + QTabWidget *_fit_params_tab_widget; QPushButton* _btn_fit_spectra; @@ -236,8 +240,6 @@ private slots: QComboBox* _cb_detector_element; - QPushButton* _btnSsettings; - bool _showDetailedFitSpec; bool _showFitIntMatrix; diff --git a/src/mvc/FittingDialog.cpp b/src/mvc/FittingDialog.cpp index 5599683..ba70459 100644 --- a/src/mvc/FittingDialog.cpp +++ b/src/mvc/FittingDialog.cpp @@ -75,13 +75,14 @@ void FittingDialog::_createLayout() _fit_params_table->setItemDelegateForColumn(3, npDelegate); _fit_params_table->setItemDelegateForColumn(4, npDelegate); _fit_params_table->setItemDelegateForColumn(5, npDelegate); - _fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + _fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + _fit_params_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); _new_fit_params_table = new QTableView(); _new_fit_params_table->setModel(_new_fit_params_table_model); _new_fit_params_table->sortByColumn(0, Qt::AscendingOrder); _new_fit_params_table->setItemDelegateForColumn(2, cbDelegate); - _new_fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + _new_fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); connect(_new_fit_params_table->verticalScrollBar(), &QAbstractSlider::valueChanged, _fit_params_table->verticalScrollBar(), &QAbstractSlider::setValue); diff --git a/src/mvc/MapsElementsWidget.cpp b/src/mvc/MapsElementsWidget.cpp index ca797b2..747fb33 100644 --- a/src/mvc/MapsElementsWidget.cpp +++ b/src/mvc/MapsElementsWidget.cpp @@ -66,7 +66,6 @@ MapsElementsWidget::MapsElementsWidget(int rows, int cols, bool create_image_nav connect(&_img_seg_diag, &ImageSegRoiDialog::onNewROIs, this, &MapsElementsWidget::on_add_new_ROIs); setAttribute(Qt::WA_DeleteOnClose, true); - connect(this, SIGNAL(destroyed()), this, SLOT(closeEvent())); _createLayout(create_image_nav, restore_floating); } diff --git a/src/mvc/SpectraWidget.cpp b/src/mvc/SpectraWidget.cpp index ea336df..22bb6e3 100644 --- a/src/mvc/SpectraWidget.cpp +++ b/src/mvc/SpectraWidget.cpp @@ -137,6 +137,10 @@ void SpectraWidget::createLayout() _btn_reset_chart_view = new QPushButton("Reset"); connect(_btn_reset_chart_view, &QPushButton::released, this, &SpectraWidget::onResetChartView); + _btnSsettings = new QPushButton(QIcon(":/images/gear.png"), "", this); + _btnSsettings->setMaximumWidth(64); + connect(_btnSsettings, &QPushButton::released, this, &SpectraWidget::onSettingsDialog); + QHBoxLayout* spectra_layout = new QHBoxLayout(); spectra_layout->addWidget(_chartView); @@ -159,7 +163,7 @@ void SpectraWidget::createLayout() options_layout->addWidget(new QLabel("Counts | ")); */ options_layout->addWidget(_btn_reset_chart_view); - + options_layout->addWidget(_btnSsettings); options_layout->addItem(new QSpacerItem(9999, 40, QSizePolicy::Maximum)); QVBoxLayout* vlayout = new QVBoxLayout(); diff --git a/src/mvc/SpectraWidget.h b/src/mvc/SpectraWidget.h index 3e6724f..e31a001 100644 --- a/src/mvc/SpectraWidget.h +++ b/src/mvc/SpectraWidget.h @@ -112,6 +112,7 @@ class SpectraWidget : public QWidget void setBackgroundBlack(bool val); signals: + void onSettingsDialog(); void trigger_connect_markers(); @@ -170,6 +171,8 @@ private slots: private: + QPushButton* _btnSsettings; + QLineEdit *_display_eneergy_max; QLineEdit *_display_eneergy_min;