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
0c11aa86
Commit
0c11aa86
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
save/load fcts specify format in fct name
parent
c32be006
No related branches found
No related tags found
1 merge request
!2387
unify code for list views
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
GUI/View/Loader/ComponentRW.cpp
+14
-14
14 additions, 14 deletions
GUI/View/Loader/ComponentRW.cpp
GUI/View/Loader/ComponentRW.h
+2
-2
2 additions, 2 deletions
GUI/View/Loader/ComponentRW.h
GUI/View/Views/InstrumentView.cpp
+2
-2
2 additions, 2 deletions
GUI/View/Views/InstrumentView.cpp
with
18 additions
and
18 deletions
GUI/View/Loader/ComponentRW.cpp
+
14
−
14
View file @
0c11aa86
...
...
@@ -21,37 +21,37 @@
namespace
{
template
<
class
T
>
void
save
(
const
QString
&
fname
,
const
T
*
t
);
template
<
class
T
>
T
*
load
(
const
QString
&
fname
);
template
<
class
T
>
void
save
ToXML
(
const
QString
&
fname
,
const
T
*
t
);
template
<
class
T
>
T
*
load
FromXML
(
const
QString
&
fname
);
template
<
>
void
save
<
InstrumentItem
>
(
const
QString
&
fname
,
const
InstrumentItem
*
t
)
template
<
>
void
save
ToXML
<
InstrumentItem
>
(
const
QString
&
fname
,
const
InstrumentItem
*
t
)
{
InstrumentXML
::
save
(
fname
,
t
);
}
template
<
>
InstrumentItem
*
load
<
InstrumentItem
>
(
const
QString
&
fname
)
template
<
>
InstrumentItem
*
load
FromXML
<
InstrumentItem
>
(
const
QString
&
fname
)
{
return
InstrumentXML
::
load
(
fname
);
}
}
// namespace
// Force instantiation by assigning the function to a global variable that will never be used:
auto
dummy_saveXML_InstrumentItem
=
&
RW
::
saveComponentToXML
<
class
InstrumentItem
>
;
auto
dummy_loadXML_InstrumentItem
=
&
RW
::
loadComponentFromXML
<
class
InstrumentItem
>
;
}
// namespace
// Force instantiation by assigning the function to a global variable that will never be used:
auto
dummy_saveComponent_InstrumentItem
=
&
RW
::
saveComponent
<
class
InstrumentItem
>
;
auto
dummy_loadComponent_InstrumentItem
=
&
RW
::
loadComponent
<
class
InstrumentItem
>
;
template
<
class
T
>
void
RW
::
saveComponent
(
const
QString
&
type
,
const
T
*
t
)
template
<
class
T
>
void
RW
::
saveComponent
ToXML
(
const
QString
&
type
,
const
T
*
t
)
{
if
(
!
t
)
return
;
QString
fname
=
GUI
::
Dialog
::
fileSaveDialog
(
"Save "
+
type
,
appSettings
->
xml_dir
,
"XML
F
iles (*.xml)"
,
t
->
name
()
+
".xml"
);
"XML
f
iles (*.xml)"
,
t
->
name
()
+
".xml"
);
if
(
fname
.
isEmpty
())
return
;
try
{
::
save
<
T
>
(
fname
,
t
);
::
save
ToXML
<
T
>
(
fname
,
t
);
}
catch
(
const
std
::
exception
&
ex
)
{
QMessageBox
(
QMessageBox
::
Warning
,
"BornAgain: failed saving"
,
ex
.
what
(),
QMessageBox
::
Ok
,
nullptr
)
...
...
@@ -59,15 +59,15 @@ template <class T> void RW::saveComponent(const QString& type, const T* t)
}
}
template
<
class
T
>
T
*
RW
::
loadComponent
(
const
QString
&
type
)
template
<
class
T
>
T
*
RW
::
loadComponent
FromXML
(
const
QString
&
type
)
{
QString
fname
=
GUI
::
Dialog
::
fileOpenDialog
(
"Load "
+
type
,
appSettings
->
xml_dir
,
"XML
F
iles (*.xml)"
);
GUI
::
Dialog
::
fileOpenDialog
(
"Load "
+
type
,
appSettings
->
xml_dir
,
"XML
f
iles (*.xml)"
);
if
(
fname
.
isEmpty
())
return
nullptr
;
try
{
return
::
load
<
T
>
(
fname
);
return
::
load
FromXML
<
T
>
(
fname
);
}
catch
(
const
std
::
exception
&
ex
)
{
QMessageBox
(
QMessageBox
::
Warning
,
"BornAgain: failed loading"
,
ex
.
what
(),
QMessageBox
::
Ok
,
nullptr
)
...
...
This diff is collapsed.
Click to expand it.
GUI/View/Loader/ComponentRW.h
+
2
−
2
View file @
0c11aa86
...
...
@@ -19,8 +19,8 @@
namespace
RW
{
template
<
class
T
>
void
saveComponent
(
const
QString
&
type
,
const
T
*
t
);
template
<
class
T
>
T
*
loadComponent
(
const
QString
&
type
);
template
<
class
T
>
void
saveComponent
ToXML
(
const
QString
&
type
,
const
T
*
t
);
template
<
class
T
>
T
*
loadComponent
FromXML
(
const
QString
&
type
);
}
// namespace RW
...
...
This diff is collapsed.
Click to expand it.
GUI/View/Views/InstrumentView.cpp
+
2
−
2
View file @
0c11aa86
...
...
@@ -96,10 +96,10 @@ InstrumentView::InstrumentView()
&
InstrumentView
::
createWidgetsForCurrentInstrument
);
connect
(
gActions
->
store_in_library_instrument
,
&
QAction
::
triggered
,
[]
{
RW
::
saveComponent
(
"instrument"
,
gDoc
->
instruments
()
->
currentItem
());
});
[]
{
RW
::
saveComponent
ToXML
(
"instrument"
,
gDoc
->
instruments
()
->
currentItem
());
});
connect
(
gActions
->
load_from_library_instrument
,
&
QAction
::
triggered
,
[
this
]
{
m_qlistmodel
->
pushInstrument
(
RW
::
loadComponent
<
InstrumentItem
>
(
"instrument"
));
m_qlistmodel
->
pushInstrument
(
RW
::
loadComponent
FromXML
<
InstrumentItem
>
(
"instrument"
));
});
updateActions
();
...
...
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