##// END OF EJS Templates
Factorisation of the lambda connected to the side pane button
perrinel -
r130:8776db221f5e
parent child
Show More
@@ -1,276 +1,235
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 <TimeWidget/TimeWidget.h>
29 #include <TimeWidget/TimeWidget.h>
30
30
31 #include <QAction>
31 #include <QAction>
32 #include <QDate>
32 #include <QDate>
33 #include <QDateTime>
33 #include <QDateTime>
34 #include <QDir>
34 #include <QDir>
35 #include <QFileDialog>
35 #include <QFileDialog>
36 #include <QToolBar>
36 #include <QToolBar>
37 #include <QToolButton>
37 #include <memory.h>
38 #include <memory.h>
38
39
39 //#include <omp.h>
40 //#include <omp.h>
40 //#include <network/filedownloader.h>
41 //#include <network/filedownloader.h>
41 //#include <qlopdatabase.h>
42 //#include <qlopdatabase.h>
42 //#include <qlopsettings.h>
43 //#include <qlopsettings.h>
43 //#include <qlopgui.h>
44 //#include <qlopgui.h>
44 //#include <spacedata.h>
45 //#include <spacedata.h>
45 //#include "qlopcore.h"
46 //#include "qlopcore.h"
46 //#include "qlopcodecmanager.h"
47 //#include "qlopcodecmanager.h"
47 //#include "cdfcodec.h"
48 //#include "cdfcodec.h"
48 //#include "amdatxtcodec.h"
49 //#include "amdatxtcodec.h"
49 //#include <qlopplotmanager.h>
50 //#include <qlopplotmanager.h>
50
51
51 #include "iostream"
52 #include "iostream"
52
53
53 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
54 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
54
55
55 namespace {
56 namespace {
56 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
57 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
57 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
58 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
58 const auto VIEWPLITTERINDEX = 2;
59 const auto VIEWPLITTERINDEX = 2;
59 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
60 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
60 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
61 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
61 }
62 }
62
63
63 class MainWindow::MainWindowPrivate {
64 class MainWindow::MainWindowPrivate {
64 public:
65 public:
65 QSize m_LastOpenLeftInspectorSize;
66 QSize m_LastOpenLeftInspectorSize;
66 QSize m_LastOpenRightInspectorSize;
67 QSize m_LastOpenRightInspectorSize;
67 };
68 };
68
69
69 MainWindow::MainWindow(QWidget *parent)
70 MainWindow::MainWindow(QWidget *parent)
70 : QMainWindow{parent},
71 : QMainWindow{parent},
71 m_Ui{new Ui::MainWindow},
72 m_Ui{new Ui::MainWindow},
72 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
73 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
73 {
74 {
74 m_Ui->setupUi(this);
75 m_Ui->setupUi(this);
75
76
76 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
77 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
77 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
78 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
78
79
79
80
80 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
81 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
81 auto openLeftInspectorAction = new QAction(
82 auto openLeftInspectorAction = new QAction(
82 QIcon{
83 QIcon{
83 ":/icones/previous.png",
84 ":/icones/previous.png",
84 },
85 },
85 tr("Show/hide the left inspector"), this);
86 tr("Show/hide the left inspector"), this);
86
87
87
88
88 QWidget *spacerLeftTop = new QWidget();
89 QWidget *spacerLeftTop = new QWidget();
89 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
90 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
90
91
91 QWidget *spacerLeftBottom = new QWidget();
92 QWidget *spacerLeftBottom = new QWidget();
92 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93
94
94 leftSidePane->addWidget(spacerLeftTop);
95 leftSidePane->addWidget(spacerLeftTop);
95 leftSidePane->addAction(openLeftInspectorAction);
96 leftSidePane->addAction(openLeftInspectorAction);
96 leftSidePane->addWidget(spacerLeftBottom);
97 leftSidePane->addWidget(spacerLeftBottom);
97
98
98
99
99 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
100 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
100 auto openRightInspectorAction = new QAction(
101 auto openRightInspectorAction = new QAction(
101 QIcon{
102 QIcon{
102 ":/icones/next.png",
103 ":/icones/next.png",
103 },
104 },
104 tr("Show/hide the right inspector"), this);
105 tr("Show/hide the right inspector"), this);
105
106
106 QWidget *spacerRightTop = new QWidget();
107 QWidget *spacerRightTop = new QWidget();
107 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
108 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
108
109
109 QWidget *spacerRightBottom = new QWidget();
110 QWidget *spacerRightBottom = new QWidget();
110 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
111 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
111
112
112 rightSidePane->addWidget(spacerRightTop);
113 rightSidePane->addWidget(spacerRightTop);
113 rightSidePane->addAction(openRightInspectorAction);
114 rightSidePane->addAction(openRightInspectorAction);
114 rightSidePane->addWidget(spacerRightBottom);
115 rightSidePane->addWidget(spacerRightBottom);
115
116
116 openLeftInspectorAction->setCheckable(true);
117 openLeftInspectorAction->setCheckable(true);
117 openRightInspectorAction->setCheckable(true);
118 openRightInspectorAction->setCheckable(true);
118
119
120 auto openInspector = [this](bool checked, bool right, auto action) {
119
121
120 // NOTE: These lambda could be factorized. Be careful of theirs parameters
122 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
121 // Lambda that defines what's happened when clicking on the leftSidePaneInspector open button
122 auto openLeftInspector = [this, openLeftInspectorAction](bool checked) {
123
123
124 if (checked) {
124 auto &lastInspectorSize
125 openLeftInspectorAction->setIcon(QIcon{
125 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
126 ":/icones/next.png",
126
127 });
127 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
128 }
128 : m_Ui->leftMainInspectorWidget->size();
129 else {
130 openLeftInspectorAction->setIcon(QIcon{
131 ":/icones/previous.png",
132 });
133 }
134
129
135 // Update of the last opened geometry
130 // Update of the last opened geometry
136 if (checked) {
131 if (checked) {
137 impl->m_LastOpenLeftInspectorSize = m_Ui->leftMainInspectorWidget->size();
132 lastInspectorSize = nextInspectorSize;
138 }
133 }
139
134
140 auto startSize = impl->m_LastOpenLeftInspectorSize;
135 auto startSize = lastInspectorSize;
141 auto endSize = startSize;
136 auto endSize = startSize;
142 endSize.setWidth(0);
137 endSize.setWidth(0);
143
138
139 auto splitterInspectorIndex
140 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
141
144 auto currentSizes = m_Ui->splitter->sizes();
142 auto currentSizes = m_Ui->splitter->sizes();
145 if (checked) {
143 if (checked) {
146 // adjust sizes individually here, e.g.
144 // adjust sizes individually here, e.g.
147 currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX]
145 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
148 -= impl->m_LastOpenLeftInspectorSize.width();
146 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
149 currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenLeftInspectorSize.width();
150 m_Ui->splitter->setSizes(currentSizes);
147 m_Ui->splitter->setSizes(currentSizes);
151 }
148 }
152 else {
149 else {
153 // adjust sizes individually here, e.g.
150 // adjust sizes individually here, e.g.
154 currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX]
151 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
155 += impl->m_LastOpenLeftInspectorSize.width();
152 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
156 currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenLeftInspectorSize.width();
157 m_Ui->splitter->setSizes(currentSizes);
153 m_Ui->splitter->setSizes(currentSizes);
158 }
154 }
159
155
160 };
156 };
161
157
162 // Lambda that defines what's happened when clicking on the SidePaneInspector open button
163 auto openRightInspector = [this, openRightInspectorAction](bool checked) {
164
158
165 if (checked) {
159 connect(openLeftInspectorAction, &QAction::triggered,
166 openRightInspectorAction->setIcon(QIcon{
160 [openInspector, openLeftInspectorAction](bool checked) {
167 ":/icones/previous.png",
161 openInspector(checked, false, openLeftInspectorAction);
168 });
162 });
169 }
163 connect(openRightInspectorAction, &QAction::triggered,
170 else {
164 [openInspector, openRightInspectorAction](bool checked) {
171 openRightInspectorAction->setIcon(QIcon{
165 openInspector(checked, true, openRightInspectorAction);
172 ":/icones/next.png",
173 });
166 });
174 }
175
176
177 // Update of the last opened geometry
178 if (checked) {
179 impl->m_LastOpenRightInspectorSize = m_Ui->rightMainInspectorWidget->size();
180 }
181
182 auto startSize = impl->m_LastOpenRightInspectorSize;
183 auto endSize = startSize;
184 endSize.setWidth(0);
185
186 auto currentSizes = m_Ui->splitter->sizes();
187 if (checked) {
188 // adjust sizes individually here, e.g.
189 currentSizes[RIGHTMAININSPECTORWIDGETSPLITTERINDEX]
190 -= impl->m_LastOpenRightInspectorSize.width();
191 currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenRightInspectorSize.width();
192 m_Ui->splitter->setSizes(currentSizes);
193 }
194 else {
195 // adjust sizes individually here, e.g.
196 currentSizes[RIGHTMAININSPECTORWIDGETSPLITTERINDEX]
197 += impl->m_LastOpenRightInspectorSize.width();
198 currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenRightInspectorSize.width();
199 m_Ui->splitter->setSizes(currentSizes);
200 }
201
202 };
203
204
205 connect(openLeftInspectorAction, &QAction::triggered, openLeftInspector);
206 connect(openRightInspectorAction, &QAction::triggered, openRightInspector);
207
208
167
209 this->menuBar()->addAction(tr("File"));
168 this->menuBar()->addAction(tr("File"));
210 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
169 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
211
170
212 mainToolBar->addWidget(new TimeWidget());
171 mainToolBar->addWidget(new TimeWidget());
213
172
214 // Widgets / controllers connections
173 // Widgets / controllers connections
215 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
174 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
216 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
175 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
217
176
218 /* QLopGUI::registerMenuBar(menuBar());
177 /* QLopGUI::registerMenuBar(menuBar());
219 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
178 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
220 this->m_progressWidget = new QWidget();
179 this->m_progressWidget = new QWidget();
221 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
180 this->m_progressLayout = new QVBoxLayout(this->m_progressWidget);
222 this->m_progressWidget->setLayout(this->m_progressLayout);
181 this->m_progressWidget->setLayout(this->m_progressLayout);
223 this->m_progressWidget->setWindowModality(Qt::WindowModal);
182 this->m_progressWidget->setWindowModality(Qt::WindowModal);
224 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
183 m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
225 for(int i=0;i<OMP_THREADS;i++)
184 for(int i=0;i<OMP_THREADS;i++)
226 {
185 {
227 this->m_progress.append(new QProgressBar(this->m_progressWidget));
186 this->m_progress.append(new QProgressBar(this->m_progressWidget));
228 this->m_progress.last()->setMinimum(0);
187 this->m_progress.last()->setMinimum(0);
229 this->m_progress.last()->setMaximum(100);
188 this->m_progress.last()->setMaximum(100);
230 this->m_progressLayout->addWidget(this->m_progress.last());
189 this->m_progressLayout->addWidget(this->m_progress.last());
231 this->m_progressWidget->hide();
190 this->m_progressWidget->hide();
232 this->m_progressThreadIds[i] = -1;
191 this->m_progressThreadIds[i] = -1;
233 }
192 }
234 this->m_progressWidget->setWindowTitle("Loading File");
193 this->m_progressWidget->setWindowTitle("Loading File");
235 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
194 const QList<QLopService*>ServicesToLoad=QList<QLopService*>()
236 << QLopCore::self()
195 << QLopCore::self()
237 << QLopPlotManager::self()
196 << QLopPlotManager::self()
238 << QLopCodecManager::self()
197 << QLopCodecManager::self()
239 << FileDownloader::self()
198 << FileDownloader::self()
240 << QLopDataBase::self()
199 << QLopDataBase::self()
241 << SpaceData::self();
200 << SpaceData::self();
242
201
243 CDFCodec::registerToManager();
202 CDFCodec::registerToManager();
244 AMDATXTCodec::registerToManager();
203 AMDATXTCodec::registerToManager();
245
204
246
205
247 for(int i=0;i<ServicesToLoad.count();i++)
206 for(int i=0;i<ServicesToLoad.count();i++)
248 {
207 {
249 qDebug()<<ServicesToLoad.at(i)->serviceName();
208 qDebug()<<ServicesToLoad.at(i)->serviceName();
250 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
209 ServicesToLoad.at(i)->initialize(); //must be called before getGUI
251 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
210 QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI();
252 if(wdgt)
211 if(wdgt)
253 {
212 {
254 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
213 wdgt->setAllowedAreas(Qt::AllDockWidgetAreas);
255 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
214 this->addDockWidget(Qt::TopDockWidgetArea,wdgt);
256 }
215 }
257 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
216 PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i));
258 }*/
217 }*/
259 }
218 }
260
219
261 MainWindow::~MainWindow()
220 MainWindow::~MainWindow()
262 {
221 {
263 }
222 }
264
223
265
224
266 void MainWindow::changeEvent(QEvent *e)
225 void MainWindow::changeEvent(QEvent *e)
267 {
226 {
268 QMainWindow::changeEvent(e);
227 QMainWindow::changeEvent(e);
269 switch (e->type()) {
228 switch (e->type()) {
270 case QEvent::LanguageChange:
229 case QEvent::LanguageChange:
271 m_Ui->retranslateUi(this);
230 m_Ui->retranslateUi(this);
272 break;
231 break;
273 default:
232 default:
274 break;
233 break;
275 }
234 }
276 }
235 }
General Comments 0
You need to be logged in to leave comments. Login now