(fw,cpn) Support commas in labels
Remove more cpn unused code
This commit is contained in:
@@ -106,6 +106,8 @@ void RadioData::convert(RadioDataConversionState & cstate)
|
||||
|
||||
void RadioData::addLabel(QString label)
|
||||
{
|
||||
label.replace("/c",",");
|
||||
label.replace("//","/");
|
||||
if(labels.indexOf(label) == -1)
|
||||
labels.append(label);
|
||||
}
|
||||
@@ -113,12 +115,16 @@ void RadioData::addLabel(QString label)
|
||||
bool RadioData::deleteLabel(QString label)
|
||||
{
|
||||
bool deleted = false;
|
||||
QString csvLabel = label;
|
||||
csvLabel.replace("/","//");
|
||||
csvLabel.replace(",","/c");
|
||||
|
||||
// Remove labels in the models
|
||||
for(auto& model : models) {
|
||||
QStringList modelLabels = QString(model.labels).split(',',QString::SkipEmptyParts);
|
||||
if(modelLabels.indexOf(label) >= 0)
|
||||
if(modelLabels.indexOf(csvLabel) >= 0)
|
||||
deleted = true;
|
||||
modelLabels.removeAll(label);
|
||||
modelLabels.removeAll(csvLabel);
|
||||
strcpy(model.labels, QString(modelLabels.join(',')).toLocal8Bit().data());
|
||||
}
|
||||
|
||||
@@ -143,6 +149,13 @@ bool RadioData::renameLabel(QString from, QString to)
|
||||
{
|
||||
bool success = true;
|
||||
int lengthdiff = to.size() - from.size();
|
||||
QString csvFrom = from;
|
||||
QString csvTo = to;
|
||||
csvFrom.replace("/","//");
|
||||
csvFrom.replace(",","/c");
|
||||
csvTo.replace("/","//");
|
||||
csvTo.replace(",","/c");
|
||||
|
||||
|
||||
// Check that rename is possible, not too long
|
||||
for(auto& model : models) {
|
||||
@@ -153,10 +166,12 @@ bool RadioData::renameLabel(QString from, QString to)
|
||||
if(success) {
|
||||
for(auto& model : models) {
|
||||
QStringList modelLabels = QString(model.labels).split(',',QString::SkipEmptyParts);
|
||||
int ind = modelLabels.indexOf(from); // TOOD: Make sure it will fit
|
||||
int ind = modelLabels.indexOf(csvFrom);
|
||||
if(ind != -1) {
|
||||
modelLabels.replace(ind, to);
|
||||
strcpy(model.labels, QString(modelLabels.join(',')).toLocal8Bit().data());
|
||||
modelLabels.replace(ind, csvTo);
|
||||
QString outputcsv = QString(modelLabels.join(','));
|
||||
if(outputcsv.toLocal8Bit().size() < (int)sizeof(model.labels));
|
||||
strcpy(model.labels, outputcsv.toLocal8Bit().data());
|
||||
}
|
||||
}
|
||||
int ind = labels.indexOf(from);
|
||||
@@ -178,6 +193,9 @@ bool RadioData::addLabelToModel(int index, QString label)
|
||||
{
|
||||
if(index >= models.size()) return false;
|
||||
|
||||
label.replace("/","//");
|
||||
label.replace(",","/c");
|
||||
|
||||
char *modelLabelCsv = models[index].labels;
|
||||
// Make sure it will fit
|
||||
if(strlen(modelLabelCsv) + label.size() + 1 < sizeof(models[index].labels)-1) {
|
||||
@@ -194,6 +212,8 @@ bool RadioData::addLabelToModel(int index, QString label)
|
||||
bool RadioData::removeLabelFromModel(int index, QString label)
|
||||
{
|
||||
if(index >= models.size()) return false;
|
||||
label.replace("/","//");
|
||||
label.replace(",","/c");
|
||||
|
||||
char *modelLabelCsv = models[index].labels;
|
||||
QStringList modelLabels = QString(modelLabelCsv).split(',',QString::SkipEmptyParts);
|
||||
|
||||
@@ -52,7 +52,7 @@ bool LabelsModel::setData(const QModelIndex &index, const QVariant &value, int r
|
||||
return true;
|
||||
} else if(role == Qt::EditRole) {
|
||||
QString replFrom = labels[index.row()].label;
|
||||
QString replTo = value.toString().replace(',','_'); // Don't allow comma, replace with _
|
||||
QString replTo = value.toString();
|
||||
if(radioData->labels.indexOf(replTo) == -1) { // Don't allow duplicates
|
||||
bool modelsChanged = radioData->renameLabel(replFrom,replTo);
|
||||
labels[index.row()].label = replTo;
|
||||
@@ -84,6 +84,8 @@ QVariant LabelsModel::data(const QModelIndex &index, int role) const
|
||||
if(index.column() == 0 && selectedModel >= 0 &&
|
||||
selectedModel < (int)radioData->models.size()) {
|
||||
QStringList modelLabels = QString(radioData->models.at(selectedModel).labels).split(',',QString::SkipEmptyParts);
|
||||
label.replace("/","//");
|
||||
label.replace(",","/c");
|
||||
return modelLabels.indexOf(label)==-1?Qt::Unchecked:Qt::Checked;
|
||||
} else if (index.column() == 0 && selectedModel == -1) {
|
||||
return Qt::Unchecked;
|
||||
|
||||
@@ -665,76 +665,6 @@ void MdiChild::onFirmwareChanged()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Categories CRUD
|
||||
*/
|
||||
|
||||
/*
|
||||
void MdiChild::categoryAdd()
|
||||
{
|
||||
// Translators do NOT use accent for this, this is the default category name on Horus.
|
||||
CategoryData category(qPrintable(tr("New category")));
|
||||
radioData.categories.push_back(category);
|
||||
setModified();
|
||||
QModelIndex idx = modelsListModel->getIndexForCategory(radioData.categories.size()-1);
|
||||
if (idx.isValid()) {
|
||||
ui->modelsList->scrollTo(idx);
|
||||
ui->modelsList->setCurrentIndex(idx);
|
||||
ui->modelsList->edit(idx);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: this does not refresh the data/view, need to call setModified() at some point afterwards.
|
||||
bool MdiChild::deleteCategory(int categoryIndex, QString * error)
|
||||
{
|
||||
if (categoryIndex < 0)
|
||||
categoryIndex = modelsListModel->getCategoryIndex(getCurrentIndex());
|
||||
if (categoryIndex < 0 || categoryIndex >= (int)radioData.categories.size()) {
|
||||
if (error)
|
||||
*error = tr("Category index out of range.");
|
||||
return false;
|
||||
}
|
||||
if (radioData.categories.size() <= 1) {
|
||||
if (error)
|
||||
*error = tr("Cannot delete the last category.");
|
||||
return false;
|
||||
}
|
||||
if (countUsedModels(categoryIndex)) {
|
||||
if (error)
|
||||
*error = tr("This category is not empty!");
|
||||
return false;
|
||||
}
|
||||
|
||||
radioData.categories.erase(radioData.categories.begin() + categoryIndex);
|
||||
|
||||
for (unsigned i=0; i < radioData.models.size(); ++i) {
|
||||
ModelData & model = radioData.models.at(i);
|
||||
if (model.used && model.category > categoryIndex) {
|
||||
--radioData.models[i].category;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MdiChild::deleteSelectedCats()
|
||||
{
|
||||
bool modified = false;
|
||||
QString error;
|
||||
QVector<int> cats = getSelectedCategories();
|
||||
std::sort(cats.begin(), cats.end());
|
||||
std::reverse(cats.begin(), cats.end());
|
||||
foreach (const int cat, cats) {
|
||||
error.clear();
|
||||
if (deleteCategory(cat, &error))
|
||||
modified = true;
|
||||
else
|
||||
showWarning(error);
|
||||
}
|
||||
if (modified)
|
||||
setModified();
|
||||
}*/
|
||||
|
||||
/*
|
||||
* Models CRUD
|
||||
*/
|
||||
|
||||
@@ -630,19 +630,10 @@ void ModelsListModel::onRowsRemoved(const QModelIndex & parent, int first, int l
|
||||
|
||||
void ModelsListModel::refresh()
|
||||
{
|
||||
ModelListItem * defaultCategoryItem = NULL;
|
||||
|
||||
this->blockSignals(true); // make sure onRowsRemoved is not triggered
|
||||
removeRows(0, rowCount());
|
||||
this->blockSignals(false);
|
||||
|
||||
/*if (hasCategories) {
|
||||
for (unsigned i = 0; i < radioData->categories.size(); i++) {
|
||||
ModelListItem * current = rootItem->appendChild(i, -1);
|
||||
current->setData(0, QString(radioData->categories[i].name));
|
||||
}
|
||||
}*/
|
||||
|
||||
for (unsigned i = 0; i < radioData->models.size(); i++) {
|
||||
ModelData & model = radioData->models[i];
|
||||
int currentColumn = 0;
|
||||
|
||||
Reference in New Issue
Block a user