-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathGeneralSettingsPage.cpp
82 lines (69 loc) · 3.02 KB
/
GeneralSettingsPage.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
//-----------------------------------------------------------------------------
// File: GeneralSettingsPage.cpp
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author: Joni-Matti Maatta
// Date: 13.6.2011
//
// Description:
// General settings property page.
//-----------------------------------------------------------------------------
#include "GeneralSettingsPage.h"
#include <KactusAPI/include/utils.h>
#include <IPXACTmodels/common/Document.h>
#include <QCoreApplication>
#include <QFormLayout>
#include <QLabel>
#include <QMessageBox>
#include <QSettings>
#include <QCheckBox>
//-----------------------------------------------------------------------------
// Function: GeneralSettingsPage()
//-----------------------------------------------------------------------------
GeneralSettingsPage::GeneralSettingsPage(QSettings& settings):
SettingsPage(settings),
usernameEdit_(new QLineEdit(this)),
revisionEdit_(new QComboBox(this)),
lockEnabledBox_(new QCheckBox(this))
{
QString username = settings.value("General/Username", Utils::getCurrentUser()).toString();
usernameEdit_->setText(username);
revisionEdit_->addItem(Document::toString(Document::Revision::Std22));
revisionEdit_->addItem(Document::toString(Document::Revision::Std14));
auto defaultRevision = settings.value("General/Revision", Document::toString(Document::Revision::Std22)).toString();
revisionEdit_->setCurrentText(defaultRevision);
bool lockEnabled = settings.value("General/EnableLocking", false).toBool();
lockEnabledBox_->setChecked(lockEnabled);
// Setup the layout.
auto layout = new QFormLayout(this);
layout->addRow(tr("Settings file:"), new QLabel(settings.fileName(), this));
layout->addRow(tr("User name:"), usernameEdit_);
layout->addRow(tr("Default IP-XACT version:"), revisionEdit_);
layout->addRow(tr("Enable editor locking:"), lockEnabledBox_);
}
//-----------------------------------------------------------------------------
// Function: validate()
//-----------------------------------------------------------------------------
bool GeneralSettingsPage::validate()
{
Q_ASSERT(prevalidate());
// Check for a valid username.
if (usernameEdit_->text().isEmpty())
{
QMessageBox msgBox(QMessageBox::Warning, QCoreApplication::applicationName(),
tr("The user name must be set."), QMessageBox::Ok, this);
msgBox.exec();
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Function: apply()
//-----------------------------------------------------------------------------
void GeneralSettingsPage::apply()
{
// Save the settings.
settings().setValue("General/Username", usernameEdit_->text());
settings().setValue("General/Revision", revisionEdit_->currentText());
settings().setValue("General/EnableLocking", lockEnabledBox_->isChecked());
}