OSDN Git Service

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