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:
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>864</width>
|
<width>865</width>
|
||||||
<height>673</height>
|
<height>673</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>3</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="profileTab">
|
<widget class="QWidget" name="profileTab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@@ -936,7 +936,7 @@ Mode 4:
|
|||||||
<string><html><head/><body><p>This option maintains the behaviour from older OpenTx versions where empty model slots are preserved when a model is deleted or moved. </p><p>When this option is de-selected, the other models may be re-arranged to fill the gap left by the removed model.</p></body></html></string>
|
<string><html><head/><body><p>This option maintains the behaviour from older OpenTx versions where empty model slots are preserved when a model is deleted or moved. </p><p>When this option is de-selected, the other models may be re-arranged to fill the gap left by the removed model.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<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>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
+13
-15
@@ -536,9 +536,8 @@ void MdiChild::initModelsList()
|
|||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
if (firmware->getCapability(Capability::HasModelLabels)) {
|
if (firmware->getCapability(Capability::HasModelLabels)) {
|
||||||
ui->modelsList->header()->resizeSection(0, ui->modelsList->header()->sectionSize(0) * 2); // pad out categories and model names
|
ui->modelsList->header()->resizeSection(0, ui->modelsList->header()->sectionSize(0) * 1.5); // pad out model names
|
||||||
} else if (firmware->getCapability(Capability::HasModelLabels)) {
|
ui->modelsList->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); // minimise rx #
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ui->modelsList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // minimise Index
|
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
|
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
|
else
|
||||||
openModelEditWindow(mIdx);
|
openModelEditWindow(mIdx);
|
||||||
}
|
}
|
||||||
else if (modelsListModel->isCategoryType(index)) {
|
|
||||||
ui->modelsList->edit(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MdiChild::onItemSelected(const QModelIndex &)
|
void MdiChild::onItemSelected(const QModelIndex &)
|
||||||
@@ -733,7 +729,7 @@ bool MdiChild::insertModelRows(int atModelIdx, int count)
|
|||||||
return true;
|
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.
|
// 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.
|
// ModelsListModel::refresh() needs to be called at some point afterwards to sync the data.
|
||||||
int MdiChild::modelAppend(const ModelData model)
|
int MdiChild::modelAppend(const ModelData model)
|
||||||
@@ -775,7 +771,6 @@ int MdiChild::newModel(int modelIndex)
|
|||||||
}
|
}
|
||||||
setModified();
|
setModified();
|
||||||
setSelectedModel(modelIndex);
|
setSelectedModel(modelIndex);
|
||||||
//qDebug() << modelIndex << categoryIndex << isNewModel;
|
|
||||||
|
|
||||||
if (isNewModel) {
|
if (isNewModel) {
|
||||||
if (g.newModelAction() == AppData::MODEL_ACT_WIZARD)
|
if (g.newModelAction() == AppData::MODEL_ACT_WIZARD)
|
||||||
@@ -863,7 +858,6 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
|
|||||||
|
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
int modelIdx = modelsListModel->getModelIndex(row);
|
int modelIdx = modelsListModel->getModelIndex(row);
|
||||||
// int categoryIdx = modelsListModel->getCategoryIndex(row);
|
|
||||||
unsigned inserts = 0;
|
unsigned inserts = 0;
|
||||||
QVector<int> deletesList;
|
QVector<int> deletesList;
|
||||||
|
|
||||||
@@ -871,17 +865,16 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
|
|||||||
bool hasOwnData = modelsListModel->hasOwnMimeData(mimeData);
|
bool hasOwnData = modelsListModel->hasOwnMimeData(mimeData);
|
||||||
move = (move && hasOwnData);
|
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
|
// Model data
|
||||||
for (int i=0; i < modelsList.size(); ++i) {
|
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 doMove = (origMdlIdx > -1 && origMdlIdx < (int)radioData.models.size() && (move || cutModels.contains(origMdlIdx))); // DnD-moved or clipboard cut
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
if (modelIdx == -1 || (!insert && modelIdx >= (int)radioData.models.size())) {
|
if (modelIdx == -1 || (!insert && modelIdx >= (int)radioData.models.size())) {
|
||||||
// This handles pasting onto a category label or pasting past the end
|
// This handles pasting past the end or when pasting multiple models.
|
||||||
// of a category when pasting multiple models.
|
|
||||||
modelIdx = modelAppend(modelsList[i]);
|
modelIdx = modelAppend(modelsList[i]);
|
||||||
if (modelIdx < 0) {
|
if (modelIdx < 0) {
|
||||||
ok = false;
|
ok = false;
|
||||||
@@ -895,8 +888,13 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
|
|||||||
++inserts;
|
++inserts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // pasting on top of a slot
|
else if (!deletesList.contains(modelIdx)) {
|
||||||
if (!radioData.models[modelIdx].isEmpty() && !deletesList.contains(modelIdx)) {
|
// pasting on top of a slot
|
||||||
|
if (radioData.models[modelIdx].isEmpty()) {
|
||||||
|
radioData.models[modelIdx] = modelsList[i];
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle(CPN_STR_APP_NAME);
|
msgBox.setWindowTitle(CPN_STR_APP_NAME);
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ class MdiChild : public QWidget
|
|||||||
ACT_GEN_CPY,
|
ACT_GEN_CPY,
|
||||||
ACT_GEN_PST,
|
ACT_GEN_PST,
|
||||||
ACT_GEN_SIM,
|
ACT_GEN_SIM,
|
||||||
ACT_ITM_EDT, // edit model/rename category
|
ACT_ITM_EDT,
|
||||||
ACT_ITM_DEL, // delete model or cat
|
ACT_ITM_DEL,
|
||||||
ACT_LBL_ADD,
|
ACT_LBL_ADD,
|
||||||
ACT_LBL_DEL,
|
ACT_LBL_DEL,
|
||||||
ACT_LBL_MVU, // Move up
|
ACT_LBL_MVU, // Move up
|
||||||
@@ -81,7 +81,6 @@ class MdiChild : public QWidget
|
|||||||
|
|
||||||
QString currentFile() const;
|
QString currentFile() const;
|
||||||
QString userFriendlyCurrentFile() const;
|
QString userFriendlyCurrentFile() const;
|
||||||
QVector<int> getSelectedCategories() const;
|
|
||||||
QVector<int> getSelectedModels() const;
|
QVector<int> getSelectedModels() const;
|
||||||
QList<QAction *> getGeneralActions();
|
QList<QAction *> getGeneralActions();
|
||||||
QList<QAction *> getEditActions();
|
QList<QAction *> getEditActions();
|
||||||
|
|||||||
@@ -23,18 +23,16 @@
|
|||||||
ModelListItem::ModelListItem(const QVector<QVariant> & itemData):
|
ModelListItem::ModelListItem(const QVector<QVariant> & itemData):
|
||||||
itemData(itemData),
|
itemData(itemData),
|
||||||
parentItem(NULL),
|
parentItem(NULL),
|
||||||
categoryIndex(-1),
|
|
||||||
modelIndex(-1),
|
modelIndex(-1),
|
||||||
flags(0),
|
flags(0),
|
||||||
highlightRX(false)
|
highlightRX(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelListItem::ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex):
|
ModelListItem::ModelListItem(ModelListItem * parent, int modelIndex):
|
||||||
ModelListItem(QVector<QVariant>(parent->columnCount()))
|
ModelListItem(QVector<QVariant>(parent->columnCount()))
|
||||||
{
|
{
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
setCategoryIndex(categoryIndex);
|
|
||||||
setModelIndex(modelIndex);
|
setModelIndex(modelIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,16 +69,16 @@ QVariant ModelListItem::data(int column) const
|
|||||||
return itemData.value(column);
|
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);
|
childItems.insert(row, item);
|
||||||
return 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)
|
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)
|
bool ModelListItem::insertChildren(int row, int count)
|
||||||
{
|
{
|
||||||
for (int i=0; i < count; ++i) {
|
for (int i=0; i < count; ++i) {
|
||||||
insertChild(row + i, -1, -1);
|
insertChild(row + i, -1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -119,11 +117,6 @@ void ModelListItem::setFlag(const quint16 & flag, const bool on)
|
|||||||
flags &= ~flag;
|
flags &= ~flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelListItem::isCategory() const
|
|
||||||
{
|
|
||||||
return (modelIndex < 0 && categoryIndex > -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ModelListItem::isModel() const
|
bool ModelListItem::isModel() const
|
||||||
{
|
{
|
||||||
return (modelIndex > -1);
|
return (modelIndex > -1);
|
||||||
@@ -443,10 +436,8 @@ void ModelsListModel::encodeModelsData(const QModelIndexList & indexes, QByteArr
|
|||||||
{
|
{
|
||||||
foreach (const QModelIndex &index, indexes) {
|
foreach (const QModelIndex &index, indexes) {
|
||||||
if (index.isValid() && index.column() == 0) {
|
if (index.isValid() && index.column() == 0) {
|
||||||
if (!getItem(index)->isCategory()) { // TODO: encode categoreis also
|
data->append('M');
|
||||||
data->append('M');
|
data->append((char *)&radioData->models[getModelIndex(index)], sizeof(ModelData));
|
||||||
data->append((char *)&radioData->models[getModelIndex(index)], sizeof(ModelData));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -555,35 +546,16 @@ QModelIndex ModelsListModel::getIndexForModel(const int modelIndex, QModelIndex
|
|||||||
return 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
|
int ModelsListModel::getModelIndex(const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
return getItem(index)->getModelIndex();
|
return getItem(index)->getModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ModelsListModel::getCategoryIndex(const QModelIndex & index) const
|
|
||||||
{
|
|
||||||
return getItem(index)->getCategoryIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ModelsListModel::rowNumber(const QModelIndex & index) const
|
int ModelsListModel::rowNumber(const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
return getItem(index)->childNumber();
|
return getItem(index)->childNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelsListModel::isCategoryType(const QModelIndex & index) const
|
|
||||||
{
|
|
||||||
return index.isValid() && getItem(index)->isCategory();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ModelsListModel::isModelType(const QModelIndex & index) const
|
bool ModelsListModel::isModelType(const QModelIndex & index) const
|
||||||
{
|
{
|
||||||
return index.isValid() && getItem(index)->isModel();
|
return index.isValid() && getItem(index)->isModel();
|
||||||
@@ -642,10 +614,10 @@ void ModelsListModel::refresh()
|
|||||||
model.modelIndex = i;
|
model.modelIndex = i;
|
||||||
|
|
||||||
if (hasLabels) {
|
if (hasLabels) {
|
||||||
current = rootItem->appendChild(0, i);
|
current = rootItem->appendChild(i);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
current = rootItem->appendChild(0, i);
|
current = rootItem->appendChild(i);
|
||||||
current->setData(currentColumn++, QString().sprintf("%02d", i + 1));
|
current->setData(currentColumn++, QString().sprintf("%02d", i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,15 +31,15 @@ class ModelListItem
|
|||||||
enum ModelListItemFlags { MarkedForCut = 0x01 };
|
enum ModelListItemFlags { MarkedForCut = 0x01 };
|
||||||
|
|
||||||
explicit ModelListItem(const QVector<QVariant> & itemData);
|
explicit ModelListItem(const QVector<QVariant> & itemData);
|
||||||
explicit ModelListItem(ModelListItem * parent, int categoryIndex, int modelIndex);
|
explicit ModelListItem(ModelListItem * parent, int modelIndex);
|
||||||
~ModelListItem();
|
~ModelListItem();
|
||||||
|
|
||||||
ModelListItem * child(int number);
|
ModelListItem * child(int number);
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
int columnCount() const;
|
int columnCount() const;
|
||||||
QVariant data(int column) const;
|
QVariant data(int column) const;
|
||||||
ModelListItem * appendChild(int categoryIndex, int modelIndex);
|
ModelListItem * appendChild( int modelIndex);
|
||||||
ModelListItem * insertChild(const int row, int categoryIndex, int modelIndex);
|
ModelListItem * insertChild(const int row, int modelIndex);
|
||||||
bool removeChildren(int position, int count);
|
bool removeChildren(int position, int count);
|
||||||
bool insertChildren(int row, int count);
|
bool insertChildren(int row, int count);
|
||||||
|
|
||||||
@@ -50,8 +50,6 @@ class ModelListItem
|
|||||||
void setParent(ModelListItem * p) { parentItem = p; }
|
void setParent(ModelListItem * p) { parentItem = p; }
|
||||||
int getModelIndex() const { return modelIndex; }
|
int getModelIndex() const { return modelIndex; }
|
||||||
void setModelIndex(int value) { modelIndex = value; }
|
void setModelIndex(int value) { modelIndex = value; }
|
||||||
int getCategoryIndex() const { return categoryIndex; }
|
|
||||||
void setCategoryIndex(int value) { categoryIndex = value; }
|
|
||||||
void setHighlightRX(int value) { highlightRX = value; }
|
void setHighlightRX(int value) { highlightRX = value; }
|
||||||
bool isHighlightRX() const { return highlightRX; }
|
bool isHighlightRX() const { return highlightRX; }
|
||||||
|
|
||||||
@@ -59,14 +57,12 @@ class ModelListItem
|
|||||||
void setFlags(const quint16 & value) { flags = value; }
|
void setFlags(const quint16 & value) { flags = value; }
|
||||||
void setFlag(const quint16 & flag, const bool on = true);
|
void setFlag(const quint16 & flag, const bool on = true);
|
||||||
|
|
||||||
bool isCategory() const;
|
|
||||||
bool isModel() const;
|
bool isModel() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ModelListItem*> childItems;
|
QList<ModelListItem*> childItems;
|
||||||
QVector<QVariant> itemData;
|
QVector<QVariant> itemData;
|
||||||
ModelListItem * parentItem;
|
ModelListItem * parentItem;
|
||||||
int categoryIndex;
|
|
||||||
int modelIndex;
|
int modelIndex;
|
||||||
quint16 flags;
|
quint16 flags;
|
||||||
bool highlightRX;
|
bool highlightRX;
|
||||||
@@ -124,11 +120,8 @@ class ModelsListModel : public QAbstractItemModel
|
|||||||
static int countModelsInMimeData(const QMimeData * mimeData);
|
static int countModelsInMimeData(const QMimeData * mimeData);
|
||||||
|
|
||||||
QModelIndex getIndexForModel(const int modelIndex, QModelIndex parent = QModelIndex());
|
QModelIndex getIndexForModel(const int modelIndex, QModelIndex parent = QModelIndex());
|
||||||
QModelIndex getIndexForCategory(const int categoryIndex);
|
|
||||||
int getModelIndex(const QModelIndex & index) const;
|
int getModelIndex(const QModelIndex & index) const;
|
||||||
int getCategoryIndex(const QModelIndex & index) const;
|
|
||||||
int rowNumber(const QModelIndex & index = QModelIndex()) const;
|
int rowNumber(const QModelIndex & index = QModelIndex()) const;
|
||||||
bool isCategoryType(const QModelIndex & index) const;
|
|
||||||
bool isModelType(const QModelIndex & index) const;
|
bool isModelType(const QModelIndex & index) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user