Skip to content

Commit

Permalink
fix two crashes and some layout problems
Browse files Browse the repository at this point in the history
  • Loading branch information
conradhuebler committed Feb 7, 2020
1 parent 15e9f1a commit 21535b0
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/client/suprafit_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <QtCore/QJsonObject>
#include <QtCore/QObject>
#include <QtCore/QVector>

class SupraFitCli : public QObject {
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ inline QString aboutHtml()
info += "<p>Created by Conrad Hübler</p>";
info += "<p>Special thanks to <strong>Prof. M. Mazik</strong>, TU Bergakademie Freiberg for her support.</p>";
info += "<p>Special thanks to <strong>Dr. Sebastian F&ouml;rster</strong> and <strong>Dr. Stefan Kaiser</strong> for finding bugs and constructive feedback.</p>";
info += "<p>Special thanks to all with constructive feedback and bug hunting: Felix Amrhein.</p>";
info += "<p>Special thanks to Alexander K&ouml;nig for testing the Quickstart, helpful comments and feedback.</p>";
info += "<p>Thanks to all encouraged me writing the application.</p>";
info += "<p>Built-in Icon Theme taken from Oxygens Icon : <a href='http://www.oxygen-icons.org'>http://www.oxygen-icons.org</a></p>";
Expand All @@ -182,6 +183,7 @@ inline QString about()
info += "\t*********************************************************************************************************\n\n";
info += "\tSpecial thanks to Prof. M. Mazik, TU Bergakademie Freiberg for her support.\n\n";
info += "\tSpecial thanks to \t Dr. Sebastian Förster \t and \t Dr. Stefan Kaiser \t for finding bugs and constructive feedback.\n";
info += "\tSpecial thanks to all with constructive feedback and bug hunting: Felix Amrhein.\n";
info += "\tSpecial thanks to Alexander König for testing the Quickstart, helpful comments and feedback.\n\n\n";
info += "\tThanks to all encouraged me writing the application.\n\n";
info += "\tSupraFit website on GitHub: https://github.com/conradhuebler/SupraFit\n\n";
Expand Down
12 changes: 12 additions & 0 deletions src/ui/dialogs/configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ void ConfigDialog::createGeneralTab()
h_layout->addWidget(m_threads);
layout->addLayout(h_layout);

m_model_element_cols = new QSpinBox;
m_model_element_cols->setMaximum(1e6);
m_model_element_cols->setValue(qApp->instance()->property("ModelParameterColums").toInt());
m_model_element_cols->setMinimum(1);

h_layout = new QHBoxLayout;
h_layout->addWidget(new QLabel(tr("Columns for Model Parameter:")));
h_layout->addWidget(m_model_element_cols);
layout->addLayout(h_layout);

layout->addWidget(new QLabel(tr("Set directory behavior to:")));

m_current_dir = new QRadioButton(tr("Current Directory, where Application was started"), generalTab);
Expand Down Expand Up @@ -438,6 +448,8 @@ void ConfigDialog::accept()
m_dirlevel = 2;

qApp->instance()->setProperty("threads", m_threads->value());
qApp->instance()->setProperty("ModelParameterColums", m_model_element_cols->value());

qApp->instance()->setProperty("workingdir", m_working->text());
qApp->instance()->setProperty("dirlevel", m_dirlevel);
qApp->instance()->setProperty("auto_confidence", m_auto_confidence->isChecked());
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/configdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ConfigDialog : public QDialog {

private:
QRadioButton *m_current_dir, *m_last_dir, *m_working_dir;
QSpinBox *m_threads, *m_XScale, *m_YScale, *m_FontSize, *m_FastConfidenceScaling, *m_FastConfidenceSteps, *m_HistBins;
QSpinBox *m_threads, *m_model_element_cols, *m_XScale, *m_YScale, *m_FontSize, *m_FastConfidenceScaling, *m_FastConfidenceSteps, *m_HistBins;
QDoubleSpinBox *m_p_value, *m_markerSize, *m_lineWidth, *m_chartScaling;
QCheckBox *m_transparentChart, *m_cropedChart, *m_ColorFullSearch, *m_advanced_ui, *m_unsafe_copy, *m_overwrite_bins, *m_initialise_random;
QLineEdit* m_working;
Expand Down
14 changes: 10 additions & 4 deletions src/ui/guitools/chartwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,8 @@ void ChartWrapper::InitaliseSeries()

void ChartWrapper::UpdateModel()
{
if (!m_working) {
m_working = m_stored_data;
m_transformed = false;
}

CheckWorking();
MakeSeries();
emit ModelChanged();
}
Expand Down Expand Up @@ -277,4 +274,13 @@ void ChartWrapper::showSeries(int i)
}
emit ShowSeries(i);
}

