Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
Takin
mag-core
Commits
79569cbb
Commit
79569cbb
authored
Jun 20, 2018
by
Tobias WEBER
Browse files
simplified ui, shared plotter
parent
83fe2936
Changes
8
Hide whitespace changes
Inline
Side-by-side
tools/in20/filebrowser.cpp
View file @
79569cbb
...
...
@@ -14,7 +14,6 @@
#include <QtWidgets/QFileDialog>
#include "tlibs/file/loadinstr.h"
#include "data.h"
using
t_real
=
t_real_dat
;
...
...
@@ -24,6 +23,8 @@ FileBrowserWidget::FileBrowserWidget(QWidget *pParent, QSettings *pSettings)
:
QWidget
(
pParent
),
m_pSettings
(
pSettings
)
{
m_pListFiles
->
setAlternatingRowColors
(
true
);
m_pListFiles
->
installEventFilter
(
this
);
// ------------------------------------------------------------------------
// layout
...
...
@@ -37,7 +38,7 @@ FileBrowserWidget::FileBrowserWidget(QWidget *pParent, QSettings *pSettings)
pGrid
->
addWidget
(
m_pListFiles
,
1
,
0
,
2
,
2
);
pGrid
->
addWidget
(
pCheckMultiSelect
,
3
,
0
,
1
,
1
);
pGrid
->
addWidget
(
pBtnTransfer
,
3
,
1
,
1
,
1
);
pGrid
->
addWidget
(
m_pPlotter
,
4
,
0
,
1
,
2
);
//
pGrid->addWidget(m_pPlotter, 4, 0, 1, 2);
// ------------------------------------------------------------------------
...
...
@@ -156,7 +157,8 @@ void FileBrowserWidget::SetFile(QListWidgetItem* pCur)
QString
file
=
pCur
->
data
(
Qt
::
UserRole
).
toString
();
if
(
auto
[
ok
,
dataset
]
=
Dataset
::
convert_instr_file
(
file
.
toStdString
().
c_str
());
ok
)
{
m_pPlotter
->
Plot
(
dataset
);
//m_pPlotter->Plot(dataset);
emit
PlotDataset
(
dataset
);
}
}
...
...
@@ -201,6 +203,23 @@ void FileBrowserWidget::TransferToWorkspace(const QList<QListWidgetItem*> &lst)
emit
TransferFiles
(
files
);
}
/**
* re-directed child events
*/
bool
FileBrowserWidget
::
eventFilter
(
QObject
*
pObj
,
QEvent
*
pEvt
)
{
if
(
pObj
==
m_pListFiles
)
{
//std::cout << int(pEvt->type()) << std::endl;
// as the file browser and the work space widget share the same plotter, re-send plot on activation
if
(
pEvt
->
type
()
==
QEvent
::
FocusIn
)
SetFile
(
m_pListFiles
->
currentItem
());
}
return
QObject
::
eventFilter
(
pObj
,
pEvt
);
}
// ----------------------------------------------------------------------------
...
...
tools/in20/filebrowser.h
View file @
79569cbb
...
...
@@ -9,6 +9,7 @@
#define __FILEBROWSER_H__
#include <QtCore/QSettings>
#include <QtCore/QEvent>
#include <QtWidgets/QWidget>
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QLineEdit>
...
...
@@ -18,7 +19,9 @@
#include <vector>
#include <string>
#include "plot.h"
#include "data.h"
//#include "plot.h"
/**
...
...
@@ -31,7 +34,7 @@ private:
QLineEdit
*
m_pEditFolder
=
new
QLineEdit
(
this
);
QListWidget
*
m_pListFiles
=
new
QListWidget
(
this
);
Plotter
*
m_pPlotter
=
new
Plotter
(
this
);
//
Plotter *m_pPlotter = new Plotter(this);
public:
FileBrowserWidget
(
QWidget
*
pParent
=
nullptr
,
QSettings
*
pSettings
=
nullptr
);
...
...
@@ -48,8 +51,11 @@ protected:
void
TransferSelectedToWorkspace
();
void
TransferToWorkspace
(
const
QList
<
QListWidgetItem
*>&
);
bool
eventFilter
(
QObject
*
pObj
,
QEvent
*
pEvt
);
signals:
void
TransferFiles
(
const
std
::
vector
<
std
::
string
>&
);
void
PlotDataset
(
const
Dataset
&
dataset
);
};
...
...
tools/in20/mainwnd.cpp
View file @
79569cbb
...
...
@@ -13,7 +13,8 @@ MainWnd::MainWnd(QSettings* pSettings)
:
QMainWindow
(),
m_pSettings
(
pSettings
),
m_pBrowser
(
new
FileBrowser
(
this
,
pSettings
)),
m_pWS
(
new
WorkSpace
(
this
,
pSettings
)),
m_pCLI
(
new
CommandLine
(
this
,
pSettings
))
m_pCLI
(
new
CommandLine
(
this
,
pSettings
)),
m_pCurPlot
(
new
PlotterDock
(
this
))
{
// the command line widget has to be accessible globally for error output
g_pCLI
=
m_pCLI
;
...
...
@@ -27,20 +28,10 @@ MainWnd::MainWnd(QSettings* pSettings)
// Menu Bar
QMenu
*
pMenuView
=
new
QMenu
(
"View"
,
m_pMenu
);
QAction
*
pShowFileBrowser
=
new
QAction
(
"Show File Browser"
,
pMenuView
);
pShowFileBrowser
->
setChecked
(
m_pBrowser
->
isVisible
());
connect
(
pShowFileBrowser
,
&
QAction
::
triggered
,
m_pBrowser
,
&
FileBrowser
::
show
);
pMenuView
->
addAction
(
pShowFileBrowser
);
QAction
*
pShowWorkSpace
=
new
QAction
(
"Show Workspace"
,
pMenuView
);
pShowWorkSpace
->
setChecked
(
m_pWS
->
isVisible
());
connect
(
pShowWorkSpace
,
&
QAction
::
triggered
,
m_pWS
,
&
FileBrowser
::
show
);
pMenuView
->
addAction
(
pShowWorkSpace
);
QAction
*
pShowCommandLine
=
new
QAction
(
"Show Command Line"
,
pMenuView
);
pShowCommandLine
->
setChecked
(
m_pCLI
->
isVisible
());
connect
(
pShowCommandLine
,
&
QAction
::
triggered
,
m_pCLI
,
&
CommandLine
::
show
);
pMenuView
->
addAction
(
pShowCommandLine
);
pMenuView
->
addAction
(
m_pBrowser
->
toggleViewAction
());
pMenuView
->
addAction
(
m_pWS
->
toggleViewAction
());
pMenuView
->
addAction
(
m_pCLI
->
toggleViewAction
());
pMenuView
->
addAction
(
m_pCurPlot
->
toggleViewAction
());
m_pMenu
->
addMenu
(
pMenuView
);
this
->
setMenuBar
(
m_pMenu
);
...
...
@@ -52,12 +43,15 @@ MainWnd::MainWnd(QSettings* pSettings)
this
->
addDockWidget
(
Qt
::
LeftDockWidgetArea
,
m_pBrowser
);
this
->
addDockWidget
(
Qt
::
RightDockWidgetArea
,
m_pWS
);
this
->
addDockWidget
(
Qt
::
BottomDockWidgetArea
,
m_pCLI
);
this
->
addDockWidget
(
Qt
::
BottomDockWidgetArea
,
m_pCurPlot
);
// ------------------------------------------------------------------------
// connections
connect
(
m_pBrowser
->
GetWidget
(),
&
FileBrowserWidget
::
TransferFiles
,
m_pWS
->
GetWidget
(),
&
WorkSpaceWidget
::
ReceiveFiles
);
connect
(
m_pWS
->
GetWidget
(),
&
WorkSpaceWidget
::
PlotDataset
,
m_pCurPlot
->
GetWidget
(),
&
Plotter
::
Plot
);
connect
(
m_pBrowser
->
GetWidget
(),
&
FileBrowserWidget
::
PlotDataset
,
m_pCurPlot
->
GetWidget
(),
&
Plotter
::
Plot
);
// link symbol maps of workspace widget and command line parser
m_pCLI
->
GetWidget
()
->
GetParserContext
().
SetWorkspace
(
m_pWS
->
GetWidget
()
->
GetWorkspace
());
...
...
tools/in20/mainwnd.h
View file @
79569cbb
...
...
@@ -17,6 +17,7 @@
#include "filebrowser.h"
#include "workspace.h"
#include "command.h"
#include "plot.h"
class
MainWnd
:
public
QMainWindow
...
...
@@ -31,6 +32,7 @@ private:
FileBrowser
*
m_pBrowser
=
nullptr
;
WorkSpace
*
m_pWS
=
nullptr
;
CommandLine
*
m_pCLI
=
nullptr
;
PlotterDock
*
m_pCurPlot
=
nullptr
;
private:
virtual
void
showEvent
(
QShowEvent
*
pEvt
)
override
;
...
...
tools/in20/plot.cpp
View file @
79569cbb
...
...
@@ -87,10 +87,16 @@ void Plotter::Plot(const Dataset &dataset)
auto
yminmax
=
std
::
minmax_element
(
daty
.
begin
(),
daty
.
end
());
auto
yerrminmax
=
std
::
minmax_element
(
datyerr
.
begin
(),
datyerr
.
end
());
xmin
=
std
::
min
(
*
xminmax
.
first
,
xmin
);
xmax
=
std
::
max
(
*
xminmax
.
second
,
xmax
);
ymin
=
std
::
min
(
*
yminmax
.
first
-
*
yerrminmax
.
first
,
ymin
);
ymax
=
std
::
max
(
*
yminmax
.
second
+
*
yerrminmax
.
second
,
ymax
);
if
(
xminmax
.
first
!=
datx
.
end
()
&&
xminmax
.
second
!=
datx
.
end
())
{
xmin
=
std
::
min
(
*
xminmax
.
first
,
xmin
);
xmax
=
std
::
max
(
*
xminmax
.
second
,
xmax
);
}
if
(
yminmax
.
first
!=
daty
.
end
()
&&
yminmax
.
second
!=
daty
.
end
())
{
ymin
=
std
::
min
(
*
yminmax
.
first
-
*
yerrminmax
.
first
,
ymin
);
ymax
=
std
::
max
(
*
yminmax
.
second
+
*
yerrminmax
.
second
,
ymax
);
}
// labels
...
...
@@ -108,3 +114,22 @@ void Plotter::Plot(const Dataset &dataset)
m_pPlotter
->
replot
();
}
// ----------------------------------------------------------------------------
// dock
PlotterDock
::
PlotterDock
(
QWidget
*
pParent
)
:
QDockWidget
(
pParent
),
m_pPlot
(
std
::
make_unique
<
Plotter
>
(
this
))
{
this
->
setObjectName
(
"plotter"
);
this
->
setWindowTitle
(
"Current Plot"
);
this
->
setWidget
(
m_pPlot
.
get
());
}
PlotterDock
::~
PlotterDock
()
{
}
// ----------------------------------------------------------------------------
\ No newline at end of file
tools/in20/plot.h
View file @
79569cbb
...
...
@@ -30,4 +30,21 @@ public:
};
/**
* the dock which contains the plotter
*/
class
PlotterDock
:
public
QDockWidget
{
private:
std
::
unique_ptr
<
Plotter
>
m_pPlot
;
public:
PlotterDock
(
QWidget
*
pParent
=
nullptr
);
virtual
~
PlotterDock
();
const
Plotter
*
GetWidget
()
const
{
return
m_pPlot
.
get
();
}
Plotter
*
GetWidget
()
{
return
m_pPlot
.
get
();
}
};
#endif
tools/in20/workspace.cpp
View file @
79569cbb
...
...
@@ -24,11 +24,11 @@ WorkSpaceWidget::WorkSpaceWidget(QWidget *pParent, QSettings *pSettings)
:
QWidget
(
pParent
),
m_pSettings
(
pSettings
)
{
m_pListFiles
->
setAlternatingRowColors
(
true
);
m_pListFiles
->
installEventFilter
(
this
);
// ------------------------------------------------------------------------
auto
*
pGrid
=
new
QGridLayout
(
this
);
pGrid
->
addWidget
(
m_pListFiles
,
1
,
0
,
2
,
2
);
pGrid
->
addWidget
(
m_pPlotter
,
3
,
0
,
1
,
2
);
// ------------------------------------------------------------------------
...
...
@@ -76,7 +76,7 @@ void WorkSpaceWidget::ItemSelected(QListWidgetItem* pCur)
}
const
Dataset
&
dataset
=
dynamic_cast
<
const
SymbolDataset
&>
(
*
symdataset
).
GetValue
();
m_pPlotter
->
Plo
t
(
dataset
);
emit
PlotDatase
t
(
dataset
);
}
...
...
@@ -141,6 +141,23 @@ void WorkSpaceWidget::UpdateList()
//pItem->setData(Qt::UserRole, qident);
}
}
/**
* re-directed child events
*/
bool
WorkSpaceWidget
::
eventFilter
(
QObject
*
pObj
,
QEvent
*
pEvt
)
{
if
(
pObj
==
m_pListFiles
)
{
// as the file browser and the work space widget share the same plotter, re-send plot on activation
if
(
pEvt
->
type
()
==
QEvent
::
FocusIn
)
ItemSelected
(
m_pListFiles
->
currentItem
());
}
return
QObject
::
eventFilter
(
pObj
,
pEvt
);
}
// ----------------------------------------------------------------------------
...
...
tools/in20/workspace.h
View file @
79569cbb
...
...
@@ -9,6 +9,7 @@
#define __WORKSPACE_H__
#include <QtCore/QSettings>
#include <QtCore/QEvent>
#include <QtWidgets/QWidget>
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QLineEdit>
...
...
@@ -18,7 +19,6 @@
#include <map>
#include "data.h"
#include "plot.h"
#include "tools/cli/cliparser.h"
...
...
@@ -27,12 +27,10 @@
* work space widget
*/
class
WorkSpaceWidget
:
public
QWidget
{
{
Q_OBJECT
private:
QSettings
*
m_pSettings
=
nullptr
;
QListWidget
*
m_pListFiles
=
new
QListWidget
(
this
);
Plotter
*
m_pPlotter
=
new
Plotter
(
this
);
// maps an identifier to a dataset
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
Symbol
>>
m_workspace
;
...
...
@@ -46,10 +44,14 @@ public:
protected:
void
ItemSelected
(
QListWidgetItem
*
pCur
);
void
ItemDoubleClicked
(
QListWidgetItem
*
pCur
);
bool
eventFilter
(
QObject
*
pObj
,
QEvent
*
pEvt
);
public:
void
ReceiveFiles
(
const
std
::
vector
<
std
::
string
>&
);
void
UpdateList
();
signals:
void
PlotDataset
(
const
Dataset
&
dataset
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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