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
e22f9417
Commit
e22f9417
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
ensure that there are no duplicate names in lists
parent
0e18dd08
No related branches found
No related tags found
1 merge request
!2404
ensure that there are no duplicate names in lists; disable cp/rm actions for empty lists
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
GUI/Model/Type/NamedItem.cpp
+60
-0
60 additions, 0 deletions
GUI/Model/Type/NamedItem.cpp
GUI/Model/Type/NamedItem.h
+6
-1
6 additions, 1 deletion
GUI/Model/Type/NamedItem.h
GUI/Model/Type/SetWithModel.h
+4
-1
4 additions, 1 deletion
GUI/Model/Type/SetWithModel.h
with
70 additions
and
2 deletions
GUI/Model/Type/NamedItem.cpp
0 → 100644
+
60
−
0
View file @
e22f9417
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Type/NamedItem.cpp
//! @brief Implements class NamedItem.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include
"GUI/Model/Type/NamedItem.h"
#include
<QRegularExpression>
#include
<QRegularExpressionMatch>
namespace
{
QStringList
splitName
(
const
QString
&
s
)
{
QRegularExpression
pattern
(
"(.*)_(
\\
d+)"
);
QRegularExpressionMatch
match
=
pattern
.
match
(
s
);
if
(
match
.
hasMatch
())
{
QStringList
groups
;
for
(
int
i
=
1
;
i
<
match
.
lastCapturedIndex
()
+
1
;
++
i
)
groups
<<
match
.
captured
(
i
);
return
groups
;
}
return
{};
// s does not contain '_\d+'
}
}
// namespace
void
NamedItem
::
renumber
(
const
QStringList
&
extant_names
)
{
// Item name consists of a stem and an optional number
QStringList
ns
=
splitName
(
name
());
QString
stem
=
ns
.
isEmpty
()
?
name
()
:
ns
[
0
];
// Determine highest number for given stem in extant_items
int
imax
=
0
;
for
(
QString
tname
:
extant_names
)
{
QStringList
ts
=
splitName
(
tname
);
if
(
ts
.
isEmpty
())
{
if
(
tname
==
stem
)
imax
=
std
::
max
(
imax
,
1
);
}
else
{
if
(
ts
[
0
]
==
stem
)
imax
=
std
::
max
(
imax
,
ts
[
1
].
toInt
());
}
}
if
(
imax
!=
0
)
setName
(
stem
+
"_"
+
QString
::
number
(
imax
+
1
));
if
(
name
().
contains
(
' '
))
setName
(
name
().
replace
(
' '
,
'_'
));
}
This diff is collapsed.
Click to expand it.
GUI/Model/Type/NamedItem.h
+
6
−
1
View file @
e22f9417
...
...
@@ -3,7 +3,7 @@
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Type/NamedItem.h
//! @brief Defines
and implements
class NamedItem.
//! @brief Defines class NamedItem.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
...
...
@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_TYPE_NAMEDITEM_H
#include
<QString>
#include
<vector>
//! Base class of items that have a name and a description.
...
...
@@ -33,6 +34,10 @@ public:
QString
description
()
const
{
return
m_description
;
}
void
setDescription
(
const
QString
&
description
)
{
m_description
=
description
;
}
//! Changes name of item to avoid duplication of any name from extant items.
//! Also replaces blank by underscore characters.
void
renumber
(
const
QStringList
&
extant_names
);
private
:
QString
m_name
;
QString
m_description
;
...
...
This diff is collapsed.
Click to expand it.
GUI/Model/Type/SetWithModel.h
+
4
−
1
View file @
e22f9417
...
...
@@ -74,6 +74,7 @@ public:
void
add_item
(
T
*
t
)
{
m_qmodel
->
beginInsertRows
({},
size
(),
size
());
t
->
renumber
(
itemNames
());
m_vec
.
push_back
(
t
);
m_idx
=
m_vec
.
size
()
-
1
;
m_qmodel
->
endInsertRows
();
...
...
@@ -82,8 +83,10 @@ public:
void
add_items
(
std
::
vector
<
T
*>
v
)
{
m_qmodel
->
beginInsertRows
({},
size
(),
size
());
for
(
T
*
t
:
v
)
for
(
T
*
t
:
v
)
{
t
->
renumber
(
itemNames
());
m_vec
.
push_back
(
t
);
}
m_idx
=
m_vec
.
size
()
-
1
;
m_qmodel
->
endInsertRows
();
emit
AbstractSetModel
::
setChanged
();
...
...
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