Commit 6e4aa3f8 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by hjk

WelcomePage: add ids to IWelcomePage and allow replacing

This patch allows replacing specific pages by id() and priority().

Change-Id: Ief0b01e6a43bdc187625c0b7aa97745588322e5e
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 65d151ce
......@@ -54,6 +54,14 @@ class QTCREATOR_UTILS_EXPORT IWelcomePage : public QObject
Q_PROPERTY(bool hasSearchBar READ hasSearchBar CONSTANT)
public:
enum Id {
GettingStarted = 0,
Develop = 1,
Examples = 2,
Tutorials = 3,
UserDefined = 32
};
IWelcomePage();
virtual ~IWelcomePage();
......@@ -62,6 +70,7 @@ public:
virtual int priority() const { return 0; }
virtual void facilitateQml(QDeclarativeEngine *) {}
virtual bool hasSearchBar() const { return false; }
virtual Id id() const = 0;
private:
// not used atm
......
......@@ -32,6 +32,8 @@
#include "projectwelcomepage.h"
#include "projectexplorerconstants.h"
#include <utils/stringutils.h>
#include <QDeclarativeEngine>
......@@ -216,6 +218,11 @@ void ProjectWelcomePage::facilitateQml(QDeclarativeEngine *engine)
ctx->setContextProperty(QLatin1String("projectWelcomePage"), this);
}
ProjectWelcomePage::Id ProjectWelcomePage::id() const
{
return Develop;
}
void ProjectWelcomePage::reloadWelcomeScreenData()
{
if (m_sessionModel)
......
......@@ -101,6 +101,7 @@ public:
QWidget *page() { return 0; }
QString title() const { return tr("Develop"); }
int priority() const { return 20; }
Id id() const;
void reloadWelcomeScreenData();
......
......@@ -35,6 +35,8 @@
#include "exampleslistmodel.h"
#include "screenshotcropper.h"
#include "qtsupportconstants.h"
#include <utils/pathchooser.h>
#include <utils/fileutils.h>
......@@ -210,7 +212,7 @@ QString GettingStartedWelcomePage::title() const
int GettingStartedWelcomePage::priority() const
{
return 0;
return 4;
}
void GettingStartedWelcomePage::facilitateQml(QDeclarativeEngine *engine)
......@@ -218,6 +220,11 @@ void GettingStartedWelcomePage::facilitateQml(QDeclarativeEngine *engine)
m_engine = engine;
}
GettingStartedWelcomePage::Id GettingStartedWelcomePage::id() const
{
return GettingStarted;
}
ExamplesWelcomePage::ExamplesWelcomePage()
: m_engine(0), m_showExamples(false)
{
......@@ -281,6 +288,11 @@ void ExamplesWelcomePage::facilitateQml(QDeclarativeEngine *engine)
rootContenxt->setContextProperty(QLatin1String("gettingStarted"), this);
}
ExamplesWelcomePage::Id ExamplesWelcomePage::id() const
{
return m_showExamples ? Examples : Tutorials;
}
void ExamplesWelcomePage::openSplitHelp(const QUrl &help)
{
Core::ICore::helpManager()->handleHelpRequest(help.toString()+QLatin1String("?view=split"));
......
......@@ -58,6 +58,7 @@ public:
QString title() const;
int priority() const;
void facilitateQml(QDeclarativeEngine *);
Id id() const;
private:
QDeclarativeEngine *m_engine;
......@@ -76,6 +77,7 @@ public:
int priority() const;
bool hasSearchBar() const;
void facilitateQml(QDeclarativeEngine *);
Id id() const;
Q_INVOKABLE QStringList tagList() const;
Q_INVOKABLE void openUrl(const QUrl &url);
......
......@@ -208,8 +208,30 @@ void WelcomeMode::initPlugins()
QDeclarativeContext *ctx = m_welcomePage->rootContext();
ctx->setContextProperty(QLatin1String("welcomeMode"), this);
QList<Utils::IWelcomePage*> plugins = PluginManager::instance()->getObjects<Utils::IWelcomePage>();
qSort(plugins.begin(), plugins.end(), &sortFunction);
QList<Utils::IWelcomePage*> duplicatePlugins = PluginManager::instance()->getObjects<Utils::IWelcomePage>();
qSort(duplicatePlugins.begin(), duplicatePlugins.end(), &sortFunction);
QList<Utils::IWelcomePage*> plugins;
QHash<Utils::IWelcomePage::Id, Utils::IWelcomePage*> pluginHash;
//avoid duplicate ids - choose by priority
foreach (Utils::IWelcomePage* plugin, duplicatePlugins) {
if (pluginHash.contains(plugin->id())) {
Utils::IWelcomePage* pluginOther = pluginHash.value(plugin->id());
if (pluginOther->priority() > plugin->priority()) {
plugins.removeAll(pluginOther);
pluginHash.remove(pluginOther->id());
plugins << plugin;
pluginHash.insert(plugin->id(), plugin);
}
} else {
plugins << plugin;
pluginHash.insert(plugin->id(), plugin);
}
}
QDeclarativeEngine *engine = m_welcomePage->engine();
if (!debug)
......@@ -252,7 +274,24 @@ QString WelcomeMode::platform() const
void WelcomeMode::welcomePluginAdded(QObject *obj)
{
QHash<Utils::IWelcomePage::Id, Utils::IWelcomePage*> pluginHash;
foreach (QObject *obj, m_pluginList) {
Utils::IWelcomePage *plugin = qobject_cast<Utils::IWelcomePage*>(obj);
pluginHash.insert(plugin->id(), plugin);
}
if (Utils::IWelcomePage *plugin = qobject_cast<Utils::IWelcomePage*>(obj)) {
//check for duplicated id
if (pluginHash.contains(plugin->id())) {
Utils::IWelcomePage* pluginOther = pluginHash.value(plugin->id());
if (pluginOther->priority() > plugin->priority()) {
m_pluginList.removeAll(pluginOther);
} else {
return;
}
}
int insertPos = 0;
foreach (Utils::IWelcomePage* p, PluginManager::instance()->getObjects<Utils::IWelcomePage>()) {
if (plugin->priority() < p->priority())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment