Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
System Settings
Commits
1f1bde69
Commit
1f1bde69
authored
Feb 25, 2021
by
Cyril Rossi
Committed by
Benjamin Port
Apr 21, 2021
Browse files
Refactor duplicated code
parent
a5c894dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
sidebar/SidebarMode.cpp
View file @
1f1bde69
...
...
@@ -618,17 +618,13 @@ void SidebarMode::updateDefaults()
item
=
subCateogryIdx
.
data
(
Qt
::
UserRole
).
value
<
MenuItem
*>
();
}
auto
*
moduleData
=
KCModuleLoader
::
loadModuleData
(
item
->
item
());
if
(
moduleData
)
{
auto
*
moduleDataSignaling
=
qobject_cast
<
KCModuleDataSignaling
*>
(
moduleData
);
if
(
moduleDataSignaling
)
{
connect
(
moduleDataSignaling
,
&
KCModuleDataSignaling
::
loaded
,
this
,
[
this
,
item
,
moduleDataSignaling
]()
{
connect
(
moduleDataSignaling
,
&
KCModuleDataSignaling
::
loaded
,
this
,
[
this
,
item
,
moduleDataSignaling
,
categoryIdx
]()
{
item
->
setDefaultIndicator
(
!
moduleDataSignaling
->
isDefaults
());
auto
itemIdx
=
d
->
model
->
indexForItem
(
item
);
emit
d
->
model
->
dataChanged
(
itemIdx
,
itemIdx
);
updateCategoryModel
(
categoryIdx
);
moduleDataSignaling
->
deleteLater
();
});
}
else
{
...
...
@@ -637,7 +633,11 @@ void SidebarMode::updateDefaults()
}
item
->
updateDefaultIndicator
();
updateCategoryModel
(
categoryIdx
);
}
void
SidebarMode
::
updateCategoryModel
(
const
QModelIndex
&
categoryIdx
)
{
auto
sourceIdx
=
d
->
categorizedModel
->
mapToSource
(
categoryIdx
);
emit
d
->
model
->
dataChanged
(
sourceIdx
,
sourceIdx
);
...
...
@@ -732,20 +732,7 @@ void SidebarMode::toggleDefaultsIndicatorsVisibility()
if
(
moduleDataSignaling
)
{
connect
(
moduleDataSignaling
,
&
KCModuleDataSignaling
::
loaded
,
this
,
[
this
,
item
,
moduleDataSignaling
]()
{
item
->
setDefaultIndicator
(
!
moduleDataSignaling
->
isDefaults
());
auto
itemIdx
=
d
->
model
->
indexForItem
(
item
);
emit
d
->
model
->
dataChanged
(
itemIdx
,
itemIdx
);
MenuItem
*
parent
=
item
->
parent
();
while
(
parent
)
{
auto
parentIdx
=
d
->
model
->
indexForItem
(
parent
);
if
(
parentIdx
.
isValid
())
{
emit
d
->
model
->
dataChanged
(
parentIdx
,
parentIdx
);
parent
=
parent
->
parent
();
}
else
{
parent
=
nullptr
;
}
}
emit
defaultsIndicatorsVisibleChanged
();
updateModelMenuItem
(
item
);
moduleDataSignaling
->
deleteLater
();
});
}
else
{
...
...
@@ -758,25 +745,29 @@ void SidebarMode::toggleDefaultsIndicatorsVisibility()
if
(
showIndicator
==
item
->
showDefaultIndicator
())
{
continue
;
}
auto
itemIdx
=
d
->
model
->
indexForItem
(
item
);
emit
d
->
model
->
dataChanged
(
itemIdx
,
itemIdx
);
MenuItem
*
parent
=
item
->
parent
();
while
(
parent
)
{
auto
parentIdx
=
d
->
model
->
indexForItem
(
parent
);
if
(
parentIdx
.
isValid
())
{
emit
d
->
model
->
dataChanged
(
parentIdx
,
parentIdx
);
parent
=
parent
->
parent
();
}
else
{
parent
=
nullptr
;
}
}
updateModelMenuItem
(
item
);
}
}
config
().
writeEntry
(
"HighlightNonDefaultSettings"
,
d
->
m_defaultsIndicatorsVisible
);
emit
defaultsIndicatorsVisibleChanged
();
}
void
SidebarMode
::
updateModelMenuItem
(
MenuItem
*
item
)
{
auto
itemIdx
=
d
->
model
->
indexForItem
(
item
);
emit
d
->
model
->
dataChanged
(
itemIdx
,
itemIdx
);
MenuItem
*
parent
=
item
->
parent
();
while
(
parent
)
{
auto
parentIdx
=
d
->
model
->
indexForItem
(
parent
);
if
(
parentIdx
.
isValid
())
{
emit
d
->
model
->
dataChanged
(
parentIdx
,
parentIdx
);
parent
=
parent
->
parent
();
}
else
{
parent
=
nullptr
;
}
}
}
int
SidebarMode
::
width
()
const
{
return
d
->
mainWidget
->
width
();
...
...
sidebar/SidebarMode.h
View file @
1f1bde69
...
...
@@ -19,6 +19,7 @@ class QAbstractItemView;
class
QAbstractItemModel
;
class
QAction
;
class
SidebarMode
;
class
MenuItem
;
class
FocusHackWidget
:
public
QWidget
{
...
...
@@ -130,6 +131,10 @@ private Q_SLOTS:
void
updateDefaults
();
void
initWidget
();
private:
void
updateModelMenuItem
(
MenuItem
*
item
);
void
updateCategoryModel
(
const
QModelIndex
&
categoryIdx
);
Q_SIGNALS:
void
activeCategoryRowChanged
();
void
activeSubCategoryRowChanged
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment