Skip to content

Commit

Permalink
fix(cpn): inputs and mixes must have source (#5798)
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower authored Feb 6, 2025
1 parent 0325bd7 commit ec3c5bf
Show file tree
Hide file tree
Showing 19 changed files with 481 additions and 21 deletions.
3 changes: 3 additions & 0 deletions companion/src/companion.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<file>images/track.png</file>
<file>images/track0.png</file>
<file>images/taranison.png</file>
<file>images/svg/circle-green.svg</file>
<file>images/svg/circle-orange.svg</file>
<file>images/svg/circle-red.svg</file>
<file>images/simulator/icons/svg/arrow_click.svg</file>
<file>images/simulator/icons/svg/camera.svg</file>
<file>images/simulator/icons/svg/camera-active.svg</file>
Expand Down
60 changes: 60 additions & 0 deletions companion/src/firmwares/modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "adjustmentreference.h"
#include "compounditemmodels.h"

#include <QMessageBox>

ModelData::ModelData()
{
clear();
Expand Down Expand Up @@ -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 changes: 8 additions & 0 deletions companion/src/firmwares/modeldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions companion/src/firmwares/radiodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 0 deletions companion/src/firmwares/radiodata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
48 changes: 48 additions & 0 deletions companion/src/images/originals/circle-green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions companion/src/images/originals/circle-orange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions companion/src/images/originals/circle-red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions companion/src/images/svg/circle-green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions companion/src/images/svg/circle-orange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ec3c5bf

Please sign in to comment.