1 /*
2 	Copyright 2006-2019 The QElectroTech Team
3 	This file is part of QElectroTech.
4 
5 	QElectroTech is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	QElectroTech is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "importelementtextpatterndialog.h"
19 #include "ui_importelementtextpatterndialog.h"
20 
ImportElementTextPatternDialog(QWidget * parent)21 ImportElementTextPatternDialog::ImportElementTextPatternDialog(QWidget *parent) :
22 	QDialog(parent),
23 	ui(new Ui::ImportElementTextPatternDialog) {
24 	ui->setupUi(this);
25 }
26 
~ImportElementTextPatternDialog()27 ImportElementTextPatternDialog::~ImportElementTextPatternDialog()
28 {
29 	delete ui;
30 }
31 
32 /**
33  * @brief ImportElementTextPatternDialog::getItem
34  * For all arguments see QInputDialog::getItem, except for erase, they store the state of the check box.
35  * @param parent
36  * @param title
37  * @param label
38  * @param items
39  * @param ok
40  * @param erase
41  * @return
42  */
getItem(QWidget * parent,const QString & title,const QString & label,const QStringList & items,bool * ok,bool * erase)43 QString ImportElementTextPatternDialog::getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, bool *ok, bool *erase)
44 {
45 	QString text(items.value(0));
46 
47    QScopedPointer<ImportElementTextPatternDialog> dialog(new ImportElementTextPatternDialog(parent));
48    dialog->setWindowTitle(title);
49    dialog->setLabelText(label);
50    dialog->setComboBoxItems(items);
51    dialog->setInputMethodHints(Qt::ImhNone);
52    const int ret = dialog->exec();
53    if (ok)
54 	   *ok = !!ret;
55    if(erase)
56 	   *erase = dialog->ui->m_erase_existing_text->isChecked();
57    if (ret) {
58 	   return dialog->textValue();
59    } else {
60 	   return text;
61    }
62 }
63 
setLabelText(const QString & label)64 void ImportElementTextPatternDialog::setLabelText(const QString &label) {
65 	ui->m_label->setText(label);
66 }
67 
setComboBoxItems(const QStringList & items)68 void ImportElementTextPatternDialog::setComboBoxItems(const QStringList &items) {
69 	ui->m_combo_box->addItems(items);
70 }
71 
textValue() const72 QString ImportElementTextPatternDialog::textValue() const {
73 	return ui->m_combo_box->currentText();
74 }
75