1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include <extensionsystem/pluginmanager.h>
43 \brief The class IWizard is the base class for all wizards
44 (for example shown in \gui {File | New}).
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.
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.
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:
57 bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
60 addAutoReleasedObject(new MyWizard);
64 \sa Core::BaseFileWizard
65 \sa Core::StandardFileWizard
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}
74 The wizard creates one or more files.
76 The wizard creates a new class (e.g. source+header files).
78 The wizard creates a new project.
82 \fn IWizard::IWizard(QObject *parent)
87 \fn IWizard::~IWizard()
92 \fn Kind IWizard::kind() const
93 Returns what kind of objects are created by the wizard.
98 \fn QIcon IWizard::icon() const
99 Returns an icon to show in the wizard selection dialog.
103 \fn QString IWizard::description() const
104 Returns a translated description to show when this wizard is selected
109 \fn QString IWizard::name() const
110 Returns the translated name of the wizard, how it should appear in the
115 \fn QString IWizard::id() const
116 Returns an arbitrary id that is used for sorting within the category.
121 \fn QString IWizard::category() const
122 Returns a category ID to add the wizard to.
126 \fn QString IWizard::displayCategory() const
127 Returns the translated string of the category, how it should appear
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
140 using namespace Core;
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)
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();
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)))
159 QList<IWizard*> IWizard::allWizards()
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>();
167 // Utility to find all registered wizards of a certain kind
169 class WizardKindPredicate {
171 WizardKindPredicate(IWizard::WizardKind kind) : m_kind(kind) {}
172 bool operator()(const IWizard &w) const { return w.kind() == m_kind; }
174 const IWizard::WizardKind m_kind;
177 QList<IWizard*> IWizard::wizardsOfKind(WizardKind kind)
179 return findWizards(WizardKindPredicate(kind));