Fixed #4375, fix pasting multiple items in Companion. (#4381)

This commit is contained in:
Kelly Byrd
2017-02-03 10:26:31 +01:00
committed by Damjan Adamic
parent 2b83160284
commit a0aa883743
3 changed files with 19 additions and 13 deletions
+15 -12
View File
@@ -236,13 +236,14 @@ void MdiChild::doCopy(QByteArray * gmData)
// gmData->append((char *) &radioData.generalSettings, sizeof(GeneralSettings));
}
void MdiChild::doPaste(QByteArray * gmData, int modelIdx, int categoryIdx)
void MdiChild::doPaste(QByteArray * gmData, QModelIndex row)
{
char * gData = gmData->data();
bool modified = false;
int size = 0;
bool pasteIntoCategory = modelIdx == -1;
int dstCategory;
int modelIdx = modelsListModel->getModelIndex(row);
int categoryIdx = modelsListModel->getCategoryIndex(row);
int childNumber = modelsListModel->rowNumber(row);
while (size < gmData->size()) {
char c = *gData++;
@@ -262,9 +263,10 @@ void MdiChild::doPaste(QByteArray * gmData, int modelIdx, int categoryIdx)
if (firmware->getCapability(Models) == 0 || modelIdx < firmware->getCapability(Models)) {
// Model data
int ret = QMessageBox::Yes;
if (pasteIntoCategory) {
// We're pasting into a category, so create a stubbed out model then
// use the regular paste-onto-model code path
if (modelIdx == -1) {
// This handles pasting onto a category label or pasting past the end
// of a category when pasting multiple models.
ModelData blank;
blank.used = false;
blank.category = categoryIdx;
@@ -277,17 +279,18 @@ void MdiChild::doPaste(QByteArray * gmData, int modelIdx, int categoryIdx)
QMessageBox::Yes | QMessageBox::No);
}
if (ret == QMessageBox::Yes) {
// Save and restore the category index, so a user can copy/paste
// across categories
dstCategory = radioData.models[modelIdx].category;
// Set the destination category, so a user can copy/paste across categories.
radioData.models[modelIdx] = *((ModelData *)gData);
radioData.models[modelIdx].category = dstCategory;
radioData.models[modelIdx].category = categoryIdx;
strcpy(radioData.models[modelIdx].filename, radioData.getNextModelFilename().toStdString().c_str());
modified = 1;
}
gData += sizeof(ModelData);
size += sizeof(ModelData);
modelIdx++;
// This gets the next row in the UI, which works for category-capable
// and non-category radio profiles. modelIndex will be -1, if there
// is no next row in the current category.
modelIdx = modelsListModel->getModelIndex(row.sibling(++childNumber, 0));
}
}
else {
@@ -306,7 +309,7 @@ void MdiChild::paste()
const QClipboard * clipboard = QApplication::clipboard();
const QMimeData * mimeData = clipboard->mimeData();
QByteArray gmData = mimeData->data("application/x-companion");
doPaste(&gmData, getCurrentModel(), getCurrentCategory());
doPaste(&gmData, ui->modelsList->currentIndex());
}
}
+1 -1
View File
@@ -102,7 +102,7 @@ class MdiChild : public QWidget
bool maybeSave();
void setCurrentFile(const QString & fileName);
void doCopy(QByteArray * gmData);
void doPaste(QByteArray * gmData, int modelIdx, int categoryIdx);
void doPaste(QByteArray * gmData, QModelIndex row);
void initModelsList();
MainWindow * parent;
+3
View File
@@ -98,6 +98,9 @@ class TreeModel : public QAbstractItemModel
return getItem(index)->getCategoryIndex();
}
int rowNumber(const QModelIndex & index = QModelIndex()) const {
return getItem(index)->childNumber();
}
private:
TreeItem * getItem(const QModelIndex & index) const;
TreeItem * rootItem;