each view now keeps one indicator configui

--curent view indicator config ui is not deleted
when the PrimaryConfigView changes its parent view.
For each view there is one indicator config ui
that is kept available to be shown when appropriate.
This way we avoid unnecessary recreations of indicator
config uis when the user cycles between different views
settings.
pull/19/head
Michail Vourlakos 5 years ago
parent 1c0f5acde8
commit 582de7afe3

@ -322,6 +322,16 @@ void Indicator::configUiFor(QString type, QQuickItem *parent)
return;
}
if (m_lastCreatedConfigUi && m_lastCreatedConfigUiType == type && !type.isEmpty()) {
//! config ui has already been created and can be provided again
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_lastCreatedConfigUi->rootObject());
if (qmlItem) {
qmlItem->setParentItem(parent);
qmlItem->setVisible(true);
}
return;
}
if (m_lastCreatedConfigUi) {
delete m_lastCreatedConfigUi;
m_lastCreatedConfigUi = nullptr;
@ -341,7 +351,7 @@ void Indicator::configUiFor(QString type, QQuickItem *parent)
QString uiPath = metadata.value("X-Latte-ConfigUi");
if (!uiPath.isEmpty()) {
m_lastCreatedConfigUi = new KDeclarative::QmlObjectSharedEngine(parent);
m_lastCreatedConfigUi = new KDeclarative::QmlObjectSharedEngine(this);
m_lastCreatedConfigUi->setTranslationDomain(QLatin1String("latte_indicator_") + m_metadata.pluginId());
m_lastCreatedConfigUi->setInitializationDelayed(true);
uiPath = m_pluginPath + "package/" + uiPath;
@ -353,14 +363,26 @@ void Indicator::configUiFor(QString type, QQuickItem *parent)
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_lastCreatedConfigUi->rootObject());
if (qmlItem) {
qmlItem->setParentItem(parent);
m_lastCreatedConfigUiType = type;
setProvidesConfigUi(true);
}
} else {
m_lastCreatedConfigUiType = "";
setProvidesConfigUi(false);
}
}
}
void Indicator::hideConfigUi()
{
if (m_lastCreatedConfigUi) {
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_lastCreatedConfigUi->rootObject());
if (qmlItem) {
qmlItem->setVisible(false);
}
}
}
void Indicator::releaseConfigUi()
{
if (m_lastCreatedConfigUi) {

@ -130,6 +130,7 @@ public slots:
Q_INVOKABLE void addIndicator();
Q_INVOKABLE void downloadIndicator();
Q_INVOKABLE void removeIndicator(QString pluginId);
void hideConfigUi();
void releaseConfigUi();
signals:
@ -181,6 +182,8 @@ private:
QPointer<IndicatorPart::Resources> m_resources;
QPointer<KDeclarative::ConfigPropertyMap> m_configuration;
QString m_lastCreatedConfigUiType;
QPointer<KDeclarative::QmlObjectSharedEngine> m_lastCreatedConfigUi;
};

@ -245,8 +245,8 @@ void PrimaryConfigView::initParentView(Latte::View *view)
setIsReady(false);
if (m_latteView && m_latteView->indicator()) {
//! destroy indicator config ui when the configuration window is closed
m_latteView->indicator()->releaseConfigUi();
//! hide indicator config ui when parent view is changing
m_latteView->indicator()->hideConfigUi();
}
SubConfigView::initParentView(view);

@ -421,9 +421,9 @@ PlasmaComponents.Page {
onCurrentChanged: {
if (current.checked) {
if (current === customIndicator.button) {
latteView.indicator.type = customIndicator.type
latteView.indicator.type = customIndicator.type;
} else {
latteView.indicator.type = current.type
latteView.indicator.type = current.type;
}
}
}

Loading…
Cancel
Save