aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/welcome/welcomeplugin.cpp
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2016-11-25 10:48:24 +0100
committerTim Jenssen <tim.jenssen@qt.io>2016-11-25 10:48:02 +0000
commit05c589b866110e0203fb7a6dc4d20cd35ed73372 (patch)
treeda8926bb649fc68a76596150b1a53aa62988b76b /src/plugins/welcome/welcomeplugin.cpp
parentabc2742f860f25a8b8035159e2a765858d2084b6 (diff)
Welcome: beautify code
Change-Id: I1dff086e7fb7839aa44383f80214a4543de916d1 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/welcome/welcomeplugin.cpp')
-rw-r--r--src/plugins/welcome/welcomeplugin.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp
index adc682267a..c10c5ffab2 100644
--- a/src/plugins/welcome/welcomeplugin.cpp
+++ b/src/plugins/welcome/welcomeplugin.cpp
@@ -160,7 +160,7 @@ private:
void welcomePluginAdded(QObject*);
void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
void facilitateQml(QQmlEngine *engine);
- void addPages(const QList<IWelcomePage *> &pages);
+ void addPages(QQmlEngine *engine, const QList<IWelcomePage *> &pages);
void addKeyboardShortcuts();
QWidget *m_modeWidget;
@@ -296,13 +296,16 @@ void WelcomeMode::initPlugins()
QSettings *settings = ICore::settings();
setActivePlugin(settings->value(QLatin1String(currentPageSettingsKeyC)).toInt());
- facilitateQml(m_welcomePage->engine());
+ QQmlEngine *engine = m_welcomePage->engine();
+ facilitateQml(engine);
QList<IWelcomePage *> availablePages = PluginManager::getObjects<IWelcomePage>();
- addPages(availablePages);
+ addPages(engine, availablePages);
// make sure later added pages are made available too:
- connect(PluginManager::instance(), &PluginManager::objectAdded,
- this, &WelcomeMode::welcomePluginAdded);
+ connect(PluginManager::instance(), &PluginManager::objectAdded, engine, [this, engine](QObject *obj) {
+ if (IWelcomePage *page = qobject_cast<IWelcomePage*>(obj))
+ addPages(engine, QList<IWelcomePage *>() << page);
+ });
QString path = resourcePath() + QLatin1String("/welcomescreen/welcomescreen.qml");
@@ -322,23 +325,14 @@ bool WelcomeMode::openDroppedFiles(const QList<QUrl> &urls)
return false;
}
-void WelcomeMode::welcomePluginAdded(QObject *obj)
-{
- IWelcomePage *page = qobject_cast<IWelcomePage*>(obj);
- if (!page)
- return;
- addPages(QList<IWelcomePage *>() << page);
-}
-
-void WelcomeMode::addPages(const QList<IWelcomePage *> &pages)
+void WelcomeMode::addPages(QQmlEngine *engine, const QList<IWelcomePage *> &pages)
{
QList<IWelcomePage *> addedPages = pages;
Utils::sort(addedPages, &IWelcomePage::priority);
// insert into m_pluginList, keeping m_pluginList sorted by priority
- QQmlEngine *engine = m_welcomePage->engine();
- auto addIt = addedPages.begin();
+ auto addIt = addedPages.cbegin();
auto currentIt = m_pluginList.begin();
- while (addIt != addedPages.end()) {
+ while (addIt != addedPages.cend()) {
IWelcomePage *page = *addIt;
QTC_ASSERT(!m_idPageMap.contains(page->id()), ++addIt; continue);
while (currentIt != m_pluginList.end() && (*currentIt)->priority() <= page->priority())