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
Utilities
Konsole
Commits
16928469
Commit
16928469
authored
Jul 31, 2021
by
Ahmad Samir
Committed by
Kurt Hindenburg
Aug 30, 2021
Browse files
Use a std::set with custom Compare to always have a sorted profiles list
parent
c46b9fc1
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/profile/ProfileManager.cpp
View file @
16928469
...
...
@@ -38,8 +38,7 @@ static bool stringLessThan(const QString& p1, const QString& p2)
}
ProfileManager
::
ProfileManager
()
:
_profiles
(
QSet
<
Profile
::
Ptr
>
())
,
_defaultProfile
(
nullptr
)
:
_defaultProfile
(
nullptr
)
,
_fallbackProfile
(
nullptr
)
,
_loadedAllProfiles
(
false
)
,
_shortcuts
(
QMap
<
QKeySequence
,
ShortcutData
>
())
...
...
@@ -75,7 +74,7 @@ ProfileManager::ProfileManager()
}
}
Q_ASSERT
(
_profiles
.
count
()
>
0
);
Q_ASSERT
(
_profiles
.
size
()
>
0
);
Q_ASSERT
(
_defaultProfile
);
// get shortcuts and paths of profiles associated with
...
...
@@ -133,7 +132,7 @@ Profile::Ptr ProfileManager::loadProfile(const QString& shortPath)
}
// check that we have not already loaded this profile
for
(
const
Profile
::
Ptr
&
profile
:
qAsConst
(
_profiles
)
)
{
for
(
const
Profile
::
Ptr
&
profile
:
_profiles
)
{
if
(
profile
->
path
()
==
path
)
{
return
profile
;
}
...
...
@@ -218,21 +217,6 @@ void ProfileManager::loadAllProfiles()
_loadedAllProfiles
=
true
;
}
void
ProfileManager
::
sortProfiles
(
QList
<
Profile
::
Ptr
>&
list
)
{
// Sort alphabetically
std
::
stable_sort
(
list
.
begin
(),
list
.
end
(),
[](
const
Profile
::
Ptr
&
p1
,
const
Profile
::
Ptr
&
p2
)
{
// Always put the Default/fallback profile at the top
if
(
p1
->
isFallback
())
{
return
true
;
}
else
if
(
p2
->
isFallback
())
{
return
false
;
}
return
QString
::
localeAwareCompare
(
p1
->
name
(),
p2
->
name
())
<
0
;
});
}
void
ProfileManager
::
saveSettings
()
{
// save default profile
...
...
@@ -250,15 +234,12 @@ QList<Profile::Ptr> ProfileManager::allProfiles()
{
loadAllProfiles
();
auto
loadedProfiles
=
_profiles
.
values
();
sortProfiles
(
loadedProfiles
);
return
loadedProfiles
;
return
loadedProfiles
();
}
QList
<
Profile
::
Ptr
>
ProfileManager
::
loadedProfiles
()
const
{
return
_profiles
.
values
();
return
{
_profiles
.
cbegin
(),
_profiles
.
cend
()
}
;
}
Profile
::
Ptr
ProfileManager
::
defaultProfile
()
const
...
...
@@ -384,7 +365,7 @@ void ProfileManager::changeProfile(Profile::Ptr profile,
void
ProfileManager
::
addProfile
(
const
Profile
::
Ptr
&
profile
)
{
if
(
_profiles
.
isE
mpty
())
{
if
(
_profiles
.
e
mpty
())
{
_defaultProfile
=
profile
;
}
...
...
@@ -409,7 +390,7 @@ bool ProfileManager::deleteProfile(Profile::Ptr profile)
}
setShortcut
(
profile
,
QKeySequence
());
_profiles
.
remov
e
(
profile
);
_profiles
.
eras
e
(
profile
);
// mark the profile as hidden so that it does not show up in the
// Manage Profiles dialog and is not saved to disk
...
...
@@ -430,7 +411,7 @@ bool ProfileManager::deleteProfile(Profile::Ptr profile)
void
ProfileManager
::
setDefaultProfile
(
const
Profile
::
Ptr
&
profile
)
{
Q_ASSERT
(
_profiles
.
conta
in
s
(
profile
));
Q_ASSERT
(
_profiles
.
f
in
d
(
profile
)
!=
_profiles
.
cend
()
);
const
auto
oldDefault
=
_defaultProfile
;
_defaultProfile
=
profile
;
...
...
src/profile/ProfileManager.h
View file @
16928469
...
...
@@ -18,6 +18,8 @@
#include
<QVariant>
#include
<QStack>
#include
<set>
// Konsole
#include
"Profile.h"
...
...
@@ -152,13 +154,6 @@ public:
*/
Profile
::
Ptr
fallbackProfile
()
const
;
/**
* Sorts @p list of profiles alphabetically.
*
* @param list The profiles list to sort
*/
void
sortProfiles
(
QList
<
Profile
::
Ptr
>
&
list
);
/**
* Associates a shortcut with a particular profile.
*/
...
...
@@ -218,7 +213,20 @@ private:
// otherwise
QString
saveProfile
(
const
Profile
::
Ptr
&
profile
);
QSet
<
Profile
::
Ptr
>
_profiles
;
// list of all loaded profiles
static
bool
profileNamesCompare
(
const
Profile
::
Ptr
&
p1
,
const
Profile
::
Ptr
&
p2
)
{
// Always put the Default/fallback profile at the top
if
(
p1
->
isFallback
())
{
return
true
;
}
else
if
(
p2
->
isFallback
())
{
return
false
;
}
return
QString
::
localeAwareCompare
(
p1
->
name
(),
p2
->
name
())
<
0
;
}
// A list of all loaded profiles, sorted by profile name
std
::
set
<
Profile
::
Ptr
,
decltype
(
profileNamesCompare
)
*>
_profiles
{
profileNamesCompare
};
Profile
::
Ptr
_defaultProfile
;
Profile
::
Ptr
_fallbackProfile
;
...
...
src/profile/ProfileModel.cpp
View file @
16928469
...
...
@@ -165,7 +165,6 @@ void ProfileModel::populate()
{
beginResetModel
();
m_profiles
=
ProfileManager
::
instance
()
->
allProfiles
();
ProfileManager
::
instance
()
->
sortProfiles
(
m_profiles
);
endResetModel
();
}
...
...
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