OSDN Git Service

286ffdd2e119b591118eb55452da7607ae9c2b36
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / dialogs / iwizard.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 "iwizard.h"
35 #include "coreimpl.h"
36
37 #include <extensionsystem/pluginmanager.h>
38
39 /*!
40     \class Core::IWizard
41     \mainclass
42
43     \brief The class IWizard is the base class for all wizards
44     (for example shown in \gui {File | New}).
45
46     The wizard interface is a very thin abstraction for the \gui{New...} wizards.
47     Basically it defines what to show to the user in the wizard selection dialogs,
48     and a hook that is called if the user selects the wizard.
49
50     Wizards can then perform any operations they like, including showing dialogs and
51     creating files. Often it is not necessary to create your own wizard from scratch,
52     instead use one of the predefined wizards and adapt it to your needs.
53
54     To make your wizard known to the system, add your IWizard instance to the
55     plugin manager's object pool in your plugin's initialize method:
56     \code
57         bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
58         {
59             // ... do setup
60             addAutoReleasedObject(new MyWizard);
61             // ... do more setup
62         }
63     \endcode
64     \sa Core::BaseFileWizard
65     \sa Core::StandardFileWizard
66 */
67
68 /*!
69     \enum Core::IWizard::WizardKind
70     Used to specify what kind of objects the wizard creates. This information is used
71     to show e.g. only wizards that create projects when selecting a \gui{New Project}
72     menu item.
73     \value FileWizard
74         The wizard creates one or more files.
75     \value ClassWizard
76         The wizard creates a new class (e.g. source+header files).
77     \value ProjectWizard
78         The wizard creates a new project.
79 */
80
81 /*!
82     \fn IWizard::IWizard(QObject *parent)
83     \internal
84 */
85
86 /*!
87     \fn IWizard::~IWizard()
88     \internal
89 */
90
91 /*!
92     \fn Kind IWizard::kind() const
93     Returns what kind of objects are created by the wizard.
94     \sa Kind
95 */
96
97 /*!
98     \fn QIcon IWizard::icon() const
99     Returns an icon to show in the wizard selection dialog.
100 */
101
102 /*!
103     \fn QString IWizard::description() const
104     Returns a translated description to show when this wizard is selected
105     in the dialog.
106 */
107
108 /*!
109     \fn QString IWizard::name() const
110     Returns the translated name of the wizard, how it should appear in the
111     dialog.
112 */
113
114 /*!
115     \fn QString IWizard::id() const
116     Returns an arbitrary id that is used for sorting within the category.
117 */
118
119
120 /*!
121     \fn QString IWizard::category() const
122     Returns a category ID to add the wizard to.
123 */
124
125 /*!
126     \fn QString IWizard::displayCategory() const
127     Returns the translated string of the category, how it should appear
128     in the dialog.
129 */
130
131 /*!
132     \fn void IWizard::runWizard(const QString &path, QWidget *parent)
133     This method is executed when the wizard has been selected by the user
134     for execution. Any dialogs the wizard opens should use the given \a parent.
135     The \a path argument is a suggestion for the location where files should be
136     created. The wizard should fill this in its path selection elements as a
137     default path.
138 */
139
140 using namespace Core;
141
142 /* A utility to find all wizards supporting a view mode and matching a predicate */
143 template <class Predicate>
144     QList<IWizard*> findWizards(Predicate predicate)
145 {
146     // Hack: Trigger delayed creation of wizards
147     if (Core::Internal::CoreImpl *ci = qobject_cast<Core::Internal::CoreImpl*>(ICore::instance()))
148         ci->emitNewItemsDialogRequested();
149     // Filter all wizards
150     const QList<IWizard*> allWizards = IWizard::allWizards();
151     QList<IWizard*> rc;
152     const QList<IWizard*>::const_iterator cend = allWizards.constEnd();
153     for (QList<IWizard*>::const_iterator it = allWizards.constBegin(); it != cend; ++it)
154         if (predicate(*(*it)))
155             rc.push_back(*it);
156     return rc;
157 }
158
159 QList<IWizard*> IWizard::allWizards()
160 {
161     // Hack: Trigger delayed creation of wizards
162     if (Core::Internal::CoreImpl *ci = qobject_cast<Core::Internal::CoreImpl*>(ICore::instance()))
163         ci->emitNewItemsDialogRequested();
164     return ExtensionSystem::PluginManager::instance()->getObjects<IWizard>();
165 }
166
167 // Utility to find all registered wizards of a certain kind
168
169 class WizardKindPredicate {
170 public:
171     WizardKindPredicate(IWizard::WizardKind kind) : m_kind(kind) {}
172     bool operator()(const IWizard &w) const { return w.kind() == m_kind; }
173 private:
174     const IWizard::WizardKind m_kind;
175 };
176
177 QList<IWizard*> IWizard::wizardsOfKind(WizardKind kind)
178 {
179     return findWizards(WizardKindPredicate(kind));
180 }
181