-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathk2envvariablesettingspage.cpp
70 lines (60 loc) · 2.36 KB
/
k2envvariablesettingspage.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
/*
* Created on: 24.5.2013
* Author: Antti Kamppi
* File name: k2envvariablesettingspage.cpp
* Project: Kactus2
*/
#include "k2envvariablesettingspage.h"
#include <common/delegates/LineEditDelegate/lineeditdelegate.h>
#include "k2envvarmodel.h"
#include <QCoreApplication>
#include <QMessageBox>
#include <QSettings>
#include <QVBoxLayout>
//-----------------------------------------------------------------------------
// Function: K2EnvVariableSettingsPage::K2EnvVariableSettingsPage()
//-----------------------------------------------------------------------------
K2EnvVariableSettingsPage::K2EnvVariableSettingsPage(QSettings& settings):
SettingsPage(settings),
view_(new EditableTableView(this)),
model_(new K2EnvVarModel(settings, this))
{
view_->setAllowImportExport(false);
view_->setItemsDraggable(false);
view_->setSortingEnabled(false);
view_->setItemDelegate(new LineEditDelegate(this));
view_->setModel(model_);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(view_);
connect(view_, SIGNAL(addItem(const QModelIndex&)),
model_, SLOT(onAddItem(const QModelIndex&)), Qt::UniqueConnection);
connect(view_, SIGNAL(removeItem(const QModelIndex&)),
model_, SLOT(onRemoveItem(const QModelIndex&)), Qt::UniqueConnection);
}
//-----------------------------------------------------------------------------
// Function: K2EnvVariableSettingsPage::apply()
//-----------------------------------------------------------------------------
void K2EnvVariableSettingsPage::apply()
{
model_->apply(settings());
}
//-----------------------------------------------------------------------------
// Function: K2EnvVariableSettingsPage::prevalidate()
//-----------------------------------------------------------------------------
bool K2EnvVariableSettingsPage::prevalidate() const
{
return !model_->containsEmptyVariables();
}
//-----------------------------------------------------------------------------
// Function: K2EnvVariableSettingsPage::validate()
//-----------------------------------------------------------------------------
bool K2EnvVariableSettingsPage::validate()
{
if (!prevalidate())
{
QMessageBox::critical(this, QCoreApplication::applicationName(),
tr("All environment variables must have defined name."));
return false;
}
return true;
}