Skip to content

Commit

Permalink
Added fit parameter presets as a combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Aug 14, 2024
1 parent d99b110 commit d7c963f
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 19 deletions.
19 changes: 15 additions & 4 deletions src/mvc/FitParamsTableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*---------------------------------------------------------------------------*/

#include "FitParamsTableModel.h"
#include "fitting/models/gaussian_model.h"
#include <QColor>

//---------------------------------------------------------------------------
Expand All @@ -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;

Expand Down Expand Up @@ -54,6 +53,16 @@ int FitParamsTableModel::columnCount(const QModelIndex &parent) const

//---------------------------------------------------------------------------

void FitParamsTableModel::setOptimizerPreset(fitting::models::Fit_Params_Preset preset)
{
fitting::models::Gaussian_Model<double> 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;
Expand All @@ -65,7 +74,7 @@ void FitParamsTableModel::setOptimizerSupportsMinMax(bool val)

//---------------------------------------------------------------------------

void FitParamsTableModel::updateFitParams(data_struct::Fit_Parameters<double>* fit_params)
void FitParamsTableModel::updateFitParams(const data_struct::Fit_Parameters<double>* fit_params)
{
if(fit_params != nullptr)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -403,13 +412,15 @@ bool FitParamsTableModel::setData(const QModelIndex &index,
else
return false;
}
/*
else if (column == STEP_SIZE)
{
if(ok)
_fit_parameters[fitp_name].step_size = dval;
else
return false;
}
*/
else if (column == BOUND_TYPE)
{
_fit_parameters[fitp_name].bound_type = (data_struct::E_Bound_Type)value.toInt();
Expand Down
7 changes: 5 additions & 2 deletions src/mvc/FitParamsTableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QModelIndex>
#include <QVariant>
#include "data_struct/fit_parameters.h"
#include "fitting/models/gaussian_model.h"


//---------------------------------------------------------------------------
Expand All @@ -36,7 +37,7 @@ class FitParamsTableModel
BOUND_TYPE,
MIN_VAL,
MAX_VAL,
STEP_SIZE,
//STEP_SIZE,
NUM_PROPS
};

Expand All @@ -49,9 +50,11 @@ class FitParamsTableModel

void setOptimizerSupportsMinMax(bool val);

void setOptimizerPreset(fitting::models::Fit_Params_Preset preset);

void setFitParams(data_struct::Fit_Parameters<double> fit_params);

void updateFitParams(data_struct::Fit_Parameters<double>* fit_params);
void updateFitParams(const data_struct::Fit_Parameters<double>* fit_params);

void only_keep_these_keys(data_struct::Fit_Parameters<double> fit_params);

Expand Down
55 changes: 48 additions & 7 deletions src/mvc/FitSpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -160,17 +159,15 @@ 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,
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/mvc/FitSpectraWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>);
Expand Down Expand Up @@ -186,6 +188,8 @@ private slots:

QComboBox *_cb_opttimizer;

QComboBox *_cb_fitting_preset;

QTabWidget *_fit_params_tab_widget;

QPushButton* _btn_fit_spectra;
Expand Down Expand Up @@ -236,8 +240,6 @@ private slots:

QComboBox* _cb_detector_element;

QPushButton* _btnSsettings;

bool _showDetailedFitSpec;

bool _showFitIntMatrix;
Expand Down
5 changes: 3 additions & 2 deletions src/mvc/FittingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/mvc/MapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion src/mvc/SpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/mvc/SpectraWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class SpectraWidget : public QWidget
void setBackgroundBlack(bool val);

signals:
void onSettingsDialog();

void trigger_connect_markers();

Expand Down Expand Up @@ -170,6 +171,8 @@ private slots:

private:

QPushButton* _btnSsettings;

QLineEdit *_display_eneergy_max;

QLineEdit *_display_eneergy_min;
Expand Down

0 comments on commit d7c963f

Please sign in to comment.