From 1073d69291c8bab260e644a22bd7c17e0f9a35c0 Mon Sep 17 00:00:00 2001 From: Neil Horne <15316949+elecpower@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:46:15 +1000 Subject: [PATCH] feat(cpn): reduce paste and drag'n'drop prompts (#7379) --- companion/src/mdichild.cpp | 46 ++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 216674ec5..8c0b80f95 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -944,6 +944,10 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, bool hasOwnData = modelsListModel->hasOwnMimeData(mimeData); move = (move && hasOwnData); + bool actionOverwrite = false; + bool actionInsert = false; + bool actionApplyAll = false; + //qDebug().nospace() << "row: " << row << "; ins: " << insert << "; mv: " << move << "; row modelIdx: " << modelIdx; // Model data @@ -974,30 +978,41 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, ok = true; } else { - QMessageBox msgBox; - msgBox.setWindowTitle(CPN_STR_APP_NAME); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setText(tr("Model already exists! Do you want to overwrite it or insert into a new slot?")); - QPushButton *overwriteButton = msgBox.addButton(tr("Overwrite"),QMessageBox::ActionRole); - QPushButton *insertButton = msgBox.addButton(tr("Insert"),QMessageBox::ActionRole); - QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel); + if (!actionApplyAll) { + actionOverwrite = false; + actionInsert = false; + QMessageBox msgBox; + msgBox.setWindowTitle(CPN_STR_APP_NAME); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setText(tr("Model already exists! Do you want to overwrite it or insert into a new slot?")); + QPushButton *overwriteButton = msgBox.addButton(tr("Overwrite"),QMessageBox::ActionRole); + QPushButton *insertButton = msgBox.addButton(tr("Insert"),QMessageBox::ActionRole); + QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel); + QCheckBox *cb = new QCheckBox(tr("Apply to all remaining models")); + msgBox.setCheckBox(cb); + connect(cb, &QCheckBox::checkStateChanged, [&](const int &state){ actionApplyAll = state; }); - msgBox.exec(); + msgBox.exec(); - if (msgBox.clickedButton() == overwriteButton) { + if (msgBox.clickedButton() == overwriteButton) { + actionOverwrite = true; + } else if (msgBox.clickedButton() == insertButton) { + actionInsert = true; + } else if (msgBox.clickedButton() == cancelButton) { + break; // stop all further processing + } + } + + if (actionOverwrite) { radioData.models[modelIdx] = modelsList->at(i); ok = true; - } - else if (msgBox.clickedButton() == insertButton) { + } else if (actionInsert) { ok = insertModelRows(modelIdx, 1); if (ok) { radioData.models[modelIdx] = modelsList->at(i); // ++inserts; } } - else if (msgBox.clickedButton() == cancelButton) { - ok = false; - } } } @@ -1009,10 +1024,12 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, lastSelectedModel = modelIdx; // after refresh the last pasted model will be selected modified = true; setModelModified(modelIdx, false); // avoid unnecessary refreshes + if (doMove) { deletesList.append(origMdlIdx); removeModelFromCutList(origMdlIdx); } + radioData.addLabelsFromModels(); } //qDebug().nospace() << "i: " << i << "; modelIdx:" << modelIdx << "; origMdlIdx: " << origMdlIdx << "; doMove: " << doMove << "; inserts:" << inserts << "; deletes: " << deletesList; @@ -1020,6 +1037,7 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row, ++modelIdx; } + // even if we cancel we need to delete those models already moved if (deletesList.size()) { deleteModels(deletesList); }