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
4a55ff40
Commit
4a55ff40
authored
8 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
ParameterTreeBuilder turned from static class to namespace.
parent
67eeead5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/coregui/Models/ParameterTreeBuilder.cpp
+45
-90
45 additions, 90 deletions
GUI/coregui/Models/ParameterTreeBuilder.cpp
GUI/coregui/Models/ParameterTreeBuilder.h
+11
-12
11 additions, 12 deletions
GUI/coregui/Models/ParameterTreeBuilder.h
with
56 additions
and
102 deletions
GUI/coregui/Models/ParameterTreeBuilder.cpp
+
45
−
90
View file @
4a55ff40
...
...
@@ -3,7 +3,7 @@
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file GUI/coregui/Models/ParameterTreeBuilder.cpp
//! @brief Implements
class
ParameterTreeBuilder
//! @brief Implements ParameterTreeBuilder
namespace
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
...
...
@@ -25,74 +25,58 @@
#include
"ScientificDoubleProperty.h"
#include
<QStack>
namespace
{
int
copyNumberOfChild
(
const
SessionItem
*
parent
,
const
SessionItem
*
item
)
{
if
(
!
item
)
return
-
1
;
int
result
=
-
1
;
int
count
=
0
;
QString
itemName
=
item
->
displayName
();
// check child items:
for
(
auto
p_child_item
:
parent
->
childItems
())
{
QString
childName
=
p_child_item
->
displayName
();
if
(
p_child_item
==
item
)
result
=
count
;
if
(
childName
==
itemName
)
++
count
;
}
if
(
count
>
1
)
return
result
;
return
-
1
;
}
void
fixDisplayName
(
SessionItem
*
parent
)
{
QVector
<
int
>
copyNumber
;
for
(
SessionItem
*
child
:
parent
->
childItems
())
{
copyNumber
.
push_back
(
copyNumberOfChild
(
parent
,
child
));
}
int
index
(
0
);
for
(
SessionItem
*
child
:
parent
->
childItems
())
{
if
(
copyNumber
[
index
]
>=
0
)
child
->
setDisplayName
(
child
->
displayName
()
+
QString
::
number
(
copyNumber
[
index
]));
++
index
;
}
for
(
SessionItem
*
child
:
parent
->
childItems
())
{
fixDisplayName
(
child
);
}
namespace
{
void
handleItem
(
SessionItem
*
tree
,
SessionItem
*
source
);
}
}
void
ParameterTreeBuilder
::
createParameterTree
(
JobItem
*
item
,
const
QString
&
tag
)
void
ParameterTreeBuilder
::
createParameterTree
(
JobItem
*
item
,
const
QString
&
tag
)
{
SessionItem
*
container
SessionItem
*
container
=
item
->
model
()
->
insertNewItem
(
Constants
::
ParameterContainerType
,
item
->
index
(),
-
1
,
tag
);
SessionItem
*
multiLayer
SessionItem
*
multiLayer
=
container
->
model
()
->
insertNewItem
(
Constants
::
ParameterLabelType
,
container
->
index
());
handleItem
(
multiLayer
,
item
->
getItem
(
JobItem
::
T_SAMPLE
));
SessionItem
*
instrument
SessionItem
*
instrument
=
container
->
model
()
->
insertNewItem
(
Constants
::
ParameterLabelType
,
container
->
index
());
handleItem
(
instrument
,
item
->
getItem
(
JobItem
::
T_INSTRUMENT
));
// fixDisplayName(container);
#ifndef NDEBUG
// Provides all items in "JobItem/Parameter Tree Container" with domain links already
// at the stage of ParameterTree creation. It is necessary for validation, in Release mode
// it will lead for unnecessary large project files.
populateDomainLinks
(
item
,
tag
);
ParameterTreeBuilder
::
populateDomainLinks
(
item
,
tag
);
#endif
}
//! For every ParameterItem in JobItem's ParameterTree container creates a link to domain.
void
ParameterTreeBuilder
::
populateDomainLinks
(
JobItem
*
jobItem
,
const
QString
&
tag
)
{
SessionItem
*
current
=
jobItem
->
getItem
(
tag
);
// this is container
QStack
<
SessionItem
*>
stack
;
stack
.
push
(
current
);
while
(
!
stack
.
empty
())
{
current
=
stack
.
pop
();
if
(
current
->
modelType
()
==
Constants
::
ParameterLabelType
||
current
->
modelType
()
==
Constants
::
ParameterContainerType
)
{
for
(
SessionItem
*
child
:
current
->
getItems
())
{
stack
.
push
(
child
);
}
}
else
{
if
(
ParameterItem
*
parItem
=
dynamic_cast
<
ParameterItem
*>
(
current
))
{
QString
translation
=
"*/"
+
ModelPath
::
itemPathTranslation
(
*
parItem
->
linkedItem
(),
jobItem
);
parItem
->
setItemValue
(
ParameterItem
::
P_DOMAIN
,
translation
);
}
}
}
}
void
ParameterTreeBuilder
::
handleItem
(
SessionItem
*
tree
,
SessionItem
*
source
)
namespace
{
void
handleItem
(
SessionItem
*
tree
,
SessionItem
*
source
)
{
if
(
tree
->
modelType
()
==
Constants
::
ParameterLabelType
)
{
tree
->
setDisplayName
(
source
->
itemName
());
...
...
@@ -103,16 +87,16 @@ void ParameterTreeBuilder::handleItem(SessionItem *tree, SessionItem *source)
tree
->
setDisplayName
(
source
->
itemName
());
double
sourceValue
=
source
->
value
().
toDouble
();
if
(
source
->
value
().
typeName
()
==
Constants
::
ScientificDoublePropertyType
)
{
if
(
source
->
value
().
typeName
()
==
Constants
::
ScientificDoublePropertyType
)
{
ScientificDoubleProperty
intensity
=
source
->
value
().
value
<
ScientificDoubleProperty
>
();
sourceValue
=
intensity
.
getValue
();
sourceValue
=
intensity
.
getValue
();
}
tree
->
setValue
(
QVariant
(
sourceValue
));
QString
path
=
ModelPath
::
getPathFromIndex
(
source
->
index
());
int
firstSlash
=
path
.
indexOf
(
'/'
);
path
=
path
.
mid
(
firstSlash
+
1
);
tree
->
setItemValue
(
ParameterItem
::
P_LINK
,
path
);
tree
->
setItemValue
(
ParameterItem
::
P_LINK
,
path
);
tree
->
setItemValue
(
ParameterItem
::
P_BACKUP
,
sourceValue
);
return
;
}
...
...
@@ -121,31 +105,28 @@ void ParameterTreeBuilder::handleItem(SessionItem *tree, SessionItem *source)
return
;
}
for
(
SessionItem
*
child
:
source
->
childItems
())
{
for
(
SessionItem
*
child
:
source
->
childItems
())
{
if
(
child
->
isVisible
()
&&
child
->
isEnabled
())
{
if
(
child
->
modelType
()
==
Constants
::
PropertyType
)
{
if
(
child
->
value
().
type
()
==
QVariant
::
Double
)
{
SessionItem
*
branch
SessionItem
*
branch
=
tree
->
model
()
->
insertNewItem
(
Constants
::
ParameterType
,
tree
->
index
());
handleItem
(
branch
,
child
);
}
else
if
(
child
->
value
().
typeName
()
==
Constants
::
ScientificDoublePropertyType
)
{
SessionItem
*
branch
}
else
if
(
child
->
value
().
typeName
()
==
Constants
::
ScientificDoublePropertyType
)
{
SessionItem
*
branch
=
tree
->
model
()
->
insertNewItem
(
Constants
::
ParameterType
,
tree
->
index
());
handleItem
(
branch
,
child
);
}
}
else
if
(
child
->
modelType
()
==
Constants
::
GroupItemType
)
{
SessionItem
*
currentItem
=
dynamic_cast
<
GroupItem
*>
(
child
)
->
currentItem
();
SessionItem
*
currentItem
=
dynamic_cast
<
GroupItem
*>
(
child
)
->
currentItem
();
if
(
currentItem
&&
currentItem
->
rowCount
()
>
0
)
{
SessionItem
*
branch
=
tree
->
model
()
->
insertNewItem
(
SessionItem
*
branch
=
tree
->
model
()
->
insertNewItem
(
Constants
::
ParameterLabelType
,
tree
->
index
());
handleItem
(
branch
,
currentItem
);
}
}
else
{
SessionItem
*
branch
SessionItem
*
branch
=
tree
->
model
()
->
insertNewItem
(
Constants
::
ParameterLabelType
,
tree
->
index
());
handleItem
(
branch
,
child
);
}
...
...
@@ -153,30 +134,4 @@ void ParameterTreeBuilder::handleItem(SessionItem *tree, SessionItem *source)
}
}
//! For every ParameterItem in JobItem's ParameterTree container creates a link to domain.
void
ParameterTreeBuilder
::
populateDomainLinks
(
JobItem
*
jobItem
,
const
QString
&
tag
)
{
SessionItem
*
current
=
jobItem
->
getItem
(
tag
);
// this is container
QStack
<
SessionItem
*>
stack
;
stack
.
push
(
current
);
while
(
!
stack
.
empty
())
{
current
=
stack
.
pop
();
if
(
current
->
modelType
()
==
Constants
::
ParameterLabelType
||
current
->
modelType
()
==
Constants
::
ParameterContainerType
)
{
for
(
SessionItem
*
child
:
current
->
getItems
())
{
stack
.
push
(
child
);
}
}
else
{
if
(
ParameterItem
*
parItem
=
dynamic_cast
<
ParameterItem
*>
(
current
))
{
// QString parItemPath = FitParameterHelper::getParameterItemPath(parItem);
// std::string domainPath = ModelPath::translateParameterName(
// jobItem, parItemPath);
// parItem->setItemValue(ParameterItem::P_DOMAIN, QString::fromStdString(domainPath));
// new way of translating
QString
translation
=
"*/"
+
ModelPath
::
itemPathTranslation
(
*
parItem
->
linkedItem
(),
jobItem
);
parItem
->
setItemValue
(
ParameterItem
::
P_DOMAIN
,
translation
);
}
}
}
}
}
// namespace
This diff is collapsed.
Click to expand it.
GUI/coregui/Models/ParameterTreeBuilder.h
+
11
−
12
View file @
4a55ff40
...
...
@@ -3,7 +3,7 @@
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file GUI/coregui/Models/ParameterTreeBuilder.h
//! @brief Defines
class
ParameterTreeBuilder
//! @brief Defines ParameterTreeBuilder
namespace
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
...
...
@@ -17,23 +17,22 @@
#ifndef PARAMETERTREEBUILDER_H
#define PARAMETERTREEBUILDER_H
#include
<QString>
#include
"WinDllMacros.h"
#include
<QString>
class
JobItem
;
class
SessionItem
;
//! The ParameterTreeBuilder
class helps JobModel
to create
a
container
with ParameterItem's.
//! The ParameterItem appears in RealTimeView and provides real
time tuning of MultiLayerItem
//! and InstrumentItem.
//! The ParameterTreeBuilder
namespace contains helper functions
to create container
//!
with ParameterItems.
The ParameterItem appears in RealTimeView and provides real
//!
time tuning of MultiLayerItem
and InstrumentItem.
class
BA_CORE_API_
ParameterTreeBuilder
namespace
ParameterTreeBuilder
{
public:
static
void
createParameterTree
(
JobItem
*
item
,
const
QString
&
tag
=
QString
());
static
void
populateDomainLinks
(
JobItem
*
jobItem
,
const
QString
&
tag
);
private:
static
void
handleItem
(
SessionItem
*
tree
,
SessionItem
*
source
);
};
BA_CORE_API_
void
createParameterTree
(
JobItem
*
item
,
const
QString
&
tag
=
QString
());
BA_CORE_API_
void
populateDomainLinks
(
JobItem
*
jobItem
,
const
QString
&
tag
);
}
#endif // PARAMETERTREEBUILDER_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