-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathNamingPolicySettingsPage.cpp
139 lines (120 loc) · 4.87 KB
/
NamingPolicySettingsPage.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//-----------------------------------------------------------------------------
// File: NamingPolicySettingsPage.cpp
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author: Joni-Matti Maatta
// Date: 13.6.2011
//
// Description:
// General settings property page.
//-----------------------------------------------------------------------------
#include "NamingPolicySettingsPage.h"
#include <common/widgets/listManager/listmanager.h>
#include <common/widgets/SnippetTextEdit/SnippetTextEdit.h>
#include <QCoreApplication>
#include <QDir>
#include <QFileDialog>
#include <QFormLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
//-----------------------------------------------------------------------------
// Function: NamingPolicySettingsPage()
//-----------------------------------------------------------------------------
NamingPolicySettingsPage::NamingPolicySettingsPage(QSettings& settings):
SettingsPage(settings),
categories_(),
curCategoryIndex_(-1),
categoryCombo_(new QComboBox(this)),
valuesList_(new ListManager(tr("Suggested values"), this)),
formatGroup_(new QGroupBox(tr("Format"), this)),
formatEdit_(new SnippetTextEdit(this))
{
// Add categories.
categories_.append(PolicyCategory("Policies/InstanceNames", "Component Instance Names", POLICY_FORMAT));
categories_.back().magicWords.append("ComponentName");
categories_.back().magicWords.append("InstanceNumber");
categories_.append(PolicyCategory("Policies/HWViewNames", "HW View Names", POLICY_ENUMERATION));
categories_.append(PolicyCategory("Policies/SWViewNames", "SW View Names", POLICY_ENUMERATION));
categories_.append(PolicyCategory("Policies/SysViewNames", "System View Names", POLICY_ENUMERATION));
QVBoxLayout* formatLayout = new QVBoxLayout(formatGroup_);
formatLayout->addWidget(formatEdit_);
// Setup the layout.
QFormLayout* policyLayout = new QFormLayout();
policyLayout->addRow(tr("Naming policy:"), categoryCombo_);
QVBoxLayout* topLayout = new QVBoxLayout(this);
topLayout->addLayout(policyLayout);
topLayout->addWidget(valuesList_);
topLayout->addWidget(formatGroup_);
topLayout->addStretch(1);
// Setup connections.
connect(categoryCombo_, SIGNAL(currentIndexChanged(int)),
this, SLOT(onCategoryChanged(int)), Qt::UniqueConnection);
// Read current values from settings and fill in the combo box.
for (int i = 0; i < categories_.size(); ++i)
{
PolicyCategory& category = categories_[i];
category.values = settings.value(category.key).toStringList();
categoryCombo_->addItem(category.name);
}
}
//-----------------------------------------------------------------------------
// Function: apply()
//-----------------------------------------------------------------------------
void NamingPolicySettingsPage::apply()
{
saveCurrentValues();
foreach (PolicyCategory const& category, categories_)
{
settings().setValue(category.key, category.values);
}
}
//-----------------------------------------------------------------------------
// Function: NamingPolicySettingsPage::onCategoryChanged()
//-----------------------------------------------------------------------------
void NamingPolicySettingsPage::onCategoryChanged(int index)
{
// Save the values of the previously selected category.
saveCurrentValues();
// Update the widgets based on the category type and content.
if (categories_.at(index).type == POLICY_ENUMERATION)
{
valuesList_->initialize(categories_.at(index).values);
formatGroup_->setVisible(false);
valuesList_->setVisible(true);
}
else
{
formatEdit_->clearMagicWords();
formatEdit_->addMagicWords(categories_.at(index).magicWords);
if (categories_.at(index).values.isEmpty())
{
formatEdit_->clear();
}
else
{
formatEdit_->setPlainText(categories_.at(index).values.first());
}
formatGroup_->setVisible(true);
valuesList_->setVisible(false);
}
curCategoryIndex_ = index;
}
//-----------------------------------------------------------------------------
// Function: NamingPolicySettingsPage::saveCurrentValues()
//-----------------------------------------------------------------------------
void NamingPolicySettingsPage::saveCurrentValues()
{
if (curCategoryIndex_ != -1)
{
if (categories_.at(curCategoryIndex_).type == POLICY_ENUMERATION)
{
categories_[curCategoryIndex_].values = valuesList_->items();
}
else
{
categories_[curCategoryIndex_].values = QStringList(formatEdit_->toPlainText());
}
}
}