Commit 9b9fdaee authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

WelcomePage: create 2 instances of GettingStartedWelcomePage

GettingStartedWelcomePage gets instanciated twice now.

The new instance does show the examples and has the title:
"Demos and Examples".

The ExamplesListModel is shared between the two instances and is
a static member.
The method examplesModel() is used to access the ExamplesListModel and
lazily creates one.

QtSupportPlugin creates the two different instances.

Change-Id: Ie5bf9ce8b25aeeacb88731ce1d3179004175fd2f
Reviewed-on: http://codereview.qt-project.org/5706

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 6fb27988
......@@ -136,6 +136,7 @@ public slots:
}
void parseSearchString(const QString& arg);
void setShowTutorialsOnly(bool showTutorialsOnly);
signals:
void showTutorialsOnlyChanged();
......@@ -144,9 +145,6 @@ signals:
void searchStrings(const QStringList& arg);
private slots:
void setShowTutorialsOnly(bool showTutorialsOnly);
private:
bool m_showTutorialsOnly;
QStringList m_filterTags;
......
......@@ -44,18 +44,24 @@
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
#include <QtCore/QWeakPointer>
#include <QtGui/QGraphicsProxyWidget>
#include <QtGui/QScrollBar>
#include <QtGui/QSortFilterProxyModel>
#include <QtSql/QSqlQueryModel>
#include <QtSql/QSqlQuery>
#include <QtDeclarative>
#include <QDebug>
namespace QtSupport {
namespace Internal {
const char *C_FALLBACK_ROOT = "ProjectsFallbackRoot";
const char C_FALLBACK_ROOT[] = "ProjectsFallbackRoot";
QWeakPointer<ExamplesListModel> &examplesModelStatic()
{
static QWeakPointer<ExamplesListModel> s_examplesModel;
return s_examplesModel;
}
class Fetcher : public QObject
{
......@@ -104,29 +110,66 @@ private:
};
GettingStartedWelcomePage::GettingStartedWelcomePage()
: m_examplesModel(0), m_engine(0)
: m_engine(0), m_showExamples(false)
{
}
void GettingStartedWelcomePage::setShowExamples(bool showExamples)
{
m_showExamples = showExamples;
}
QString GettingStartedWelcomePage::title() const
{
if (m_showExamples)
return tr("Demos and Examples");
else
return tr("Getting Started");
}
int GettingStartedWelcomePage::priority() const
{
if (m_showExamples)
return 30;
else
return 10;
}
bool GettingStartedWelcomePage::hasSearchBar() const
{
if (m_showExamples)
return true;
else
return false;
}
QUrl GettingStartedWelcomePage::pageLocation() const
{
return QUrl::fromLocalFile(Core::ICore::instance()->resourcePath() + QLatin1String("/welcomescreen/gettingstarted.qml"));
if (m_showExamples)
return QUrl::fromLocalFile(Core::ICore::instance()->resourcePath() + QLatin1String("/welcomescreen/examples.qml"));
else
return QUrl::fromLocalFile(Core::ICore::instance()->resourcePath() + QLatin1String("/welcomescreen/gettingstarted.qml"));
}
void GettingStartedWelcomePage::facilitateQml(QDeclarativeEngine *engine)
{
m_engine = engine;
m_engine->addImageProvider(QLatin1String("helpimage"), new HelpImageProvider);
m_examplesModel = new ExamplesListModel(this);
connect (m_examplesModel, SIGNAL(tagsUpdated()), SLOT(updateTagsModel()));
connect (examplesModel(), SIGNAL(tagsUpdated()), SLOT(updateTagsModel()));
ExamplesListModelFilter *proxy = new ExamplesListModelFilter(this);
proxy->setSourceModel(m_examplesModel);
proxy->setSourceModel(examplesModel());
proxy->setDynamicSortFilter(true);
proxy->sort(0);
proxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
QDeclarativeContext *rootContenxt = m_engine->rootContext();
rootContenxt->setContextProperty(QLatin1String("examplesModel"), proxy);
if (m_showExamples) {
proxy->setShowTutorialsOnly(false);
rootContenxt->setContextProperty(QLatin1String("examplesModel"), proxy);
} else {
rootContenxt->setContextProperty(QLatin1String("tutorialsModel"), proxy);
}
rootContenxt->setContextProperty(QLatin1String("gettingStarted"), this);
}
......@@ -137,7 +180,7 @@ void GettingStartedWelcomePage::openSplitHelp(const QUrl &help)
QStringList GettingStartedWelcomePage::tagList() const
{
return m_examplesModel->tags();
return examplesModel()->tags();
}
QString GettingStartedWelcomePage::copyToAlternativeLocation(const QFileInfo& proFileInfo, QStringList &filesToOpen)
......@@ -230,10 +273,19 @@ void GettingStartedWelcomePage::openProject(const QString &projectFile, const QS
void GettingStartedWelcomePage::updateTagsModel()
{
m_engine->rootContext()->setContextProperty(QLatin1String("tagsList"), m_examplesModel->tags());
m_engine->rootContext()->setContextProperty(QLatin1String("tagsList"), examplesModel()->tags());
emit tagsUpdated();
}
ExamplesListModel *GettingStartedWelcomePage::examplesModel() const
{
if (examplesModelStatic())
return examplesModelStatic().data();
examplesModelStatic() = new ExamplesListModel(const_cast<GettingStartedWelcomePage*>(this));
return examplesModelStatic().data();
}
} // namespace Internal
} // namespace QtSupport
......
......@@ -55,9 +55,11 @@ class GettingStartedWelcomePage : public Utils::IWelcomePage
public:
GettingStartedWelcomePage();
void setShowExamples(bool showExamples);
QUrl pageLocation() const;
QString title() const { return tr("Getting Started");}
int priority() const { return 10; }
QString title() const;
int priority() const;
bool hasSearchBar() const;
void facilitateQml(QDeclarativeEngine *);
Q_INVOKABLE QStringList tagList() const;
......@@ -70,9 +72,10 @@ public slots:
void updateTagsModel();
private:
ExamplesListModel *examplesModel() const;
QString copyToAlternativeLocation(const QFileInfo &fileInfo, QStringList &filesToOpen);
ExamplesListModel *m_examplesModel;
QDeclarativeEngine *m_engine;
bool m_showExamples;
};
} // namespace Internal
......
......@@ -68,6 +68,10 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
m_welcomePage = new GettingStartedWelcomePage;
addObject(m_welcomePage);
m_welcomePage = new GettingStartedWelcomePage;
m_welcomePage->setShowExamples(true);
addObject(m_welcomePage);
return true;
}
......
Supports Markdown
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