##// END OF EJS Templates
Add a button in the application toolbar to open the catalogues
trabillard -
r1094:1d52e9600333
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
@@ -1,353 +1,364
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 #include <Catalogue/CatalogueExplorer.h>
25 26 #include <DataSource/DataSourceController.h>
26 27 #include <DataSource/DataSourceWidget.h>
27 28 #include <Settings/SqpSettingsDialog.h>
28 29 #include <Settings/SqpSettingsGeneralWidget.h>
29 30 #include <SidePane/SqpSidePane.h>
30 31 #include <SqpApplication.h>
31 32 #include <Time/TimeController.h>
32 33 #include <TimeWidget/TimeWidget.h>
33 34 #include <Variable/Variable.h>
34 35 #include <Variable/VariableController.h>
35 36 #include <Visualization/VisualizationController.h>
36 37
37 38 #include <QAction>
38 39 #include <QDate>
39 40 #include <QDir>
40 41 #include <QFileDialog>
41 42 #include <QToolBar>
42 43 #include <QToolButton>
43 44 #include <memory.h>
44 45
45 46 #include "iostream"
46 47
47 48 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
48 49
49 50 namespace {
50 51 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
51 52 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
52 53 const auto VIEWPLITTERINDEX = 2;
53 54 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
54 55 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
55 56 }
56 57
57 58 class MainWindow::MainWindowPrivate {
58 59 public:
59 60 explicit MainWindowPrivate(MainWindow *mainWindow)
60 61 : m_LastOpenLeftInspectorSize{},
61 62 m_LastOpenRightInspectorSize{},
62 63 m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}},
63 m_SettingsDialog{new SqpSettingsDialog{mainWindow}}
64 m_SettingsDialog{new SqpSettingsDialog{mainWindow}},
65 m_CatalogExplorer{new CatalogueExplorer{mainWindow}}
64 66 {
65 67 }
66 68
67 69 QSize m_LastOpenLeftInspectorSize;
68 70 QSize m_LastOpenRightInspectorSize;
69 71 /// General settings widget. MainWindow has the ownership
70 72 SqpSettingsGeneralWidget *m_GeneralSettingsWidget;
71 73 /// Settings dialog. MainWindow has the ownership
72 74 SqpSettingsDialog *m_SettingsDialog;
75 /// Catalogue dialog. MainWindow has the ownership
76 CatalogueExplorer *m_CatalogExplorer;
73 77 };
74 78
75 79 MainWindow::MainWindow(QWidget *parent)
76 80 : QMainWindow{parent},
77 81 m_Ui{new Ui::MainWindow},
78 82 impl{spimpl::make_unique_impl<MainWindowPrivate>(this)}
79 83 {
80 84 m_Ui->setupUi(this);
81 85
82 86 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
83 87 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
84 88
85 89
86 90 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
87 91 auto openLeftInspectorAction = new QAction{QIcon{
88 92 ":/icones/previous.png",
89 93 },
90 94 tr("Show/hide the left inspector"), this};
91 95
92 96
93 97 auto spacerLeftTop = new QWidget{};
94 98 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
95 99
96 100 auto spacerLeftBottom = new QWidget{};
97 101 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
98 102
99 103 leftSidePane->addWidget(spacerLeftTop);
100 104 leftSidePane->addAction(openLeftInspectorAction);
101 105 leftSidePane->addWidget(spacerLeftBottom);
102 106
103 107
104 108 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
105 109 auto openRightInspectorAction = new QAction{QIcon{
106 110 ":/icones/next.png",
107 111 },
108 112 tr("Show/hide the right inspector"), this};
109 113
110 114 auto spacerRightTop = new QWidget{};
111 115 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112 116
113 117 auto spacerRightBottom = new QWidget{};
114 118 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
115 119
116 120 rightSidePane->addWidget(spacerRightTop);
117 121 rightSidePane->addAction(openRightInspectorAction);
118 122 rightSidePane->addWidget(spacerRightBottom);
119 123
120 124 openLeftInspectorAction->setCheckable(true);
121 125 openRightInspectorAction->setCheckable(true);
122 126
123 127 auto openInspector = [this](bool checked, bool right, auto action) {
124 128
125 129 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
126 130
127 131 auto &lastInspectorSize
128 132 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
129 133
130 134 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
131 135 : m_Ui->leftMainInspectorWidget->size();
132 136
133 137 // Update of the last opened geometry
134 138 if (checked) {
135 139 lastInspectorSize = nextInspectorSize;
136 140 }
137 141
138 142 auto startSize = lastInspectorSize;
139 143 auto endSize = startSize;
140 144 endSize.setWidth(0);
141 145
142 146 auto splitterInspectorIndex
143 147 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
144 148
145 149 auto currentSizes = m_Ui->splitter->sizes();
146 150 if (checked) {
147 151 // adjust sizes individually here, e.g.
148 152 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
149 153 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
150 154 m_Ui->splitter->setSizes(currentSizes);
151 155 }
152 156 else {
153 157 // adjust sizes individually here, e.g.
154 158 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
155 159 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
156 160 m_Ui->splitter->setSizes(currentSizes);
157 161 }
158 162
159 163 };
160 164
161 165
162 166 connect(openLeftInspectorAction, &QAction::triggered,
163 167 [openInspector, openLeftInspectorAction](bool checked) {
164 168 openInspector(checked, false, openLeftInspectorAction);
165 169 });
166 170 connect(openRightInspectorAction, &QAction::triggered,
167 171 [openInspector, openRightInspectorAction](bool checked) {
168 172 openInspector(checked, true, openRightInspectorAction);
169 173 });
170 174
171 175 // //////////////// //
172 176 // Menu and Toolbar //
173 177 // //////////////// //
174 178 this->menuBar()->addAction(tr("File"));
175 179 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
176 180 toolsMenu->addAction(tr("Settings..."), [this]() {
177 181 // Loads settings
178 182 impl->m_SettingsDialog->loadSettings();
179 183
180 184 // Open settings dialog and save settings if the dialog is accepted
181 185 if (impl->m_SettingsDialog->exec() == QDialog::Accepted) {
182 186 impl->m_SettingsDialog->saveSettings();
183 187 }
184 188
185 189 });
186 190
187 191 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
188 192
189 193 auto timeWidget = new TimeWidget{};
190 194 mainToolBar->addWidget(timeWidget);
191 195
196 // Interaction modes
192 197 auto actionPointerMode = new QAction{QIcon(":/icones/pointer.png"), "Move", this};
193 198 actionPointerMode->setCheckable(true);
194 199 actionPointerMode->setChecked(sqpApp->plotsInteractionMode()
195 200 == SqpApplication::PlotsInteractionMode::None);
196 201 connect(actionPointerMode, &QAction::triggered,
197 202 []() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::None); });
198 203
199 204 auto actionZoomMode = new QAction{QIcon(":/icones/zoom.png"), "Zoom", this};
200 205 actionZoomMode->setCheckable(true);
201 206 actionZoomMode->setChecked(sqpApp->plotsInteractionMode()
202 207 == SqpApplication::PlotsInteractionMode::ZoomBox);
203 208 connect(actionZoomMode, &QAction::triggered, []() {
204 209 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::ZoomBox);
205 210 });
206 211
207 212 auto actionOrganisationMode = new QAction{QIcon(":/icones/drag.png"), "Organize", this};
208 213 actionOrganisationMode->setCheckable(true);
209 214 actionOrganisationMode->setChecked(sqpApp->plotsInteractionMode()
210 215 == SqpApplication::PlotsInteractionMode::DragAndDrop);
211 216 connect(actionOrganisationMode, &QAction::triggered, []() {
212 217 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::DragAndDrop);
213 218 });
214 219
215 220 auto actionZonesMode = new QAction{QIcon(":/icones/rectangle.png"), "Zones", this};
216 221 actionZonesMode->setCheckable(true);
217 222 actionZonesMode->setChecked(sqpApp->plotsInteractionMode()
218 223 == SqpApplication::PlotsInteractionMode::SelectionZones);
219 224 connect(actionZonesMode, &QAction::triggered, []() {
220 225 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::SelectionZones);
221 226 });
222 227
223 228 auto modeActionGroup = new QActionGroup{this};
224 229 modeActionGroup->addAction(actionZoomMode);
225 230 modeActionGroup->addAction(actionZonesMode);
226 231 modeActionGroup->addAction(actionOrganisationMode);
227 232 modeActionGroup->addAction(actionPointerMode);
228 233 modeActionGroup->setExclusive(true);
229 234
230 235 mainToolBar->addSeparator();
231 236 mainToolBar->addAction(actionPointerMode);
232 237 mainToolBar->addAction(actionZoomMode);
233 238 mainToolBar->addAction(actionOrganisationMode);
234 239 mainToolBar->addAction(actionZonesMode);
235 240 mainToolBar->addSeparator();
236 241
242 // Cursors
237 243 auto btnCursor = new QToolButton{this};
238 244 btnCursor->setIcon(QIcon(":/icones/cursor.png"));
239 245 btnCursor->setText("Cursor");
240 246 btnCursor->setToolTip("Cursor");
241 247 btnCursor->setPopupMode(QToolButton::InstantPopup);
242 248 auto cursorMenu = new QMenu("CursorMenu", this);
243 249 btnCursor->setMenu(cursorMenu);
244 250
245 251 auto noCursorAction = cursorMenu->addAction("No Cursor");
246 252 noCursorAction->setCheckable(true);
247 253 noCursorAction->setChecked(sqpApp->plotsCursorMode()
248 254 == SqpApplication::PlotsCursorMode::NoCursor);
249 255 connect(noCursorAction, &QAction::triggered,
250 256 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::NoCursor); });
251 257
252 258 cursorMenu->addSeparator();
253 259 auto verticalCursorAction = cursorMenu->addAction("Vertical Cursor");
254 260 verticalCursorAction->setCheckable(true);
255 261 verticalCursorAction->setChecked(sqpApp->plotsCursorMode()
256 262 == SqpApplication::PlotsCursorMode::Vertical);
257 263 connect(verticalCursorAction, &QAction::triggered,
258 264 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Vertical); });
259 265
260 266 auto temporalCursorAction = cursorMenu->addAction("Temporal Cursor");
261 267 temporalCursorAction->setCheckable(true);
262 268 temporalCursorAction->setChecked(sqpApp->plotsCursorMode()
263 269 == SqpApplication::PlotsCursorMode::Temporal);
264 270 connect(temporalCursorAction, &QAction::triggered,
265 271 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Temporal); });
266 272
267 273 auto horizontalCursorAction = cursorMenu->addAction("Horizontal Cursor");
268 274 horizontalCursorAction->setCheckable(true);
269 275 horizontalCursorAction->setChecked(sqpApp->plotsCursorMode()
270 276 == SqpApplication::PlotsCursorMode::Horizontal);
271 277 connect(horizontalCursorAction, &QAction::triggered,
272 278 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Horizontal); });
273 279
274 280 auto crossCursorAction = cursorMenu->addAction("Cross Cursor");
275 281 crossCursorAction->setCheckable(true);
276 282 crossCursorAction->setChecked(sqpApp->plotsCursorMode()
277 283 == SqpApplication::PlotsCursorMode::Cross);
278 284 connect(crossCursorAction, &QAction::triggered,
279 285 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Cross); });
280 286
281 287 mainToolBar->addWidget(btnCursor);
282 288
283 289 auto cursorModeActionGroup = new QActionGroup{this};
284 290 cursorModeActionGroup->setExclusive(true);
285 291 cursorModeActionGroup->addAction(noCursorAction);
286 292 cursorModeActionGroup->addAction(verticalCursorAction);
287 293 cursorModeActionGroup->addAction(temporalCursorAction);
288 294 cursorModeActionGroup->addAction(horizontalCursorAction);
289 295 cursorModeActionGroup->addAction(crossCursorAction);
290 296
297 // Catalog
298 mainToolBar->addSeparator();
299 mainToolBar->addAction(QIcon(":/icones/catalogue.png"), "Catalogues",
300 [this]() { impl->m_CatalogExplorer->show(); });
301
291 302 // //////// //
292 303 // Settings //
293 304 // //////// //
294 305
295 306 // Registers "general settings" widget to the settings dialog
296 307 impl->m_SettingsDialog->registerWidget(QStringLiteral("General"),
297 308 impl->m_GeneralSettingsWidget);
298 309
299 310 // /////////// //
300 311 // Connections //
301 312 // /////////// //
302 313
303 314 // Controllers / controllers connections
304 315 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpRange)), &sqpApp->variableController(),
305 316 SLOT(onDateTimeOnSelection(SqpRange)));
306 317
307 318 // Widgets / controllers connections
308 319
309 320 // DataSource
310 321 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
311 322 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
312 323
313 324 // Time
314 325 connect(timeWidget, SIGNAL(timeUpdated(SqpRange)), &sqpApp->timeController(),
315 326 SLOT(onTimeToUpdate(SqpRange)));
316 327
317 328 // Visualization
318 329 connect(&sqpApp->visualizationController(),
319 330 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
320 331 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
321 332
322 333 connect(&sqpApp->visualizationController(),
323 334 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), m_Ui->view,
324 335 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
325 336
326 337 // Widgets / widgets connections
327 338
328 339 // For the following connections, we use DirectConnection to allow each widget that can
329 340 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
330 341 // The order of connections is also important, since it determines the order in which each
331 342 // widget will attach its menu
332 343 connect(
333 344 m_Ui->variableInspectorWidget,
334 345 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
335 346 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
336 347 Qt::DirectConnection);
337 348 }
338 349
339 350 MainWindow::~MainWindow()
340 351 {
341 352 }
342 353
343 354 void MainWindow::changeEvent(QEvent *e)
344 355 {
345 356 QMainWindow::changeEvent(e);
346 357 switch (e->type()) {
347 358 case QEvent::LanguageChange:
348 359 m_Ui->retranslateUi(this);
349 360 break;
350 361 default:
351 362 break;
352 363 }
353 364 }
@@ -1,22 +1,23
1 1 <RCC>
2 2 <qresource prefix="/">
3 3 <file>icones/dataSourceComponent.png</file>
4 4 <file>icones/dataSourceNode.png</file>
5 5 <file>icones/dataSourceProduct.png</file>
6 6 <file>icones/dataSourceRoot.png</file>
7 7 <file>icones/delete.png</file>
8 8 <file>icones/down.png</file>
9 9 <file>icones/openInspector.png</file>
10 10 <file>icones/next.png</file>
11 11 <file>icones/plot.png</file>
12 12 <file>icones/previous.png</file>
13 13 <file>icones/unplot.png</file>
14 14 <file>icones/up.png</file>
15 15 <file>icones/time.png</file>
16 16 <file>icones/zoom.png</file>
17 17 <file>icones/rectangle.png</file>
18 18 <file>icones/drag.png</file>
19 19 <file>icones/cursor.png</file>
20 20 <file>icones/pointer.png</file>
21 <file>icones/catalogue.png</file>
21 22 </qresource>
22 23 </RCC>
General Comments 0
You need to be logged in to leave comments. Login now