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
+3 -3
View File
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>864</width>
<width>865</width>
<height>673</height>
</rect>
</property>
@@ -45,7 +45,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>3</number>
<number>1</number>
</property>
<widget class="QWidget" name="profileTab">
<attribute name="title">
@@ -936,7 +936,7 @@ Mode 4:
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This option maintains the behaviour from older OpenTx versions where empty model slots are preserved when a model is deleted or moved. &lt;/p&gt;&lt;p&gt;When this option is de-selected, the other models may be re-arranged to fill the gap left by the removed model.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Remove empty model slots when deleting models (only applies for radios w/out categories)</string>
<string>Remove empty model slots when deleting models (only applies for radios w/out labels)</string>
</property>
</widget>
</item>
+13 -15
View File
@@ -536,9 +536,8 @@ void MdiChild::initModelsList()
refresh();
if (firmware->getCapability(Capability::HasModelLabels)) {
ui->modelsList->header()->resizeSection(0, ui->modelsList->header()->sectionSize(0) * 2); // pad out categories and model names
} else if (firmware->getCapability(Capability::HasModelLabels)) {
ui->modelsList->header()->resizeSection(0, ui->modelsList->header()->sectionSize(0) * 1.5); // pad out model names
ui->modelsList->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); // minimise rx #
} else {
ui->modelsList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // minimise Index
ui->modelsList->header()->resizeSection(1, ui->modelsList->header()->sectionSize(1) * 1.5); // pad out model names
@@ -571,9 +570,6 @@ void MdiChild::onItemActivated(const QModelIndex index)
else
openModelEditWindow(mIdx);
}
else if (modelsListModel->isCategoryType(index)) {
ui->modelsList->edit(index);
}
}
void MdiChild::onItemSelected(const QModelIndex &)
@@ -733,7 +729,7 @@ bool MdiChild::insertModelRows(int atModelIdx, int count)
return true;
}
// Finds the first empty slot and inserts the model into it. In case of category-style models, will append to end of list.
// Finds the first empty slot and inserts the model into it.
// Return -1 if no slot was found, otherwise new array index.
// ModelsListModel::refresh() needs to be called at some point afterwards to sync the data.
int MdiChild::modelAppend(const ModelData model)
@@ -775,7 +771,6 @@ int MdiChild::newModel(int modelIndex)
}
setModified();
setSelectedModel(modelIndex);
//qDebug() << modelIndex << categoryIndex << isNewModel;
if (isNewModel) {
if (g.newModelAction() == AppData::MODEL_ACT_WIZARD)
@@ -863,7 +858,6 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
bool modified = false;
int modelIdx = modelsListModel->getModelIndex(row);
// int categoryIdx = modelsListModel->getCategoryIndex(row);
unsigned inserts = 0;
QVector<int> deletesList;
@@ -871,17 +865,16 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
bool hasOwnData = modelsListModel->hasOwnMimeData(mimeData);
move = (move && hasOwnData);
//qDebug().nospace() << "row: " << row << "; ins: " << insert << "; mv: " << move << "; row modelIdx: " << modelIdx << "; row categoryIdx: " << categoryIdx << "; removeSlots: " << removeModelSlotsWhenDeleting;
//qDebug().nospace() << "row: " << row << "; ins: " << insert << "; mv: " << move << "; row modelIdx: " << modelIdx;
// Model data
for (int i=0; i < modelsList.size(); ++i) {
int origMdlIdx = hasOwnData ? modelsList.at(i).modelIndex : -1; // where is the modeul in *our* current array?
int origMdlIdx = hasOwnData ? modelsList.at(i).modelIndex : -1; // where is the model in *our* current array?
bool doMove = (origMdlIdx > -1 && origMdlIdx < (int)radioData.models.size() && (move || cutModels.contains(origMdlIdx))); // DnD-moved or clipboard cut
bool ok = true;
if (modelIdx == -1 || (!insert && modelIdx >= (int)radioData.models.size())) {
// This handles pasting onto a category label or pasting past the end
// of a category when pasting multiple models.
// This handles pasting past the end or when pasting multiple models.
modelIdx = modelAppend(modelsList[i]);
if (modelIdx < 0) {
ok = false;
@@ -895,8 +888,13 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
++inserts;
}
}
else { // pasting on top of a slot
if (!radioData.models[modelIdx].isEmpty() && !deletesList.contains(modelIdx)) {
else if (!deletesList.contains(modelIdx)) {
// pasting on top of a slot
if (radioData.models[modelIdx].isEmpty()) {
radioData.models[modelIdx] = modelsList[i];
ok = true;
}
else {
QMessageBox msgBox;
msgBox.setWindowTitle(CPN_STR_APP_NAME);
msgBox.setIcon(QMessageBox::Warning);
+2 -3
View File
@@ -53,8 +53,8 @@ class MdiChild : public QWidget
ACT_GEN_CPY,
ACT_GEN_PST,
ACT_GEN_SIM,
ACT_ITM_EDT, // edit model/rename category
ACT_ITM_DEL, // delete model or cat
ACT_ITM_EDT,
ACT_ITM_DEL,
ACT_LBL_ADD,
ACT_LBL_DEL,
ACT_LBL_MVU, // Move up
@@ -81,7 +81,6 @@ class MdiChild : public QWidget
QString currentFile() const;
QString userFriendlyCurrentFile() const;
QVector<int> getSelectedCategories() const;
QVector<int> getSelectedModels() const;
QList<QAction *> getGeneralActions();
QList<QAction *> getEditActions();
+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));
}
+4 -11
View File
@@ -31,15 +31,15 @@ class ModelListItem
enum ModelListItemFlags { MarkedForCut = 0x01 };
explicit ModelListItem(const QVector<QVariant> & itemData);
explicit ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex);
explicit ModelListItem(ModelListItem * parent, int modelIndex);
~ModelListItem();
ModelListItem * child(int number);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
ModelListItem * appendChild(int categoryIndex, int modelIndex);
ModelListItem * insertChild(const int row, int categoryIndex, int modelIndex);
ModelListItem * appendChild( int modelIndex);
ModelListItem * insertChild(const int row, int modelIndex);
bool removeChildren(int position, int count);
bool insertChildren(int row, int count);
@@ -50,8 +50,6 @@ class ModelListItem
void setParent(ModelListItem * p) { parentItem = p; }
int getModelIndex() const { return modelIndex; }
void setModelIndex(int value) { modelIndex = value; }
int getCategoryIndex() const { return categoryIndex; }
void setCategoryIndex(int value) { categoryIndex = value; }
void setHighlightRX(int value) { highlightRX = value; }
bool isHighlightRX() const { return highlightRX; }
@@ -59,14 +57,12 @@ class ModelListItem
void setFlags(const quint16 & value) { flags = value; }
void setFlag(const quint16 & flag, const bool on = true);
bool isCategory() const;
bool isModel() const;
private:
QList<ModelListItem*> childItems;
QVector<QVariant> itemData;
ModelListItem * parentItem;
int categoryIndex;
int modelIndex;
quint16 flags;
bool highlightRX;
@@ -92,7 +88,7 @@ class ModelsListModel : public QAbstractItemModel
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
@@ -124,11 +120,8 @@ class ModelsListModel : public QAbstractItemModel
static int countModelsInMimeData(const QMimeData * mimeData);
QModelIndex getIndexForModel(const int modelIndex, QModelIndex parent = QModelIndex());
QModelIndex getIndexForCategory(const int categoryIndex);
int getModelIndex(const QModelIndex & index) const;
int getCategoryIndex(const QModelIndex & index) const;
int rowNumber(const QModelIndex & index = QModelIndex()) const;
bool isCategoryType(const QModelIndex & index) const;
bool isModelType(const QModelIndex & index) const;
public slots: