OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / cpp / cppsettingspage.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "cppsettingspage.h"
34 #include "designerconstants.h"
35
36 #include <QtCore/QCoreApplication>
37 #include <QtCore/QTextStream>
38 #include <coreplugin/icore.h>
39
40 namespace Designer {
41 namespace Internal {
42
43 // ---------- CppSettingsPageWidget
44
45 CppSettingsPageWidget::CppSettingsPageWidget(QWidget *parent) :
46         QWidget(parent)
47 {
48     m_ui.setupUi(this);
49 }
50
51 FormClassWizardGenerationParameters CppSettingsPageWidget::parameters() const
52 {
53     FormClassWizardGenerationParameters rc;
54     rc.embedding = static_cast<UiClassEmbedding>(uiEmbedding());
55     rc.retranslationSupport =m_ui.retranslateCheckBox->isChecked();
56     rc.includeQtModule = m_ui.includeQtModuleCheckBox->isChecked();
57     return rc;
58 }
59
60 void CppSettingsPageWidget::setParameters(const FormClassWizardGenerationParameters &p)
61 {
62     m_ui.retranslateCheckBox->setChecked(p.retranslationSupport);
63     m_ui.includeQtModuleCheckBox->setChecked(p.includeQtModule);
64     setUiEmbedding(p.embedding);
65 }
66
67 int CppSettingsPageWidget::uiEmbedding() const
68 {
69     if (m_ui.ptrAggregationRadioButton->isChecked())
70         return PointerAggregatedUiClass;
71     if (m_ui.aggregationButton->isChecked())
72         return AggregatedUiClass;
73     return InheritedUiClass;
74 }
75
76 void CppSettingsPageWidget::setUiEmbedding(int v)
77 {
78     switch (v) {
79     case PointerAggregatedUiClass:
80         m_ui.ptrAggregationRadioButton->setChecked(true);
81         break;
82     case AggregatedUiClass:
83         m_ui.aggregationButton->setChecked(true);
84         break;
85     case InheritedUiClass:
86         m_ui.multipleInheritanceButton->setChecked(true);
87         break;
88     }
89 }
90
91 QString CppSettingsPageWidget::searchKeywords() const
92 {
93     QString rc;
94     QTextStream(&rc) << m_ui.ptrAggregationRadioButton->text()
95             << ' ' << m_ui.aggregationButton->text()
96             << ' ' << m_ui.multipleInheritanceButton->text()
97             << ' ' << m_ui.retranslateCheckBox->text()
98             << ' ' << m_ui.includeQtModuleCheckBox->text();
99     rc.remove(QLatin1Char('&'));
100     return rc;
101 }
102
103 // ---------- CppSettingsPage
104 CppSettingsPage::CppSettingsPage(QObject *parent) : Core::IOptionsPage(parent)
105 {
106     m_parameters.fromSettings(Core::ICore::instance()->settings());
107 }
108
109 QString CppSettingsPage::id() const
110 {
111     return QLatin1String(Designer::Constants::SETTINGS_CPP_SETTINGS_ID);
112 }
113
114 QString CppSettingsPage::displayName() const
115 {
116     return QCoreApplication::translate("Designer", Designer::Constants::SETTINGS_CPP_SETTINGS_NAME);
117 }
118
119 QString CppSettingsPage::category() const
120 {
121     return QLatin1String(Designer::Constants::SETTINGS_CATEGORY);
122 }
123
124 QString CppSettingsPage::displayCategory() const
125 {
126     return QCoreApplication::translate("Designer", Designer::Constants::SETTINGS_TR_CATEGORY);
127 }
128
129 QIcon CppSettingsPage::categoryIcon() const
130 {
131     return QIcon(QLatin1String(Designer::Constants::SETTINGS_CATEGORY_ICON));
132 }
133
134 QWidget *CppSettingsPage::createPage(QWidget *parent)
135 {
136     m_widget = new CppSettingsPageWidget(parent);
137     m_widget->setParameters(m_parameters);
138     if (m_searchKeywords.isEmpty())
139         m_searchKeywords = m_widget->searchKeywords();
140     return m_widget;
141 }
142
143 void CppSettingsPage::apply()
144 {
145     if (m_widget) {
146         const FormClassWizardGenerationParameters newParameters = m_widget->parameters();
147         if (newParameters != m_parameters) {
148             m_parameters = newParameters;
149             m_parameters.toSettings(Core::ICore::instance()->settings());
150         }
151     }
152 }
153
154 void CppSettingsPage::finish()
155 {
156 }
157
158 bool CppSettingsPage::matches(const QString &s) const
159 {
160     return m_searchKeywords.contains(s, Qt::CaseInsensitive);
161 }
162
163 } // namespace Internal
164 } // namespace Designer