Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Port away from deprecated QMessageBox::question
Freya Lupena1db68cbd901
diff --git a/libs/resourcewidgets/KisTagChooserWidget.cpp b/libs/resourcewidgets/KisTagChooserWidget.cppindex 28b2ca8b2f..44ab92b305 100644--- a/libs/resourcewidgets/KisTagChooserWidget.cpp+++ b/libs/resourcewidgets/KisTagChooserWidget.cpp@@ -260,15 +260,25 @@ void KisTagChooserWidget::addTag(const QString &tag)addTag(tag, 0);}-KisTagChooserWidget::OverwriteDialogOptions KisTagChooserWidget::overwriteTagDialog(KisTagChooserWidget* parent, bool tagIsActive)+QMessageBox::ButtonRole KisTagChooserWidget::overwriteTagDialog(KisTagChooserWidget* parent, bool tagIsActive){QString undeleteOption = !tagIsActive ? i18nc("Option in a dialog to undelete (reactivate) existing tag with its old assigned resources", "Restore previous tag"): i18nc("Option in a dialog to use existing tag with its old assigned resources", "Use existing tag");- // if you use this simple cast, the order of buttons must match order of options in the enum- return (KisTagChooserWidget::OverwriteDialogOptions)QMessageBox::question(parent, i18nc("Dialog title", "Overwrite tag?"), i18nc("Question to the user in a dialog about creating a tag",- "A tag with this unique name already exists. Do you want to replace it?"),- i18nc("Option in a dialog to discard the previously existing tag and creating a new one in its place", "Replace (overwrite) tag"),- undeleteOption, i18n("Cancel"));+ QMessageBox question = QMessageBox(QMessageBox::Question,+ i18nc("Dialog title", "Overwrite tag?"),+ i18nc("Question to the user in a dialog about creating a tag",+ "A tag with this unique name already exists. Do you want to replace it?")+ );+ question.setParent(parent);+ question.addButton(+ i18nc("Option in a dialog to discard the previously existing tag and creating a new one in its place",+ "Replace (overwrite) tag"),+ QMessageBox::DestructiveRole+ );+ question.addButton(undeleteOption, QMessageBox::AcceptRole);+ question.addButton(QMessageBox::Cancel);+ question.exec();+ return question.buttonRole(question.clickedButton());}void KisTagChooserWidget::addTag(const QString &tagName, KoResourceSP resource)@@ -283,14 +293,14 @@ void KisTagChooserWidget::addTag(const QString &tagName, KoResourceSP resource)KisTagSP tagForUrl = d->model->tagForUrl(tagName);if (!tagForUrl.isNull()) {int response = overwriteTagDialog(this, tagForUrl->active());- if (response == Undelete) { // Undelete+ if (response == QMessageBox::AcceptRole) { // Undeleted->model->setTagActive(tagForUrl);if (!resource.isNull()) {KisTagResourceModel(d->resourceType).tagResources(tagForUrl, QVector<int>() << resource->resourceId());}d->model->sort(KisAllTagsModel::Name);return;- } else if (response == Cancel) { // Cancel+ } else if (response == QMessageBox::RejectRole) { // Cancelreturn;}}@@ -309,14 +319,14 @@ void KisTagChooserWidget::addTag(KisTagSP tag, KoResourceSP resource)KisTagSP tagForUrl = d->model->tagForUrl(tag->url());if (!tagForUrl.isNull()) {int response = overwriteTagDialog(this, tagForUrl->active());- if (response == Undelete) { // Undelete+ if (response == QMessageBox::AcceptRole) { // Undeleted->model->setTagActive(tagForUrl);if (!resource.isNull()) {KisTagResourceModel(d->resourceType).tagResources(tagForUrl, QVector<int>() << resource->resourceId());}d->model->sort(KisAllTagsModel::Name);return;- } else if (response == Cancel) { // Cancel+ } else if (response == QMessageBox::RejectRole) { // Cancelreturn;}}diff --git a/libs/resourcewidgets/KisTagChooserWidget.h b/libs/resourcewidgets/KisTagChooserWidget.hindex cdf468df8e..009c177d47 100644--- a/libs/resourcewidgets/KisTagChooserWidget.h+++ b/libs/resourcewidgets/KisTagChooserWidget.h@@ -9,6 +9,7 @@#define KISTAGCHOOSERWIDGET_H#include <QWidget>+#include <QMessageBox>#include "kritaresourcewidgets_export.h"#include <KisTag.h>@@ -116,13 +117,7 @@ private:/// \param index index is the index of the tag in the comboboxvoid setCurrentIndex(int index);- enum OverwriteDialogOptions {- Replace,- Undelete,- Cancel- };-- OverwriteDialogOptions overwriteTagDialog(KisTagChooserWidget* parent, bool undelete);+ QMessageBox::ButtonRole overwriteTagDialog(KisTagChooserWidget* parent, bool undelete);private:class Private;diff --git a/plugins/extensions/resourcemanager/wdgtagselection.cpp b/plugins/extensions/resourcemanager/wdgtagselection.cppindex 13755007bc..a55da24bba 100644--- a/plugins/extensions/resourcemanager/wdgtagselection.cpp+++ b/plugins/extensions/resourcemanager/wdgtagselection.cpp@@ -103,15 +103,27 @@ void KisWdgTagSelectionControllerOneResource::slotCreateNewTag(QString tag)m_tagModel->addTag(tag, false, vec);tagsp = m_tagModel->tagForUrl(tag);} else if (!tagsp->active()) { // if tag is active, simply use that tag- // if you use this simple cast, the order of buttons must match order of options in the enum- int response = QMessageBox::question(0, i18nc("Dialog title", "Overwrite tag?"), i18nc("Question to the user in a dialog about creating a tag",- "A tag with this unique name already exists. Do you want to replace it?"),- i18nc("Option in a dialog to discard the previously existing tag and creating a new one in its place", "Replace (overwrite) tag"),- i18nc("Option in a dialog to undelete (reactivate) existing tag with its old assigned resources", "Restore previous tag"), i18n("Cancel"));- if (response == 0) { // Overwrite+ QMessageBox question = QMessageBox(QMessageBox::Question,+ i18nc("Dialog title", "Overwrite tag?"),+ i18nc("Question to the user in a dialog about creating a tag",+ "A tag with this unique name already exists. Do you want to replace it?")+ );+ question.addButton(+ i18nc("Option in a dialog to discard the previously existing tag and creating a new one in its place",+ "Replace (overwrite) tag"),+ QMessageBox::DestructiveRole+ );+ question.addButton(+ i18nc("Option in a dialog to undelete (reactivate) existing tag with its old assigned resources",+ "Restore previous tag"),+ QMessageBox::AcceptRole);+ question.addButton(QMessageBox::Cancel);+ question.exec();+ QMessageBox::ButtonRole response = question.buttonRole(question.clickedButton());+ if (response == QMessageBox::DestructiveRole) { // Overwritem_tagModel->addTag(tag, true, QVector<KoResourceSP>()); // will overwrite the tagtagsp = m_tagModel->tagForUrl(tag);- } else if (response == 1) { // Restore/use previously existing one+ } else if (response == QMessageBox::AcceptRole) { // Restore/use previously existing onem_tagModel->setTagActive(tagsp);} else {updateView();