fix(cpn): Preserve sort order and selected labels (#3580)

* fix(cpn): read/write models Sort Order (based on work by dlktdr)

* fix(cpn): read and write labels and selected
This commit is contained in:
Neil Horne
2023-05-23 13:41:41 +10:00
committed by GitHub
parent 48e5d141aa
commit ad5d8e190e
6 changed files with 96 additions and 34 deletions
+29 -9
View File
@@ -22,7 +22,8 @@
#include "radiodataconversionstate.h"
#include "eeprominterface.h"
RadioData::RadioData()
RadioData::RadioData() :
sortOrder(0)
{
models.resize(getCurrentFirmware()->getCapability(Models));
}
@@ -120,8 +121,11 @@ void RadioData::addLabel(QString label)
output.truncate(truncateAt);
}
label = QString(output);
if (labels.indexOf(label) == -1)
labels.append(label);
if (indexOfLabel(label) < 0) {
LabelData ld = { label, false };
labels.append(ld);
}
}
bool RadioData::deleteLabel(QString label)
@@ -139,7 +143,9 @@ bool RadioData::deleteLabel(QString label)
}
// Remove the label from the global list
labels.removeAll(label);
int index = indexOfLabel(label);
if (index > -1)
labels.remove(index);
// If no labels remain, add a Favorites one
if (!labels.size()) {
@@ -151,7 +157,7 @@ bool RadioData::deleteLabel(QString label)
bool RadioData::deleteLabel(int index)
{
if (index >= labels.size()) return false;
QString modelLabel = labels.at(index);
QString modelLabel = labels.at(index).name;
return deleteLabel(modelLabel);
}
@@ -188,9 +194,9 @@ bool RadioData::renameLabel(QString from, QString to)
}
}
}
int ind = labels.indexOf(from);
int ind = indexOfLabel(from);
if (ind != -1) {
labels.replace(ind, to);
labels[ind].name = to;
}
}
return success;
@@ -199,7 +205,7 @@ bool RadioData::renameLabel(QString from, QString to)
bool RadioData::renameLabel(int index, QString to)
{
if (index >= labels.size()) return false;
QString from = labels.at(index);
QString from = labels.at(index).name;
return renameLabel(from, to);
}
@@ -211,7 +217,7 @@ void RadioData::swapLabel(int indFrom, int indTo)
indFrom < 0 ||
indTo < 0)
return;
QString tmplbl = labels.at(indFrom);
LabelData tmplbl = labels.at(indFrom);
labels.replace(indFrom, labels.at(indTo));
labels.replace(indTo, tmplbl);
}
@@ -258,6 +264,20 @@ void RadioData::addLabelsFromModels()
}
}
int RadioData::indexOfLabel(QString & label) const
{
int index = -1;
for (int i = 0; i < labels.size(); i++) {
if (labels.at(i).name == label) {
index = i;
break;
}
}
return index;
}
QStringList RadioData::fromCSV(const QString &csv)
{
QStringList lbls = QString(csv).split(',',QString::SkipEmptyParts);