##// END OF EJS Templates
Temporal parameters of the selected variables can be updated using the...
perrinel -
r304:08349e12a7ef
parent child
Show More
@@ -1,256 +1,261
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SciQLop Software
3 3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "MainWindow.h"
23 23 #include "ui_MainWindow.h"
24 24
25 25 #include <DataSource/DataSourceController.h>
26 26 #include <DataSource/DataSourceWidget.h>
27 27 #include <SidePane/SqpSidePane.h>
28 28 #include <SqpApplication.h>
29 29 #include <Time/TimeController.h>
30 30 #include <TimeWidget/TimeWidget.h>
31 31 #include <Variable/Variable.h>
32 #include <Variable/VariableController.h>
32 33 #include <Visualization/VisualizationController.h>
33 34
34 35 #include <QAction>
35 36 #include <QDate>
36 37 #include <QDateTime>
37 38 #include <QDir>
38 39 #include <QFileDialog>
39 40 #include <QToolBar>
40 41 #include <QToolButton>
41 42 #include <memory.h>
42 43
43 44 //#include <omp.h>
44 45 //#include <network/filedownloader.h>
45 46 //#include <qlopdatabase.h>
46 47 //#include <qlopsettings.h>
47 48 //#include <qlopgui.h>
48 49 //#include <spacedata.h>
49 50 //#include "qlopcore.h"
50 51 //#include "qlopcodecmanager.h"
51 52 //#include "cdfcodec.h"
52 53 //#include "amdatxtcodec.h"
53 54 //#include <qlopplotmanager.h>
54 55
55 56 #include "iostream"
56 57
57 58 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
58 59
59 60 namespace {
60 61 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
61 62 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
62 63 const auto VIEWPLITTERINDEX = 2;
63 64 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
64 65 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
65 66 }
66 67
67 68 class MainWindow::MainWindowPrivate {
68 69 public:
69 70 QSize m_LastOpenLeftInspectorSize;
70 71 QSize m_LastOpenRightInspectorSize;
71 72 };
72 73
73 74 MainWindow::MainWindow(QWidget *parent)
74 75 : QMainWindow{parent},
75 76 m_Ui{new Ui::MainWindow},
76 77 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
77 78 {
78 79 m_Ui->setupUi(this);
79 80
80 81 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
81 82 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
82 83
83 84
84 85 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
85 86 auto openLeftInspectorAction = new QAction{QIcon{
86 87 ":/icones/previous.png",
87 88 },
88 89 tr("Show/hide the left inspector"), this};
89 90
90 91
91 92 auto spacerLeftTop = new QWidget{};
92 93 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93 94
94 95 auto spacerLeftBottom = new QWidget{};
95 96 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
96 97
97 98 leftSidePane->addWidget(spacerLeftTop);
98 99 leftSidePane->addAction(openLeftInspectorAction);
99 100 leftSidePane->addWidget(spacerLeftBottom);
100 101
101 102
102 103 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
103 104 auto openRightInspectorAction = new QAction{QIcon{
104 105 ":/icones/next.png",
105 106 },
106 107 tr("Show/hide the right inspector"), this};
107 108
108 109 auto spacerRightTop = new QWidget{};
109 110 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
110 111
111 112 auto spacerRightBottom = new QWidget{};
112 113 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113 114
114 115 rightSidePane->addWidget(spacerRightTop);
115 116 rightSidePane->addAction(openRightInspectorAction);
116 117 rightSidePane->addWidget(spacerRightBottom);
117 118
118 119 openLeftInspectorAction->setCheckable(true);
119 120 openRightInspectorAction->setCheckable(true);
120 121
121 122 auto openInspector = [this](bool checked, bool right, auto action) {
122 123
123 124 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
124 125
125 126 auto &lastInspectorSize
126 127 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
127 128
128 129 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
129 130 : m_Ui->leftMainInspectorWidget->size();
130 131
131 132 // Update of the last opened geometry
132 133 if (checked) {
133 134 lastInspectorSize = nextInspectorSize;
134 135 }
135 136
136 137 auto startSize = lastInspectorSize;
137 138 auto endSize = startSize;
138 139 endSize.setWidth(0);
139 140
140 141 auto splitterInspectorIndex
141 142 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
142 143
143 144 auto currentSizes = m_Ui->splitter->sizes();
144 145 if (checked) {
145 146 // adjust sizes individually here, e.g.
146 147 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
147 148 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
148 149 m_Ui->splitter->setSizes(currentSizes);
149 150 }
150 151 else {
151 152 // adjust sizes individually here, e.g.
152 153 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
153 154 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
154 155 m_Ui->splitter->setSizes(currentSizes);
155 156 }
156 157
157 158 };
158 159
159 160
160 161 connect(openLeftInspectorAction, &QAction::triggered,
161 162 [openInspector, openLeftInspectorAction](bool checked) {
162 163 openInspector(checked, false, openLeftInspectorAction);
163 164 });
164 165 connect(openRightInspectorAction, &QAction::triggered,
165 166 [openInspector, openRightInspectorAction](bool checked) {
166 167 openInspector(checked, true, openRightInspectorAction);
167 168 });
168 169
169 170 this->menuBar()->addAction(tr("File"));
170 171 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
171 172
172 173 auto timeWidget = new TimeWidget{};
173 174 mainToolBar->addWidget(timeWidget);
174 175
175 176 // Widgets / controllers connections
176 177
177 178 // DataSource
178 179 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
179 180 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
180 181
181 182 // Time
182 183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
183 184 SLOT(onTimeToUpdate(SqpDateTime)));
184 185
186 qRegisterMetaType<SqpDateTime>();
187 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
188 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
189
185 190 // Widgets / widgets connections
186 191 qRegisterMetaType<std::shared_ptr<Variable> >();
187 192
188 193 // For the following connections, we use DirectConnection to allow each widget that can
189 194 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
190 195 // The order of connections is also important, since it determines the order in which each
191 196 // widget will attach its menu
192 197 connect(
193 198 m_Ui->variableInspectorWidget,
194 199 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
195 200 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
196 201 Qt::DirectConnection);
197 202
198 203 /* QLopGUI::registerMenuBar(menuBar());
199 204 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
200 205 this->m_progressWidget = new QWidget();
201 206 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
202 207 this->m_progressWidget->setLayout(this->m_progressLayout);
203 208 this->m_progressWidget->setWindowModality(Qt::WindowModal);
204 209 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
205 210 for(int i=0;i<OMP_THREADS;i++)
206 211 {
207 212 this->m_progress.append(new QProgressBar(this->m_progressWidget));
208 213 this->m_progress.last()->setMinimum(0);
209 214 this->m_progress.last()->setMaximum(100);
210 215 this->m_progressLayout->addWidget(this->m_progress.last());
211 216 this->m_progressWidget->hide();
212 217 this->m_progressThreadIds[i] = -1;
213 218 }
214 219 this->m_progressWidget->setWindowTitle("Loading File");
215 220 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
216 221 << QLopCore::self()
217 222 << QLopPlotManager::self()
218 223 << QLopCodecManager::self()
219 224 << FileDownloader::self()
220 225 << QLopDataBase::self()
221 226 << SpaceData::self();
222 227
223 228 CDFCodec::registerToManager();
224 229 AMDATXTCodec::registerToManager();
225 230
226 231
227 232 for(int i=0;i<ServicesToLoad.count();i++)
228 233 {
229 234 qDebug()<<ServicesToLoad.at(i)->serviceName();
230 235 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
231 236 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
232 237 if(wdgt)
233 238 {
234 239 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
235 240 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
236 241 }
237 242 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
238 243 }*/
239 244 }
240 245
241 246 MainWindow::~MainWindow()
242 247 {
243 248 }
244 249
245 250
246 251 void MainWindow::changeEvent(QEvent *e)
247 252 {
248 253 QMainWindow::changeEvent(e);
249 254 switch (e->type()) {
250 255 case QEvent::LanguageChange:
251 256 m_Ui->retranslateUi(this);
252 257 break;
253 258 default:
254 259 break;
255 260 }
256 261 }
@@ -1,56 +1,55
1 1 #ifndef SCIQLOP_VARIABLE_H
2 2 #define SCIQLOP_VARIABLE_H
3 3
4 4 #include <Data/SqpDateTime.h>
5 5
6 6
7 7 #include <QLoggingCategory>
8 8 #include <QObject>
9 9
10 10 #include <Common/spimpl.h>
11 11
12 12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13 13
14 14 class IDataSeries;
15 15 class QString;
16 16
17 17 /**
18 18 * @brief The Variable class represents a variable in SciQlop.
19 19 */
20 20 class Variable : public QObject {
21 21
22 22 Q_OBJECT
23 23
24 24 public:
25 25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
26 26 const SqpDateTime &dateTime);
27 27
28 28 QString name() const noexcept;
29 29 QString mission() const noexcept;
30 30 QString unit() const noexcept;
31 31 SqpDateTime dateTime() const noexcept;
32 32 void setDateTime(const SqpDateTime &dateTime) noexcept;
33 33
34 34 /// @return the data of the variable, nullptr if there is no data
35 35 IDataSeries *dataSeries() const noexcept;
36 36
37 37 bool contains(const SqpDateTime &dateTime);
38 38 bool intersect(const SqpDateTime &dateTime);
39 39 void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
40 40
41 41 public slots:
42 42 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
43 43
44 44 signals:
45 45 void updated();
46 46
47
48 47 private:
49 48 class VariablePrivate;
50 49 spimpl::unique_impl_ptr<VariablePrivate> impl;
51 50 };
52 51
53 52 // Required for using shared_ptr in signals/slots
54 53 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
55 54
56 55 #endif // SCIQLOP_VARIABLE_H
@@ -1,57 +1,61
1 1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 2 #define SCIQLOP_VARIABLECONTROLLER_H
3 3
4 4 #include <Data/SqpDateTime.h>
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QObject>
8 8
9 9 #include <Common/spimpl.h>
10 10
11
12 11 class IDataProvider;
12 class QItemSelectionModel;
13 13 class TimeController;
14 14 class Variable;
15 15 class VariableModel;
16 16
17 17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
18 18
19 19 /**
20 20 * @brief The VariableController class aims to handle the variables in SciQlop.
21 21 */
22 22 class VariableController : public QObject {
23 23 Q_OBJECT
24 24 public:
25 25 explicit VariableController(QObject *parent = 0);
26 26 virtual ~VariableController();
27 27
28 28 VariableModel *variableModel() noexcept;
29 QItemSelectionModel *variableSelectionModel() noexcept;
29 30
30 31 void setTimeController(TimeController *timeController) noexcept;
31 32
32 33
33 34 signals:
34 35 /// Signal emitted when a variable has been created
35 36 void variableCreated(std::shared_ptr<Variable> variable);
36 37
37 38 public slots:
38 39 /// Request the data loading of the variable whithin dateTime
39 40 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
40 41 /**
41 42 * Creates a new variable and adds it to the model
42 43 * @param name the name of the new variable
43 44 * @param provider the data provider for the new variable
44 45 */
45 46 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
46 47
48 /// Update the temporal parameters of every selected variable to dateTime
49 void onDateTimeOnSelection(const SqpDateTime &dateTime);
50
47 51 void initialize();
48 52 void finalize();
49 53
50 54 private:
51 55 void waitForFinish();
52 56
53 57 class VariableControllerPrivate;
54 58 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
55 59 };
56 60
57 61 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,157 +1,176
1 1 #include <Variable/Variable.h>
2 2 #include <Variable/VariableCacheController.h>
3 3 #include <Variable/VariableController.h>
4 4 #include <Variable/VariableModel.h>
5 5
6 6 #include <Data/DataProviderParameters.h>
7 7 #include <Data/IDataProvider.h>
8 8 #include <Data/IDataSeries.h>
9 9 #include <Time/TimeController.h>
10 10
11 11 #include <QDateTime>
12 12 #include <QMutex>
13 13 #include <QThread>
14 #include <QtCore/QItemSelectionModel>
14 15
15 16 #include <unordered_map>
16 17
17 18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 19
19 20 namespace {
20 21
21 22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 23 /// will be deleted when the timerange is recovered from SciQlop
23 24 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 25 const SqpDateTime &dateTime) noexcept
25 26 {
26 27 auto parameters = DataProviderParameters{dateTime};
27 28
28 29 return provider.retrieveData(parameters);
29 30 }
30 31
31 32 } // namespace
32 33
33 34 struct VariableController::VariableControllerPrivate {
34 35 explicit VariableControllerPrivate(VariableController *parent)
35 36 : m_WorkingMutex{},
36 37 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
37 39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
38 40 {
39 41 }
40 42
41 43 QMutex m_WorkingMutex;
42 44 /// Variable model. The VariableController has the ownership
43 45 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
44 47
45 48
46 49 TimeController *m_TimeController{nullptr};
47 50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
48 51
49 52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
50 53 m_VariableToProviderMap;
51 54 };
52 55
53 56 VariableController::VariableController(QObject *parent)
54 57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
55 58 {
56 59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
57 60 << QThread::currentThread();
58 61 }
59 62
60 63 VariableController::~VariableController()
61 64 {
62 65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
63 66 << QThread::currentThread();
64 67 this->waitForFinish();
65 68 }
66 69
67 70 VariableModel *VariableController::variableModel() noexcept
68 71 {
69 72 return impl->m_VariableModel;
70 73 }
71 74
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
77 return impl->m_VariableSelectionModel;
78 }
79
72 80 void VariableController::setTimeController(TimeController *timeController) noexcept
73 81 {
74 82 impl->m_TimeController = timeController;
75 83 }
76 84
77 85 void VariableController::createVariable(const QString &name,
78 86 std::shared_ptr<IDataProvider> provider) noexcept
79 87 {
80 88
81 89 if (!impl->m_TimeController) {
82 90 qCCritical(LOG_VariableController())
83 91 << tr("Impossible to create variable: The time controller is null");
84 92 return;
85 93 }
86 94
87 95
88 96 /// @todo : for the moment :
89 97 /// - the provider is only used to retrieve data from the variable for its initialization, but
90 98 /// it will be retained later
91 99 /// - default data are generated for the variable, without taking into account the timerange set
92 100 /// in sciqlop
93 101 auto dateTime = impl->m_TimeController->dateTime();
94 102 if (auto newVariable = impl->m_VariableModel->createVariable(
95 103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
96 104
97 105 // store the provider
98 106 impl->m_VariableToProviderMap[newVariable] = provider;
99 107 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
100 108 qRegisterMetaType<SqpDateTime>();
101 109 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
102 110 &Variable::onAddDataSeries);
103 111
104 112
105 113 // store in cache
106 114 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
107 115
108 116 // notify the creation
109 117 emit variableCreated(newVariable);
110 118 }
111 119 }
112 120
121 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
122 {
123 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
124
125 for (const auto &selectedRow : qAsConst(selectedRows)) {
126 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
127 selectedVariable->setDateTime(dateTime);
128 }
129 }
130 }
131
113 132
114 133 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
115 134 const SqpDateTime &dateTime)
116 135 {
117 136 // we want to load data of the variable for the dateTime.
118 137 // First we check if the cache contains some of them.
119 138 // For the other, we ask the provider to give them.
120 139 if (variable) {
121 140
122 141 auto dateTimeListNotInCache
123 142 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
124 143
125 144 if (!dateTimeListNotInCache.empty()) {
126 145 // Ask the provider for each data on the dateTimeListNotInCache
127 146 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
128 147 std::move(dateTimeListNotInCache));
129 148 // store in cache
130 149 impl->m_VariableCacheController->addDateTime(variable, dateTime);
131 150 }
132 151 else {
133 152 emit variable->updated();
134 153 }
135 154 }
136 155 else {
137 156 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
138 157 }
139 158 }
140 159
141 160
142 161 void VariableController::initialize()
143 162 {
144 163 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
145 164 impl->m_WorkingMutex.lock();
146 165 qCDebug(LOG_VariableController()) << tr("VariableController init END");
147 166 }
148 167
149 168 void VariableController::finalize()
150 169 {
151 170 impl->m_WorkingMutex.unlock();
152 171 }
153 172
154 173 void VariableController::waitForFinish()
155 174 {
156 175 QMutexLocker locker{&impl->m_WorkingMutex};
157 176 }
@@ -1,38 +1,48
1 1 #include "TimeWidget/TimeWidget.h"
2 2 #include "ui_TimeWidget.h"
3 3
4 4 #include <SqpApplication.h>
5 5 #include <Time/TimeController.h>
6 6
7 7 TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget}
8 8 {
9 9 ui->setupUi(this);
10 10
11 11 ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton));
12 12
13 13 // Connection
14 14 connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
15 15 &TimeWidget::onTimeUpdateRequested);
16 16
17 17 connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
18 18 &TimeWidget::onTimeUpdateRequested);
19 19
20 20
21 21 connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(),
22 22 &TimeController::onTimeNotify);
23
24 // Initialisation
25 ui->startDateTimeEdit->setDateTime(
26 QDateTime::currentDateTime().addSecs(-3600)); // one hour berefore
27 ui->endDateTimeEdit->setDateTime(QDateTime::currentDateTime());
28
29 auto dateTime
30 = SqpDateTime{QDateTime::currentDateTime().addSecs(-3600).toMSecsSinceEpoch() / 1000.0,
31 QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0};
32 sqpApp->timeController().onTimeToUpdate(dateTime);
23 33 }
24 34
25 35
26 36 TimeWidget::~TimeWidget()
27 37 {
28 38 delete ui;
29 39 }
30 40
31 41 void TimeWidget::onTimeUpdateRequested()
32 42 {
33 43 auto dateTime = SqpDateTime{
34 44 static_cast<double>(ui->startDateTimeEdit->dateTime().toMSecsSinceEpoch() / 1000.),
35 45 static_cast<double>(ui->endDateTimeEdit->dateTime().toMSecsSinceEpoch()) / 1000.};
36 46
37 47 emit timeUpdated(std::move(dateTime));
38 48 }
@@ -1,88 +1,89
1 1 #include <Variable/VariableController.h>
2 2 #include <Variable/VariableInspectorWidget.h>
3 3 #include <Variable/VariableMenuHeaderWidget.h>
4 4 #include <Variable/VariableModel.h>
5 5
6 6 #include <ui_VariableInspectorWidget.h>
7 7
8 8 #include <QSortFilterProxyModel>
9 9 #include <QWidgetAction>
10 10
11 11 #include <SqpApplication.h>
12 12
13 13 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
14 14
15 15 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
16 16 : QWidget{parent}, ui{new Ui::VariableInspectorWidget}
17 17 {
18 18 ui->setupUi(this);
19 19
20 20 // Sets model for table
21 auto sortFilterModel = new QSortFilterProxyModel{this};
22 sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
21 // auto sortFilterModel = new QSortFilterProxyModel{this};
22 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
23 23
24 ui->tableView->setModel(sortFilterModel);
24 ui->tableView->setModel(sqpApp->variableController().variableModel());
25 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
25 26
26 27 // Fixes column sizes
27 28 auto model = ui->tableView->model();
28 29 const auto count = model->columnCount();
29 30 for (auto i = 0; i < count; ++i) {
30 31 ui->tableView->setColumnWidth(
31 32 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
32 33 }
33 34
34 35 // Sets selection options
35 36 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
36 37 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
37 38
38 39 // Connection to show a menu when right clicking on the tree
39 40 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
40 41 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
41 42 &VariableInspectorWidget::onTableMenuRequested);
42 43 }
43 44
44 45 VariableInspectorWidget::~VariableInspectorWidget()
45 46 {
46 47 delete ui;
47 48 }
48 49
49 50 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
50 51 {
51 52 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
52 53
53 54 // Gets the model to retrieve the underlying selected variables
54 55 auto model = sqpApp->variableController().variableModel();
55 56 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
56 57 for (const auto &selectedRow : qAsConst(selectedRows)) {
57 58 if (auto selectedVariable = model->variable(selectedRow.row())) {
58 59 selectedVariables.push_back(selectedVariable);
59 60 }
60 61 }
61 62
62 63 QMenu tableMenu{};
63 64
64 65 // Emits a signal so that potential receivers can populate the menu before displaying it
65 66 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
66 67
67 68 // Adds menu-specific actions
68 69 if (!selectedVariables.isEmpty()) {
69 70 // 'Delete' action
70 71 auto deleteFun = []() {
71 72 /// @todo ALX : call variable deletion
72 73 };
73 74
74 75 tableMenu.addSeparator();
75 76 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
76 77 }
77 78
78 79 if (!tableMenu.isEmpty()) {
79 80 // Generates menu header (inserted before first action)
80 81 auto firstAction = tableMenu.actions().first();
81 82 auto headerAction = new QWidgetAction{&tableMenu};
82 83 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
83 84 tableMenu.insertAction(firstAction, headerAction);
84 85
85 86 // Displays menu
86 87 tableMenu.exec(mapToGlobal(pos));
87 88 }
88 89 }
General Comments 0
You need to be logged in to leave comments. Login now