Commit f2909a90 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

sidebar: Load placeHolderWidget only when needed

This slightly reduces the startup time of the sidebar mode, and
potentially fixes the crash when switching from the icon mode to
the sidebar mode.

CCBUG: 449853


(cherry picked from commit e7dab853)
parent b327dde6
Pipeline #139758 passed with stage
in 1 minute and 25 seconds
......@@ -581,7 +581,9 @@ void SidebarMode::loadModule(const QModelIndex &activeModule, const QStringList
void SidebarMode::moduleLoaded()
{
d->placeHolderWidget->hide();
if (d->placeHolderWidget) {
d->placeHolderWidget->hide();
}
d->moduleView->show();
if (applicationMode() == BaseMode::InfoCenter) {
d->moduleView->setSaveStatistics(false);
......@@ -650,7 +652,9 @@ void SidebarMode::setIntroPageVisible(const bool &introPageVisible)
// TODO: Make the intro page of SystemSettings a KCM as well
if (homeItem()) {
d->placeHolderWidget->hide();
if (d->placeHolderWidget) {
d->placeHolderWidget->hide();
}
d->moduleView->show();
if (introPageVisible) {
QModelIndex index = d->categorizedModel->mapFromSource(d->model->indexForItem(homeItem()));
......@@ -672,10 +676,15 @@ void SidebarMode::setIntroPageVisible(const bool &introPageVisible)
Q_EMIT activeCategoryRowChanged();
d->activeSubCategoryRow = -1;
Q_EMIT activeSubCategoryRowChanged();
if (!d->placeHolderWidget) {
initPlaceHolderWidget();
}
d->placeHolderWidget->show();
d->moduleView->hide();
} else {
d->placeHolderWidget->hide();
if (d->placeHolderWidget) {
d->placeHolderWidget->hide();
}
d->moduleView->show();
}
}
......@@ -823,34 +832,21 @@ void SidebarMode::initWidget()
d->quickWidget->installEventFilter(this);
d->placeHolderWidget = new QQuickWidget(d->mainWidget);
d->placeHolderWidget->quickWindow()->setTitle(i18n("Most Used"));
d->placeHolderWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
d->placeHolderWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(d->placeHolderWidget));
d->placeHolderWidget->engine()->rootContext()->setContextProperty(QStringLiteral("systemsettings"), this);
d->placeHolderWidget->setSource(QUrl::fromLocalFile(d->package.filePath("ui", QStringLiteral("introPage.qml"))));
connect(d->placeHolderWidget->rootObject(), SIGNAL(focusNextRequest()), d->mainWidget, SLOT(focusNext()));
connect(d->placeHolderWidget->rootObject(), SIGNAL(focusPreviousRequest()), d->mainWidget, SLOT(focusPrevious()));
d->placeHolderWidget->installEventFilter(this);
d->mainLayout->addWidget(d->quickWidget);
d->moduleView->hide();
d->mainLayout->addWidget(d->moduleView);
d->mainLayout->addWidget(d->placeHolderWidget);
Q_EMIT changeToolBarItems(BaseMode::NoItems);
d->toolTipManager = new ToolTipManager(d->categorizedModel, d->quickWidget, ToolTipManager::ToolTipPosition::Right);
d->mostUsedToolTipManager = new ToolTipManager(d->mostUsedModel, d->placeHolderWidget, ToolTipManager::ToolTipPosition::BottomCenter);
d->mostUsedModel->setResultModel(new ResultModel(AllResources | Agent(QStringLiteral("org.kde.systemsettings")) | HighScoredFirst | Limit(5), this));
if (!startupModule().isEmpty()) {
initPlaceHolderWidget();
d->placeHolderWidget->show();
MenuItem *item = rootItem()->descendantForModule(startupModule());
if (item) {
loadModule(d->model->indexForItem(item), startupModuleArgs());
}
} else if (homeItem()) {
d->placeHolderWidget->hide();
d->moduleView->show();
QModelIndex index = d->categorizedModel->mapFromSource(d->model->indexForItem(homeItem()));
if (index.isValid()) {
......@@ -858,9 +854,30 @@ void SidebarMode::initWidget()
} else {
d->moduleView->loadModule( d->model->indexForItem(homeItem()), QStringList() );
}
} else {
initPlaceHolderWidget();
d->placeHolderWidget->show();
}
}
void SidebarMode::initPlaceHolderWidget()
{
d->placeHolderWidget = new QQuickWidget(d->mainWidget);
d->placeHolderWidget->quickWindow()->setTitle(i18n("Most Used"));
d->placeHolderWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
d->placeHolderWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(d->placeHolderWidget));
d->placeHolderWidget->engine()->rootContext()->setContextProperty(QStringLiteral("systemsettings"), this);
d->placeHolderWidget->setSource(QUrl::fromLocalFile(d->package.filePath("ui", QStringLiteral("introPage.qml"))));
connect(d->placeHolderWidget->rootObject(), SIGNAL(focusNextRequest()), d->mainWidget, SLOT(focusNext()));
connect(d->placeHolderWidget->rootObject(), SIGNAL(focusPreviousRequest()), d->mainWidget, SLOT(focusPrevious()));
d->placeHolderWidget->installEventFilter(this);
d->mainLayout->addWidget(d->placeHolderWidget);
d->mostUsedToolTipManager = new ToolTipManager(d->mostUsedModel, d->placeHolderWidget, ToolTipManager::ToolTipPosition::BottomCenter);
d->mostUsedModel->setResultModel(new ResultModel(AllResources | Agent(QStringLiteral("org.kde.systemsettings")) | HighScoredFirst | Limit(5), this));
}
void SidebarMode::reloadStartupModule()
{
if (!startupModule().isEmpty()) {
......
......@@ -132,6 +132,7 @@ private Q_SLOTS:
void initWidget();
private:
void initPlaceHolderWidget();
void updateModelMenuItem(MenuItem *item);
void updateCategoryModel(const QModelIndex &categoryIdx);
void refreshDefaults();
......
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