Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
79f102ba
Commit
79f102ba
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
add abstract base class for SelectionDescriptors to ease referencing
parent
95885831
No related branches found
Branches containing commit
No related tags found
1 merge request
!415
Unit handling in layer oriented sample editor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GUI/Models/SelectionDescriptor.h
+25
-9
25 additions, 9 deletions
GUI/Models/SelectionDescriptor.h
with
25 additions
and
9 deletions
GUI/Models/SelectionDescriptor.h
+
25
−
9
View file @
79f102ba
...
...
@@ -23,6 +23,18 @@
using
std
::
function
;
//! Abstract base class for SelectionDescriptor to ease referencing.
class
AbstractSelectionDescriptor
{
public:
virtual
~
AbstractSelectionDescriptor
()
=
default
;
//! Set currently selected option
virtual
void
setCurrentIndex
(
int
newIndex
)
const
=
0
;
//! Get currently selected option
virtual
int
currentIndex
()
const
=
0
;
};
//! Describes a selection (various possibilities and the current one).
//!
//! Usually a selection is presented as a combo box.
...
...
@@ -38,7 +50,7 @@ using std::function;
//! By using this class, the underlying data scheme is hidden from the user of the data. This e.g.
//! eases SessionItem migration. The underlying implementation can be a GroupItem, a simple pointer
//! member, a std::variant or any other construction to define a selection.
template
<
typename
T
>
class
SelectionDescriptor
{
template
<
typename
T
>
class
SelectionDescriptor
:
public
AbstractSelectionDescriptor
{
public:
SelectionDescriptor
()
=
default
;
...
...
@@ -51,7 +63,7 @@ public:
{
label
=
item
->
displayName
();
options
=
item
->
value
().
value
<
ComboProperty
>
().
getValues
();
setC
urrentIndex
=
[
=
](
int
index
)
{
c
urrentIndex
Setter
=
[
=
](
int
index
)
{
ComboProperty
comboProperty
=
item
->
value
().
value
<
ComboProperty
>
();
if
(
comboProperty
.
currentIndex
()
!=
index
)
{
...
...
@@ -59,18 +71,22 @@ public:
item
->
setValue
(
QVariant
::
fromValue
<
ComboProperty
>
(
comboProperty
));
}
};
currentIndex
=
[
=
]
{
return
item
->
value
().
value
<
ComboProperty
>
().
currentIndex
();
};
currentIndex
Getter
=
[
=
]
{
return
item
->
value
().
value
<
ComboProperty
>
().
currentIndex
();
};
if
constexpr
(
std
::
is_pointer
<
T
>::
value
)
currentItem
=
[
=
]
{
return
dynamic_cast
<
T
>
(
item
->
currentItem
());
};
}
QString
label
;
//!< A label text (short, no trailing colon)
QString
tooltip
;
//!< Tooltip text
QStringList
options
;
//!< List of options, usually presented as combo entries
function
<
void
(
int
)
>
setCurrentIndex
;
//!< Function to set currently selected option
function
<
int
()
>
currentIndex
;
//!< Function to get currently selected option
function
<
T
()
>
currentItem
;
//!< Function to get currently selected item
virtual
void
setCurrentIndex
(
int
newIndex
)
const
override
{
currentIndexSetter
(
newIndex
);
}
virtual
int
currentIndex
()
const
override
{
return
currentIndexGetter
();
}
QString
label
;
//!< A label text (short, no trailing colon)
QString
tooltip
;
//!< Tooltip text
QStringList
options
;
//!< List of options, usually presented as combo entries
function
<
void
(
int
)
>
currentIndexSetter
;
//!< Function to set currently selected option
function
<
int
()
>
currentIndexGetter
;
//!< Function to get currently selected option
function
<
T
()
>
currentItem
;
//!< Function to get currently selected item
};
#endif // BORNAGAIN_GUI_MODELS_SELECTIONDESCRIPTOR_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment