feat(cpn): refactor handling of erroneous models (#7377)
This commit is contained in:
+57
-12
@@ -38,6 +38,17 @@
|
||||
#include <algorithm>
|
||||
#include <ExportableTableView>
|
||||
|
||||
|
||||
void StatusBarIcon::mouseDoubleClickEvent(QMouseEvent * event)
|
||||
{
|
||||
QLabel::mouseDoubleClickEvent(event);
|
||||
emit doubleClicked();
|
||||
}
|
||||
|
||||
/*
|
||||
class MdiChild
|
||||
*/
|
||||
|
||||
MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
||||
QWidget(parent, f),
|
||||
ui(new Ui::MdiChild),
|
||||
@@ -352,7 +363,7 @@ void MdiChild::updateNavigation()
|
||||
cboModelSortOrder->setCurrentIndex(radioData.sortOrder);
|
||||
cboModelSortOrder->blockSignals(false);
|
||||
}
|
||||
action[ACT_GEN_SIM]->setEnabled(!invalidModels());
|
||||
action[ACT_GEN_SIM]->setEnabled(true);
|
||||
action[ACT_GEN_SRT]->setVisible(hasLabels);
|
||||
|
||||
action[ACT_MDL_DEL]->setEnabled(modelsSelected);
|
||||
@@ -375,7 +386,7 @@ void MdiChild::updateNavigation()
|
||||
action[ACT_MDL_WIZ]->setEnabled(singleModelSelected);
|
||||
action[ACT_MDL_DFT]->setEnabled(singleModelSelected && getCurrentModel() != (int)radioData.generalSettings.currModelIndex);
|
||||
action[ACT_MDL_PRT]->setEnabled(singleModelSelected);
|
||||
action[ACT_MDL_SIM]->setEnabled(singleModelSelected && !invalidModels());
|
||||
action[ACT_MDL_SIM]->setEnabled(singleModelSelected);
|
||||
action[ACT_MDL_ERR]->setEnabled(singleModelSelected && radioData.models[getCurrentModel()].modelErrors);
|
||||
|
||||
emit navigationUpdated();
|
||||
@@ -1285,12 +1296,35 @@ void MdiChild::setDefault()
|
||||
|
||||
void MdiChild::radioSimulate()
|
||||
{
|
||||
// safeguard as the menu actions are enabled
|
||||
int cnt = radioData.invalidModels();
|
||||
|
||||
if (cnt) {
|
||||
QMessageBox::critical(this, tr("Simulate Radio"),
|
||||
tr("Operation aborted: %1 models have errors that may affect simulation.\n%2")
|
||||
.arg(cnt)
|
||||
.arg(radioData.modelErrorsList().join("\n")));
|
||||
return;
|
||||
}
|
||||
|
||||
startSimulation(this, radioData, -1);
|
||||
}
|
||||
|
||||
void MdiChild::modelSimulate()
|
||||
{
|
||||
startSimulation(this, radioData, getCurrentModel());
|
||||
int currMdlIdx = getCurrentModel();
|
||||
|
||||
if (currMdlIdx > -1 && !radioData.models[currMdlIdx].isValid()) {
|
||||
QMessageBox::critical(this, tr("Simulate Model"),
|
||||
tr("Operation aborted: selected model has errors that may affect simulation.\n%1")
|
||||
.arg(radioData.models[currMdlIdx].errorsList().join("\n")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currMdlIdx < 0)
|
||||
radioSimulate();
|
||||
else
|
||||
startSimulation(this, radioData, getCurrentModel());
|
||||
}
|
||||
|
||||
void MdiChild::newFile(bool useProfileSettings)
|
||||
@@ -1541,11 +1575,14 @@ int MdiChild::askQuestion(const QString & msg, QMessageBox::StandardButtons butt
|
||||
|
||||
void MdiChild::writeSettings(StatusDialog * status, bool toRadio)
|
||||
{
|
||||
// safeguard as the menu actions should be disabled
|
||||
// safeguard as the menu actions are enabled
|
||||
int cnt = radioData.invalidModels();
|
||||
|
||||
if (cnt) {
|
||||
QMessageBox::critical(this, tr("Write Models and Settings"), tr("Operation aborted as %1 models have significant errors that may affect model operation.").arg(cnt));
|
||||
QMessageBox::critical(this, tr("Write Models and Settings"),
|
||||
tr("Operation aborted as %1 models have significant errors that may affect model operation.\n%2")
|
||||
.arg(cnt)
|
||||
.arg(radioData.modelErrorsList().join("\n")));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1915,9 +1952,14 @@ QAction * MdiChild::actionsSeparator()
|
||||
return act;
|
||||
}
|
||||
|
||||
bool MdiChild::invalidModels()
|
||||
int MdiChild::invalidModels()
|
||||
{
|
||||
return (bool)radioData.invalidModels();
|
||||
return radioData.invalidModels();
|
||||
}
|
||||
|
||||
QStringList MdiChild::modelErrorsList()
|
||||
{
|
||||
return radioData.modelErrorsList();
|
||||
}
|
||||
|
||||
void MdiChild::modelShowErrors()
|
||||
@@ -1938,7 +1980,7 @@ void MdiChild::setupStatusBar()
|
||||
ui->statusBarLayout->addWidget(statusBar);
|
||||
QLabel *lbl = new QLabel(tr("Models status"));
|
||||
statusBar->addPermanentWidget(lbl);
|
||||
statusBarIcon = new QLabel();
|
||||
statusBarIcon = new StatusBarIcon(this);
|
||||
statusBar->addPermanentWidget(statusBarIcon);
|
||||
statusBarCount = new QLabel();
|
||||
statusBar->addPermanentWidget(statusBarCount);
|
||||
@@ -1949,13 +1991,16 @@ void MdiChild::updateStatusBar()
|
||||
QPixmap p;
|
||||
QLabel cnt;
|
||||
int invalid = radioData.invalidModels();
|
||||
disconnect(statusBarIcon, &StatusBarIcon::doubleClicked, nullptr, nullptr);
|
||||
|
||||
if (!invalidModels()) {
|
||||
statusBarIcon->setToolTip(tr("No errors"));
|
||||
p.load(":/images/png/tick-green.png");
|
||||
}
|
||||
else {
|
||||
statusBarIcon->setToolTip(tr("Errors"));
|
||||
} else {
|
||||
statusBarIcon->setToolTip(tr("Double click to display errors"));
|
||||
connect(statusBarIcon, &StatusBarIcon::doubleClicked, [this] () {
|
||||
QMessageBox::critical(this, tr("Models Status"), radioData.modelErrorsList().join("\n"));
|
||||
});
|
||||
p.load(":/images/png/cross-red.png");
|
||||
cnt.setText(QString::number(invalid));
|
||||
}
|
||||
@@ -2039,4 +2084,4 @@ void MdiChild::modelImport()
|
||||
refresh();
|
||||
setModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user