Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / coreplugin / dialogs / iwizard.cpp
blob202f3996da80426842c9b83c247a81703620061a
1 /**
2 ******************************************************************************
4 * @file iwizard.cpp
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
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
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
22 * for more details.
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
29 #include "iwizard.h"
31 #include <extensionsystem/pluginmanager.h>
33 /*!
34 \class Core::IWizard
35 \mainclass
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:
50 \code
51 bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
53 // ... do setup
54 addAutoReleasedObject(new MyWizard);
55 // ... do more setup
57 \endcode
58 \sa Core::BaseFileWizard
59 \sa Core::StandardFileWizard
62 /*!
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}
66 menu item.
67 \value FileWizard
68 The wizard creates one or more files.
69 \value ClassWizard
70 The wizard creates a new class (e.g. source+header files).
71 \value ProjectWizard
72 The wizard creates a new project.
75 /*!
76 \fn IWizard::IWizard(QObject *parent)
77 \internal
80 /*!
81 \fn IWizard::~IWizard()
82 \internal
85 /*!
86 \fn Kind IWizard::kind() const
87 Returns what kind of objects are created by the wizard.
88 \sa Kind
91 /*!
92 \fn QIcon IWizard::icon() const
93 Returns an icon to show in the wizard selection dialog.
96 /*!
97 \fn QString IWizard::description() const
98 Returns a translated description to show when this wizard is selected
99 in the dialog.
103 \fn QString IWizard::name() const
104 Returns the translated name of the wizard, how it should appear in the
105 dialog.
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
116 in the dialog.
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
125 default path.
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();
138 QList<IWizard *> rc;
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))) {
142 rc.push_back(*it);
145 return rc;
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 {
156 public:
157 WizardKindPredicate(IWizard::Kind kind) : m_kind(kind) {}
158 bool operator()(const IWizard &w) const
160 return w.kind() == m_kind;
162 private:
163 const IWizard::Kind m_kind;
166 QList<IWizard *> IWizard::wizardsOfKind(Kind kind)
168 return findWizards(WizardKindPredicate(kind));