Skip to content
GitLab
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
364ece1d
Commit
364ece1d
authored
Aug 05, 2022
by
Ahmad Samir
Browse files
Use Profile::PropertyMap in EditProfileDialog
This simplifies the code a bit.
parent
6a341a52
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/widgets/EditProfileDialog.cpp
View file @
364ece1d
...
...
@@ -233,7 +233,7 @@ void EditProfileDialog::save()
// to unpreview()
const
Profile
::
PropertyMap
&
map
=
_tempProfile
->
properties
();
for
(
const
auto
&
[
property
,
_
]
:
map
)
{
_previewedProperties
.
remov
e
(
property
);
_previewedProperties
.
eras
e
(
property
);
}
// Update the default profile if needed
...
...
@@ -1022,34 +1022,26 @@ QSize EditProfileDialog::sizeHint() const
void
EditProfileDialog
::
unpreviewAll
()
{
Profile
::
PropertyMap
map
;
QHashIterator
<
int
,
QVariant
>
iter
(
_previewedProperties
);
while
(
iter
.
hasNext
())
{
iter
.
next
();
map
.
insert
({
static_cast
<
Profile
::
Property
>
(
iter
.
key
()),
iter
.
value
()});
}
// undo any preview changes
if
(
!
map
.
empty
())
{
ProfileManager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
if
(
!
_previewedProperties
.
empty
())
{
ProfileManager
::
instance
()
->
changeProfile
(
_profile
,
_previewedProperties
,
false
);
}
}
void
EditProfileDialog
::
unpreview
(
int
p
roperty
)
void
EditProfileDialog
::
unpreview
(
Profile
::
P
roperty
prop
)
{
if
(
!
_previewedProperties
.
contains
(
property
))
{
auto
node
=
_previewedProperties
.
extract
(
prop
);
if
(
!
node
)
{
return
;
}
const
Profile
::
PropertyMap
map
({{
static_cast
<
Profile
::
Property
>
(
property
),
_previewedProperties
[
property
]}});
Profile
::
PropertyMap
map
;
map
.
insert
(
std
::
move
(
node
));
ProfileManager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
_previewedProperties
.
remove
(
property
);
}
void
EditProfileDialog
::
preview
(
int
p
roperty
,
const
QVariant
&
value
)
void
EditProfileDialog
::
preview
(
Profile
::
P
roperty
prop
,
const
QVariant
&
value
)
{
const
Profile
::
PropertyMap
map
{{
static_cast
<
Profile
::
Property
>
(
property
),
value
}};
const
Profile
::
Ptr
original
=
lookupProfile
();
// skip previews for profile groups if the profiles in the group
...
...
@@ -1057,16 +1049,14 @@ void EditProfileDialog::preview(int property, const QVariant &value)
//
// TODO - Save the original values for each profile and use to unpreview properties
ProfileGroup
::
Ptr
group
=
original
->
asGroup
();
if
(
group
&&
group
->
profiles
().
count
()
>
1
&&
original
->
property
<
QVariant
>
(
static_cast
<
Profile
::
Property
>
(
property
)
).
isNull
())
{
if
(
group
&&
group
->
profiles
().
count
()
>
1
&&
original
->
property
<
QVariant
>
(
prop
).
isNull
())
{
return
;
}
if
(
!
_previewedProperties
.
contains
(
property
))
{
_previewedProperties
.
insert
(
property
,
original
->
property
<
QVariant
>
(
static_cast
<
Profile
::
Property
>
(
property
)));
}
_previewedProperties
.
insert
({
prop
,
original
->
property
<
QVariant
>
(
prop
)});
// temporary change to color scheme
ProfileManager
::
instance
()
->
changeProfile
(
_profile
,
map
,
false
);
ProfileManager
::
instance
()
->
changeProfile
(
_profile
,
{{
prop
,
value
}}
,
false
);
}
void
EditProfileDialog
::
previewColorScheme
(
const
QModelIndex
&
index
)
...
...
@@ -1346,26 +1336,29 @@ void EditProfileDialog::updateTempProfileProperty(Profile::Property property, co
void
EditProfileDialog
::
updateButtonApply
()
{
bool
userModified
=
false
;
const
Profile
::
PropertyMap
&
map
=
_tempProfile
->
properties
();
for
(
const
auto
&
[
property
,
value
]
:
map
)
{
auto
filterFunc
=
[
this
](
const
auto
&
keyValue
)
{
const
auto
&
[
property
,
value
]
=
keyValue
;
// for previewed property
if
(
_previewedProperties
.
contains
(
static_cast
<
int
>
(
property
)
))
{
if
(
value
!=
_previewedProperties
.
value
(
static_cast
<
int
>
(
property
)
))
{
userModified
=
true
;
b
re
ak
;
auto
it
=
_previewedProperties
.
find
(
property
)
;
if
(
it
!=
_previewedProperties
.
cend
(
))
{
if
(
value
!=
it
->
second
)
{
re
turn
true
;
}
// for not-previewed property
//
// for the Profile::KeyBindings property, if it's set in the _tempProfile
// then the user opened the edit key bindings dialog and clicked
// OK, and could have add/removed a key bindings rule
}
else
if
(
property
==
Profile
::
KeyBindings
||
(
value
!=
_profile
->
property
<
QVariant
>
(
property
)))
{
userModified
=
true
;
b
re
ak
;
}
else
if
(
property
==
Profile
::
KeyBindings
//
||
value
!=
_profile
->
property
<
QVariant
>
(
property
))
{
re
turn
true
;
}
}
return
false
;
};
const
Profile
::
PropertyMap
&
map
=
_tempProfile
->
properties
();
bool
userModified
=
std
::
any_of
(
map
.
cbegin
(),
map
.
cend
(),
filterFunc
);
if
(
_generalUi
->
setAsDefaultButton
->
isChecked
()
!=
_isDefault
)
{
userModified
=
true
;
...
...
src/widgets/EditProfileDialog.h
View file @
364ece1d
...
...
@@ -272,8 +272,8 @@ private:
void
showColorSchemeEditor
(
bool
isNewScheme
);
void
closeColorSchemeEditor
();
void
preview
(
int
p
roperty
,
const
QVariant
&
value
);
void
unpreview
(
int
p
roperty
);
void
preview
(
Profile
::
P
roperty
prop
,
const
QVariant
&
value
);
void
unpreview
(
Profile
::
P
roperty
prop
);
void
unpreviewAll
();
void
enableIfNonEmptySelection
(
QWidget
*
widget
,
QItemSelectionModel
*
selectionModel
);
...
...
@@ -344,8 +344,7 @@ private:
bool
_isDefault
=
false
;
QHash
<
int
,
QVariant
>
_previewedProperties
;
Profile
::
PropertyMap
_previewedProperties
;
ColorSchemeEditor
*
_colorDialog
=
nullptr
;
QDialogButtonBox
*
_buttonBox
=
nullptr
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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