##// END OF EJS Templates
Changes signal to pass a list of variables...
Alexandre Leroux -
r288:abba90cff944
parent child
Show More
@@ -1,254 +1,256
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SciQLop Software
2 -- This file is a part of the SciQLop Software
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <DataSource/DataSourceController.h>
25 #include <DataSource/DataSourceController.h>
26 #include <DataSource/DataSourceWidget.h>
26 #include <DataSource/DataSourceWidget.h>
27 #include <SidePane/SqpSidePane.h>
27 #include <SidePane/SqpSidePane.h>
28 #include <SqpApplication.h>
28 #include <SqpApplication.h>
29 #include <Time/TimeController.h>
29 #include <Time/TimeController.h>
30 #include <TimeWidget/TimeWidget.h>
30 #include <TimeWidget/TimeWidget.h>
31 #include <Variable/Variable.h>
31 #include <Variable/Variable.h>
32 #include <Visualization/VisualizationController.h>
32 #include <Visualization/VisualizationController.h>
33
33
34 #include <QAction>
34 #include <QAction>
35 #include <QDate>
35 #include <QDate>
36 #include <QDateTime>
36 #include <QDateTime>
37 #include <QDir>
37 #include <QDir>
38 #include <QFileDialog>
38 #include <QFileDialog>
39 #include <QToolBar>
39 #include <QToolBar>
40 #include <QToolButton>
40 #include <QToolButton>
41 #include <memory.h>
41 #include <memory.h>
42
42
43 //#include <omp.h>
43 //#include <omp.h>
44 //#include <network/filedownloader.h>
44 //#include <network/filedownloader.h>
45 //#include <qlopdatabase.h>
45 //#include <qlopdatabase.h>
46 //#include <qlopsettings.h>
46 //#include <qlopsettings.h>
47 //#include <qlopgui.h>
47 //#include <qlopgui.h>
48 //#include <spacedata.h>
48 //#include <spacedata.h>
49 //#include "qlopcore.h"
49 //#include "qlopcore.h"
50 //#include "qlopcodecmanager.h"
50 //#include "qlopcodecmanager.h"
51 //#include "cdfcodec.h"
51 //#include "cdfcodec.h"
52 //#include "amdatxtcodec.h"
52 //#include "amdatxtcodec.h"
53 //#include <qlopplotmanager.h>
53 //#include <qlopplotmanager.h>
54
54
55 #include "iostream"
55 #include "iostream"
56
56
57 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
57 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
58
58
59 namespace {
59 namespace {
60 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
60 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
61 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
61 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
62 const auto VIEWPLITTERINDEX = 2;
62 const auto VIEWPLITTERINDEX = 2;
63 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
63 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
64 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
64 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
65 }
65 }
66
66
67 class MainWindow::MainWindowPrivate {
67 class MainWindow::MainWindowPrivate {
68 public:
68 public:
69 QSize m_LastOpenLeftInspectorSize;
69 QSize m_LastOpenLeftInspectorSize;
70 QSize m_LastOpenRightInspectorSize;
70 QSize m_LastOpenRightInspectorSize;
71 };
71 };
72
72
73 MainWindow::MainWindow(QWidget *parent)
73 MainWindow::MainWindow(QWidget *parent)
74 : QMainWindow{parent},
74 : QMainWindow{parent},
75 m_Ui{new Ui::MainWindow},
75 m_Ui{new Ui::MainWindow},
76 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
76 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
77 {
77 {
78 m_Ui->setupUi(this);
78 m_Ui->setupUi(this);
79
79
80 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
80 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
81 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
81 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
82
82
83
83
84 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
84 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
85 auto openLeftInspectorAction = new QAction{QIcon{
85 auto openLeftInspectorAction = new QAction{QIcon{
86 ":/icones/previous.png",
86 ":/icones/previous.png",
87 },
87 },
88 tr("Show/hide the left inspector"), this};
88 tr("Show/hide the left inspector"), this};
89
89
90
90
91 auto spacerLeftTop = new QWidget{};
91 auto spacerLeftTop = new QWidget{};
92 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
92 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93
93
94 auto spacerLeftBottom = new QWidget{};
94 auto spacerLeftBottom = new QWidget{};
95 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
95 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
96
96
97 leftSidePane->addWidget(spacerLeftTop);
97 leftSidePane->addWidget(spacerLeftTop);
98 leftSidePane->addAction(openLeftInspectorAction);
98 leftSidePane->addAction(openLeftInspectorAction);
99 leftSidePane->addWidget(spacerLeftBottom);
99 leftSidePane->addWidget(spacerLeftBottom);
100
100
101
101
102 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
102 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
103 auto openRightInspectorAction = new QAction{QIcon{
103 auto openRightInspectorAction = new QAction{QIcon{
104 ":/icones/next.png",
104 ":/icones/next.png",
105 },
105 },
106 tr("Show/hide the right inspector"), this};
106 tr("Show/hide the right inspector"), this};
107
107
108 auto spacerRightTop = new QWidget{};
108 auto spacerRightTop = new QWidget{};
109 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
109 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
110
110
111 auto spacerRightBottom = new QWidget{};
111 auto spacerRightBottom = new QWidget{};
112 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113
113
114 rightSidePane->addWidget(spacerRightTop);
114 rightSidePane->addWidget(spacerRightTop);
115 rightSidePane->addAction(openRightInspectorAction);
115 rightSidePane->addAction(openRightInspectorAction);
116 rightSidePane->addWidget(spacerRightBottom);
116 rightSidePane->addWidget(spacerRightBottom);
117
117
118 openLeftInspectorAction->setCheckable(true);
118 openLeftInspectorAction->setCheckable(true);
119 openRightInspectorAction->setCheckable(true);
119 openRightInspectorAction->setCheckable(true);
120
120
121 auto openInspector = [this](bool checked, bool right, auto action) {
121 auto openInspector = [this](bool checked, bool right, auto action) {
122
122
123 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
123 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
124
124
125 auto &lastInspectorSize
125 auto &lastInspectorSize
126 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
126 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
127
127
128 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
128 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
129 : m_Ui->leftMainInspectorWidget->size();
129 : m_Ui->leftMainInspectorWidget->size();
130
130
131 // Update of the last opened geometry
131 // Update of the last opened geometry
132 if (checked) {
132 if (checked) {
133 lastInspectorSize = nextInspectorSize;
133 lastInspectorSize = nextInspectorSize;
134 }
134 }
135
135
136 auto startSize = lastInspectorSize;
136 auto startSize = lastInspectorSize;
137 auto endSize = startSize;
137 auto endSize = startSize;
138 endSize.setWidth(0);
138 endSize.setWidth(0);
139
139
140 auto splitterInspectorIndex
140 auto splitterInspectorIndex
141 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
141 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
142
142
143 auto currentSizes = m_Ui->splitter->sizes();
143 auto currentSizes = m_Ui->splitter->sizes();
144 if (checked) {
144 if (checked) {
145 // adjust sizes individually here, e.g.
145 // adjust sizes individually here, e.g.
146 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
146 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
147 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
147 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
148 m_Ui->splitter->setSizes(currentSizes);
148 m_Ui->splitter->setSizes(currentSizes);
149 }
149 }
150 else {
150 else {
151 // adjust sizes individually here, e.g.
151 // adjust sizes individually here, e.g.
152 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
152 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
153 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
153 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
154 m_Ui->splitter->setSizes(currentSizes);
154 m_Ui->splitter->setSizes(currentSizes);
155 }
155 }
156
156
157 };
157 };
158
158
159
159
160 connect(openLeftInspectorAction, &QAction::triggered,
160 connect(openLeftInspectorAction, &QAction::triggered,
161 [openInspector, openLeftInspectorAction](bool checked) {
161 [openInspector, openLeftInspectorAction](bool checked) {
162 openInspector(checked, false, openLeftInspectorAction);
162 openInspector(checked, false, openLeftInspectorAction);
163 });
163 });
164 connect(openRightInspectorAction, &QAction::triggered,
164 connect(openRightInspectorAction, &QAction::triggered,
165 [openInspector, openRightInspectorAction](bool checked) {
165 [openInspector, openRightInspectorAction](bool checked) {
166 openInspector(checked, true, openRightInspectorAction);
166 openInspector(checked, true, openRightInspectorAction);
167 });
167 });
168
168
169 this->menuBar()->addAction(tr("File"));
169 this->menuBar()->addAction(tr("File"));
170 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
170 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
171
171
172 auto timeWidget = new TimeWidget{};
172 auto timeWidget = new TimeWidget{};
173 mainToolBar->addWidget(timeWidget);
173 mainToolBar->addWidget(timeWidget);
174
174
175 // Widgets / controllers connections
175 // Widgets / controllers connections
176
176
177 // DataSource
177 // DataSource
178 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
178 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
179 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
179 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
180
180
181 // Time
181 // Time
182 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
182 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
183 SLOT(onTimeToUpdate(SqpDateTime)));
183 SLOT(onTimeToUpdate(SqpDateTime)));
184
184
185 // Widgets / widgets connections
185 // Widgets / widgets connections
186 qRegisterMetaType<std::shared_ptr<Variable> >();
186 qRegisterMetaType<std::shared_ptr<Variable> >();
187
187
188 // For the following connections, we use DirectConnection to allow each widget that can
188 // For the following connections, we use DirectConnection to allow each widget that can
189 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
189 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
190 // The order of connections is also important, since it determines the order in which each
190 // The order of connections is also important, since it determines the order in which each
191 // widget will attach its menu
191 // widget will attach its menu
192 connect(m_Ui->variableInspectorWidget,
192 connect(
193 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, std::shared_ptr<Variable>)), m_Ui->view,
193 m_Ui->variableInspectorWidget,
194 SLOT(attachVariableMenu(QMenu *, std::shared_ptr<Variable>)), Qt::DirectConnection);
194 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
195 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
196 Qt::DirectConnection);
195
197
196 /* QLopGUI::registerMenuBar(menuBar());
198 /* QLopGUI::registerMenuBar(menuBar());
197 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
199 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
198 this->m_progressWidget = new QWidget();
200 this->m_progressWidget = new QWidget();
199 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
201 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
200 this->m_progressWidget->setLayout(this->m_progressLayout);
202 this->m_progressWidget->setLayout(this->m_progressLayout);
201 this->m_progressWidget->setWindowModality(Qt::WindowModal);
203 this->m_progressWidget->setWindowModality(Qt::WindowModal);
202 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
204 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
203 for(int i=0;i<OMP_THREADS;i++)
205 for(int i=0;i<OMP_THREADS;i++)
204 {
206 {
205 this->m_progress.append(new QProgressBar(this->m_progressWidget));
207 this->m_progress.append(new QProgressBar(this->m_progressWidget));
206 this->m_progress.last()->setMinimum(0);
208 this->m_progress.last()->setMinimum(0);
207 this->m_progress.last()->setMaximum(100);
209 this->m_progress.last()->setMaximum(100);
208 this->m_progressLayout->addWidget(this->m_progress.last());
210 this->m_progressLayout->addWidget(this->m_progress.last());
209 this->m_progressWidget->hide();
211 this->m_progressWidget->hide();
210 this->m_progressThreadIds[i] = -1;
212 this->m_progressThreadIds[i] = -1;
211 }
213 }
212 this->m_progressWidget->setWindowTitle("Loading File");
214 this->m_progressWidget->setWindowTitle("Loading File");
213 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
215 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
214 << QLopCore::self()
216 << QLopCore::self()
215 << QLopPlotManager::self()
217 << QLopPlotManager::self()
216 << QLopCodecManager::self()
218 << QLopCodecManager::self()
217 << FileDownloader::self()
219 << FileDownloader::self()
218 << QLopDataBase::self()
220 << QLopDataBase::self()
219 << SpaceData::self();
221 << SpaceData::self();
220
222
221 CDFCodec::registerToManager();
223 CDFCodec::registerToManager();
222 AMDATXTCodec::registerToManager();
224 AMDATXTCodec::registerToManager();
223
225
224
226
225 for(int i=0;i<ServicesToLoad.count();i++)
227 for(int i=0;i<ServicesToLoad.count();i++)
226 {
228 {
227 qDebug()<<ServicesToLoad.at(i)->serviceName();
229 qDebug()<<ServicesToLoad.at(i)->serviceName();
228 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
230 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
229 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
231 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
230 if(wdgt)
232 if(wdgt)
231 {
233 {
232 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
234 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
233 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
235 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
234 }
236 }
235 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
237 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
236 }*/
238 }*/
237 }
239 }
238
240
239 MainWindow::~MainWindow()
241 MainWindow::~MainWindow()
240 {
242 {
241 }
243 }
242
244
243
245
244 void MainWindow::changeEvent(QEvent *e)
246 void MainWindow::changeEvent(QEvent *e)
245 {
247 {
246 QMainWindow::changeEvent(e);
248 QMainWindow::changeEvent(e);
247 switch (e->type()) {
249 switch (e->type()) {
248 case QEvent::LanguageChange:
250 case QEvent::LanguageChange:
249 m_Ui->retranslateUi(this);
251 m_Ui->retranslateUi(this);
250 break;
252 break;
251 default:
253 default:
252 break;
254 break;
253 }
255 }
254 }
256 }
@@ -1,49 +1,50
1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
2 #define SCIQLOP_VARIABLEINSPECTORWIDGET_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QMenu>
5 #include <QMenu>
6 #include <QWidget>
6 #include <QWidget>
7
7
8 #include <memory>
8 #include <memory>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget)
11
11
12 class Variable;
12 class Variable;
13
13
14 namespace Ui {
14 namespace Ui {
15 class VariableInspectorWidget;
15 class VariableInspectorWidget;
16 } // Ui
16 } // Ui
17
17
18 /**
18 /**
19 * @brief The VariableInspectorWidget class representes represents the variable inspector, from
19 * @brief The VariableInspectorWidget class representes represents the variable inspector, from
20 * which it is possible to view the loaded variables, handle them or trigger their display in
20 * which it is possible to view the loaded variables, handle them or trigger their display in
21 * visualization
21 * visualization
22 */
22 */
23 class VariableInspectorWidget : public QWidget {
23 class VariableInspectorWidget : public QWidget {
24 Q_OBJECT
24 Q_OBJECT
25
25
26 public:
26 public:
27 explicit VariableInspectorWidget(QWidget *parent = 0);
27 explicit VariableInspectorWidget(QWidget *parent = 0);
28 virtual ~VariableInspectorWidget();
28 virtual ~VariableInspectorWidget();
29
29
30 signals:
30 signals:
31 /**
31 /**
32 * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets
32 * Signal emitted before a menu concerning variables is displayed. It is used for other widgets
33 * to complete the menu.
33 * to complete the menu.
34 * @param tableMenu the menu to be completed
34 * @param tableMenu the menu to be completed
35 * @param variable the variable concerned by the menu
35 * @param variables the variables concerned by the menu
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
36 * @remarks To make the dynamic addition of menus work, the connections to this signal must be
37 * in Qt :: DirectConnection
37 * in Qt :: DirectConnection
38 */
38 */
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable);
39 void tableMenuAboutToBeDisplayed(QMenu *tableMenu,
40 const QVector<std::shared_ptr<Variable> > &variables);
40
41
41 private:
42 private:
42 Ui::VariableInspectorWidget *ui;
43 Ui::VariableInspectorWidget *ui;
43
44
44 private slots:
45 private slots:
45 /// Slot called when right clicking on an variable in the table (displays a menu)
46 /// Slot called when right clicking on an variable in the table (displays a menu)
46 void onTableMenuRequested(const QPoint &pos) noexcept;
47 void onTableMenuRequested(const QPoint &pos) noexcept;
47 };
48 };
48
49
49 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
50 #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H
@@ -1,43 +1,44
1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
2 #define SCIQLOP_VISUALIZATIONWIDGET_H
2 #define SCIQLOP_VISUALIZATIONWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10
10
11 class QMenu;
11 class QMenu;
12 class Variable;
12 class Variable;
13 class VisualizationTabWidget;
13 class VisualizationTabWidget;
14
14
15 namespace Ui {
15 namespace Ui {
16 class VisualizationWidget;
16 class VisualizationWidget;
17 } // namespace Ui
17 } // namespace Ui
18
18
19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
20 Q_OBJECT
20 Q_OBJECT
21
21
22 public:
22 public:
23 explicit VisualizationWidget(QWidget *parent = 0);
23 explicit VisualizationWidget(QWidget *parent = 0);
24 virtual ~VisualizationWidget();
24 virtual ~VisualizationWidget();
25
25
26 // IVisualizationWidget interface
26 // IVisualizationWidget interface
27 void accept(IVisualizationWidgetVisitor *visitor) override;
27 void accept(IVisualizationWidgetVisitor *visitor) override;
28 bool canDrop(const Variable &variable) const override;
28 bool canDrop(const Variable &variable) const override;
29 QString name() const override;
29 QString name() const override;
30
30
31 public slots:
31 public slots:
32 /**
32 /**
33 * Attaches to a menu the menu relating to the visualization of a variable
33 * Attaches to a menu the menu relative to the visualization of variables
34 * @param menu the parent menu of the generated menu
34 * @param menu the parent menu of the generated menu
35 * @param variable the variable for which to generate the menu
35 * @param variables the variables for which to generate the menu
36 */
36 */
37 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
37 void attachVariableMenu(QMenu *menu,
38 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
38
39
39 private:
40 private:
40 Ui::VisualizationWidget *ui;
41 Ui::VisualizationWidget *ui;
41 };
42 };
42
43
43 #endif // VISUALIZATIONWIDGET_H
44 #endif // VISUALIZATIONWIDGET_H
@@ -1,70 +1,69
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableInspectorWidget.h>
2 #include <Variable/VariableInspectorWidget.h>
3 #include <Variable/VariableModel.h>
3 #include <Variable/VariableModel.h>
4
4
5 #include <ui_VariableInspectorWidget.h>
5 #include <ui_VariableInspectorWidget.h>
6
6
7 #include <QSortFilterProxyModel>
7 #include <QSortFilterProxyModel>
8
8
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
11 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
12
12
13 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
13 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
14 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
14 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
15 {
15 {
16 ui->setupUi(this);
16 ui->setupUi(this);
17
17
18 // Sets model for table
18 // Sets model for table
19 auto sortFilterModel = new QSortFilterProxyModel{this};
19 auto sortFilterModel = new QSortFilterProxyModel{this};
20 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
20 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
21
21
22 ui->tableView->setModel(sortFilterModel);
22 ui->tableView->setModel(sortFilterModel);
23
23
24 // Fixes column sizes
24 // Fixes column sizes
25 auto model = ui->tableView->model();
25 auto model = ui->tableView->model();
26 const auto count = model->columnCount();
26 const auto count = model->columnCount();
27 for (auto i = 0; i < count; ++i) {
27 for (auto i = 0; i < count; ++i) {
28 ui->tableView->setColumnWidth(
28 ui->tableView->setColumnWidth(
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
29 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
30 }
30 }
31
31
32 // Sets selection options
32 // Sets selection options
33 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
33 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
34 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
34 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
35
35
36 // Connection to show a menu when right clicking on the tree
36 // Connection to show a menu when right clicking on the tree
37 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
37 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
38 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
38 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
39 &VariableInspectorWidget::onTableMenuRequested);
39 &VariableInspectorWidget::onTableMenuRequested);
40 }
40 }
41
41
42 VariableInspectorWidget::~VariableInspectorWidget()
42 VariableInspectorWidget::~VariableInspectorWidget()
43 {
43 {
44 delete ui;
44 delete ui;
45 }
45 }
46
46
47 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
47 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
48 {
48 {
49 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
49 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
50
50
51 // Gets the model to retrieve the underlying selected variables
51 // Gets the model to retrieve the underlying selected variables
52 auto model = sqpApp->variableController().variableModel();
52 auto model = sqpApp->variableController().variableModel();
53 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
53 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
54 for (const auto &selectedRow : qAsConst(selectedRows)) {
54 for (const auto &selectedRow : qAsConst(selectedRows)) {
55 if (auto selectedVariable = model->variable(selectedRow.row())) {
55 if (auto selectedVariable = model->variable(selectedRow.row())) {
56 selectedVariables.push_back(selectedVariable);
56 selectedVariables.push_back(selectedVariable);
57 }
57 }
58 }
58 }
59
59
60 QMenu tableMenu{};
60 QMenu tableMenu{};
61
61
62 // Emits a signal so that potential receivers can populate the menu before displaying it
62 // Emits a signal so that potential receivers can populate the menu before displaying it
63 /// @todo ALX : handles list of variables in the signal
64 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
63 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
65
64
66 if (!tableMenu.isEmpty()) {
65 if (!tableMenu.isEmpty()) {
67 // Displays menu
66 // Displays menu
68 tableMenu.exec(mapToGlobal(pos));
67 tableMenu.exec(mapToGlobal(pos));
69 }
68 }
70 }
69 }
@@ -1,115 +1,129
1 #include "Visualization/VisualizationWidget.h"
1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationGraphWidget.h"
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 #include "Visualization/qcustomplot.h"
7 #include "Visualization/qcustomplot.h"
8
8
9 #include "ui_VisualizationWidget.h"
9 #include "ui_VisualizationWidget.h"
10
10
11 #include <QToolButton>
11 #include <QToolButton>
12
12
13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
14
14
15 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 VisualizationWidget::VisualizationWidget(QWidget *parent)
16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
17 {
17 {
18 ui->setupUi(this);
18 ui->setupUi(this);
19
19
20 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 auto addTabViewButton = new QToolButton{ui->tabWidget};
21 addTabViewButton->setText(tr("Add View"));
21 addTabViewButton->setText(tr("Add View"));
22 addTabViewButton->setCursor(Qt::ArrowCursor);
22 addTabViewButton->setCursor(Qt::ArrowCursor);
23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
24
24
25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
26
26
27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
28 auto width = enable ? tabViewCornerWidget->width() : 0;
28 auto width = enable ? tabViewCornerWidget->width() : 0;
29 auto height = enable ? tabViewCornerWidget->height() : 0;
29 auto height = enable ? tabViewCornerWidget->height() : 0;
30 tabViewCornerWidget->setMinimumHeight(height);
30 tabViewCornerWidget->setMinimumHeight(height);
31 tabViewCornerWidget->setMinimumWidth(width);
31 tabViewCornerWidget->setMinimumWidth(width);
32 ui->tabWidget->setMinimumHeight(height);
32 ui->tabWidget->setMinimumHeight(height);
33 ui->tabWidget->setMinimumWidth(width);
33 ui->tabWidget->setMinimumWidth(width);
34 };
34 };
35
35
36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
38 ui->tabWidget};
38 ui->tabWidget};
39 auto index = ui->tabWidget->addTab(widget, widget->name());
39 auto index = ui->tabWidget->addTab(widget, widget->name());
40 if (ui->tabWidget->count() > 0) {
40 if (ui->tabWidget->count() > 0) {
41 enableMinimumCornerWidgetSize(false);
41 enableMinimumCornerWidgetSize(false);
42 }
42 }
43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
44 };
44 };
45
45
46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
47 if (ui->tabWidget->count() == 1) {
47 if (ui->tabWidget->count() == 1) {
48 enableMinimumCornerWidgetSize(true);
48 enableMinimumCornerWidgetSize(true);
49 }
49 }
50
50
51 // Removes widget from tab and closes it
51 // Removes widget from tab and closes it
52 auto widget = ui->tabWidget->widget(index);
52 auto widget = ui->tabWidget->widget(index);
53 ui->tabWidget->removeTab(index);
53 ui->tabWidget->removeTab(index);
54 if (widget) {
54 if (widget) {
55 widget->close();
55 widget->close();
56 }
56 }
57
57
58 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
58 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
59
59
60 };
60 };
61
61
62 ui->tabWidget->setTabsClosable(true);
62 ui->tabWidget->setTabsClosable(true);
63
63
64 connect(addTabViewButton, &QToolButton::clicked, addTabView);
64 connect(addTabViewButton, &QToolButton::clicked, addTabView);
65 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
65 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
66
66
67 // Adds default tab
67 // Adds default tab
68 addTabView();
68 addTabView();
69 }
69 }
70
70
71 VisualizationWidget::~VisualizationWidget()
71 VisualizationWidget::~VisualizationWidget()
72 {
72 {
73 delete ui;
73 delete ui;
74 }
74 }
75
75
76 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
76 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
77 {
77 {
78 if (visitor) {
78 if (visitor) {
79 visitor->visitEnter(this);
79 visitor->visitEnter(this);
80
80
81 // Apply visitor for tab children
81 // Apply visitor for tab children
82 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
82 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
83 // Widgets different from tabs are not visited (no action)
83 // Widgets different from tabs are not visited (no action)
84 if (auto visualizationTabWidget
84 if (auto visualizationTabWidget
85 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
85 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
86 visualizationTabWidget->accept(visitor);
86 visualizationTabWidget->accept(visitor);
87 }
87 }
88 }
88 }
89
89
90 visitor->visitLeave(this);
90 visitor->visitLeave(this);
91 }
91 }
92 else {
92 else {
93 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
93 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
94 }
94 }
95 }
95 }
96
96
97 bool VisualizationWidget::canDrop(const Variable &variable) const
97 bool VisualizationWidget::canDrop(const Variable &variable) const
98 {
98 {
99 // The main widget can never accomodate a variable
99 // The main widget can never accomodate a variable
100 Q_UNUSED(variable);
100 Q_UNUSED(variable);
101 return false;
101 return false;
102 }
102 }
103
103
104 QString VisualizationWidget::name() const
104 QString VisualizationWidget::name() const
105 {
105 {
106 return QStringLiteral("MainView");
106 return QStringLiteral("MainView");
107 }
107 }
108
108
109 void VisualizationWidget::attachVariableMenu(QMenu *menu,
109 void VisualizationWidget::attachVariableMenu(
110 std::shared_ptr<Variable> variable) noexcept
110 QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept
111 {
111 {
112 // Generates the actions that make it possible to visualize the variable
112 // Menu is generated only if there is a single variable
113 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
113 if (variables.size() == 1) {
114 accept(&generateVariableMenuOperation);
114 if (auto variable = variables.first()) {
115 // Generates the actions that make it possible to visualize the variable
116 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
117 accept(&generateVariableMenuOperation);
118 }
119 else {
120 qCCritical(LOG_VisualizationWidget()) << tr(
121 "Can't generate the menu relative to the visualization: the variable is null");
122 }
123 }
124 else {
125 qCDebug(LOG_VisualizationWidget())
126 << tr("No generation of the menu related to the visualization: several variables are "
127 "selected");
128 }
115 }
129 }
General Comments 0
You need to be logged in to leave comments. Login now