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
16a24457
Commit
16a24457
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
still cannot read, but printing proper error message
parent
a48a4453
No related branches found
No related tags found
1 merge request
!2331
store instruments in file system, not in a "library" of our own making (#896)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
App/main.cpp
+1
-1
1 addition, 1 deletion
App/main.cpp
GUI/View/Instrument/InstrumentsQListView.cpp
+47
-30
47 additions, 30 deletions
GUI/View/Instrument/InstrumentsQListView.cpp
with
48 additions
and
31 deletions
App/main.cpp
+
1
−
1
View file @
16a24457
...
@@ -33,7 +33,7 @@ void custom_terminate_handler()
...
@@ -33,7 +33,7 @@ void custom_terminate_handler()
try
{
try
{
std
::
rethrow_exception
(
std
::
current_exception
());
std
::
rethrow_exception
(
std
::
current_exception
());
}
catch
(
const
std
::
exception
&
ex
)
{
}
catch
(
const
std
::
exception
&
ex
)
{
std
::
cerr
<<
"terminate called after throwing a
n instance of 'std::runtime_error
'
\n
"
std
::
cerr
<<
"terminate called after throwing a
std exception
'
\n
"
<<
"what():"
<<
std
::
endl
;
<<
"what():"
<<
std
::
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
GUI/View/Instrument/InstrumentsQListView.cpp
+
47
−
30
View file @
16a24457
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
// ************************************************************************************************
// ************************************************************************************************
#include
"GUI/View/Instrument/InstrumentsQListView.h"
#include
"GUI/View/Instrument/InstrumentsQListView.h"
#include
"Base/Util/Assert.h"
#include
"GUI/Model/Device/InstrumentLibrary.h"
#include
"GUI/Model/Device/InstrumentLibrary.h"
#include
"GUI/Model/Project/ProjectDocument.h"
#include
"GUI/Model/Project/ProjectDocument.h"
#include
"GUI/View/Instrument/InstrumentLibraryDialog.h"
#include
"GUI/View/Instrument/InstrumentLibraryDialog.h"
...
@@ -20,20 +21,20 @@
...
@@ -20,20 +21,20 @@
#include
"GUI/View/Setup/FrameActions.h"
#include
"GUI/View/Setup/FrameActions.h"
#include
"GUI/View/Tool/Globals.h"
#include
"GUI/View/Tool/Globals.h"
#include
<QFile>
#include
<QFile>
#include
<QMessageBox>
#include
<QVBoxLayout>
#include
<QVBoxLayout>
#include
"GUI/Model/Descriptor/SelectionProperty.h"
#include
"GUI/Model/Descriptor/SelectionProperty.h"
#include
"GUI/Model/Device/InstrumentItems.h"
#include
"GUI/Model/Device/InstrumentItemCatalog.h"
#include
"GUI/Model/Device/InstrumentItemCatalog.h"
#include
"GUI/Model/Device/InstrumentItems.h"
#include
"GUI/Support/XML/UtilXML.h"
#include
"GUI/Support/XML/UtilXML.h"
#include
<QMessageBox>
namespace
{
namespace
{
const
QString
XML_ROOT_TAG
=
"BornAgain::Instrument"
;
const
QString
XML_ROOT_TAG
=
"BornAgain::Instrument"
;
const
QString
XML_VERSION_TAG
=
"Version"
;
const
QString
XML_VERSION_TAG
=
"Version"
;
}
}
// namespace
InstrumentsQListView
::
InstrumentsQListView
()
InstrumentsQListView
::
InstrumentsQListView
()
:
m_instrument_library
(
std
::
make_unique
<
InstrumentLibrary
>
())
:
m_instrument_library
(
std
::
make_unique
<
InstrumentLibrary
>
())
...
@@ -162,7 +163,7 @@ void InstrumentsQListView::onCopy()
...
@@ -162,7 +163,7 @@ void InstrumentsQListView::onCopy()
void
InstrumentsQListView
::
onStoreInLibrary
()
void
InstrumentsQListView
::
onStoreInLibrary
()
{
{
//InstrumentLibraryDialog dlg(GUI::Global::mainWindow, m_instrument_library.get());
//
InstrumentLibraryDialog dlg(GUI::Global::mainWindow, m_instrument_library.get());
QFile
file
(
"/tmp/instrument.xml"
);
QFile
file
(
"/tmp/instrument.xml"
);
if
(
!
file
.
open
(
QFile
::
ReadWrite
|
QIODevice
::
Truncate
|
QFile
::
Text
))
if
(
!
file
.
open
(
QFile
::
ReadWrite
|
QIODevice
::
Truncate
|
QFile
::
Text
))
...
@@ -191,35 +192,51 @@ void InstrumentsQListView::onStoreInLibrary()
...
@@ -191,35 +192,51 @@ void InstrumentsQListView::onStoreInLibrary()
void
InstrumentsQListView
::
onLoadFromLibrary
()
void
InstrumentsQListView
::
onLoadFromLibrary
()
{
{
InstrumentItem
*
ii
=
nullptr
;
QFile
file
(
"/tmp/instrument.xml"
);
QFile
file
(
"/tmp/instrument.xml"
);
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
throw
std
::
runtime_error
(
"Cannot open instrument file for reading"
);
try
{
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
/*
throw
std
::
runtime_error
(
"Cannot open instrument file for reading"
);
InstrumentItem ii;
QXmlStreamReader
r
(
&
file
);
while
(
!
r
.
atEnd
())
{
QXmlStreamReader r(&file);
r
.
readNext
();
if
(
r
.
isStartElement
())
{
while (!r.atEnd()) {
if
(
r
.
name
()
==
XML_ROOT_TAG
)
{
r.readNext();
const
int
foundVersion
=
r
.
attributes
().
value
(
XML_VERSION_TAG
).
toString
().
toInt
();
if (r.isStartElement()) {
if
(
foundVersion
!=
1
)
if (r.name() == XML_ROOT_TAG) {
throw
std
::
runtime_error
(
"Unsupported version of instrument file"
);
const int foundVersion =
r.attributes().value(XML_VERSION_TAG).toString().toInt();
const
uint
selection_version
=
if (foundVersion != 1)
XML
::
readUIntAttribute
(
&
r
,
XML
::
Attrib
::
selection_version
);
throw std::runtime_error("Unsupported version of instrument file");
if
(
selection_version
!=
2
)
throw
std
::
runtime_error
(
"Unsupported version of instrument stance"
);
ii.readFrom(&r);
}
const
uint
typeIndex
=
XML
::
readUIntAttribute
(
&
r
,
XML
::
Attrib
::
type
);
}
const
auto
type
=
static_cast
<
typename
InstrumentItemCatalog
::
Type
>
(
typeIndex
);
ii
=
InstrumentItemCatalog
::
create
(
type
);
ASSERT
(
ii
);
ii
->
readFrom
(
&
r
);
}
}
}
if
(
r
.
hasError
())
throw
std
::
runtime_error
(
QString
(
"Error in instrument file, line %1, column %2: %3"
)
.
arg
(
r
.
lineNumber
())
.
arg
(
r
.
columnNumber
())
.
arg
(
r
.
errorString
())
.
toStdString
());
file
.
close
();
}
catch
(
const
std
::
exception
&
ex
)
{
QMessageBox
msgbox
(
QMessageBox
::
Warning
,
"BornAgain: failed import"
,
QString
(
ex
.
what
()),
QMessageBox
::
Ok
,
nullptr
);
msgbox
.
exec
();
return
;
}
}
if (r.hasError())
throw std::runtime_error("Error while reading instrument file");
QModelIndex idx = m_model->copyInstrument(&ii);
selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
*/
file
.
close
();
QModelIndex
idx
=
m_model
->
copyInstrument
(
ii
);
selectionModel
()
->
select
(
idx
,
QItemSelectionModel
::
ClearAndSelect
);
}
}
void
InstrumentsQListView
::
updateActions
()
void
InstrumentsQListView
::
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