fix(cpn): Inability to paste model to empty slot on B&W radios (#3371)

* Fix(cpn) - paste model to empty slot non-labels radios
Chore(cpn) - remove traces of categories

* Turn off debug msgs
This commit is contained in:
Neil Horne
2023-03-27 13:34:00 +10:00
committed by GitHub
parent ebef94d993
commit 45e76f3a3d
5 changed files with 32 additions and 70 deletions
+10 -38
View File
@@ -23,18 +23,16 @@
ModelListItem::ModelListItem(const QVector<QVariant> & itemData):
itemData(itemData),
parentItem(NULL),
categoryIndex(-1),
modelIndex(-1),
flags(0),
highlightRX(false)
{
}
ModelListItem::ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex):
ModelListItem::ModelListItem(ModelListItem * parent, int modelIndex):
ModelListItem(QVector<QVariant>(parent->columnCount()))
{
setParent(parent);
setCategoryIndex(categoryIndex);
setModelIndex(modelIndex);
}
@@ -71,16 +69,16 @@ QVariant ModelListItem::data(int column) const
return itemData.value(column);
}
ModelListItem *ModelListItem::insertChild(const int row, int categoryIndex, int modelIndex)
ModelListItem *ModelListItem::insertChild(const int row, int modelIndex)
{
ModelListItem * item = new ModelListItem(this, categoryIndex, modelIndex);
ModelListItem * item = new ModelListItem(this, modelIndex);
childItems.insert(row, item);
return item;
}
ModelListItem * ModelListItem::appendChild(int categoryIndex, int modelIndex)
ModelListItem * ModelListItem::appendChild(int modelIndex)
{
return insertChild(childItems.size(), categoryIndex, modelIndex);
return insertChild(childItems.size(), modelIndex);
}
bool ModelListItem::removeChildren(int position, int count)
@@ -97,7 +95,7 @@ bool ModelListItem::removeChildren(int position, int count)
bool ModelListItem::insertChildren(int row, int count)
{
for (int i=0; i < count; ++i) {
insertChild(row + i, -1, -1);
insertChild(row + i, -1);
}
return true;
}
@@ -119,11 +117,6 @@ void ModelListItem::setFlag(const quint16 & flag, const bool on)
flags &= ~flag;
}
bool ModelListItem::isCategory() const
{
return (modelIndex < 0 && categoryIndex > -1);
}
bool ModelListItem::isModel() const
{
return (modelIndex > -1);
@@ -443,10 +436,8 @@ void ModelsListModel::encodeModelsData(const QModelIndexList & indexes, QByteArr
{
foreach (const QModelIndex &index, indexes) {
if (index.isValid() && index.column() == 0) {
if (!getItem(index)->isCategory()) { // TODO: encode categoreis also
data->append('M');
data->append((char *)&radioData->models[getModelIndex(index)], sizeof(ModelData));
}
data->append('M');
data->append((char *)&radioData->models[getModelIndex(index)], sizeof(ModelData));
}
}
}
@@ -555,35 +546,16 @@ QModelIndex ModelsListModel::getIndexForModel(const int modelIndex, QModelIndex
return QModelIndex();
}
QModelIndex ModelsListModel::getIndexForCategory(const int categoryIndex)
{
for (int i = 0; i < rowCount(); ++i) {
if (getItem(index(i, 0))->getCategoryIndex() == categoryIndex)
return index(i, 0);
}
return QModelIndex();
}
int ModelsListModel::getModelIndex(const QModelIndex & index) const
{
return getItem(index)->getModelIndex();
}
int ModelsListModel::getCategoryIndex(const QModelIndex & index) const
{
return getItem(index)->getCategoryIndex();
}
int ModelsListModel::rowNumber(const QModelIndex & index) const
{
return getItem(index)->childNumber();
}
bool ModelsListModel::isCategoryType(const QModelIndex & index) const
{
return index.isValid() && getItem(index)->isCategory();
}
bool ModelsListModel::isModelType(const QModelIndex & index) const
{
return index.isValid() && getItem(index)->isModel();
@@ -642,10 +614,10 @@ void ModelsListModel::refresh()
model.modelIndex = i;
if (hasLabels) {
current = rootItem->appendChild(0, i);
current = rootItem->appendChild(i);
}
else {
current = rootItem->appendChild(0, i);
current = rootItem->appendChild(i);
current->setData(currentColumn++, QString().sprintf("%02d", i + 1));
}