feat(cpn): reduce paste and drag'n'drop prompts (#7379)

This commit is contained in:
Neil Horne
2026-06-12 11:46:15 +10:00
committed by GitHub
parent b317b611d3
commit 1073d69291
+32 -14
View File
@@ -944,6 +944,10 @@ 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);
bool actionOverwrite = false;
bool actionInsert = false;
bool actionApplyAll = false;
//qDebug().nospace() << "row: " << row << "; ins: " << insert << "; mv: " << move << "; row modelIdx: " << modelIdx; //qDebug().nospace() << "row: " << row << "; ins: " << insert << "; mv: " << move << "; row modelIdx: " << modelIdx;
// Model data // Model data
@@ -974,30 +978,41 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
ok = true; ok = true;
} }
else { else {
QMessageBox msgBox; if (!actionApplyAll) {
msgBox.setWindowTitle(CPN_STR_APP_NAME); actionOverwrite = false;
msgBox.setIcon(QMessageBox::Warning); actionInsert = false;
msgBox.setText(tr("Model already exists! Do you want to overwrite it or insert into a new slot?")); QMessageBox msgBox;
QPushButton *overwriteButton = msgBox.addButton(tr("Overwrite"),QMessageBox::ActionRole); msgBox.setWindowTitle(CPN_STR_APP_NAME);
QPushButton *insertButton = msgBox.addButton(tr("Insert"),QMessageBox::ActionRole); msgBox.setIcon(QMessageBox::Warning);
QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel); 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); radioData.models[modelIdx] = modelsList->at(i);
ok = true; ok = true;
} } else if (actionInsert) {
else if (msgBox.clickedButton() == insertButton) {
ok = insertModelRows(modelIdx, 1); ok = insertModelRows(modelIdx, 1);
if (ok) { if (ok) {
radioData.models[modelIdx] = modelsList->at(i); radioData.models[modelIdx] = modelsList->at(i);
// ++inserts; // ++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 lastSelectedModel = modelIdx; // after refresh the last pasted model will be selected
modified = true; modified = true;
setModelModified(modelIdx, false); // avoid unnecessary refreshes setModelModified(modelIdx, false); // avoid unnecessary refreshes
if (doMove) { if (doMove) {
deletesList.append(origMdlIdx); deletesList.append(origMdlIdx);
removeModelFromCutList(origMdlIdx); removeModelFromCutList(origMdlIdx);
} }
radioData.addLabelsFromModels(); radioData.addLabelsFromModels();
} }
//qDebug().nospace() << "i: " << i << "; modelIdx:" << modelIdx << "; origMdlIdx: " << origMdlIdx << "; doMove: " << doMove << "; inserts:" << inserts << "; deletes: " << deletesList; //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; ++modelIdx;
} }
// even if we cancel we need to delete those models already moved
if (deletesList.size()) { if (deletesList.size()) {
deleteModels(deletesList); deleteModels(deletesList);
} }