File indexing completed on 2024-05-19 16:14:59

0001 /*
0002     SPDX-FileCopyrightText: 2011-2012 Alessandro Russo <axela74@yahoo.it>
0003     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "ktagreassigndlg.h"
0008 
0009 // ----------------------------------------------------------------------------
0010 // QT Includes
0011 
0012 #include <QList>
0013 #include <QPushButton>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 #include <KMessageBox>
0019 #include <kguiutils.h>
0020 #include <KLocalizedString>
0021 
0022 // ----------------------------------------------------------------------------
0023 // Project Includes
0024 
0025 #include "ui_ktagreassigndlg.h"
0026 #include <kmymoneymvccombo.h>
0027 
0028 KTagReassignDlg::KTagReassignDlg(QWidget* parent) :
0029     QDialog(parent),
0030     ui(new Ui::KTagReassignDlg)
0031 {
0032     ui->setupUi(this);
0033     auto mandatory = new KMandatoryFieldGroup(this);
0034     mandatory->add(ui->tagCombo);
0035     mandatory->setOkButton(ui->buttonBox->button(QDialogButtonBox::Ok));
0036 }
0037 
0038 KTagReassignDlg::~KTagReassignDlg()
0039 {
0040     delete ui;
0041 }
0042 
0043 QString KTagReassignDlg::show(const QList<MyMoneyTag>& tagslist)
0044 {
0045     if (tagslist.isEmpty())
0046         return QString(); // no tag available? nothing can be selected...
0047 
0048     ui->tagCombo->loadTags(tagslist);
0049 
0050     // execute dialog and if aborted, return empty string
0051     if (this->exec() == QDialog::Rejected)
0052         return QString();
0053 
0054     // otherwise return index of selected tag
0055     return ui->tagCombo->selectedItem();
0056 }
0057 
0058 void KTagReassignDlg::accept()
0059 {
0060     // force update of ui->tagCombo
0061     ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus();
0062 
0063     if (ui->tagCombo->selectedItem().isEmpty()) {
0064         KMessageBox::information(this, i18n("This dialog does not allow new tags to be created. Please pick a tag from the list."), i18n("Tag creation"));
0065     } else {
0066         QDialog::accept();
0067     }
0068 }