feat(cpn): refactor handling of erroneous models (#7377)
This commit is contained in:
@@ -2128,7 +2128,7 @@ void ModelData::validate()
|
|||||||
|
|
||||||
QStringList ModelData::errorsList()
|
QStringList ModelData::errorsList()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list { "" };
|
||||||
|
|
||||||
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
|
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
|
||||||
if (!expoData[i].isEmpty() && expoData[i].srcRaw == SOURCE_TYPE_NONE)
|
if (!expoData[i].isEmpty() && expoData[i].srcRaw == SOURCE_TYPE_NONE)
|
||||||
|
|||||||
@@ -358,3 +358,18 @@ int RadioData::invalidModels()
|
|||||||
|
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList RadioData::modelErrorsList()
|
||||||
|
{
|
||||||
|
QStringList ret;
|
||||||
|
|
||||||
|
for(auto &model: models) {
|
||||||
|
if (!model.isValid()) {
|
||||||
|
ret.append("");
|
||||||
|
ret.append(model.name);
|
||||||
|
ret.append(model.errorsList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class RadioData {
|
|||||||
QString getNextModelFilename();
|
QString getNextModelFilename();
|
||||||
void validateModels();
|
void validateModels();
|
||||||
int invalidModels();
|
int invalidModels();
|
||||||
|
QStringList modelErrorsList();
|
||||||
|
|
||||||
static QString modelSortOrderToString(int value);
|
static QString modelSortOrderToString(int value);
|
||||||
static AbstractStaticItemModel * modelSortOrderItemModel();
|
static AbstractStaticItemModel * modelSortOrderItemModel();
|
||||||
|
|||||||
@@ -677,9 +677,9 @@ void MainWindow::updateMenus()
|
|||||||
saveAsAct->setEnabled(activeChild);
|
saveAsAct->setEnabled(activeChild);
|
||||||
closeAct->setEnabled(activeChild);
|
closeAct->setEnabled(activeChild);
|
||||||
compareAct->setEnabled(activeChild);
|
compareAct->setEnabled(activeChild);
|
||||||
writeSettingsAct->setEnabled(activeChild && !activeMdiChild()->invalidModels());
|
writeSettingsAct->setEnabled(activeChild);
|
||||||
readSettingsAct->setEnabled(true);
|
readSettingsAct->setEnabled(true);
|
||||||
writeSettingsSDPathAct->setEnabled(activeChild && isSDPathValid() && !activeMdiChild()->invalidModels());
|
writeSettingsSDPathAct->setEnabled(activeChild && isSDPathValid());
|
||||||
readSettingsSDPathAct->setEnabled(isSDPathValid());
|
readSettingsSDPathAct->setEnabled(isSDPathValid());
|
||||||
writeBUToRadioAct->setEnabled(false);
|
writeBUToRadioAct->setEnabled(false);
|
||||||
readBUToFileAct->setEnabled(false);
|
readBUToFileAct->setEnabled(false);
|
||||||
@@ -1518,12 +1518,22 @@ bool MainWindow::readSettingsFromSDPath(const QString & filename)
|
|||||||
|
|
||||||
void MainWindow::writeSettingsSDPath()
|
void MainWindow::writeSettingsSDPath()
|
||||||
{
|
{
|
||||||
StatusDialog *status = new StatusDialog(this, tr("Writing models and settings to SD path"), tr("In progress..."), 400);
|
if (activeMdiChild()) {
|
||||||
|
int cnt = activeMdiChild()->invalidModels();
|
||||||
|
|
||||||
if (activeMdiChild())
|
if (cnt) {
|
||||||
|
QMessageBox::critical(this, tr("Write Models and Settings to SD Path"),
|
||||||
|
tr("Operation aborted: %1 models have errors that may affect operation.\n%2")
|
||||||
|
.arg(cnt)
|
||||||
|
.arg(activeMdiChild()->modelErrorsList().join("\n")));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusDialog *status = new StatusDialog(this, tr("Writing models and settings to SD path"), tr("In progress..."), 400);
|
||||||
activeMdiChild()->writeSettings(status, false);
|
activeMdiChild()->writeSettings(status, false);
|
||||||
|
delete status;
|
||||||
delete status;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::isSDPathValid()
|
bool MainWindow::isSDPathValid()
|
||||||
|
|||||||
+57
-12
@@ -38,6 +38,17 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ExportableTableView>
|
#include <ExportableTableView>
|
||||||
|
|
||||||
|
|
||||||
|
void StatusBarIcon::mouseDoubleClickEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
QLabel::mouseDoubleClickEvent(event);
|
||||||
|
emit doubleClicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
class MdiChild
|
||||||
|
*/
|
||||||
|
|
||||||
MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
MdiChild::MdiChild(QWidget * parent, QWidget * parentWin, Qt::WindowFlags f):
|
||||||
QWidget(parent, f),
|
QWidget(parent, f),
|
||||||
ui(new Ui::MdiChild),
|
ui(new Ui::MdiChild),
|
||||||
@@ -352,7 +363,7 @@ void MdiChild::updateNavigation()
|
|||||||
cboModelSortOrder->setCurrentIndex(radioData.sortOrder);
|
cboModelSortOrder->setCurrentIndex(radioData.sortOrder);
|
||||||
cboModelSortOrder->blockSignals(false);
|
cboModelSortOrder->blockSignals(false);
|
||||||
}
|
}
|
||||||
action[ACT_GEN_SIM]->setEnabled(!invalidModels());
|
action[ACT_GEN_SIM]->setEnabled(true);
|
||||||
action[ACT_GEN_SRT]->setVisible(hasLabels);
|
action[ACT_GEN_SRT]->setVisible(hasLabels);
|
||||||
|
|
||||||
action[ACT_MDL_DEL]->setEnabled(modelsSelected);
|
action[ACT_MDL_DEL]->setEnabled(modelsSelected);
|
||||||
@@ -375,7 +386,7 @@ void MdiChild::updateNavigation()
|
|||||||
action[ACT_MDL_WIZ]->setEnabled(singleModelSelected);
|
action[ACT_MDL_WIZ]->setEnabled(singleModelSelected);
|
||||||
action[ACT_MDL_DFT]->setEnabled(singleModelSelected && getCurrentModel() != (int)radioData.generalSettings.currModelIndex);
|
action[ACT_MDL_DFT]->setEnabled(singleModelSelected && getCurrentModel() != (int)radioData.generalSettings.currModelIndex);
|
||||||
action[ACT_MDL_PRT]->setEnabled(singleModelSelected);
|
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);
|
action[ACT_MDL_ERR]->setEnabled(singleModelSelected && radioData.models[getCurrentModel()].modelErrors);
|
||||||
|
|
||||||
emit navigationUpdated();
|
emit navigationUpdated();
|
||||||
@@ -1285,12 +1296,35 @@ void MdiChild::setDefault()
|
|||||||
|
|
||||||
void MdiChild::radioSimulate()
|
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);
|
startSimulation(this, radioData, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MdiChild::modelSimulate()
|
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)
|
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)
|
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();
|
int cnt = radioData.invalidModels();
|
||||||
|
|
||||||
if (cnt) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1915,9 +1952,14 @@ QAction * MdiChild::actionsSeparator()
|
|||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MdiChild::invalidModels()
|
int MdiChild::invalidModels()
|
||||||
{
|
{
|
||||||
return (bool)radioData.invalidModels();
|
return radioData.invalidModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList MdiChild::modelErrorsList()
|
||||||
|
{
|
||||||
|
return radioData.modelErrorsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MdiChild::modelShowErrors()
|
void MdiChild::modelShowErrors()
|
||||||
@@ -1938,7 +1980,7 @@ void MdiChild::setupStatusBar()
|
|||||||
ui->statusBarLayout->addWidget(statusBar);
|
ui->statusBarLayout->addWidget(statusBar);
|
||||||
QLabel *lbl = new QLabel(tr("Models status"));
|
QLabel *lbl = new QLabel(tr("Models status"));
|
||||||
statusBar->addPermanentWidget(lbl);
|
statusBar->addPermanentWidget(lbl);
|
||||||
statusBarIcon = new QLabel();
|
statusBarIcon = new StatusBarIcon(this);
|
||||||
statusBar->addPermanentWidget(statusBarIcon);
|
statusBar->addPermanentWidget(statusBarIcon);
|
||||||
statusBarCount = new QLabel();
|
statusBarCount = new QLabel();
|
||||||
statusBar->addPermanentWidget(statusBarCount);
|
statusBar->addPermanentWidget(statusBarCount);
|
||||||
@@ -1949,13 +1991,16 @@ void MdiChild::updateStatusBar()
|
|||||||
QPixmap p;
|
QPixmap p;
|
||||||
QLabel cnt;
|
QLabel cnt;
|
||||||
int invalid = radioData.invalidModels();
|
int invalid = radioData.invalidModels();
|
||||||
|
disconnect(statusBarIcon, &StatusBarIcon::doubleClicked, nullptr, nullptr);
|
||||||
|
|
||||||
if (!invalidModels()) {
|
if (!invalidModels()) {
|
||||||
statusBarIcon->setToolTip(tr("No errors"));
|
statusBarIcon->setToolTip(tr("No errors"));
|
||||||
p.load(":/images/png/tick-green.png");
|
p.load(":/images/png/tick-green.png");
|
||||||
}
|
} else {
|
||||||
else {
|
statusBarIcon->setToolTip(tr("Double click to display errors"));
|
||||||
statusBarIcon->setToolTip(tr("Errors"));
|
connect(statusBarIcon, &StatusBarIcon::doubleClicked, [this] () {
|
||||||
|
QMessageBox::critical(this, tr("Models Status"), radioData.modelErrorsList().join("\n"));
|
||||||
|
});
|
||||||
p.load(":/images/png/cross-red.png");
|
p.load(":/images/png/cross-red.png");
|
||||||
cnt.setText(QString::number(invalid));
|
cnt.setText(QString::number(invalid));
|
||||||
}
|
}
|
||||||
@@ -2039,4 +2084,4 @@ void MdiChild::modelImport()
|
|||||||
refresh();
|
refresh();
|
||||||
setModified();
|
setModified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,21 @@ class MdiChild;
|
|||||||
class LabelsDelegate;
|
class LabelsDelegate;
|
||||||
class LabelsProxy;
|
class LabelsProxy;
|
||||||
|
|
||||||
|
class StatusBarIcon : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
StatusBarIcon(QWidget * parent) : QLabel(parent) {}
|
||||||
|
virtual ~StatusBarIcon() {}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void doubleClicked();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void mouseDoubleClickEvent(QMouseEvent * event);
|
||||||
|
};
|
||||||
|
|
||||||
class MdiChild : public QWidget
|
class MdiChild : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -91,7 +106,8 @@ class MdiChild : public QWidget
|
|||||||
QList<QAction *> getModelActions();
|
QList<QAction *> getModelActions();
|
||||||
QList<QAction *> getLabelsActions();
|
QList<QAction *> getLabelsActions();
|
||||||
QAction * getAction(const Actions type);
|
QAction * getAction(const Actions type);
|
||||||
bool invalidModels();
|
int invalidModels();
|
||||||
|
QStringList modelErrorsList();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void newFile(bool useProfileSettings = false);
|
void newFile(bool useProfileSettings = false);
|
||||||
@@ -228,7 +244,7 @@ class MdiChild : public QWidget
|
|||||||
QToolBar * labelsToolbar;
|
QToolBar * labelsToolbar;
|
||||||
QLabel *lblLabels;
|
QLabel *lblLabels;
|
||||||
QStatusBar *statusBar;
|
QStatusBar *statusBar;
|
||||||
QLabel *statusBarIcon;
|
StatusBarIcon *statusBarIcon;
|
||||||
QLabel *statusBarCount;
|
QLabel *statusBarCount;
|
||||||
|
|
||||||
Firmware * firmware;
|
Firmware * firmware;
|
||||||
|
|||||||
@@ -168,5 +168,12 @@ void ModelEdit::onTabIndexChanged(int index)
|
|||||||
|
|
||||||
void ModelEdit::launchSimulation()
|
void ModelEdit::launchSimulation()
|
||||||
{
|
{
|
||||||
|
if (!radioData.models[modelId].isValid()) {
|
||||||
|
QMessageBox::critical(this, tr("Simulate Model"),
|
||||||
|
tr("Operation aborted: model has errors that may affect simulation.\n%1")
|
||||||
|
.arg(radioData.models[modelId].errorsList().join("\n")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
startSimulation(this, radioData, modelId);
|
startSimulation(this, radioData, modelId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user