Commit b217162d authored by Huff, Israel's avatar Huff, Israel
Browse files

- implementing add/delete/edit in ensemble selection widget

parent 5dcd1ace
Pipeline #97986 passed with stages
in 5 minutes and 28 seconds
......@@ -74,27 +74,21 @@ void LineEditFocusSelectAll::focusInEvent(QFocusEvent *event)
APTEnsWidget::APTEnsWidget(QWidget *parent)
: QWidget(parent)
{
mCurrentModel = "untitled";
mDataModels[mCurrentModel] = APTEnsDataModel();
APTEnsDataModel *model = &mDataModels[mCurrentModel];
// TODO: remove temporary code
model->metFileSets().append("asdf");
model->metFileSets().append("zxcv");
model->setupCfgs().append("sdfg");
model->setupCfgs().append("xcvb");
QGridLayout *mainLayout = new QGridLayout(this);
mSelectModelBox = new CenterTitleGroupBox("Select Model", this);
mSelectModelBox = new CenterTitleGroupBox("Ensembles", this);
mCurrentModelBox = new CenterTitleGroupBox("", this);
mainLayout->addWidget(mSelectModelBox, 0, 0);
mainLayout->addWidget(mCurrentModelBox, 0, 1);
QGridLayout *smLayout = new QGridLayout(mSelectModelBox);
mNewModelLineEdit = new QLineEdit(this);
mModelListWidget = new QListWidget(mSelectModelBox);
smLayout->addWidget(mNewModelLineEdit, 0, 0);
smLayout->setSpacing(0);
smLayout->setMargin(0);
mNewModelButton = new QPushButton("New", this);
mModelListWidget = new EditableListWidget(mSelectModelBox);
mNewModelButton->setStyleSheet(
"margin : 0.7em 0 0 0; padding : 0.1em 0.1em 0.1em 0.1em;");
smLayout->addWidget(mNewModelButton, 0, 0);
smLayout->addWidget(mModelListWidget, 1, 0);
QGridLayout *cmLayout = new QGridLayout(mCurrentModelBox);
......@@ -270,50 +264,91 @@ APTEnsWidget::APTEnsWidget(QWidget *parent)
meLayout->addWidget(mMetEnsNumLineEdit, 0, 1);
meLayout->addWidget(meSpacer, 0, 2);
// select ensemble connections
connect(mNewModelButton, &QPushButton::clicked, this,
[=]() { addNewEnsemble(); });
connect(mModelListWidget, &QListWidget::clicked, this, [=]() {
mCurrentModel = mModelListWidget->currentItem()->text();
updateGUIFromDataModel();
});
connect(mModelListWidget, &EditableListWidget::itemChanged, this, [=]() {
QString newKey = mModelListWidget->currentItem()->text().trimmed();
if (newKey.length() == 0 || mDataModels.find(newKey) != mDataModels.end())
{
mModelListWidget->currentItem()->setText(mCurrentModel);
return;
}
// write trimmed version back to list view
mModelListWidget->currentItem()->setText(newKey);
mDataModels[newKey] = mDataModels[mCurrentModel];
mDataModels.erase(mDataModels.find(mCurrentModel));
mCurrentModel = newKey;
updateGUIFromDataModel();
});
connect(mModelListWidget, &EditableListWidget::sigEditItem, this, [=]() {
mModelListWidget->editItem(mModelListWidget->currentItem());
});
connect(mModelListWidget, &EditableListWidget::sigRemoveItem, this, [=]() {
// TODO: fix crash
mDataModels.erase(mDataModels.find(mCurrentModel));
int row = mModelListWidget->currentRow();
auto it = mModelListWidget->takeItem(row);
delete it;
if (mDataModels.size() == 0)
{
addNewEnsemble();
return;
}
QString newKey = mModelListWidget->currentItem()->text();
mCurrentModel = newKey;
updateGUIFromDataModel();
});
// event definition connections
connect(mLatLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setLatitude(
mDataModels[mCurrentModel].setLatitude(
APTEnsDataModel::textFieldToDouble(mLatLineEdit->text()));
mLatLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->latitude()));
mLatLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].latitude()));
});
connect(mLonLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setLongitude(
mDataModels[mCurrentModel].setLongitude(
APTEnsDataModel::textFieldToDouble(mLonLineEdit->text()));
mLonLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->longitude()));
mLonLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].longitude()));
});
connect(mAltLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setAltitude(
mDataModels[mCurrentModel].setAltitude(
APTEnsDataModel::textFieldToDouble(mAltLineEdit->text()));
mAltLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->altitude()));
mAltLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].altitude()));
});
// yield ensemble definition connections
connect(mTotalYieldLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setTotalYield(
mDataModels[mCurrentModel].setTotalYield(
APTEnsDataModel::textFieldToDouble(mTotalYieldLineEdit->text()));
mTotalYieldLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->totalYield()));
mTotalYieldLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].totalYield()));
});
connect(mNumYieldsLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setNumYields(
mDataModels[mCurrentModel].setNumYields(
APTEnsDataModel::textFieldToUnsigned(mNumYieldsLineEdit->text()));
mNumYieldsLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->numYields()));
mNumYieldsLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].numYields()));
});
connect(mMinYieldLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setMinYield(
mDataModels[mCurrentModel].setMinYield(
APTEnsDataModel::textFieldToDouble(mMinYieldLineEdit->text()));
mMinYieldLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->minYield()));
mMinYieldLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].minYield()));
});
connect(mMaxYieldLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setMaxYield(
mDataModels[mCurrentModel].setMaxYield(
APTEnsDataModel::textFieldToDouble(mMaxYieldLineEdit->text()));
mMaxYieldLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->maxYield()));
mMaxYieldLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].maxYield()));
});
connect(mYieldDefineEnsCheckBox, &QCheckBox::stateChanged, this,
......@@ -321,28 +356,28 @@ APTEnsWidget::APTEnsWidget(QWidget *parent)
// height of burst ensemble connections
connect(mHOBLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setHeightOfBurst(
mDataModels[mCurrentModel].setHeightOfBurst(
APTEnsDataModel::textFieldToDouble(mHOBLineEdit->text()));
mHOBLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->heightOfBurst()));
mHOBLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].heightOfBurst()));
});
connect(mNumHOBsLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setNumHOBs(
mDataModels[mCurrentModel].setNumHOBs(
APTEnsDataModel::textFieldToUnsigned(mNumHOBsLineEdit->text()));
mNumHOBsLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->numHOBs()));
mNumHOBsLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].numHOBs()));
});
connect(mMinHOBLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setMinHOB(
mDataModels[mCurrentModel].setMinHOB(
APTEnsDataModel::textFieldToDouble(mMinHOBLineEdit->text()));
mMinHOBLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->minHOB()));
mMinHOBLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].minHOB()));
});
connect(mMaxHOBLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setMaxHOB(
mDataModels[mCurrentModel].setMaxHOB(
APTEnsDataModel::textFieldToDouble(mMaxHOBLineEdit->text()));
mMaxHOBLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->maxHOB()));
mMaxHOBLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].maxHOB()));
});
connect(mHOBDefineEnsCheckBox, &QCheckBox::stateChanged, this,
&APTEnsWidget::hobDefineEnsStateChange);
......@@ -361,21 +396,22 @@ APTEnsWidget::APTEnsWidget(QWidget *parent)
// turbulence ensemble connections
connect(mTurbEnsNumLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setTurbEnsNum(
mDataModels[mCurrentModel].setTurbEnsNum(
APTEnsDataModel::textFieldToUnsigned(mTurbEnsNumLineEdit->text()));
mTurbEnsNumLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->turbEnsNum()));
mTurbEnsNumLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].turbEnsNum()));
});
// meteorology ensemble connections
connect(mMetEnsNumLineEdit, &QLineEdit::editingFinished, this, [=]() {
model->setMetEnsNum(
mDataModels[mCurrentModel].setMetEnsNum(
APTEnsDataModel::textFieldToUnsigned(mMetEnsNumLineEdit->text()));
mMetEnsNumLineEdit->setText(
APTEnsDataModel::doubleToTextField(model->metEnsNum()));
mMetEnsNumLineEdit->setText(APTEnsDataModel::doubleToTextField(
mDataModels[mCurrentModel].metEnsNum()));
});
readFromDataModel();
// add an empty ensemble
addNewEnsemble();
}
void APTEnsWidget::createMenus(QMenuBar *menuBar)
......@@ -410,7 +446,7 @@ void APTEnsWidget::resetWindowTitle()
this->setWindowTitle(windowTitle);
}
void APTEnsWidget::readFromDataModel()
void APTEnsWidget::updateGUIFromDataModel()
{
APTEnsDataModel &model = mDataModels[mCurrentModel];
......@@ -456,12 +492,30 @@ void APTEnsWidget::readFromDataModel()
mMetEnsNumLineEdit->setText(QString::number(model.metEnsNum()));
}
void APTEnsWidget::addNewEnsemble()
{
QString key = "untitled";
int index = 2;
while (mDataModels.keys().contains(key))
{
key = "untitled" + QString::number(index);
index++;
};
mDataModels[key] = APTEnsDataModel();
QListWidgetItem *newItem = new QListWidgetItem(key);
newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
mModelListWidget->addItem(newItem);
mModelListWidget->setCurrentItem(newItem);
mCurrentModel = key;
updateGUIFromDataModel();
}
void APTEnsWidget::openEnsembleEvent()
{
Settings settings;
QString fileName = QFileDialog::getOpenFileName(
this, tr("Open ensemble file"), settings.workspace().path(),
tr("MSTAR project, *.ensz"));
tr("APTEns project, *.aptensz"));
if (!fileName.isEmpty())
{
radix_line("Opening ensemble: " << fileName.toStdString());
......@@ -498,9 +552,9 @@ void APTEnsWidget::saveAsEnsembleEvent()
QString fileName = QFileDialog::getSaveFileName(
this, tr("Save as"), settings.workspace().path(),
tr("MSTAR project, *.mstarz"));
tr("APTEns project, *.aptensz"));
if (fileName.isEmpty()) return;
if (!fileName.endsWith(".mstarz")) fileName.append(".mstarz");
if (!fileName.endsWith(".aptensz")) fileName.append(".aptensz");
QFileInfo fileInfo(fileName);
// mProjectController.save(Manager::instance()->project().get(),
......
......@@ -4,6 +4,7 @@
#include <QCheckBox>
#include <QComboBox>
#include <QGroupBox>
#include <QKeyEvent>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
......@@ -43,6 +44,52 @@ class LineEditFocusSelectAll : public QLineEdit
void focusInEvent(QFocusEvent *event) override;
};
class EditableListWidget : public QListWidget
{
Q_OBJECT
public:
EditableListWidget(QWidget *parent = nullptr)
: QListWidget(parent)
{
}
protected:
void keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Delete:
{
emit sigRemoveItem();
break;
}
case Qt::Key_Enter:
case Qt::Key_Return:
{
emit sigEditItem();
break;
}
default:
QListWidget::keyPressEvent(event);
}
}
void mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::MouseButton::LeftButton)
{
emit sigEditItem();
return;
}
QListWidget::mouseDoubleClickEvent(event);
}
signals:
void sigEditItem();
void sigRemoveItem();
};
class APTEnsWidget : public QWidget
{
Q_OBJECT
......@@ -59,8 +106,8 @@ class APTEnsWidget : public QWidget
CenterTitleGroupBox *mSelectModelBox;
CenterTitleGroupBox *mCurrentModelBox;
QLineEdit *mNewModelLineEdit;
QListWidget *mModelListWidget;
QPushButton *mNewModelButton;
EditableListWidget *mModelListWidget;
CenterTitleGroupBox *mEventDefBox;
CenterTitleGroupBox *mYieldEnsBox;
......@@ -125,7 +172,8 @@ class APTEnsWidget : public QWidget
void createMenus(QMenuBar *menuBar);
void resetWindowTitle();
void readFromDataModel();
void updateGUIFromDataModel();
void addNewEnsemble();
public:
APTEnsWidget(QWidget *parent = nullptr);
......
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