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
172c8f2b
Commit
172c8f2b
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
Cloned Base/Types/VectorWC -> GUI/Model/Type/SetWithModel
parent
e924d3b9
No related branches found
No related tags found
1 merge request
!2397
InstrumentsSet and SamplesSet based on SetWithModel, which owns a QListModel
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GUI/Model/Type/SetWithModel.h
+113
-0
113 additions, 0 deletions
GUI/Model/Type/SetWithModel.h
with
113 additions
and
0 deletions
GUI/Model/Type/SetWithModel.h
0 → 100644
+
113
−
0
View file @
172c8f2b
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Type/SetWithModel.h
//! @brief Defines and implements templated class VectorWC.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifdef SWIG
#error no need to expose this header to Swig
#endif // SWIG
#ifndef BORNAGAIN_GUI_MODEL_TYPE_SETWITHMODEL_H
#define BORNAGAIN_GUI_MODEL_TYPE_SETWITHMODEL_H
#include
"Base/Types/OwningVector.h"
#include
"Base/Util/Assert.h"
//! An OwningVector with a current index.
template
<
class
T
>
class
VectorWC
:
public
OwningVector
<
T
>
{
using
super
=
OwningVector
<
T
>
;
public:
void
push_back
(
T
*
e
)
{
super
::
push_back
(
e
);
m_current_index
=
super
::
size
()
-
1
;
}
void
insert_at
(
size_t
i
,
T
*
e
)
{
super
::
insert_at
(
i
,
e
);
m_current_index
=
i
;
}
void
replace_at
(
size_t
i
,
T
*
e
)
{
super
::
replace_at
(
i
,
e
);
m_current_index
=
i
;
}
void
delete_element
(
const
T
*
e
)
{
super
::
delete_element
(
e
);
update_current
();
}
void
delete_at
(
size_t
i
)
{
super
::
delete_at
(
i
);
update_current
();
}
void
delete_current
()
{
ASSERT
(
m_current_index
!=
size_t
(
-
1
));
super
::
delete_at
(
m_current_index
);
update_current
();
}
T
*
release_at
(
size_t
i
)
{
super
::
release_at
(
i
);
update_current
();
}
T
*
release_back
()
{
super
::
release_back
();
update_current
();
}
T
*
release_front
()
{
super
::
release_front
();
update_current
();
}
void
swap
(
size_t
from
,
size_t
to
)
{
super
::
swap
(
from
,
to
);
// TODO update m_current_index ?
}
void
clear
()
{
super
::
clear
();
m_current_index
=
-
1
;
}
void
setCurrentIndex
(
size_t
i
)
{
ASSERT
(
i
<
super
::
size
()
||
i
==
size_t
(
-
1
));
if
(
i
!=
m_current_index
)
m_current_index
=
i
;
}
size_t
currentIndex
()
const
{
return
m_current_index
;
}
const
T
*
currentItem
()
const
{
return
m_current_index
<
super
::
size
()
?
super
::
at
(
m_current_index
)
:
(
T
*
)
nullptr
;
}
T
*
currentItem
()
{
return
m_current_index
<
super
::
size
()
?
super
::
at
(
m_current_index
)
:
(
T
*
)
nullptr
;
}
private
:
void
update_current
()
{
if
(
m_current_index
==
super
::
size
())
m_current_index
=
super
::
size
()
-
1
;
}
size_t
m_current_index
=
-
1
;
};
#endif // BORNAGAIN_GUI_MODEL_TYPE_SETWITHMODEL_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