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
7f8a7f0c
Commit
7f8a7f0c
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
improve function ptr initialization
parent
3e48ebe6
No related branches found
No related tags found
1 merge request
!393
Selection descriptor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GUI/Models/SelectionDescriptor.h
+19
-8
19 additions, 8 deletions
GUI/Models/SelectionDescriptor.h
with
19 additions
and
8 deletions
GUI/Models/SelectionDescriptor.h
+
19
−
8
View file @
7f8a7f0c
...
...
@@ -40,14 +40,25 @@ using std::function;
//! member, a std::variant or any other construction to define a selection.
template
<
typename
T
>
class
SelectionDescriptor
{
public:
SelectionDescriptor
()
=
default
;
SelectionDescriptor
()
{
// initialize function pointers to a lambda which throws an error. This helps later on if
// accidentally the real initialization has been forgotten.
setCurrentIndex
=
[](
int
)
{
throw
std
::
runtime_error
(
"Function pointer not initialized"
);
};
currentIndex
=
[]()
->
int
{
throw
std
::
runtime_error
(
"Function pointer not initialized"
);
};
currentItem
=
[]()
->
T
{
throw
std
::
runtime_error
(
"Function pointer not initialized"
);
};
}
//! Initialize the members by means of a GroupItem.
//!
//! currentItem can only be initialized if the template parameter is a pointer (like
//! RotationItem*). If it is e.g. a std::variant<>, the currentItem has to be initialized by the
//! caller. Only for easier migration. Should be removed after SessionItem refactoring.
explicit
SelectionDescriptor
(
GroupItem
*
item
)
explicit
SelectionDescriptor
(
GroupItem
*
item
)
:
SelectionDescriptor
()
{
label
=
item
->
displayName
();
options
=
item
->
value
().
value
<
ComboProperty
>
().
getValues
();
...
...
@@ -65,12 +76,12 @@ public:
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
=
nullptr
;
//!< Function to set currently selected option
function
<
int
()
>
currentIndex
=
nullptr
;
//!< Function to get currently selected option
function
<
T
()
>
currentItem
=
nullptr
;
//!< Function to get currently selected item
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
};
#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