Commit 17a7bd17 authored by Thomas Hartmann's avatar Thomas Hartmann

Wizards: allows filtering of wizards based on Qt version

Every wizard now implements requiredFeatures() to define a feature set.
If the feature set is not satisfied by the available Qt Versions,
the wizard is not shown in the create file/project dialog.

Every Qt version can define the provided feature set in availableFeatures()
defined in BaseQtVersion.

Change-Id: Ie9e2c210d19187b2296451948c36d274f2096623
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@nokia.com>
parent 31d5ec9c
......@@ -37,7 +37,7 @@ the project file goes last.
The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and
leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project" firstpage="10" id="S.Plain C (CMake)" category="I.Projects">
<wizard version="1" kind="project" firstpage="10" id="S.Plain C (CMake)" category="I.Projects" featuresRequired="QtSupport.Wizards.FeatureGenericCppEntryPoint">
<icon>console.png</icon>
<description>Creates a plain C project using CMake, not using the Qt library.</description>
<displayname>Plain C Project (CMake Build)</displayname>;
......
......@@ -39,7 +39,8 @@ leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project"
class="qt4project" firstpage="10"
id="R.Plain C" category="I.Projects">
id="R.Plain C" category="I.Projects"
featuresRequired="QtSupport.Wizards.FeatureGenericCppEntryPoint">
<icon>console.png</icon>
<description>Creates a plain C project using qmake, not using the Qt library.</description>
<displayname>Plain C Project</displayname>;
......
......@@ -37,7 +37,7 @@ the project file goes last.
The "class" and "firstpage" attributes specify that it is a Qt 4 wizard and
leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project" firstpage="10" id="S.Plain C++ (CMake)" category="I.Projects">
<wizard version="1" kind="project" firstpage="10" id="S.Plain C++ (CMake)" category="I.Projects" featuresRequired="QtSupport.Wizards.FeatureGenericCppEntryPoint">
<icon>console.png</icon>
<description>Creates a plain C++ project using CMake, not using the Qt library.</description>
<displayname>Plain C++ Project (CMake Build)</displayname>;
......
......@@ -39,7 +39,8 @@ leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project"
class="qt4project" firstpage="10"
id="R.Plain C++" category="I.Projects">
id="R.Plain C++" category="I.Projects"
featuresRequired="QtSupport.Wizards.FeatureGenericCppEntryPoint">
<icon>console.png</icon>
<description>Creates a plain C++ project using qmake, not using the Qt library.</description>
<displayname>Plain C++ Project</displayname>;
......
......@@ -39,7 +39,8 @@ leave room for the Qt 4 target page.
-->
<wizard version="1" kind="project"
class="qt4project" firstpage="10"
id="R.QtCreatorPlugin" category="F.QtProjects">
id="R.QtCreatorPlugin" category="F.QtProjects"
featuresRequired="QtSupport.Wizards.FeatureGenericCppEntryPoint,QtSupport.Wizards.FeatureQt">
<icon>qtcreator_logo_24.png</icon>
<description>Creates a custom Qt Creator plugin.</description>
<displayname>Qt Creator Plugin</displayname>;
......
......@@ -86,6 +86,7 @@ public:
QString id;
QString category;
QString displayCategory;
Core::FeatureSet requiredFeatures;
};
BaseFileWizardParameterData::BaseFileWizardParameterData(IWizard::WizardKind k) :
......@@ -145,7 +146,8 @@ CORE_EXPORT QDebug operator<<(QDebug d, const BaseFileWizardParameters &p)
<< " Category: " << p.category()
<< " DisplayName: " << p.displayName()
<< " Description: " << p.description()
<< " DisplayCategory: " << p.displayCategory();
<< " DisplayCategory: " << p.displayCategory()
<< " Required Features: " << p.requiredFeatures().toStringList();
return d;
}
......@@ -214,6 +216,17 @@ QString BaseFileWizardParameters::displayCategory() const
return m_d->displayCategory;
}
Core::FeatureSet BaseFileWizardParameters::requiredFeatures() const
{
return m_d->requiredFeatures;
}
void BaseFileWizardParameters::setRequiredFeatures(Core::FeatureSet features)
{
m_d->requiredFeatures = features;
}
void BaseFileWizardParameters::setDisplayCategory(const QString &v)
{
m_d->displayCategory = v;
......@@ -349,6 +362,11 @@ BaseFileWizard::BaseFileWizard(const BaseFileWizardParameters &parameters,
{
}
BaseFileWizardParameters BaseFileWizard::baseFileWizardParameters() const
{
return d->m_parameters;
}
BaseFileWizard::~BaseFileWizard()
{
delete d;
......@@ -497,6 +515,12 @@ void BaseFileWizard::runWizard(const QString &path, QWidget *parent)
QMessageBox::critical(0, tr("File Generation Failure"), errorMessage);
}
Core::FeatureSet BaseFileWizard::requiredFeatures() const
{
return d->m_parameters.requiredFeatures();
}
/*!
\fn virtual QWizard *Core::BaseFileWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
......
......@@ -91,6 +91,9 @@ public:
QString displayCategory() const;
void setDisplayCategory(const QString &trCategory);
Core::FeatureSet requiredFeatures() const;
void setRequiredFeatures(Core::FeatureSet features);
private:
QSharedDataPointer<BaseFileWizardParameterData> m_d;
};
......@@ -115,6 +118,7 @@ public:
virtual QString displayCategory() const;
virtual void runWizard(const QString &path, QWidget *parent);
virtual Core::FeatureSet requiredFeatures() const;
static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
static void setupWizard(QWizard *);
......@@ -125,6 +129,8 @@ protected:
explicit BaseFileWizard(const BaseFileWizardParameters &parameters, QObject *parent = 0);
BaseFileWizardParameters baseFileWizardParameters() const;
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const = 0;
......
......@@ -95,7 +95,8 @@ SOURCES += mainwindow.cpp \
mimetypesettings.cpp \
dialogs/promptoverwritedialog.cpp \
fileutils.cpp \
textfile.cpp
textfile.cpp \
featureprovider.cpp
HEADERS += mainwindow.h \
editmode.h \
......@@ -192,7 +193,8 @@ HEADERS += mainwindow.h \
fileutils.h \
externaltoolmanager.h \
textfile.h \
generatedfile.h
generatedfile.h \
featureprovider.h
FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \
......
......@@ -35,6 +35,8 @@
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QStringList>
/*!
\class Core::IWizard
\mainclass
......@@ -178,3 +180,14 @@ QList<IWizard*> IWizard::wizardsOfKind(WizardKind kind)
return findWizards(WizardKindPredicate(kind));
}
bool IWizard::isAvailable() const
{
FeatureSet availableFeatures;
const QList<Core::IFeatureProvider*> featureManagers = ExtensionSystem::PluginManager::instance()->getObjects<Core::IFeatureProvider>();
foreach (const Core::IFeatureProvider *featureManager, featureManagers)
availableFeatures |= featureManager->availableFeatures();
return availableFeatures.contains(requiredFeatures());
}
......@@ -34,6 +34,8 @@
#define IWIZARD_H
#include <coreplugin/core_global.h>
#include <coreplugin/featureprovider.h>
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
......@@ -66,8 +68,12 @@ public:
virtual QString category() const = 0;
virtual QString displayCategory() const = 0;
virtual FeatureSet requiredFeatures() const = 0;
virtual void runWizard(const QString &path, QWidget *parent) = 0;
bool isAvailable() const;
// Utility to find all registered wizards
static QList<IWizard*> allWizards();
// Utility to find all registered wizards of a certain kind
......
......@@ -37,7 +37,7 @@
#include <utils/stylehelper.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/dialogs/iwizard.h>
#include <coreplugin/featureprovider.h>
#include <QtGui/QAbstractProxyModel>
#include <QtGui/QItemSelectionModel>
......@@ -249,19 +249,21 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
cit = categories.insert(categoryName, categoryItem);
}
// add item
QStandardItem *wizardItem = new QStandardItem(wizard->displayName());
QIcon wizardIcon;
// spacing hack. Add proper icons instead
if (wizard->icon().isNull()) {
wizardIcon = m_dummyIcon;
} else {
wizardIcon = wizard->icon();
if (wizard->isAvailable()) {
QStandardItem *wizardItem = new QStandardItem(wizard->displayName());
QIcon wizardIcon;
// spacing hack. Add proper icons instead
if (wizard->icon().isNull()) {
wizardIcon = m_dummyIcon;
} else {
wizardIcon = wizard->icon();
}
wizardItem->setIcon(wizardIcon);
wizardItem->setData(QVariant::fromValue(wizard), Qt::UserRole);
wizardItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
cit.value()->appendRow(wizardItem);
}
wizardItem->setIcon(wizardIcon);
wizardItem->setData(QVariant::fromValue(wizard), Qt::UserRole);
wizardItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
cit.value()->appendRow(wizardItem);
}
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "featureprovider.h"
/*!
\class Core::IFeatureProvider
\mainclass
\brief The class IFeatureProvider defines an interface to manage features for wizards
The features provided by an object in the object pool implementing IFeatureProvider
will be respected by wizards implementing IWizard.
This feature set, provided by all instances of IFeatureProvider in the object pool, is checked against IWizard::requiredFeatures()
and only if all required features are available the wizard is displayed when creating a new file or project.
Qt4VersionManager creates an instance of IFeatureProvider and provides Qt specific features for the available
versions of Qt.
\sa Core::IWizard
\sa QtSupport::QtVersionManager
*/
/*!
\fn IFeatureProvider::IFeatureProvider()
\internal
*/
/*!
\fn IFeatureProvider::~IFeatureProvider()
\internal
*/
/*!
\fn FeatureProvider::Features availableFeatures() const;
Returns available features provided by this manager.
\sa FeatureProvider::Features
*/
/*!
\class Core::FeatureProvider::Feature
\brief This class describes a single Feature
This class describes a single Feature to be used
in Core::FeatureProvider::Features.
\sa Core::FeatureProvider::Features
\sa Core::IWizard
\sa QtSupport::QtVersionManager
*/
/*!
\class Core::FeatureProvider::Features
\brief This class is a set of features
Features is used to describe available or
required feature sets and behaves similar to QFlags.
But instead of enums Features relies on string ids
and is therefore extendable.
\sa Core::FeatureProvider::Feature
\sa Core::IWizard
\sa QtSupport::QtVersionManager
*/
/*!
\fn bool Features::~contains(const Feature &feature)()
\returns true if the \param features is available.
*/
/*!
\fn bool Features::~contains(const Features &features)()
\returns true if all \param features are available.
*/
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef FEATUREMANAGER_H
#define FEATUREMANAGER_H
#include "core_global.h"
#include <coreplugin/id.h>
#include <QtCore/QObject>
#include <QtCore/QSet>
#include <QtCore/QStringList>
namespace Utils {
class AbstractMacroExpander;
}
namespace Core {
class CORE_EXPORT FeatureSet;
class CORE_EXPORT IFeatureProvider : public QObject
{
Q_OBJECT
public:
IFeatureProvider() {}
virtual ~IFeatureProvider() {}
virtual FeatureSet availableFeatures() const = 0;
};
class CORE_EXPORT Feature : public Id
{
friend class FeatureSet;
public:
Feature(const char *name) : Id(name) {}
explicit Feature(const QString &name) : Id(name) {}
};
class CORE_EXPORT FeatureSet : private QSet<Feature>
{
public:
FeatureSet() {}
FeatureSet(const Feature &feature)
{
if (feature.toString().isEmpty())
return;
insert(feature);
}
FeatureSet(const FeatureSet &other) : QSet<Feature>(other) {}
FeatureSet &operator=(const FeatureSet &other)
{
QSet<Feature>::operator=(other);
return *this;
}
bool contains(const Feature &feature) const
{
return QSet<Feature>::contains(feature);
}
bool contains(const FeatureSet &features) const
{
return QSet<Feature>::contains(features);
}
void remove(const Feature &feature)
{
QSet<Feature>::remove(feature);
}
FeatureSet operator|(const Feature &feature) const
{
FeatureSet copy = *this;
if (feature.isValid())
copy.insert(feature);
return copy;
}
FeatureSet operator|(const FeatureSet &features) const
{
FeatureSet copy = *this;
if (!features.isEmpty())
copy.unite(features);
return copy;
}
FeatureSet &operator|=(const Feature &feature)
{
if (feature.isValid())
insert(feature);
return *this;
}
FeatureSet &operator|=(const FeatureSet &features)
{
if (!features.isEmpty())
unite(features);
return *this;
}
QStringList toStringList() const
{
QStringList stringList;
foreach (const Feature &feature, QSet<Feature>(*this))
stringList.append(feature.toString());
return stringList;
}
};
} // namespace Core
/*
The following operators have to be defined in the global namespace!
Otherwise "using namespace Core" would hide other | operators
defined in the global namespace (e. g. QFlags).
*/
inline Core::FeatureSet operator |(Core::Feature feature1, Core::Feature feature2)
{ return Core::FeatureSet(feature1) | feature2; }
inline Core::FeatureSet operator|(Core::Feature feature1, Core::FeatureSet feature2)
{ return feature2 | feature1; }
#endif // FEATUREANAGER_H
......@@ -155,6 +155,11 @@ CppClassWizard::CppClassWizard(const Core::BaseFileWizardParameters &parameters,
{
}
Core::FeatureSet CppClassWizard::requiredFeatures() const
{
return Core::FeatureSet();
}
QString CppClassWizard::sourceSuffix() const
{
return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
......
......@@ -102,6 +102,8 @@ public:
explicit CppClassWizard(const Core::BaseFileWizardParameters &parameters,
QObject *parent = 0);
virtual Core::FeatureSet requiredFeatures() const;
protected:
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
......
......@@ -35,6 +35,7 @@
#include "designerconstants.h"
#include "formwindoweditor.h"
#include "qtdesignerformclasscodegenerator.h"
#include <qtsupport/qtsupportconstants.h>
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
......@@ -65,6 +66,11 @@ QString FormClassWizard::formSuffix() const
return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
}
Core::FeatureSet FormClassWizard::requiredFeatures() const
{
return Core::Feature(QtSupport::Constants::FEATURE_QWIDGETS);
}
QWizard *FormClassWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
......
......@@ -55,6 +55,8 @@ public:
QString sourceSuffix() const;
QString formSuffix() const;
virtual Core::FeatureSet requiredFeatures() const;
protected:
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
......
......@@ -34,6 +34,7 @@
#include "formwizarddialog.h"
#include "formwindoweditor.h"
#include "designerconstants.h"
#include <qtsupport/qtsupportconstants.h>
#include <QtCore/QDebug>
......@@ -45,6 +46,11 @@ FormWizard::FormWizard(const BaseFileWizardParameters &parameters, QObject *pare
{
}
Core::FeatureSet FormWizard::requiredFeatures() const
{
return Core::Feature(QtSupport::Constants::FEATURE_QWIDGETS);
}
QWizard *FormWizard::createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const
......
......@@ -47,6 +47,8 @@ public:
FormWizard(const BaseFileWizardParameters &parameters, QObject *parent);
virtual Core::FeatureSet requiredFeatures() const;
protected:
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
......
......@@ -116,6 +116,11 @@ GenericProjectWizard::GenericProjectWizard()
GenericProjectWizard::~GenericProjectWizard()
{ }
Core::FeatureSet GenericProjectWizard::requiredFeatures() const
{
return Core::FeatureSet();
}