mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-30 14:50:12 +03:00
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.
This commit is contained in:
parent
d43f3d5ac4
commit
538dba0a02
@ -514,83 +514,38 @@ 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;
|
||||
}
|
||||
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) {
|
||||
QVariant appletVariant = item->property("applet");
|
||||
if (!appletVariant.isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QObject *applet = appletVariant.value<QObject *>();
|
||||
QObject *applet = appletVariant.value<QObject *>();
|
||||
|
||||
if (!applet) {
|
||||
continue;
|
||||
}
|
||||
if (!applet) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint id = applet->property("id").toUInt();
|
||||
uint id = applet->property("id").toUInt();
|
||||
|
||||
if (id>0) {
|
||||
startChilds++;
|
||||
appletIds << id;
|
||||
if (id>0) {
|
||||
childCount++;
|
||||
appletIds << id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return childCount;
|
||||
};
|
||||
|
||||
int mainChilds{0};
|
||||
for(int i=0; i<m_mainLayout->childItems().count(); ++i) {
|
||||
QQuickItem *item = m_mainLayout->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) {
|
||||
mainChilds++;
|
||||
appletIds << id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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…
x
Reference in New Issue
Block a user