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
440214d3
Commit
440214d3
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
refactor & reformat LinkManager
parent
5a06fc03
No related branches found
No related tags found
1 merge request
!302
Simplify instrument linking
Pipeline
#44216
failed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/Views/ImportDataWidgets/LinkInstrumentManager.cpp
+30
-60
30 additions, 60 deletions
GUI/Views/ImportDataWidgets/LinkInstrumentManager.cpp
GUI/Views/ImportDataWidgets/LinkInstrumentManager.h
+4
-5
4 additions, 5 deletions
GUI/Views/ImportDataWidgets/LinkInstrumentManager.h
with
34 additions
and
65 deletions
GUI/Views/ImportDataWidgets/LinkInstrumentManager.cpp
+
30
−
60
View file @
440214d3
...
@@ -22,17 +22,33 @@
...
@@ -22,17 +22,33 @@
#include
<QMessageBox>
#include
<QMessageBox>
#include
<QPushButton>
#include
<QPushButton>
using
namespace
GUI
::
View
;
namespace
{
namespace
{
bool
QuestionOnInstrumentReshaping
(
const
QString
&
message
);
bool
QuestionOnInstrumentReshaping
(
const
QString
&
message
)
{
QMessageBox
msgBox
;
msgBox
.
setText
(
"Instrument description conflicts with the experimental data."
);
QString
informative
;
informative
.
append
(
message
);
informative
.
append
(
"
\n\n
Do you want to adjust the instrument to the experimental data?
\n\n
"
);
msgBox
.
setInformativeText
(
informative
);
QPushButton
*
modifyInstrumentButton
=
msgBox
.
addButton
(
"Yes, please modify instrument"
,
QMessageBox
::
YesRole
);
msgBox
.
addButton
(
"No, leave as it is"
,
QMessageBox
::
NoRole
);
msgBox
.
exec
();
return
msgBox
.
clickedButton
()
==
modifyInstrumentButton
;
}
}
// namespace
}
// namespace
LinkInstrumentManager
::
LinkInstrumentManager
(
InstrumentModel
*
instrumentModel
,
LinkInstrumentManager
::
LinkInstrumentManager
(
InstrumentModel
*
instrumentModel
,
RealDataModel
*
realDataModel
)
RealDataModel
*
realDataModel
)
:
m_instrumentModel
(
instrumentModel
),
m_realDataModel
(
realDataModel
)
:
m_instrumentModel
(
instrumentModel
),
m_realDataModel
(
realDataModel
)
{
{
ASSERT
(
m_instrumentModel
!=
nullptr
);
ASSERT
(
m_realDataModel
!=
nullptr
);
connect
(
m_instrumentModel
,
&
InstrumentModel
::
instrumentAddedOrRemoved
,
this
,
connect
(
m_instrumentModel
,
&
InstrumentModel
::
instrumentAddedOrRemoved
,
this
,
&
LinkInstrumentManager
::
onInstrumentAddedOrRemoved
);
&
LinkInstrumentManager
::
onInstrumentAddedOrRemoved
);
...
@@ -40,9 +56,6 @@ LinkInstrumentManager::LinkInstrumentManager(InstrumentModel* instrumentModel,
...
@@ -40,9 +56,6 @@ LinkInstrumentManager::LinkInstrumentManager(InstrumentModel* instrumentModel,
&
LinkInstrumentManager
::
onInstrumentChanged
);
&
LinkInstrumentManager
::
onInstrumentChanged
);
}
}
//! Returns true if RealDataItem can be linked to the instrument (same number of bins).
//! Also offers dialog to adjust instrument to match shape of real data.
bool
LinkInstrumentManager
::
canLinkDataToInstrument
(
const
RealDataItem
*
realDataItem
,
bool
LinkInstrumentManager
::
canLinkDataToInstrument
(
const
RealDataItem
*
realDataItem
,
const
QString
&
identifier
,
const
QString
&
identifier
,
bool
quiet
/*= false*/
)
bool
quiet
/*= false*/
)
...
@@ -53,9 +66,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
...
@@ -53,9 +66,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
if
(
!
instrumentItem
)
if
(
!
instrumentItem
)
return
true
;
return
true
;
const
bool
isCompatible
=
if
(
!
ImportDataUtils
::
Compatible
(
*
instrumentItem
,
*
realDataItem
))
{
GUI
::
View
::
ImportDataUtils
::
Compatible
(
*
instrumentItem
,
*
realDataItem
);
if
(
!
isCompatible
)
{
if
(
!
quiet
)
if
(
!
quiet
)
QMessageBox
::
warning
(
baWin
,
"Can't link to instrument"
,
QMessageBox
::
warning
(
baWin
,
"Can't link to instrument"
,
"Can't link, data is incompatible with the instrument."
);
"Can't link, data is incompatible with the instrument."
);
...
@@ -74,8 +85,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
...
@@ -74,8 +85,7 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
QString
message
=
QString
message
=
realDataItem
->
holdsDimensionalData
()
realDataItem
->
holdsDimensionalData
()
?
"Experimental data carries information on the range/points of measurement."
?
"Experimental data carries information on the range/points of measurement."
:
GUI
::
View
::
ImportDataUtils
::
printShapeMessage
(
instrumentItem
->
shape
(),
:
ImportDataUtils
::
printShapeMessage
(
instrumentItem
->
shape
(),
realDataItem
->
shape
());
realDataItem
->
shape
());
if
(
!
QuestionOnInstrumentReshaping
(
message
))
if
(
!
QuestionOnInstrumentReshaping
(
message
))
return
false
;
return
false
;
...
@@ -85,61 +95,21 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
...
@@ -85,61 +95,21 @@ bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realData
void
LinkInstrumentManager
::
onInstrumentChanged
(
const
InstrumentItem
*
instrument
)
void
LinkInstrumentManager
::
onInstrumentChanged
(
const
InstrumentItem
*
instrument
)
{
{
ASSERT
(
instrument
!=
nullptr
);
// Run through all RealDataItem and refresh linking to match possible change in detector
// Run through all RealDataItem and refresh linking to match possible change in detector
// axes definition.
// axes definition.
for
(
auto
realDataItem
:
linkedRealDataItems
(
instrument
))
for
(
auto
realDataItem
:
m_realDataModel
->
realDataItems
())
if
(
!
instrument
->
alignedWith
(
realDataItem
))
if
(
realDataItem
->
instrumentId
()
==
instrument
->
id
())
{
realDataItem
->
clearInstrumentId
();
if
(
!
instrument
->
alignedWith
(
realDataItem
))
else
realDataItem
->
clearInstrumentId
();
realDataItem
->
updateToInstrument
(
instrument
);
else
realDataItem
->
updateToInstrument
(
instrument
);
}
}
}
void
LinkInstrumentManager
::
onInstrumentAddedOrRemoved
()
void
LinkInstrumentManager
::
onInstrumentAddedOrRemoved
()
{
{
// remove links in realDataItems (in case of a linked instrument was removed)
// remove links in realDataItems (in case of a linked instrument was removed)
for
(
auto
realDataItem
:
m_realDataModel
->
realDataItems
())
{
for
(
auto
realDataItem
:
m_realDataModel
->
realDataItems
())
if
(
!
m_instrumentModel
->
instrumentExists
(
realDataItem
->
instrumentId
()))
if
(
!
m_instrumentModel
->
instrumentExists
(
realDataItem
->
instrumentId
()))
realDataItem
->
clearInstrumentId
();
realDataItem
->
clearInstrumentId
();
}
}
//! Returns list of RealDataItem's linked to given instrument.
QList
<
RealDataItem
*>
LinkInstrumentManager
::
linkedRealDataItems
(
const
InstrumentItem
*
instrumentItem
)
{
ASSERT
(
instrumentItem
!=
nullptr
);
QList
<
RealDataItem
*>
result
;
for
(
auto
realDataItem
:
m_realDataModel
->
realDataItems
())
{
const
QString
linkedIdentifier
=
realDataItem
->
instrumentId
();
const
QString
instrumentIdentifier
=
instrumentItem
->
id
();
if
(
linkedIdentifier
==
instrumentIdentifier
)
result
.
append
(
realDataItem
);
}
return
result
;
}
namespace
{
bool
QuestionOnInstrumentReshaping
(
const
QString
&
message
)
{
QMessageBox
msgBox
;
msgBox
.
setText
(
"Instrument description conflicts with the experimental data."
);
QString
informative
;
informative
.
append
(
message
);
informative
.
append
(
"
\n\n
Do you want to adjust the instrument to the experimental data?
\n\n
"
);
msgBox
.
setInformativeText
(
informative
);
QPushButton
*
modifyInstrumentButton
=
msgBox
.
addButton
(
"Yes, please modify instrument"
,
QMessageBox
::
YesRole
);
msgBox
.
addButton
(
"No, leave as it is"
,
QMessageBox
::
NoRole
);
msgBox
.
exec
();
return
msgBox
.
clickedButton
()
==
modifyInstrumentButton
;
}
}
}
// namespace
This diff is collapsed.
Click to expand it.
GUI/Views/ImportDataWidgets/LinkInstrumentManager.h
+
4
−
5
View file @
440214d3
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
class
InstrumentModel
;
class
InstrumentModel
;
class
RealDataModel
;
class
RealDataModel
;
class
SessionItem
;
class
InstrumentItem
;
class
InstrumentItem
;
class
RealDataItem
;
class
RealDataItem
;
...
@@ -36,17 +35,17 @@ class LinkInstrumentManager : public QObject {
...
@@ -36,17 +35,17 @@ class LinkInstrumentManager : public QObject {
Q_OBJECT
Q_OBJECT
public:
public:
explicit
LinkInstrumentManager
(
InstrumentModel
*
instrumentModel
,
RealDataModel
*
realDataModel
);
LinkInstrumentManager
(
InstrumentModel
*
instrumentModel
,
RealDataModel
*
realDataModel
);
//! Returns true if RealDataItem can be linked to the instrument (same number of bins).
//! Also offers dialog to adjust instrument to match shape of real data.
//! quiet defines whether a "not possible" message box is shown if link is not possible. Use
//! quiet defines whether a "not possible" message box is shown if link is not possible. Use
//! this e.g. for unit tests. The question for adjusting the instrument is not suppressed by
//! this e.g. for unit tests. The question for adjusting the instrument is not suppressed by
//! this flag.
//! this flag.
bool
canLinkDataToInstrument
(
const
RealDataItem
*
realDataItem
,
const
QString
&
identifier
,
bool
canLinkDataToInstrument
(
const
RealDataItem
*
realDataItem
,
const
QString
&
identifier
,
bool
quiet
=
false
);
bool
quiet
=
false
);
QList
<
RealDataItem
*>
linkedRealDataItems
(
const
InstrumentItem
*
instrumentItem
);
private:
private
slots
:
void
onInstrumentChanged
(
const
InstrumentItem
*
instrument
);
void
onInstrumentChanged
(
const
InstrumentItem
*
instrument
);
void
onInstrumentAddedOrRemoved
();
void
onInstrumentAddedOrRemoved
();
...
...
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