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)); // 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(); char * gData = gmData->data();
bool modified = false; bool modified = false;
int size = 0; int size = 0;
bool pasteIntoCategory = modelIdx == -1; int modelIdx = modelsListModel->getModelIndex(row);
int dstCategory; int categoryIdx = modelsListModel->getCategoryIndex(row);
int childNumber = modelsListModel->rowNumber(row);
while (size < gmData->size()) { while (size < gmData->size()) {
char c = *gData++; 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)) { if (firmware->getCapability(Models) == 0 || modelIdx < firmware->getCapability(Models)) {
// Model data // Model data
int ret = QMessageBox::Yes; int ret = QMessageBox::Yes;
if (pasteIntoCategory) {
// We're pasting into a category, so create a stubbed out model then if (modelIdx == -1) {
// use the regular paste-onto-model code path // This handles pasting onto a category label or pasting past the end
// of a category when pasting multiple models.
ModelData blank; ModelData blank;
blank.used = false; blank.used = false;
blank.category = categoryIdx; blank.category = categoryIdx;
@@ -277,17 +279,18 @@ void MdiChild::doPaste(QByteArray * gmData, int modelIdx, int categoryIdx)
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
} }
if (ret == QMessageBox::Yes) { if (ret == QMessageBox::Yes) {
// Save and restore the category index, so a user can copy/paste // Set the destination category, so a user can copy/paste across categories.
// across categories
dstCategory = radioData.models[modelIdx].category;
radioData.models[modelIdx] = *((ModelData *)gData); 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()); strcpy(radioData.models[modelIdx].filename, radioData.getNextModelFilename().toStdString().c_str());
modified = 1; modified = 1;
} }
gData += sizeof(ModelData); gData += sizeof(ModelData);
size += 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 { else {
@@ -306,7 +309,7 @@ void MdiChild::paste()
const QClipboard * clipboard = QApplication::clipboard(); const QClipboard * clipboard = QApplication::clipboard();
const QMimeData * mimeData = clipboard->mimeData(); const QMimeData * mimeData = clipboard->mimeData();
QByteArray gmData = mimeData->data("application/x-companion"); 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(); bool maybeSave();
void setCurrentFile(const QString & fileName); void setCurrentFile(const QString & fileName);
void doCopy(QByteArray * gmData); void doCopy(QByteArray * gmData);
void doPaste(QByteArray * gmData, int modelIdx, int categoryIdx); void doPaste(QByteArray * gmData, QModelIndex row);
void initModelsList(); void initModelsList();
MainWindow * parent; MainWindow * parent;
+3
View File
@@ -98,6 +98,9 @@ class TreeModel : public QAbstractItemModel
return getItem(index)->getCategoryIndex(); return getItem(index)->getCategoryIndex();
} }
int rowNumber(const QModelIndex & index = QModelIndex()) const {
return getItem(index)->childNumber();
}
private: private:
TreeItem * getItem(const QModelIndex & index) const; TreeItem * getItem(const QModelIndex & index) const;
TreeItem * rootItem; TreeItem * rootItem;