2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup CorePlugin Core Plugin
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <extensionsystem/pluginmanager.h>
37 \brief The class IWizard is the base class for all wizards
38 (for example shown in \gui {File | New}).
40 The wizard interface is a very thin abstraction for the \gui{New...} wizards.
41 Basically it defines what to show to the user in the wizard selection dialogs,
42 and a hook that is called if the user selects the wizard.
44 Wizards can then perform any operations they like, including showing dialogs and
45 creating files. Often it is not necessary to create your own wizard from scratch,
46 instead use one of the predefined wizards and adapt it to your needs.
48 To make your wizard known to the system, add your IWizard instance to the
49 plugin manager's object pool in your plugin's initialize method:
51 bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
54 addAutoReleasedObject(new MyWizard);
58 \sa Core::BaseFileWizard
59 \sa Core::StandardFileWizard
63 \enum Core::IWizard::Kind
64 Used to specify what kind of objects the wizard creates. This information is used
65 to show e.g. only wizards that create projects when selecting a \gui{New Project}
68 The wizard creates one or more files.
70 The wizard creates a new class (e.g. source+header files).
72 The wizard creates a new project.
76 \fn IWizard::IWizard(QObject *parent)
81 \fn IWizard::~IWizard()
86 \fn Kind IWizard::kind() const
87 Returns what kind of objects are created by the wizard.
92 \fn QIcon IWizard::icon() const
93 Returns an icon to show in the wizard selection dialog.
97 \fn QString IWizard::description() const
98 Returns a translated description to show when this wizard is selected
103 \fn QString IWizard::name() const
104 Returns the translated name of the wizard, how it should appear in the
109 \fn QString IWizard::category() const
110 Returns a category ID to add the wizard to.
114 \fn QString IWizard::trCategory() const
115 Returns the translated string of the category, how it should appear
120 \fn QStringList IWizard::runWizard(const QString &path, QWidget *parent)
121 This method is executed when the wizard has been selected by the user
122 for execution. Any dialogs the wizard opens should use the given \a parent.
123 The \a path argument is a suggestion for the location where files should be
124 created. The wizard should fill this in its path selection elements as a
126 Returns a list of files (absolute paths) that have been created, if any.
129 using namespace Core
;
131 /* A utility to find all wizards supporting a view mode and matching a predicate */
132 template <class Predicate
>
133 QList
<IWizard
*> findWizards(Predicate predicate
)
135 // Filter all wizards
136 const QList
<IWizard
*> allWizards
= IWizard::allWizards();
139 const QList
<IWizard
*>::const_iterator cend
= allWizards
.constEnd();
140 for (QList
<IWizard
*>::const_iterator it
= allWizards
.constBegin(); it
!= cend
; ++it
) {
141 if (predicate(*(*it
))) {
148 QList
<IWizard
*> IWizard::allWizards()
150 return ExtensionSystem::PluginManager::instance()->getObjects
<IWizard
>();
153 // Utility to find all registered wizards of a certain kind
155 class WizardKindPredicate
{
157 WizardKindPredicate(IWizard::Kind kind
) : m_kind(kind
) {}
158 bool operator()(const IWizard
&w
) const
160 return w
.kind() == m_kind
;
163 const IWizard::Kind m_kind
;
166 QList
<IWizard
*> IWizard::wizardsOfKind(Kind kind
)
168 return findWizards(WizardKindPredicate(kind
));