fix(cpn): inputs and mixes must have source (#5798)

This commit is contained in:
Neil Horne
2025-02-06 12:05:31 +10:00
committed by GitHub
parent 0325bd776b
commit ec3c5bf188
19 changed files with 481 additions and 21 deletions
+60
View File
@@ -29,6 +29,8 @@
#include "adjustmentreference.h"
#include "compounditemmodels.h"
#include <QMessageBox>
ModelData::ModelData()
{
clear();
@@ -1924,3 +1926,61 @@ int ModelData::getCustomScreensCount() const
return cnt;
}
void ModelData::validate()
{
modelErrors = false;
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
if (!expoData[i].isEmpty() && expoData[i].srcRaw == SOURCE_TYPE_NONE) {
modelErrors = true;
return;
}
}
for (int i = 0; i < CPN_MAX_MIXERS; i++) {
if (!mixData[i].isEmpty() && mixData[i].srcRaw == SOURCE_TYPE_NONE) {
modelErrors = true;
return;
}
}
}
QStringList ModelData::errorsList()
{
QStringList list;
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
if (!expoData[i].isEmpty() && expoData[i].srcRaw == SOURCE_TYPE_NONE)
list.append(tr("Error - Input %1 Line %2 %3").arg(expoData[i].chn + 1).arg(getInputLine(i)).arg(tr("has no source")));
}
for (int i = 0; i < CPN_MAX_MIXERS; i++) {
if (!mixData[i].isEmpty() && mixData[i].srcRaw == SOURCE_TYPE_NONE)
list.append(tr("Error - Mix %1 Line %2 %3").arg(mixData[i].destCh).arg(getMixLine(i)).arg(tr("has no source")));
}
return list;
}
int ModelData::getMixLine(int index) const
{
int cnt = 1;
for (int i = index - 1; i >= 0 && mixData[i].destCh == mixData[index].destCh; i--)
cnt++;
return cnt;
}
int ModelData::getInputLine(int index) const
{
int cnt = 1;
for (int i = 0; i < index; i++) {
if (expoData[i].chn == expoData[index].chn)
cnt++;
}
return cnt;
}
+8
View File
@@ -140,6 +140,7 @@ class ModelData {
char labels[100];
int modelIndex; // Companion only, temporary index position managed by data model.
bool modelUpdated; // Companion only, used to highlight if changed in models list
bool modelErrors; // Companion only, used to highlight if data errors in models list
TimerData timers[CPN_MAX_TIMERS];
bool noGlobalFunctions;
@@ -366,11 +367,18 @@ class ModelData {
static AbstractStaticItemModel * funcSwitchStartItemModel();
int getCustomScreensCount() const;
bool hasErrors() { return modelErrors; }
bool isValid() { return !hasErrors(); }
void validate();
QStringList errorsList();
protected:
void removeGlobalVar(int & var);
private:
int getMixLine(int index) const;
int getInputLine(int index) const;
QVector<UpdateReferenceParams> *updRefList = nullptr;
struct UpdateReferenceInfo
+16
View File
@@ -343,3 +343,19 @@ AbstractStaticItemModel * RadioData::modelSortOrderItemModel()
mdl->loadItemList();
return mdl;
}
void RadioData::validateModels()
{
for(auto &model: models)
model.validate();
}
int RadioData::invalidModels()
{
int cnt = 0;
for(auto &model: models)
cnt += model.isValid() ? 0 : 1;
return cnt;
}
+2
View File
@@ -66,6 +66,8 @@ class RadioData {
void setCurrentModel(unsigned int index);
void fixModelFilenames();
QString getNextModelFilename();
void validateModels();
int invalidModels();
static QString modelSortOrderToString(int value);
static AbstractStaticItemModel * modelSortOrderItemModel();