void ChartWrapper::CheckWorking()
{
if (!m_working) {
m_working = m_stored_data;
m_transformed = false;
}
}

#include "chartwrapper.moc"
15 changes: 12 additions & 3 deletions src/ui/guitools/chartwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ class ChartWrapper : public QObject {

static QColor ColorCode(int i);

inline QString XLabel() const { return m_working.data()->XLabel(); }

inline QString YLabel() const { return m_working.data()->YLabel(); }
inline QString XLabel()
{
CheckWorking();
return m_working.data()->XLabel();
}

inline QString YLabel()
{
CheckWorking();
return m_working.data()->YLabel();
}

public slots:
void UpdateModel();
Expand All @@ -83,6 +91,7 @@ public slots:

bool m_blocked, m_transformed, m_flipable;
void InitaliseSeries();
void CheckWorking();

signals:
void ModelChanged();
Expand Down
3 changes: 3 additions & 0 deletions src/ui/mainwindow/suprafitgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,9 @@ void SupraFitGui::ReadSettings()
QTimer::singleShot(10, this, SLOT(FirstStart()));
}

if (qApp->instance()->property("ModelParameterColums") == QVariant())
qApp->instance()->setProperty("ModelParameterColums", 2);

if (qApp->instance()->property("xSize") == QVariant())
qApp->instance()->setProperty("xSize", 600);

Expand Down
3 changes: 2 additions & 1 deletion src/ui/mainwindow/suprafitgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ public slots:
<< "StoreFileName"
<< "StoreAbsolutePath"
<< "StoreFileHash"
<< "FindFileRecursive";
<< "FindFileRecursive"
<< "ModelParameterColums";

