Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
Takin
mag-core
Commits
dc3e99d1
Verified
Commit
dc3e99d1
authored
Jun 06, 2022
by
Tobias WEBER
Browse files
bz tool: added recent files menu
parent
3d02d4c5
Changes
4
Hide whitespace changes
Inline
Side-by-side
tools/bz/CMakeLists.txt
View file @
dc3e99d1
...
...
@@ -73,6 +73,7 @@ add_executable(takin_bz
bz_plot.cpp bz_main.cpp
bz_ops.cpp bz.h globals.h
plot_cut.cpp plot_cut.h
../../tlibs2/libs/qt/recent.cpp ../../tlibs2/libs/qt/recent.h
../../tlibs2/libs/qt/gl.cpp ../../tlibs2/libs/qt/gl.h
../../tlibs2/libs/qt/glplot.cpp ../../tlibs2/libs/qt/glplot.h
)
...
...
tools/bz/bz.cpp
View file @
dc3e99d1
...
...
@@ -408,9 +408,16 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
auto
menuFile
=
new
QMenu
(
"File"
,
m_menu
);
auto
menuBZ
=
new
QMenu
(
"Brillouin Zone"
,
m_menu
);
// recent files menu
m_menuOpenRecent
=
new
QMenu
(
"Open Recent"
,
menuFile
);
m_recent
.
SetRecentFilesMenu
(
m_menuOpenRecent
);
m_recent
.
SetMaxRecentFiles
(
16
);
m_recent
.
SetOpenFunc
(
&
m_open_func
);
// file menu
auto
acNew
=
new
QAction
(
"New"
,
menuFile
);
auto
acLoad
=
new
QAction
(
"
Load
..."
,
menuFile
);
auto
acLoad
=
new
QAction
(
"
Open
..."
,
menuFile
);
auto
acSave
=
new
QAction
(
"Save..."
,
menuFile
);
auto
acImportCIF
=
new
QAction
(
"Import CIF..."
,
menuFile
);
auto
acExit
=
new
QAction
(
"Quit"
,
menuFile
);
...
...
@@ -431,6 +438,7 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
acExit
->
setIcon
(
QIcon
::
fromTheme
(
"application-exit"
));
acAboutQt
->
setIcon
(
QIcon
::
fromTheme
(
"help-about"
));
acAbout
->
setIcon
(
QIcon
::
fromTheme
(
"help-about"
));
m_menuOpenRecent
->
setIcon
(
QIcon
::
fromTheme
(
"document-open-recent"
));
acNew
->
setShortcut
(
QKeySequence
::
New
);
acLoad
->
setShortcut
(
QKeySequence
::
Open
);
...
...
@@ -447,6 +455,8 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
menuFile
->
addAction
(
acNew
);
menuFile
->
addSeparator
();
menuFile
->
addAction
(
acLoad
);
menuFile
->
addMenu
(
m_menuOpenRecent
);
menuFile
->
addSeparator
();
menuFile
->
addAction
(
acSave
);
menuFile
->
addSeparator
();
menuFile
->
addAction
(
acImportCIF
);
...
...
@@ -462,8 +472,8 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
menuHelp
->
addAction
(
acAbout
);
connect
(
acNew
,
&
QAction
::
triggered
,
this
,
&
BZDlg
::
NewFile
);
connect
(
acLoad
,
&
QAction
::
triggered
,
this
,
&
BZDlg
::
Load
);
connect
(
acSave
,
&
QAction
::
triggered
,
this
,
&
BZDlg
::
Save
);
connect
(
acLoad
,
&
QAction
::
triggered
,
this
,
static_cast
<
void
(
BZDlg
::*
)()
>
(
&
BZDlg
::
Load
)
)
;
connect
(
acSave
,
&
QAction
::
triggered
,
this
,
static_cast
<
void
(
BZDlg
::*
)()
>
(
&
BZDlg
::
Save
)
)
;
connect
(
acImportCIF
,
&
QAction
::
triggered
,
this
,
&
BZDlg
::
ImportCIF
);
connect
(
acExit
,
&
QAction
::
triggered
,
this
,
&
QDialog
::
close
);
connect
(
ac3DView
,
&
QAction
::
triggered
,
this
,
&
BZDlg
::
ShowBZPlot
);
...
...
@@ -490,12 +500,17 @@ BZDlg::BZDlg(QWidget* pParent) : QDialog{pParent},
}
// restore window size and position
if
(
m_sett
&&
m_sett
->
contains
(
"geo"
))
restoreGeometry
(
m_sett
->
value
(
"geo"
).
toByteArray
());
else
resize
(
600
,
500
);
if
(
m_sett
)
{
// restore window size and position
if
(
m_sett
->
contains
(
"geo"
))
restoreGeometry
(
m_sett
->
value
(
"geo"
).
toByteArray
());
else
resize
(
600
,
500
);
if
(
m_sett
->
contains
(
"recent_files"
))
m_recent
.
SetRecentFiles
(
m_sett
->
value
(
"recent_files"
).
toStringList
());
}
m_ignoreChanges
=
0
;
}
...
...
@@ -505,6 +520,9 @@ void BZDlg::closeEvent(QCloseEvent *)
{
if
(
m_sett
)
{
m_recent
.
TrimEntries
();
m_sett
->
setValue
(
"recent_files"
,
m_recent
.
GetRecentFiles
());
m_sett
->
setValue
(
"geo"
,
saveGeometry
());
if
(
m_dlgPlot
)
m_sett
->
setValue
(
"geo_3dview"
,
m_dlgPlot
->
saveGeometry
());
...
...
tools/bz/bz.h
View file @
dc3e99d1
...
...
@@ -47,6 +47,7 @@
#include
"globals.h"
#include
"plot_cut.h"
#include
"tlibs2/libs/qt/recent.h"
#include
"tlibs2/libs/qt/glplot.h"
#include
"tlibs2/libs/qt/numerictablewidgetitem.h"
...
...
@@ -105,12 +106,24 @@ protected:
QDoubleSpinBox
*
m_cutD
=
nullptr
;
QSpinBox
*
m_BZDrawOrder
=
nullptr
;
QSpinBox
*
m_BZCalcOrder
=
nullptr
;
QAction
*
m_acCutHull
=
nullptr
;
// results panel
QPlainTextEdit
*
m_bzresults
=
nullptr
;
std
::
string
m_descrBZ
,
m_descrBZCut
;
// text description of the results
// menu
QAction
*
m_acCutHull
=
nullptr
;
// recently opened files
tl2
::
RecentFiles
m_recent
{};
QMenu
*
m_menuOpenRecent
{};
// function to call for the recent file menu items
std
::
function
<
bool
(
const
QString
&
filename
)
>
m_open_func
=
[
this
](
const
QString
&
filename
)
->
bool
{
return
this
->
Load
(
filename
);
};
QMenu
*
m_tabContextMenu
=
nullptr
;
// menu in case a symop is selected
QMenu
*
m_tabContextMenuNoItem
=
nullptr
;
// menu if nothing is selected
...
...
@@ -143,6 +156,9 @@ protected:
void
GetSymOpsFromSG
();
void
SaveCutSVG
();
bool
Load
(
const
QString
&
filename
);
bool
Save
(
const
QString
&
filename
);
// calculation functions
std
::
vector
<
t_mat
>
GetSymOps
(
bool
only_centring
=
false
)
const
;
void
CalcB
(
bool
full_recalc
=
true
);
...
...
tools/bz/bz_file.cpp
View file @
dc3e99d1
...
...
@@ -79,20 +79,12 @@ void BZDlg::NewFile()
}
void
BZDlg
::
Load
()
bool
BZDlg
::
Load
(
const
QString
&
filename
)
{
m_ignoreCalc
=
1
;
try
{
QString
dirLast
=
m_sett
->
value
(
"dir"
,
""
).
toString
();
QString
filename
=
QFileDialog
::
getOpenFileName
(
this
,
"Load File"
,
dirLast
,
"XML Files (*.xml *.XML)"
);
if
(
filename
==
""
||
!
QFile
::
exists
(
filename
))
return
;
m_sett
->
setValue
(
"dir"
,
QFileInfo
(
filename
).
path
());
pt
::
ptree
node
;
std
::
ifstream
ifstr
{
filename
.
toStdString
()};
...
...
@@ -104,7 +96,8 @@ void BZDlg::Load()
{
QMessageBox
::
critical
(
this
,
"Brillouin Zones"
,
"Unrecognised file format."
);
return
;
m_ignoreCalc
=
0
;
return
false
;
}
...
...
@@ -200,29 +193,25 @@ void BZDlg::Load()
catch
(
const
std
::
exception
&
ex
)
{
QMessageBox
::
critical
(
this
,
"Brillouin Zones"
,
ex
.
what
());
m_ignoreCalc
=
0
;
return
false
;
}
m_ignoreCalc
=
0
;
CalcB
(
true
);
return
true
;
}
void
BZDlg
::
Save
()
bool
BZDlg
::
Save
(
const
QString
&
filename
)
{
QString
dirLast
=
m_sett
->
value
(
"dir"
,
""
).
toString
();
QString
filename
=
QFileDialog
::
getSaveFileName
(
this
,
"Save File"
,
dirLast
,
"XML Files (*.xml *.XML)"
);
if
(
filename
==
""
)
return
;
m_sett
->
setValue
(
"dir"
,
QFileInfo
(
filename
).
path
());
pt
::
ptree
node
;
// meta infos
node
.
put
<
std
::
string
>
(
"bz.meta.info"
,
"bz_tool"
);
node
.
put
<
std
::
string
>
(
"bz.meta.date"
,
tl2
::
epoch_to_str
<
t_real
>
(
tl2
::
epoch
<
t_real
>
()));
// lattice
t_real
a
,
b
,
c
,
alpha
,
beta
,
gamma
;
std
::
istringstream
{
m_editA
->
text
().
toStdString
()}
>>
a
;
...
...
@@ -264,10 +253,44 @@ void BZDlg::Save()
if
(
!
ofstr
)
{
QMessageBox
::
critical
(
this
,
"Brillouin Zones"
,
"Cannot open file for writing."
);
return
;
return
false
;
}
ofstr
.
precision
(
g_prec
);
pt
::
write_xml
(
ofstr
,
node
,
pt
::
xml_writer_make_settings
(
'\t'
,
1
,
std
::
string
{
"utf-8"
}));
return
true
;
}
void
BZDlg
::
Load
()
{
QString
dirLast
=
m_sett
->
value
(
"dir"
,
""
).
toString
();
QString
filename
=
QFileDialog
::
getOpenFileName
(
this
,
"Load File"
,
dirLast
,
"XML Files (*.xml *.XML)"
);
if
(
filename
==
""
||
!
QFile
::
exists
(
filename
))
return
;
if
(
Load
(
filename
))
{
m_sett
->
setValue
(
"dir"
,
QFileInfo
(
filename
).
path
());
m_recent
.
AddRecentFile
(
filename
);
}
}
void
BZDlg
::
Save
()
{
QString
dirLast
=
m_sett
->
value
(
"dir"
,
""
).
toString
();
QString
filename
=
QFileDialog
::
getSaveFileName
(
this
,
"Save File"
,
dirLast
,
"XML Files (*.xml *.XML)"
);
if
(
filename
==
""
)
return
;
if
(
Save
(
filename
))
{
m_sett
->
setValue
(
"dir"
,
QFileInfo
(
filename
).
path
());
m_recent
.
AddRecentFile
(
filename
);
}
}
...
...
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