##// END OF EJS Templates
Variable deletion (7)...
Alexandre Leroux -
r310:a99b8b976014
parent child
Show More
@@ -1,259 +1,265
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 <Variable/VariableController.h>
32 #include <Variable/VariableController.h>
33 #include <Visualization/VisualizationController.h>
33 #include <Visualization/VisualizationController.h>
34
34
35 #include <QAction>
35 #include <QAction>
36 #include <QDate>
36 #include <QDate>
37 #include <QDateTime>
37 #include <QDateTime>
38 #include <QDir>
38 #include <QDir>
39 #include <QFileDialog>
39 #include <QFileDialog>
40 #include <QToolBar>
40 #include <QToolBar>
41 #include <QToolButton>
41 #include <QToolButton>
42 #include <memory.h>
42 #include <memory.h>
43
43
44 //#include <omp.h>
44 //#include <omp.h>
45 //#include <network/filedownloader.h>
45 //#include <network/filedownloader.h>
46 //#include <qlopdatabase.h>
46 //#include <qlopdatabase.h>
47 //#include <qlopsettings.h>
47 //#include <qlopsettings.h>
48 //#include <qlopgui.h>
48 //#include <qlopgui.h>
49 //#include <spacedata.h>
49 //#include <spacedata.h>
50 //#include "qlopcore.h"
50 //#include "qlopcore.h"
51 //#include "qlopcodecmanager.h"
51 //#include "qlopcodecmanager.h"
52 //#include "cdfcodec.h"
52 //#include "cdfcodec.h"
53 //#include "amdatxtcodec.h"
53 //#include "amdatxtcodec.h"
54 //#include <qlopplotmanager.h>
54 //#include <qlopplotmanager.h>
55
55
56 #include "iostream"
56 #include "iostream"
57
57
58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
59
59
60 namespace {
60 namespace {
61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
63 const auto VIEWPLITTERINDEX = 2;
63 const auto VIEWPLITTERINDEX = 2;
64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
66 }
66 }
67
67
68 class MainWindow::MainWindowPrivate {
68 class MainWindow::MainWindowPrivate {
69 public:
69 public:
70 QSize m_LastOpenLeftInspectorSize;
70 QSize m_LastOpenLeftInspectorSize;
71 QSize m_LastOpenRightInspectorSize;
71 QSize m_LastOpenRightInspectorSize;
72 };
72 };
73
73
74 MainWindow::MainWindow(QWidget *parent)
74 MainWindow::MainWindow(QWidget *parent)
75 : QMainWindow{parent},
75 : QMainWindow{parent},
76 m_Ui{new Ui::MainWindow},
76 m_Ui{new Ui::MainWindow},
77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
78 {
78 {
79 m_Ui->setupUi(this);
79 m_Ui->setupUi(this);
80
80
81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
83
83
84
84
85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
86 auto openLeftInspectorAction = new QAction{QIcon{
86 auto openLeftInspectorAction = new QAction{QIcon{
87 ":/icones/previous.png",
87 ":/icones/previous.png",
88 },
88 },
89 tr("Show/hide the left inspector"), this};
89 tr("Show/hide the left inspector"), this};
90
90
91
91
92 auto spacerLeftTop = new QWidget{};
92 auto spacerLeftTop = new QWidget{};
93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
94
94
95 auto spacerLeftBottom = new QWidget{};
95 auto spacerLeftBottom = new QWidget{};
96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
97
97
98 leftSidePane->addWidget(spacerLeftTop);
98 leftSidePane->addWidget(spacerLeftTop);
99 leftSidePane->addAction(openLeftInspectorAction);
99 leftSidePane->addAction(openLeftInspectorAction);
100 leftSidePane->addWidget(spacerLeftBottom);
100 leftSidePane->addWidget(spacerLeftBottom);
101
101
102
102
103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
104 auto openRightInspectorAction = new QAction{QIcon{
104 auto openRightInspectorAction = new QAction{QIcon{
105 ":/icones/next.png",
105 ":/icones/next.png",
106 },
106 },
107 tr("Show/hide the right inspector"), this};
107 tr("Show/hide the right inspector"), this};
108
108
109 auto spacerRightTop = new QWidget{};
109 auto spacerRightTop = new QWidget{};
110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
111
111
112 auto spacerRightBottom = new QWidget{};
112 auto spacerRightBottom = new QWidget{};
113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
114
114
115 rightSidePane->addWidget(spacerRightTop);
115 rightSidePane->addWidget(spacerRightTop);
116 rightSidePane->addAction(openRightInspectorAction);
116 rightSidePane->addAction(openRightInspectorAction);
117 rightSidePane->addWidget(spacerRightBottom);
117 rightSidePane->addWidget(spacerRightBottom);
118
118
119 openLeftInspectorAction->setCheckable(true);
119 openLeftInspectorAction->setCheckable(true);
120 openRightInspectorAction->setCheckable(true);
120 openRightInspectorAction->setCheckable(true);
121
121
122 auto openInspector = [this](bool checked, bool right, auto action) {
122 auto openInspector = [this](bool checked, bool right, auto action) {
123
123
124 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
124 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
125
125
126 auto &lastInspectorSize
126 auto &lastInspectorSize
127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
128
128
129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
130 : m_Ui->leftMainInspectorWidget->size();
130 : m_Ui->leftMainInspectorWidget->size();
131
131
132 // Update of the last opened geometry
132 // Update of the last opened geometry
133 if (checked) {
133 if (checked) {
134 lastInspectorSize = nextInspectorSize;
134 lastInspectorSize = nextInspectorSize;
135 }
135 }
136
136
137 auto startSize = lastInspectorSize;
137 auto startSize = lastInspectorSize;
138 auto endSize = startSize;
138 auto endSize = startSize;
139 endSize.setWidth(0);
139 endSize.setWidth(0);
140
140
141 auto splitterInspectorIndex
141 auto splitterInspectorIndex
142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
143
143
144 auto currentSizes = m_Ui->splitter->sizes();
144 auto currentSizes = m_Ui->splitter->sizes();
145 if (checked) {
145 if (checked) {
146 // adjust sizes individually here, e.g.
146 // adjust sizes individually here, e.g.
147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
149 m_Ui->splitter->setSizes(currentSizes);
149 m_Ui->splitter->setSizes(currentSizes);
150 }
150 }
151 else {
151 else {
152 // adjust sizes individually here, e.g.
152 // adjust sizes individually here, e.g.
153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
155 m_Ui->splitter->setSizes(currentSizes);
155 m_Ui->splitter->setSizes(currentSizes);
156 }
156 }
157
157
158 };
158 };
159
159
160
160
161 connect(openLeftInspectorAction, &QAction::triggered,
161 connect(openLeftInspectorAction, &QAction::triggered,
162 [openInspector, openLeftInspectorAction](bool checked) {
162 [openInspector, openLeftInspectorAction](bool checked) {
163 openInspector(checked, false, openLeftInspectorAction);
163 openInspector(checked, false, openLeftInspectorAction);
164 });
164 });
165 connect(openRightInspectorAction, &QAction::triggered,
165 connect(openRightInspectorAction, &QAction::triggered,
166 [openInspector, openRightInspectorAction](bool checked) {
166 [openInspector, openRightInspectorAction](bool checked) {
167 openInspector(checked, true, openRightInspectorAction);
167 openInspector(checked, true, openRightInspectorAction);
168 });
168 });
169
169
170 this->menuBar()->addAction(tr("File"));
170 this->menuBar()->addAction(tr("File"));
171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
172
172
173 auto timeWidget = new TimeWidget{};
173 auto timeWidget = new TimeWidget{};
174 mainToolBar->addWidget(timeWidget);
174 mainToolBar->addWidget(timeWidget);
175
175
176 // Controllers / controllers connections
177 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
178 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
179
176 // Widgets / controllers connections
180 // Widgets / controllers connections
177
181
178 // DataSource
182 // DataSource
179 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
183 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
180 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
184 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
181
185
182 // Time
186 // Time
183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
187 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
184 SLOT(onTimeToUpdate(SqpDateTime)));
188 SLOT(onTimeToUpdate(SqpDateTime)));
185
189
186 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
190 // Visualization
187 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
191 connect(&sqpApp->visualizationController(),
192 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
193 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
188
194
189 // Widgets / widgets connections
195 // Widgets / widgets connections
190
196
191 // For the following connections, we use DirectConnection to allow each widget that can
197 // For the following connections, we use DirectConnection to allow each widget that can
192 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
198 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
193 // The order of connections is also important, since it determines the order in which each
199 // The order of connections is also important, since it determines the order in which each
194 // widget will attach its menu
200 // widget will attach its menu
195 connect(
201 connect(
196 m_Ui->variableInspectorWidget,
202 m_Ui->variableInspectorWidget,
197 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
203 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
198 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
204 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
199 Qt::DirectConnection);
205 Qt::DirectConnection);
200
206
201 /* QLopGUI::registerMenuBar(menuBar());
207 /* QLopGUI::registerMenuBar(menuBar());
202 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
208 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
203 this->m_progressWidget = new QWidget();
209 this->m_progressWidget = new QWidget();
204 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
210 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
205 this->m_progressWidget->setLayout(this->m_progressLayout);
211 this->m_progressWidget->setLayout(this->m_progressLayout);
206 this->m_progressWidget->setWindowModality(Qt::WindowModal);
212 this->m_progressWidget->setWindowModality(Qt::WindowModal);
207 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
213 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
208 for(int i=0;i<OMP_THREADS;i++)
214 for(int i=0;i<OMP_THREADS;i++)
209 {
215 {
210 this->m_progress.append(new QProgressBar(this->m_progressWidget));
216 this->m_progress.append(new QProgressBar(this->m_progressWidget));
211 this->m_progress.last()->setMinimum(0);
217 this->m_progress.last()->setMinimum(0);
212 this->m_progress.last()->setMaximum(100);
218 this->m_progress.last()->setMaximum(100);
213 this->m_progressLayout->addWidget(this->m_progress.last());
219 this->m_progressLayout->addWidget(this->m_progress.last());
214 this->m_progressWidget->hide();
220 this->m_progressWidget->hide();
215 this->m_progressThreadIds[i] = -1;
221 this->m_progressThreadIds[i] = -1;
216 }
222 }
217 this->m_progressWidget->setWindowTitle("Loading File");
223 this->m_progressWidget->setWindowTitle("Loading File");
218 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
224 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
219 << QLopCore::self()
225 << QLopCore::self()
220 << QLopPlotManager::self()
226 << QLopPlotManager::self()
221 << QLopCodecManager::self()
227 << QLopCodecManager::self()
222 << FileDownloader::self()
228 << FileDownloader::self()
223 << QLopDataBase::self()
229 << QLopDataBase::self()
224 << SpaceData::self();
230 << SpaceData::self();
225
231
226 CDFCodec::registerToManager();
232 CDFCodec::registerToManager();
227 AMDATXTCodec::registerToManager();
233 AMDATXTCodec::registerToManager();
228
234
229
235
230 for(int i=0;i<ServicesToLoad.count();i++)
236 for(int i=0;i<ServicesToLoad.count();i++)
231 {
237 {
232 qDebug()<<ServicesToLoad.at(i)->serviceName();
238 qDebug()<<ServicesToLoad.at(i)->serviceName();
233 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
239 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
234 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
240 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
235 if(wdgt)
241 if(wdgt)
236 {
242 {
237 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
243 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
238 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
244 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
239 }
245 }
240 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
246 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
241 }*/
247 }*/
242 }
248 }
243
249
244 MainWindow::~MainWindow()
250 MainWindow::~MainWindow()
245 {
251 {
246 }
252 }
247
253
248
254
249 void MainWindow::changeEvent(QEvent *e)
255 void MainWindow::changeEvent(QEvent *e)
250 {
256 {
251 QMainWindow::changeEvent(e);
257 QMainWindow::changeEvent(e);
252 switch (e->type()) {
258 switch (e->type()) {
253 case QEvent::LanguageChange:
259 case QEvent::LanguageChange:
254 m_Ui->retranslateUi(this);
260 m_Ui->retranslateUi(this);
255 break;
261 break;
256 default:
262 default:
257 break;
263 break;
258 }
264 }
259 }
265 }
@@ -1,79 +1,82
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 class IDataProvider;
11 class IDataProvider;
12 class QItemSelectionModel;
12 class QItemSelectionModel;
13 class TimeController;
13 class TimeController;
14 class Variable;
14 class Variable;
15 class VariableModel;
15 class VariableModel;
16
16
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
18
18
19 /**
19 /**
20 * @brief The VariableController class aims to handle the variables in SciQlop.
20 * @brief The VariableController class aims to handle the variables in SciQlop.
21 */
21 */
22 class VariableController : public QObject {
22 class VariableController : public QObject {
23 Q_OBJECT
23 Q_OBJECT
24 public:
24 public:
25 explicit VariableController(QObject *parent = 0);
25 explicit VariableController(QObject *parent = 0);
26 virtual ~VariableController();
26 virtual ~VariableController();
27
27
28 VariableModel *variableModel() noexcept;
28 VariableModel *variableModel() noexcept;
29 QItemSelectionModel *variableSelectionModel() noexcept;
29 QItemSelectionModel *variableSelectionModel() noexcept;
30
30
31 void setTimeController(TimeController *timeController) noexcept;
31 void setTimeController(TimeController *timeController) noexcept;
32
32
33 /**
33 /**
34 * Deletes from the controller the variable passed in parameter.
34 * Deletes from the controller the variable passed in parameter.
35 *
35 *
36 * Delete a variable includes:
36 * Delete a variable includes:
37 * - the deletion of the various references to the variable in SciQlop
37 * - the deletion of the model variable
38 * - the deletion of the model variable
38 * - the deletion of the provider associated with the variable
39 * - the deletion of the provider associated with the variable
39 * - removing the cache associated with the variable
40 * - removing the cache associated with the variable
40 *
41 *
41 * @param variable the variable to delete from the controller.
42 * @param variable the variable to delete from the controller.
42 */
43 */
43 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
44 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
44
45
45 /**
46 /**
46 * Deletes from the controller the variables passed in parameter.
47 * Deletes from the controller the variables passed in parameter.
47 * @param variables the variables to delete from the controller.
48 * @param variables the variables to delete from the controller.
48 * @sa deleteVariable()
49 * @sa deleteVariable()
49 */
50 */
50 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
51 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
51
52
52 signals:
53 signals:
54 /// Signal emitted when a variable is about to be deleted from the controller
55 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
53 /// Signal emitted when a variable has been created
56 /// Signal emitted when a variable has been created
54 void variableCreated(std::shared_ptr<Variable> variable);
57 void variableCreated(std::shared_ptr<Variable> variable);
55
58
56 public slots:
59 public slots:
57 /// Request the data loading of the variable whithin dateTime
60 /// Request the data loading of the variable whithin dateTime
58 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
61 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
59 /**
62 /**
60 * Creates a new variable and adds it to the model
63 * Creates a new variable and adds it to the model
61 * @param name the name of the new variable
64 * @param name the name of the new variable
62 * @param provider the data provider for the new variable
65 * @param provider the data provider for the new variable
63 */
66 */
64 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
67 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
65
68
66 /// Update the temporal parameters of every selected variable to dateTime
69 /// Update the temporal parameters of every selected variable to dateTime
67 void onDateTimeOnSelection(const SqpDateTime &dateTime);
70 void onDateTimeOnSelection(const SqpDateTime &dateTime);
68
71
69 void initialize();
72 void initialize();
70 void finalize();
73 void finalize();
71
74
72 private:
75 private:
73 void waitForFinish();
76 void waitForFinish();
74
77
75 class VariableControllerPrivate;
78 class VariableControllerPrivate;
76 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
79 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
77 };
80 };
78
81
79 #endif // SCIQLOP_VARIABLECONTROLLER_H
82 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,118 +1,122
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <QThread>
5 #include <QThread>
6 #include <Time/TimeController.h>
6 #include <Time/TimeController.h>
7 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
8 #include <Variable/VariableController.h>
8 #include <Variable/VariableController.h>
9 #include <Visualization/VisualizationController.h>
9 #include <Visualization/VisualizationController.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
12
12
13 class SqpApplication::SqpApplicationPrivate {
13 class SqpApplication::SqpApplicationPrivate {
14 public:
14 public:
15 SqpApplicationPrivate()
15 SqpApplicationPrivate()
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
17 m_TimeController{std::make_unique<TimeController>()},
17 m_TimeController{std::make_unique<TimeController>()},
18 m_VariableController{std::make_unique<VariableController>()},
18 m_VariableController{std::make_unique<VariableController>()},
19 m_VisualizationController{std::make_unique<VisualizationController>()}
19 m_VisualizationController{std::make_unique<VisualizationController>()}
20 {
20 {
21 // /////////////////////////////// //
21 // /////////////////////////////// //
22 // Connections between controllers //
22 // Connections between controllers //
23 // /////////////////////////////// //
23 // /////////////////////////////// //
24
24
25 // VariableController <-> DataSourceController
25 // VariableController <-> DataSourceController
26 connect(m_DataSourceController.get(),
26 connect(m_DataSourceController.get(),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
28 m_VariableController.get(),
28 m_VariableController.get(),
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
30
30
31 // VariableController <-> VisualizationController
31 // VariableController <-> VisualizationController
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
33 m_VisualizationController.get(),
33 m_VisualizationController.get(),
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
35 connect(m_VariableController.get(),
36 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
37 m_VisualizationController.get(),
38 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
35
39
36 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
40 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
37 m_VariableController->moveToThread(&m_VariableControllerThread);
41 m_VariableController->moveToThread(&m_VariableControllerThread);
38 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
42 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
39
43
40 // Additionnal init
44 // Additionnal init
41 m_VariableController->setTimeController(m_TimeController.get());
45 m_VariableController->setTimeController(m_TimeController.get());
42 }
46 }
43
47
44 virtual ~SqpApplicationPrivate()
48 virtual ~SqpApplicationPrivate()
45 {
49 {
46 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
50 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
47 m_DataSourceControllerThread.quit();
51 m_DataSourceControllerThread.quit();
48 m_DataSourceControllerThread.wait();
52 m_DataSourceControllerThread.wait();
49
53
50 m_VariableControllerThread.quit();
54 m_VariableControllerThread.quit();
51 m_VariableControllerThread.wait();
55 m_VariableControllerThread.wait();
52
56
53 m_VisualizationControllerThread.quit();
57 m_VisualizationControllerThread.quit();
54 m_VisualizationControllerThread.wait();
58 m_VisualizationControllerThread.wait();
55 }
59 }
56
60
57 std::unique_ptr<DataSourceController> m_DataSourceController;
61 std::unique_ptr<DataSourceController> m_DataSourceController;
58 std::unique_ptr<VariableController> m_VariableController;
62 std::unique_ptr<VariableController> m_VariableController;
59 std::unique_ptr<TimeController> m_TimeController;
63 std::unique_ptr<TimeController> m_TimeController;
60 std::unique_ptr<VisualizationController> m_VisualizationController;
64 std::unique_ptr<VisualizationController> m_VisualizationController;
61 QThread m_DataSourceControllerThread;
65 QThread m_DataSourceControllerThread;
62 QThread m_VariableControllerThread;
66 QThread m_VariableControllerThread;
63 QThread m_VisualizationControllerThread;
67 QThread m_VisualizationControllerThread;
64 };
68 };
65
69
66
70
67 SqpApplication::SqpApplication(int &argc, char **argv)
71 SqpApplication::SqpApplication(int &argc, char **argv)
68 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
72 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
69 {
73 {
70 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
74 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
71
75
72 connect(&impl->m_DataSourceControllerThread, &QThread::started,
76 connect(&impl->m_DataSourceControllerThread, &QThread::started,
73 impl->m_DataSourceController.get(), &DataSourceController::initialize);
77 impl->m_DataSourceController.get(), &DataSourceController::initialize);
74 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
78 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
75 impl->m_DataSourceController.get(), &DataSourceController::finalize);
79 impl->m_DataSourceController.get(), &DataSourceController::finalize);
76
80
77 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
81 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
78 &VariableController::initialize);
82 &VariableController::initialize);
79 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
83 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
80 &VariableController::finalize);
84 &VariableController::finalize);
81
85
82 connect(&impl->m_VisualizationControllerThread, &QThread::started,
86 connect(&impl->m_VisualizationControllerThread, &QThread::started,
83 impl->m_VisualizationController.get(), &VisualizationController::initialize);
87 impl->m_VisualizationController.get(), &VisualizationController::initialize);
84 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
88 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
85 impl->m_VisualizationController.get(), &VisualizationController::finalize);
89 impl->m_VisualizationController.get(), &VisualizationController::finalize);
86
90
87 impl->m_DataSourceControllerThread.start();
91 impl->m_DataSourceControllerThread.start();
88 impl->m_VariableControllerThread.start();
92 impl->m_VariableControllerThread.start();
89 impl->m_VisualizationControllerThread.start();
93 impl->m_VisualizationControllerThread.start();
90 }
94 }
91
95
92 SqpApplication::~SqpApplication()
96 SqpApplication::~SqpApplication()
93 {
97 {
94 }
98 }
95
99
96 void SqpApplication::initialize()
100 void SqpApplication::initialize()
97 {
101 {
98 }
102 }
99
103
100 DataSourceController &SqpApplication::dataSourceController() noexcept
104 DataSourceController &SqpApplication::dataSourceController() noexcept
101 {
105 {
102 return *impl->m_DataSourceController;
106 return *impl->m_DataSourceController;
103 }
107 }
104
108
105 TimeController &SqpApplication::timeController() noexcept
109 TimeController &SqpApplication::timeController() noexcept
106 {
110 {
107 return *impl->m_TimeController;
111 return *impl->m_TimeController;
108 }
112 }
109
113
110 VariableController &SqpApplication::variableController() noexcept
114 VariableController &SqpApplication::variableController() noexcept
111 {
115 {
112 return *impl->m_VariableController;
116 return *impl->m_VariableController;
113 }
117 }
114
118
115 VisualizationController &SqpApplication::visualizationController() noexcept
119 VisualizationController &SqpApplication::visualizationController() noexcept
116 {
120 {
117 return *impl->m_VisualizationController;
121 return *impl->m_VisualizationController;
118 }
122 }
@@ -1,89 +1,89
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableInspectorWidget.h>
2 #include <Variable/VariableInspectorWidget.h>
3 #include <Variable/VariableMenuHeaderWidget.h>
3 #include <Variable/VariableMenuHeaderWidget.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <ui_VariableInspectorWidget.h>
6 #include <ui_VariableInspectorWidget.h>
7
7
8 #include <QSortFilterProxyModel>
8 #include <QSortFilterProxyModel>
9 #include <QWidgetAction>
9 #include <QWidgetAction>
10
10
11 #include <SqpApplication.h>
11 #include <SqpApplication.h>
12
12
13 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
13 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
14
14
15 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
15 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
16 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
16 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
17 {
17 {
18 ui->setupUi(this);
18 ui->setupUi(this);
19
19
20 // Sets model for table
20 // Sets model for table
21 // auto sortFilterModel = new QSortFilterProxyModel{this};
21 // auto sortFilterModel = new QSortFilterProxyModel{this};
22 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
22 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
23
23
24 ui->tableView->setModel(sqpApp->variableController().variableModel());
24 ui->tableView->setModel(sqpApp->variableController().variableModel());
25 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
25 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
26
26
27 // Fixes column sizes
27 // Fixes column sizes
28 auto model = ui->tableView->model();
28 auto model = ui->tableView->model();
29 const auto count = model->columnCount();
29 const auto count = model->columnCount();
30 for (auto i = 0; i < count; ++i) {
30 for (auto i = 0; i < count; ++i) {
31 ui->tableView->setColumnWidth(
31 ui->tableView->setColumnWidth(
32 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
32 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
33 }
33 }
34
34
35 // Sets selection options
35 // Sets selection options
36 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
36 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
37 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
37 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
38
38
39 // Connection to show a menu when right clicking on the tree
39 // Connection to show a menu when right clicking on the tree
40 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
40 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
41 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
41 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
42 &VariableInspectorWidget::onTableMenuRequested);
42 &VariableInspectorWidget::onTableMenuRequested);
43 }
43 }
44
44
45 VariableInspectorWidget::~VariableInspectorWidget()
45 VariableInspectorWidget::~VariableInspectorWidget()
46 {
46 {
47 delete ui;
47 delete ui;
48 }
48 }
49
49
50 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
50 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
51 {
51 {
52 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
52 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
53
53
54 // Gets the model to retrieve the underlying selected variables
54 // Gets the model to retrieve the underlying selected variables
55 auto model = sqpApp->variableController().variableModel();
55 auto model = sqpApp->variableController().variableModel();
56 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
56 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
57 for (const auto &selectedRow : qAsConst(selectedRows)) {
57 for (const auto &selectedRow : qAsConst(selectedRows)) {
58 if (auto selectedVariable = model->variable(selectedRow.row())) {
58 if (auto selectedVariable = model->variable(selectedRow.row())) {
59 selectedVariables.push_back(selectedVariable);
59 selectedVariables.push_back(selectedVariable);
60 }
60 }
61 }
61 }
62
62
63 QMenu tableMenu{};
63 QMenu tableMenu{};
64
64
65 // Emits a signal so that potential receivers can populate the menu before displaying it
65 // Emits a signal so that potential receivers can populate the menu before displaying it
66 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
66 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
67
67
68 // Adds menu-specific actions
68 // Adds menu-specific actions
69 if (!selectedVariables.isEmpty()) {
69 if (!selectedVariables.isEmpty()) {
70 // 'Delete' action
70 // 'Delete' action
71 auto deleteFun = []() {
71 auto deleteFun = [&selectedVariables]() {
72 /// @todo ALX : call variable deletion
72 sqpApp->variableController().deleteVariables(selectedVariables);
73 };
73 };
74
74
75 tableMenu.addSeparator();
75 tableMenu.addSeparator();
76 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
76 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
77 }
77 }
78
78
79 if (!tableMenu.isEmpty()) {
79 if (!tableMenu.isEmpty()) {
80 // Generates menu header (inserted before first action)
80 // Generates menu header (inserted before first action)
81 auto firstAction = tableMenu.actions().first();
81 auto firstAction = tableMenu.actions().first();
82 auto headerAction = new QWidgetAction{&tableMenu};
82 auto headerAction = new QWidgetAction{&tableMenu};
83 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
83 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
84 tableMenu.insertAction(firstAction, headerAction);
84 tableMenu.insertAction(firstAction, headerAction);
85
85
86 // Displays menu
86 // Displays menu
87 tableMenu.exec(mapToGlobal(pos));
87 tableMenu.exec(mapToGlobal(pos));
88 }
88 }
89 }
89 }
General Comments 0
You need to be logged in to leave comments. Login now