QDockWidget* m_message_dock;
MessageDock* m_messages_widget;
Expand Down
5 changes: 3 additions & 2 deletions src/ui/widgets/parameterwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
LocalParameterWidget::LocalParameterWidget(QSharedPointer<AbstractModel> model)
: m_model(model)
{
QVBoxLayout* layout = new QVBoxLayout;
int columns = qApp->instance()->property("ModelParameterColums").toInt();
QGridLayout* layout = new QGridLayout;
for (int i = 0; i < m_model.data()->LocalParameterSize(); i++) {
QWidget* widget = new QWidget;
QHBoxLayout* hlayout = new QHBoxLayout;
Expand Down Expand Up @@ -89,7 +90,7 @@ LocalParameterWidget::LocalParameterWidget(QSharedPointer<AbstractModel> model)
m_parameter << box;
hlayout->addWidget(check);
check->setHidden(m_model.data()->isSimulation());
layout->addWidget(widget);
layout->addWidget(widget, i / columns, i % columns);
}

setLayout(layout);
Expand Down
24 changes: 15 additions & 9 deletions src/ui/widgets/thermogramwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ void ThermogramWidget::setUi()
m_table->setToolTip(tr("This table hold all peaks, consisting of the integral, start time and end time. Double click on a peak will toggle the <i>Peak Integration mode</i>. Double click of within the thermogram selects the appropriate peak in this table (if any peaks already exists"));

m_peak_rule_list = new QTableWidget;
PeakRule* prototype = new PeakRule;
m_peak_rule_list->setItemPrototype(prototype);
m_peak_rule_list->setRowCount(1);
m_peak_rule_list->setColumnCount(2);
m_peak_rule_list->setContextMenuPolicy(Qt::ActionsContextMenu);
Expand Down Expand Up @@ -435,9 +437,9 @@ void ThermogramWidget::setUi()
m_splitter->restoreState(settings.value("splitterSizes").toByteArray());
m_iterations->setValue(settings.value("iterations", 15).toInt());
// m_integration_range->setCurrentText(settings.value("integration_range", m_Peak_Cut_Options[0]).toString());
QTableWidgetItem* item = new QTableWidgetItem(QString::number(m_peaks_start->value()));
PeakRule* item = new PeakRule(QString::number(m_peaks_start->value()));
m_peak_rule_list->setItem(m_current_peaks_rule, 0, item);
item = new QTableWidgetItem(QString::number(m_peaks_time->value()));
item = new PeakRule(QString::number(m_peaks_time->value()));
m_peak_rule_list->setItem(m_current_peaks_rule, 1, item);

connect(m_integration_range, &QComboBox::currentTextChanged, this, &ThermogramWidget::CutAllLimits);
Expand Down Expand Up @@ -508,14 +510,17 @@ void ThermogramWidget::setThermogram(PeakPick::spectrum* spec, qreal offset)

void ThermogramWidget::setPeakList(const std::vector<PeakPick::Peak>& peak_list)
{
if (peak_list.size() == 0)
return;

const QSignalBlocker blocker_a(m_peaks_time);
const QSignalBlocker blocker_b(m_peaks_start);

double time_pred = 0;
m_peak_list = peak_list;
m_peak_rule_list->clear();
int row = 0;
for (int i = 0; i < m_peak_list.size(); ++i) {
for (std::size_t i = 0; i < m_peak_list.size(); ++i) {
double time = m_peak_list[i].end * m_spec.Step() - m_peak_list[i].start * m_spec.Step() + m_spec.Step();
double start = m_peak_list[i].start * m_spec.Step() - m_spec.Step();
if (!qFuzzyCompare(time_pred, time)) {
Expand Down Expand Up @@ -873,21 +878,22 @@ void ThermogramWidget::setFit(const QJsonObject& fit)
QList<QPointF> points = ToolSet::String2Points(fit["rules_list"].toString());
m_peak_rule_list->setRowCount(points.size());
for (int i = 0; i < m_peak_rule_list->rowCount(); ++i) {
QTableWidgetItem* item = new QTableWidgetItem(QString::number(points[i].x()));
PeakRule* item = new PeakRule(QString::number(points[i].x()));
m_peak_rule_list->setItem(i, 0, item);

item = new QTableWidgetItem(QString::number(points[i].y()));
item = new PeakRule(QString::number(points[i].y()));
m_peak_rule_list->setItem(i, 1, item);
}
UpdatePeaks();
points = ToolSet::String2Points(fit["peak_int_ranges"].toString());
for (int i = 0; i < m_peak_list.size(); ++i) {
for (std::size_t i = 0; i < m_peak_list.size(); ++i) {
m_peak_list[i].int_start = points[i].x();
m_peak_list[i].int_end = points[i].y();
}
FitBaseLine();
Update();
m_block = false;
setEnabled(true);
}

QJsonObject ThermogramWidget::Fit() const
Expand Down Expand Up @@ -962,11 +968,11 @@ void ThermogramWidget::UpdatePeaks()
m_peak_list.clear();
PeakPick::Peak peak;


for (int j = 0; j < rules_size; ++j) {
QTableWidgetItem* item = (m_peak_rule_list->item(j, 0));
PeakRule* item = dynamic_cast<PeakRule*>(m_peak_rule_list->item(j, 0));
double index_start = m_spec.XtoIndex(item->data(Qt::DisplayRole).toDouble());
item = m_peak_rule_list->item(j, 1);
item = dynamic_cast<PeakRule*>(m_peak_rule_list->item(j, 1));

double timestep = item->data(Qt::DisplayRole).toDouble() / m_spec.Step();
if (timestep <= 0) {
m_guide_label->setText(QString("<font color='red'>Sorry, but Peak rule %1 contains a zero as peak time. That means, if I did not stop right here, you would be waiting for Godot</font>").arg(j + 1));
Expand Down
4 changes: 3 additions & 1 deletion src/ui/widgets/thermogramwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ class ScatterSeries;

class PeakRule : public QTableWidgetItem {
public:
PeakRule() = default;

PeakRule(const QString& str)
: QTableWidgetItem(str)
{
}

bool operator<(const QTableWidgetItem& other) const
bool operator<(const QTableWidgetItem& other) const override
{
return (this->text().toDouble() < other.text().toDouble());
}
Expand Down

0 comments on commit 21535b0

Please sign in to comment.