Skip to content
Snippets Groups Projects
Commit 0c11aa86 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

save/load fcts specify format in fct name

parent c32be006
No related branches found
No related tags found
1 merge request!2387unify code for list views
......@@ -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 saveToXML(const QString& fname, const T* t);
template <class T> T* loadFromXML(const QString& fname);
template <> void save<InstrumentItem>(const QString& fname, const InstrumentItem* t)
template <> void saveToXML<InstrumentItem>(const QString& fname, const InstrumentItem* t)
{
InstrumentXML::save(fname, t);
}
template <> InstrumentItem* load<InstrumentItem>(const QString& fname)
template <> InstrumentItem* loadFromXML<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::saveComponentToXML(const QString& type, const T* t)
{
if (!t)
return;
QString fname = GUI::Dialog::fileSaveDialog("Save " + type, appSettings->xml_dir,
"XML Files (*.xml)", t->name() + ".xml");
"XML files (*.xml)", t->name() + ".xml");
if (fname.isEmpty())
return;
try {
::save<T>(fname, t);
::saveToXML<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::loadComponentFromXML(const QString& type)
{
QString fname =
GUI::Dialog::fileOpenDialog("Load " + type, appSettings->xml_dir, "XML Files (*.xml)");
GUI::Dialog::fileOpenDialog("Load " + type, appSettings->xml_dir, "XML files (*.xml)");
if (fname.isEmpty())
return nullptr;
try {
return ::load<T>(fname);
return ::loadFromXML<T>(fname);
} catch (const std::exception& ex) {
QMessageBox(QMessageBox::Warning, "BornAgain: failed loading", ex.what(), QMessageBox::Ok,
nullptr)
......
......@@ -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 saveComponentToXML(const QString& type, const T* t);
template <class T> T* loadComponentFromXML(const QString& type);
} // namespace RW
......
......@@ -96,10 +96,10 @@ InstrumentView::InstrumentView()
&InstrumentView::createWidgetsForCurrentInstrument);
connect(gActions->store_in_library_instrument, &QAction::triggered,
[] { RW::saveComponent("instrument", gDoc->instruments()->currentItem()); });
[] { RW::saveComponentToXML("instrument", gDoc->instruments()->currentItem()); });
connect(gActions->load_from_library_instrument, &QAction::triggered, [this] {
m_qlistmodel->pushInstrument(RW::loadComponent<InstrumentItem>("instrument"));
m_qlistmodel->pushInstrument(RW::loadComponentFromXML<InstrumentItem>("instrument"));
});
updateActions();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment