This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArgumentEditor.cpp
67 lines (59 loc) · 1.88 KB
/
ArgumentEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "ArgumentEditor.hpp"
#include "ui_ArgumentEditor.h"
//#include "CVarDialog.hpp"
#include <QSettings>
#include <QInputDialog>
#include <QDebug>
ArgumentEditor::ArgumentEditor(QWidget* parent) : QDialog(parent), m_ui(std::make_unique<Ui::ArgumentEditor>()) {
m_ui->setupUi(this);
m_model.setStringList(QSettings().value(QStringLiteral("urde_arguments")).toStringList());
m_ui->argumentEditor->setModel(&m_model);
}
ArgumentEditor::~ArgumentEditor() = default;
void ArgumentEditor::on_addButton_clicked() {
QInputDialog input(this);
int code = input.exec();
if (code == DialogCode::Accepted) {
QStringList list = m_model.stringList();
list << input.textValue();
m_model.setStringList(list);
}
}
void ArgumentEditor::on_addCvarButton_clicked() {
CVarDialog input(this);
int code = input.exec();
if (code == DialogCode::Accepted) {
QStringList list = m_model.stringList();
list << input.textValue();
m_model.setStringList(list);
}
}
void ArgumentEditor::on_editButton_clicked() {
QModelIndex index = m_ui->argumentEditor->currentIndex();
if (!index.isValid()) {
return;
}
QInputDialog input(this);
input.setTextValue(m_model.stringList().value(index.row()));
int code = input.exec();
if (code == DialogCode::Accepted) {
QStringList list = m_model.stringList();
list[index.row()] = input.textValue();
m_model.setStringList(list);
}
}
void ArgumentEditor::on_deleteButton_clicked() {
QModelIndex index = m_ui->argumentEditor->currentIndex();
if (index.isValid()) {
m_model.removeRows(index.row(), 1);
}
}
void ArgumentEditor::on_buttonBox_clicked(QAbstractButton* button) {
auto* buttonBox = qobject_cast<QDialogButtonBox*>(sender());
if (button == buttonBox->button(QDialogButtonBox::Ok)) {
QSettings().setValue(QStringLiteral("urde_arguments"), m_model.stringList());
accept();
} else {
reject();
}
}