refactor LayoutManager::save() to remove code repetition

Hey, first KDE contribution here. I was digging through code trying to fix [bug 427530](https://bugs.kde.org/show_bug.cgi?id=427530) when I found this copied-and-pasted block in LayoutManager::save(). This MR moves the block into a lambda to remove code repetition.

I am not a C++ programmer and although nothing changed that I could notice, it would be smart to sanity check and/or test this before merging.
work/usta_fix_ecm_version_check
Amy Rose 3 years ago committed by Michail Vourlakos
parent d43f3d5ac4
commit 538dba0a02

@ -514,35 +514,10 @@ void LayoutManager::save()
reorderParabolicSpacers();
int startChilds{0};
for(int i=0; i<m_startLayout->childItems().count(); ++i) {
QQuickItem *item = m_startLayout->childItems()[i];
bool isInternalSplitter = item->property("isInternalViewSplitter").toBool();
bool isParabolicEdgeSpacer = item->property("isParabolicEdgeSpacer").toBool();
if (!isInternalSplitter && !isParabolicEdgeSpacer) {
QVariant appletVariant = item->property("applet");
if (!appletVariant.isValid()) {
continue;
}
QObject *applet = appletVariant.value<QObject *>();
if (!applet) {
continue;
}
uint id = applet->property("id").toUInt();
if (id>0) {
startChilds++;
appletIds << id;
}
}
}
int mainChilds{0};
for(int i=0; i<m_mainLayout->childItems().count(); ++i) {
QQuickItem *item = m_mainLayout->childItems()[i];
auto collectLayoutAppletIds = [](QQuickItem *layout, QList<int> &appletIds) {
int childCount = 0;
for (int i=0; i<layout->childItems().count(); ++i) {
QQuickItem *item = layout->childItems()[i];
bool isInternalSplitter = item->property("isInternalViewSplitter").toBool();
bool isParabolicEdgeSpacer = item->property("isParabolicEdgeSpacer").toBool();
if (!isInternalSplitter && !isParabolicEdgeSpacer) {
@ -560,37 +535,17 @@ void LayoutManager::save()
uint id = applet->property("id").toUInt();
if (id>0) {
mainChilds++;
childCount++;
appletIds << id;
}
}
}
return childCount;
};
int endChilds{0};
for(int i=0; i<m_endLayout->childItems().count(); ++i) {
QQuickItem *item = m_endLayout->childItems()[i];
bool isInternalSplitter = item->property("isInternalViewSplitter").toBool();
bool isParabolicEdgeSpacer = item->property("isParabolicEdgeSpacer").toBool();
if (!isInternalSplitter && !isParabolicEdgeSpacer) {
QVariant appletVariant = item->property("applet");
if (!appletVariant.isValid()) {
continue;
}
QObject *applet = appletVariant.value<QObject *>();
if (!applet) {
continue;
}
uint id = applet->property("id").toUInt();
if (id>0) {
endChilds++;
appletIds << id;
}
}
}
int startChilds = collectLayoutAppletIds(m_startLayout, appletIds);
int mainChilds = collectLayoutAppletIds(m_mainLayout, appletIds);
int endChilds = collectLayoutAppletIds(m_endLayout, appletIds);
Latte::Types::Alignment alignment = static_cast<Latte::Types::Alignment>((*m_configuration)["alignment"].toInt());

Loading…
Cancel
Save