Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
e88687e3
Commit
e88687e3
authored
Oct 03, 2019
by
Anthony Lim
Browse files
refs #26726 ALFView clean up code and GUI
parent
51381721
Changes
9
Hide whitespace changes
Inline
Side-by-side
qt/scientific_interfaces/Direct/ALFView.cpp
View file @
e88687e3
...
...
@@ -18,7 +18,6 @@
namespace
MantidQt
{
namespace
CustomInterfaces
{
DECLARE_SUBWINDOW
(
ALFView
)
/// static logger
...
...
@@ -28,7 +27,7 @@ ALFView::ALFView(QWidget *parent)
:
UserSubWindow
(
parent
),
m_view
(
nullptr
),
m_presenter
(
nullptr
)
{
m_model
=
new
ALFView_model
();
m_view
=
new
ALFView_view
(
m_model
->
getInstrument
(),
this
);
m_presenter
=
new
ALFView_presenter
(
m_view
,
m_model
);
m_presenter
=
new
ALFView_presenter
(
m_view
,
m_model
);
}
void
ALFView
::
initLayout
()
{
...
...
qt/scientific_interfaces/Direct/ALFView.h
View file @
e88687e3
...
...
@@ -33,9 +33,9 @@ protected:
void
initLayout
()
override
;
private:
//std::unique_ptr<ALFView_view> m_view;
//std::unique_ptr<ALFView_model> m_model;
//std::unique_ptr<ALFView_presenter> m_presenter;
//
std::unique_ptr<ALFView_view> m_view;
//
std::unique_ptr<ALFView_model> m_model;
//
std::unique_ptr<ALFView_presenter> m_presenter;
ALFView_view
*
m_view
;
ALFView_model
*
m_model
;
ALFView_presenter
*
m_presenter
;
...
...
qt/scientific_interfaces/Direct/ALFView_model.cpp
View file @
e88687e3
...
...
@@ -29,7 +29,6 @@ using namespace Mantid::API;
namespace
MantidQt
{
namespace
CustomInterfaces
{
void
ALFView_model
::
loadEmptyInstrument
()
{
auto
alg
=
Mantid
::
API
::
AlgorithmManager
::
Instance
().
create
(
"LoadEmptyInstrument"
);
...
...
@@ -51,8 +50,7 @@ int ALFView_model::loadData(const std::string &name) {
alg
->
setProperty
(
"OutputWorkspace"
,
TMPNAME
);
// write to tmp ws
alg
->
execute
();
auto
ws
=
AnalysisDataService
::
Instance
()
.
retrieveWS
<
MatrixWorkspace
>
(
TMPNAME
);
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
TMPNAME
);
return
ws
->
getRunNumber
();
}
/*
...
...
@@ -62,8 +60,7 @@ int ALFView_model::loadData(const std::string &name) {
*/
std
::
map
<
std
::
string
,
bool
>
ALFView_model
::
isDataValid
()
{
auto
ws
=
AnalysisDataService
::
Instance
()
.
retrieveWS
<
MatrixWorkspace
>
(
TMPNAME
);
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
TMPNAME
);
bool
isItALF
=
false
;
bool
isItDSpace
=
false
;
...
...
@@ -87,15 +84,13 @@ std::map<std::string, bool> ALFView_model::isDataValid() {
* If already d-space does nothing.
*/
void
ALFView_model
::
transformData
()
{
auto
normAlg
=
AlgorithmManager
::
Instance
().
create
(
"NormaliseByCurrent"
);
auto
normAlg
=
AlgorithmManager
::
Instance
().
create
(
"NormaliseByCurrent"
);
normAlg
->
initialize
();
normAlg
->
setProperty
(
"InputWorkspace"
,
WSNAME
);
normAlg
->
setProperty
(
"OutputWorkspace"
,
WSNAME
);
normAlg
->
execute
();
auto
dSpacingAlg
=
AlgorithmManager
::
Instance
().
create
(
"ConvertUnits"
);
auto
dSpacingAlg
=
AlgorithmManager
::
Instance
().
create
(
"ConvertUnits"
);
dSpacingAlg
->
initialize
();
dSpacingAlg
->
setProperty
(
"InputWorkspace"
,
WSNAME
);
dSpacingAlg
->
setProperty
(
"Target"
,
"dSpacing"
);
...
...
@@ -114,8 +109,7 @@ int ALFView_model::currentRun() {
try
{
auto
ws
=
AnalysisDataService
::
Instance
()
.
retrieveWS
<
MatrixWorkspace
>
(
WSNAME
);
AnalysisDataService
::
Instance
().
retrieveWS
<
MatrixWorkspace
>
(
WSNAME
);
return
ws
->
getRunNumber
();
}
catch
(...)
{
return
ERRORCODE
;
...
...
qt/scientific_interfaces/Direct/ALFView_model.h
View file @
e88687e3
...
...
@@ -23,7 +23,7 @@ public:
int
currentRun
();
bool
isErrorCode
(
const
int
run
);
std
::
string
getInstrument
();
};
};
}
// namespace CustomInterfaces
}
// namespace MantidQt
...
...
qt/scientific_interfaces/Direct/ALFView_presenter.cpp
View file @
e88687e3
...
...
@@ -17,8 +17,7 @@ namespace CustomInterfaces {
ALFView_presenter
::
ALFView_presenter
(
ALFView_view
*
view
,
ALFView_model
*
model
)
:
m_view
(
view
),
m_model
(
model
),
m_currentRun
(
0
),
m_loadRunObserver
(
nullptr
),
m_currentFile
(
""
)
{
m_currentFile
(
""
)
{
m_loadRunObserver
=
new
VoidObserver
();
m_model
->
loadEmptyInstrument
();
}
...
...
@@ -41,7 +40,7 @@ void ALFView_presenter::loadAndAnalysis(const std::string &pathToRun) {
m_currentRun
=
runNumber
;
m_currentFile
=
pathToRun
;
}
else
{
// reset to the previous data
// reset to the previous data
std
::
string
message
=
"Not the corrct instrument, expected "
+
m_model
->
getInstrument
();
m_view
->
warningBox
(
message
);
...
...
@@ -49,24 +48,23 @@ void ALFView_presenter::loadAndAnalysis(const std::string &pathToRun) {
}
// make displayed run number be in sinc
m_view
->
setRunQuietly
(
std
::
to_string
(
m_currentRun
));
if
(
bools
[
"IsValidInstrument"
]
&&
!
bools
[
"IsItDSpace"
])
{
m_model
->
transformData
();
}
}
catch
(...)
{
m_view
->
setRunQuietly
(
std
::
to_string
(
m_currentRun
));
}
}
}
void
ALFView_presenter
::
loadRunNumber
()
{
auto
pathToRun
=
m_view
->
getFile
();
const
int
currentRunInADS
=
m_model
->
currentRun
();
if
(
pathToRun
==
""
||
m_currentFile
==
pathToRun
)
{
if
(
pathToRun
==
""
||
m_currentFile
==
pathToRun
)
{
return
;
}
loadAndAnalysis
(
pathToRun
);
}
}
// namespace CustomInterfaces
}
// namespace MantidQt
\ No newline at end of file
qt/scientific_interfaces/Direct/ALFView_presenter.h
View file @
e88687e3
...
...
@@ -10,8 +10,8 @@
#include
"ALFView_model.h"
#include
"ALFView_view.h"
#include
"DllConfig.h"
#include
"MantidQtWidgets/Common/UserSubWindow.h"
#include
"MantidQtWidgets/Common/ObserverPattern.h"
#include
"MantidQtWidgets/Common/UserSubWindow.h"
#include
<string>
...
...
@@ -22,17 +22,17 @@ class MANTIDQT_DIRECT_DLL ALFView_presenter : public QObject {
Q_OBJECT
public:
ALFView_presenter
(
ALFView_view
*
view
,
ALFView_model
*
model
);
ALFView_presenter
(
ALFView_view
*
view
,
ALFView_model
*
model
);
~
ALFView_presenter
(){};
void
initLayout
();
private
slots
:
void
loadRunNumber
();
private:
void
loadAndAnalysis
(
const
std
::
string
&
run
);
ALFView_view
*
m_view
;
ALFView_view
*
m_view
;
ALFView_model
*
m_model
;
int
m_currentRun
;
std
::
string
m_currentFile
;
...
...
qt/scientific_interfaces/Direct/ALFView_view.cpp
View file @
e88687e3
...
...
@@ -6,12 +6,9 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include
"ALFView_view.h"
#include
<QFileDialog>
#include
<QGridLayout>
#include
<QLineEdit>
#include
<QMessageBox>
#include
<Q
RegExpValidator
>
#include
<QSp
inBox
>
#include
<Q
SizePolicy
>
#include
<QSp
acerItem
>
#include
<QVBoxLayout>
namespace
MantidQt
{
...
...
@@ -19,19 +16,32 @@ namespace CustomInterfaces {
ALFView_view
::
ALFView_view
(
const
std
::
string
instrument
,
QWidget
*
parent
)
:
QSplitter
(
Qt
::
Vertical
,
parent
),
m_loadRunObservable
(
nullptr
),
m_files
(
nullptr
),
m_instrument
(
QString
::
fromStdString
(
instrument
))
{
generateLoadWidget
();
this
->
addWidget
(
m_files
);
m_files
(
nullptr
),
m_instrument
(
QString
::
fromStdString
(
instrument
))
{
auto
loadWidget
=
generateLoadWidget
();
this
->
addWidget
(
loadWidget
);
}
void
ALFView_view
::
generateLoadWidget
()
{
QWidget
*
ALFView_view
::
generateLoadWidget
()
{
m_loadRunObservable
=
new
Observable
();
m_files
=
new
API
::
MWRunFiles
(
this
);
m_files
->
setLabelText
(
m_instrument
);
m_files
->
allowMultipleFiles
(
false
);
m_files
->
setInstrumentOverride
(
m_instrument
);
m_files
->
isForRunFiles
(
true
);
connect
(
m_files
,
SIGNAL
(
fileFindingFinished
()),
this
,
SLOT
(
fileLoaded
()));
auto
loadWidget
=
new
QWidget
();
auto
loadLayout
=
new
QHBoxLayout
(
loadWidget
);
loadLayout
->
addItem
(
new
QSpacerItem
(
20
,
40
,
QSizePolicy
::
Minimum
,
QSizePolicy
::
Expanding
));
loadLayout
->
addWidget
(
m_files
);
loadLayout
->
addItem
(
new
QSpacerItem
(
20
,
40
,
QSizePolicy
::
Minimum
,
QSizePolicy
::
Expanding
));
return
loadWidget
;
}
std
::
string
ALFView_view
::
getFile
()
{
...
...
@@ -60,8 +70,8 @@ void ALFView_view::warningBox(const std::string message) {
warningBox
(
QString
::
fromStdString
(
message
));
}
void
ALFView_view
::
warningBox
(
const
QString
message
)
{
QMessageBox
::
warning
(
this
,
m_instrument
+
" view"
,
message
);
}
QMessageBox
::
warning
(
this
,
m_instrument
+
" view"
,
message
);
}
}
// namespace CustomInterfaces
}
// namespace MantidQt
\ No newline at end of file
qt/scientific_interfaces/Direct/ALFView_view.h
View file @
e88687e3
...
...
@@ -8,16 +8,14 @@
#define MANTIDQT_CUSTOMINTERFACES_ALFVIEW_VIEW_H_
#include
"DllConfig.h"
#include
"MantidQtWidgets/Common/ObserverPattern.h"
#include
"MantidQtWidgets/Common/MWRunFiles.h"
#include
"MantidQtWidgets/Common/ObserverPattern.h"
#include
"MantidQtWidgets/InstrumentView/InstrumentWidget.h"
#include
<string>
#include
<QLineEdit>
#include
<QObject>
#include
<QPushButton>
#include
<QSplitter>
#include
<QString>
#include
<string>
namespace
MantidQt
{
namespace
CustomInterfaces
{
...
...
@@ -26,7 +24,8 @@ class ALFView_view : public QSplitter {
Q_OBJECT
public:
explicit
ALFView_view
(
const
std
::
string
instrument
,
QWidget
*
parent
=
nullptr
);
explicit
ALFView_view
(
const
std
::
string
instrument
,
QWidget
*
parent
=
nullptr
);
std
::
string
getFile
();
void
setRunQuietly
(
const
std
::
string
runNumber
);
void
observeLoadRun
(
Observer
*
listener
)
{
...
...
@@ -34,11 +33,11 @@ public:
};
void
warningBox
(
const
std
::
string
message
);
public
slots
:
void
fileLoaded
();
public
slots
:
void
fileLoaded
();
private:
void
generateLoadWidget
();
QWidget
*
generateLoadWidget
();
void
warningBox
(
const
QString
message
);
Observable
*
m_loadRunObservable
;
...
...
qt/widgets/common/inc/MantidQtWidgets/Common/ObserverPattern.h
View file @
e88687e3
...
...
@@ -11,9 +11,9 @@
#include
<string>
/**
* Simple classes for observer and observable pattern.
* These can be used to replace signals and slots for mocking
**/
* Simple classes for observer and observable pattern.
* These can be used to replace signals and slots for mocking
**/
class
Observable
;
...
...
@@ -23,25 +23,25 @@ public:
};
/**
* Simple observable class. This is used
* to signify if a change has been made and then needs to
* notify its observers.
**/
* Simple observable class. This is used
* to signify if a change has been made and then needs to
* notify its observers.
**/
class
Observable
{
std
::
set
<
Observer
*>
m_observers
;
public:
/**
* @param listener :: want to be notified when this observer changes
**/
* @param listener :: want to be notified when this observer changes
**/
void
attach
(
Observer
*
listener
)
{
m_observers
.
insert
(
listener
);
};
/**
* @param listener :: no longer want to be notified when this observer changes
**/
void
detach
(
Observer
*
listener
)
{
m_observers
.
erase
(
listener
);
};
/**
* Update all of the observers that a change has been made
**/
* Update all of the observers that a change has been made
**/
void
notify
()
{
for
(
auto
&
listener
:
m_observers
)
{
listener
->
update
();
...
...
@@ -58,10 +58,10 @@ public:
VoidObserver
()
:
m_slot
(
nullptr
){};
~
VoidObserver
(){};
/**
* Sets the function/slot for the oberver
* @param func:: the void function we want to call when the observer
* sends a notify signal
**/
* Sets the function/slot for the oberver
* @param func:: the void function we want to call when the observer
* sends a notify signal
**/
void
setSlot
(
std
::
function
<
void
()
>
&
func
)
{
m_slot
=
func
;
};
/**
* Calls the function/slot
...
...
@@ -72,5 +72,4 @@ private:
std
::
function
<
void
()
>
m_slot
;
};
#endif
/* MANTIDQT_CUSTOMINTERFACES_OBSERVERPATTERN_H_ */
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment