Commit 474985d6 authored by Huff, Israel's avatar Huff, Israel
Browse files

- connected aptens controls to data model

- added double and unsigned validation for line edit controls
- added open file dialogs for meteorology and disp phys ensemble files
parent c9ad6728
Pipeline #97673 failed with stages
in 37 seconds
...@@ -66,6 +66,31 @@ class APTEnsDataModel ...@@ -66,6 +66,31 @@ class APTEnsDataModel
static const QMap<SoilType, QString> soilTypeStrings; static const QMap<SoilType, QString> soilTypeStrings;
static const QMap<FissionID, QString> fissionIDStrings; static const QMap<FissionID, QString> fissionIDStrings;
// returns double value on success or 0. on failure
static double textFieldToDouble(const QString &str)
{
if (str.trimmed().isEmpty()) return 0.;
bool ok;
double value = str.toDouble(&ok);
if (ok) return value;
return 0.;
}
static QString doubleToTextField(double value)
{
return QString::number(value);
}
// returns unsigned value on success or 0 on failure
static unsigned textFieldToUnsigned(const QString &str)
{
if (str.trimmed().isEmpty()) return 0;
bool ok;
int value = str.toInt(&ok);
if (ok && value >= 0) return static_cast<unsigned>(value);
return 0;
}
// getters // getters
double latitude() { return mLatitude; } double latitude() { return mLatitude; }
double longitude() { return mLongitude; } double longitude() { return mLongitude; }
......
#include "aptenswidget.hh" #include "aptenswidget.hh"
#include <QFileDialog>
#include <QFileInfo>
#include <QGridLayout> #include <QGridLayout>
#include <QTimer> #include <QTimer>
...@@ -68,6 +70,12 @@ void LineEditFocusSelectAll::focusInEvent(QFocusEvent *event) ...@@ -68,6 +70,12 @@ void LineEditFocusSelectAll::focusInEvent(QFocusEvent *event)
APTEnsWidget::APTEnsWidget(QWidget *parent) APTEnsWidget::APTEnsWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
// TODO: remove temporary code
mDataModel.metFileSets().append("asdf");
mDataModel.metFileSets().append("zxcv");
mDataModel.setupCfgs().append("sdfg");
mDataModel.setupCfgs().append("xcvb");
QGridLayout *layout = new QGridLayout(this); QGridLayout *layout = new QGridLayout(this);
mEventDefBox = new CenterTitleGroupBox("Event Definition", this); mEventDefBox = new CenterTitleGroupBox("Event Definition", this);
mYieldEnsBox = new CenterTitleGroupBox("Yield Ensemble", this); mYieldEnsBox = new CenterTitleGroupBox("Yield Ensemble", this);
...@@ -210,8 +218,8 @@ APTEnsWidget::APTEnsWidget(QWidget *parent) ...@@ -210,8 +218,8 @@ APTEnsWidget::APTEnsWidget(QWidget *parent)
mSetupCfgsBox = new LeftTitleGroupBox("SETUP.CFG Files", mDispPhysEnsBox); mSetupCfgsBox = new LeftTitleGroupBox("SETUP.CFG Files", mDispPhysEnsBox);
mSetupCfgsListWidget = new QListWidget(mSetupCfgsBox); mSetupCfgsListWidget = new QListWidget(mSetupCfgsBox);
QGridLayout *dpeSFLayout = new QGridLayout(mSetupCfgsBox); QGridLayout *dpeSFLayout = new QGridLayout(mSetupCfgsBox);
mSetupCfgsImportButton = new QPushButton("Add Set", mDispPhysEnsBox); mSetupCfgsImportButton = new QPushButton("Import", mDispPhysEnsBox);
mSetupCfgsRemoveButton = new QPushButton("Remove Set", mDispPhysEnsBox); mSetupCfgsRemoveButton = new QPushButton("Remove", mDispPhysEnsBox);
dpeSFLayout->addWidget(mSetupCfgsListWidget); dpeSFLayout->addWidget(mSetupCfgsListWidget);
row = 0; row = 0;
dpeLayout->addWidget(mSetupCfgsBox, row, 0, 1, 5); dpeLayout->addWidget(mSetupCfgsBox, row, 0, 1, 5);
...@@ -241,11 +249,111 @@ APTEnsWidget::APTEnsWidget(QWidget *parent) ...@@ -241,11 +249,111 @@ APTEnsWidget::APTEnsWidget(QWidget *parent)
meLayout->addWidget(mMetEnsNumLineEdit, 0, 1); meLayout->addWidget(mMetEnsNumLineEdit, 0, 1);
meLayout->addWidget(meSpacer, 0, 2); meLayout->addWidget(meSpacer, 0, 2);
// event definition connections
connect(mLatLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setLatitude(
APTEnsDataModel::textFieldToDouble(mLatLineEdit->text()));
mLatLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.latitude()));
});
connect(mLonLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setLongitude(
APTEnsDataModel::textFieldToDouble(mLonLineEdit->text()));
mLonLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.longitude()));
});
connect(mAltLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setAltitude(
APTEnsDataModel::textFieldToDouble(mAltLineEdit->text()));
mAltLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.altitude()));
});
// yield ensemble definition connections
connect(mTotalYieldLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setTotalYield(
APTEnsDataModel::textFieldToDouble(mTotalYieldLineEdit->text()));
mTotalYieldLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.totalYield()));
});
connect(mNumYieldsLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setNumYields(
APTEnsDataModel::textFieldToUnsigned(mNumYieldsLineEdit->text()));
mNumYieldsLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.numYields()));
});
connect(mMinYieldLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setMinYield(
APTEnsDataModel::textFieldToDouble(mMinYieldLineEdit->text()));
mMinYieldLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.minYield()));
});
connect(mMaxYieldLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setMaxYield(
APTEnsDataModel::textFieldToDouble(mMaxYieldLineEdit->text()));
mMaxYieldLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.maxYield()));
});
connect(mYieldDefineEnsCheckBox, &QCheckBox::stateChanged, this, connect(mYieldDefineEnsCheckBox, &QCheckBox::stateChanged, this,
&APTEnsWidget::yieldDefineEnsStateChange); &APTEnsWidget::yieldDefineEnsStateChange);
// height of burst ensemble connections
connect(mHOBLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setHeightOfBurst(
APTEnsDataModel::textFieldToDouble(mHOBLineEdit->text()));
mHOBLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.heightOfBurst()));
});
connect(mNumHOBsLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setNumHOBs(
APTEnsDataModel::textFieldToUnsigned(mNumHOBsLineEdit->text()));
mNumHOBsLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.numHOBs()));
});
connect(mMinHOBLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setMinHOB(
APTEnsDataModel::textFieldToDouble(mMinHOBLineEdit->text()));
mMinHOBLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.minHOB()));
});
connect(mMaxHOBLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setMaxHOB(
APTEnsDataModel::textFieldToDouble(mMaxHOBLineEdit->text()));
mMaxHOBLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.maxHOB()));
});
connect(mHOBDefineEnsCheckBox, &QCheckBox::stateChanged, this, connect(mHOBDefineEnsCheckBox, &QCheckBox::stateChanged, this,
&APTEnsWidget::hobDefineEnsStateChange); &APTEnsWidget::hobDefineEnsStateChange);
// meteorology file sets connections
connect(mMetAddButton, &QPushButton::clicked, this,
&APTEnsWidget::addMeteorologyFile);
connect(mMetRemoveButton, &QPushButton::clicked, this,
&APTEnsWidget::removeMeteorologyFile);
// dispersion physics ensemble SETUP.CFG files connections
connect(mSetupCfgsImportButton, &QPushButton::clicked, this,
&APTEnsWidget::importSetupCfgFile);
connect(mSetupCfgsRemoveButton, &QPushButton::clicked, this,
&APTEnsWidget::removeSetupCfgtFile);
// turbulence ensemble connections
connect(mTurbEnsNumLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setTurbEnsNum(
APTEnsDataModel::textFieldToUnsigned(mTurbEnsNumLineEdit->text()));
mTurbEnsNumLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.turbEnsNum()));
});
// meteorology ensemble connections
connect(mMetEnsNumLineEdit, &QLineEdit::editingFinished, this, [=]() {
mDataModel.setMetEnsNum(
APTEnsDataModel::textFieldToUnsigned(mMetEnsNumLineEdit->text()));
mMetEnsNumLineEdit->setText(
APTEnsDataModel::doubleToTextField(mDataModel.metEnsNum()));
});
readInputsFromDM(); readInputsFromDM();
} }
...@@ -278,12 +386,10 @@ void APTEnsWidget::readInputsFromDM() ...@@ -278,12 +386,10 @@ void APTEnsWidget::readInputsFromDM()
mHOBSamplingComboBox->setCurrentIndex(Sampling::gaussian == mHOBSamplingComboBox->setCurrentIndex(Sampling::gaussian ==
mDataModel.hobSampling()); mDataModel.hobSampling());
mDataModel.metFileSets().append("asdf"); mMetFileSetsListWidget->clear();
mDataModel.metFileSets().append("zxcv");
mMetFileSetsListWidget->addItems(mDataModel.metFileSets()); mMetFileSetsListWidget->addItems(mDataModel.metFileSets());
mDataModel.setupCfgs().append("sdfg"); mSetupCfgsListWidget->clear();
mDataModel.setupCfgs().append("xcvb");
mSetupCfgsListWidget->addItems(mDataModel.setupCfgs()); mSetupCfgsListWidget->addItems(mDataModel.setupCfgs());
mTurbEnsNumLineEdit->setText(QString::number(mDataModel.turbEnsNum())); mTurbEnsNumLineEdit->setText(QString::number(mDataModel.turbEnsNum()));
...@@ -325,3 +431,43 @@ void APTEnsWidget::hobDefineEnsStateChange(int state) ...@@ -325,3 +431,43 @@ void APTEnsWidget::hobDefineEnsStateChange(int state)
mHOBSamplingLabel->setEnabled(checked); mHOBSamplingLabel->setEnabled(checked);
mHOBSamplingComboBox->setEnabled(checked); mHOBSamplingComboBox->setEnabled(checked);
} }
void APTEnsWidget::addMeteorologyFile()
{
QString fileName = QFileDialog::getOpenFileName(
this, tr("Add meteorology file"), ".", tr("meteorology file, *"));
if (!fileName.isEmpty())
{
mDataModel.metFileSets().append(fileName);
mMetFileSetsListWidget->addItem(fileName);
}
}
void APTEnsWidget::removeMeteorologyFile()
{
int row = mMetFileSetsListWidget->currentRow();
if (row < 0) return;
auto it = mMetFileSetsListWidget->takeItem(row);
mDataModel.metFileSets().removeAll(it->text());
delete it;
}
void APTEnsWidget::importSetupCfgFile()
{
QString fileName = QFileDialog::getOpenFileName(
this, tr("Add SETUP.CFG file"), ".", tr("SETUP.CFG file, *"));
if (!fileName.isEmpty())
{
mDataModel.setupCfgs().append(fileName);
mSetupCfgsListWidget->addItem(fileName);
}
}
void APTEnsWidget::removeSetupCfgtFile()
{
int row = mSetupCfgsListWidget->currentRow();
if (row < 0) return;
auto it = mSetupCfgsListWidget->takeItem(row);
mDataModel.setupCfgs().removeAll(it->text());
delete it;
}
...@@ -119,6 +119,11 @@ class APTEnsWidget : public QWidget ...@@ -119,6 +119,11 @@ class APTEnsWidget : public QWidget
public slots: public slots:
void yieldDefineEnsStateChange(int state); void yieldDefineEnsStateChange(int state);
void hobDefineEnsStateChange(int state); void hobDefineEnsStateChange(int state);
void addMeteorologyFile();
void removeMeteorologyFile();
void importSetupCfgFile();
void removeSetupCfgtFile();
}; };
} // namespace AptEns } // namespace AptEns
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment