-
Notifications
You must be signed in to change notification settings - Fork 1
/
environmentvariablesdialog.cpp
123 lines (88 loc) · 2.96 KB
/
environmentvariablesdialog.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "environmentvariablesdialog.h"
#include "ui_environmentvariablesdialog.h"
#include <QMap>
#include "constants.h"
#include "configuration.h"
EnvironmentVariablesDialog::EnvironmentVariablesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EnvironmentVariablesDialog)
{
ui->setupUi(this);
QStringList labels;
labels << "Name" << "Value";
itemModel = new QStandardItemModel(3, 2);
itemModel->setHorizontalHeaderLabels(labels);
ui->envVars->horizontalHeader()->setStretchLastSection(true);
this->setWindowTitle(tr("Environment variables for %1").arg(titleConsole));
this->titleConsole = GLOBAL;
loadSettings();
ui->envVars->setModel(itemModel);
}
EnvironmentVariablesDialog::EnvironmentVariablesDialog(const QString &titleConsole, QWidget *parent) :
QDialog(parent),
ui(new Ui::EnvironmentVariablesDialog)
{
ui->setupUi(this);
QStringList labels;
labels << "Name" << "Value";
itemModel = new QStandardItemModel(3, 2);
itemModel->setHorizontalHeaderLabels(labels);
ui->envVars->horizontalHeader()->setStretchLastSection(true);
this->setWindowTitle(tr("Environment variables for %1").arg(titleConsole));
this->titleConsole = titleConsole;
loadSettings();
ui->envVars->setModel(itemModel);
}
EnvironmentVariablesDialog::~EnvironmentVariablesDialog()
{
delete ui;
}
void EnvironmentVariablesDialog::accept()
{
Configuration &configuration = Configuration::getInstance();
QMap<QString, QString> newVars;
int totalRows = itemModel->rowCount();
for(int r = 0; r < totalRows; r++){
QStandardItem *itemName = itemModel->item(r, 0);
QStandardItem *itemValue = itemModel->item(r, 1);
newVars[itemName->text()] = itemValue->text();
}
configuration.updateEnv(titleConsole, newVars);
QDialog::accept();
}
void EnvironmentVariablesDialog::reject()
{
QDialog::reject();
}
void EnvironmentVariablesDialog::loadSettings()
{
Configuration &configuration = Configuration::getInstance();
QMap<QString, QString> env;
QMap<QString, QString>::iterator i;
int row = 0;
configuration.getEnv(titleConsole, env);
itemModel->setRowCount(env.size());
for (i = env.begin(); i != env.end(); ++i)
{
itemModel->setItem(row, 0, new QStandardItem(i.key()));
itemModel->setItem(row, 1, new QStandardItem(i.value()));
row++;
}
}
void EnvironmentVariablesDialog::addVar()
{
QList<QStandardItem *> items;
QStandardItem *itemName = new QStandardItem("type-name");
QStandardItem *itemValue = new QStandardItem("type-value");
items << itemName << itemValue;
itemModel->appendRow(items);
}
void EnvironmentVariablesDialog::deleteVar()
{
QItemSelectionModel *itemsSelected = ui->envVars->selectionModel();
QModelIndexList modelIndexList = itemsSelected->selectedRows();
if(modelIndexList.size()){
int row = modelIndexList.at(0).row();
itemModel->removeRow(row);
}
}