##// END OF EJS Templates
Settings binding (4)...
Alexandre Leroux -
r433:7a2eb58d2083
parent child
Show More
@@ -1,248 +1,255
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 <Settings/SqpSettingsDialog.h>
27 #include <Settings/SqpSettingsDialog.h>
28 #include <Settings/SqpSettingsGeneralWidget.h>
28 #include <Settings/SqpSettingsGeneralWidget.h>
29 #include <SidePane/SqpSidePane.h>
29 #include <SidePane/SqpSidePane.h>
30 #include <SqpApplication.h>
30 #include <SqpApplication.h>
31 #include <Time/TimeController.h>
31 #include <Time/TimeController.h>
32 #include <TimeWidget/TimeWidget.h>
32 #include <TimeWidget/TimeWidget.h>
33 #include <Variable/Variable.h>
33 #include <Variable/Variable.h>
34 #include <Variable/VariableController.h>
34 #include <Variable/VariableController.h>
35 #include <Visualization/VisualizationController.h>
35 #include <Visualization/VisualizationController.h>
36
36
37 #include <QAction>
37 #include <QAction>
38 #include <QDate>
38 #include <QDate>
39 #include <QDateTime>
39 #include <QDateTime>
40 #include <QDir>
40 #include <QDir>
41 #include <QFileDialog>
41 #include <QFileDialog>
42 #include <QToolBar>
42 #include <QToolBar>
43 #include <QToolButton>
43 #include <QToolButton>
44 #include <memory.h>
44 #include <memory.h>
45
45
46 #include "iostream"
46 #include "iostream"
47
47
48 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
48 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
49
49
50 namespace {
50 namespace {
51 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
51 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
52 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
52 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
53 const auto VIEWPLITTERINDEX = 2;
53 const auto VIEWPLITTERINDEX = 2;
54 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
54 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
55 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
55 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
56 }
56 }
57
57
58 class MainWindow::MainWindowPrivate {
58 class MainWindow::MainWindowPrivate {
59 public:
59 public:
60 explicit MainWindowPrivate(MainWindow *mainWindow)
60 explicit MainWindowPrivate(MainWindow *mainWindow)
61 : m_LastOpenLeftInspectorSize{},
61 : m_LastOpenLeftInspectorSize{},
62 m_LastOpenRightInspectorSize{},
62 m_LastOpenRightInspectorSize{},
63 m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}},
63 m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}},
64 m_SettingsDialog{new SqpSettingsDialog{mainWindow}}
64 m_SettingsDialog{new SqpSettingsDialog{mainWindow}}
65 {
65 {
66 }
66 }
67
67
68 QSize m_LastOpenLeftInspectorSize;
68 QSize m_LastOpenLeftInspectorSize;
69 QSize m_LastOpenRightInspectorSize;
69 QSize m_LastOpenRightInspectorSize;
70 /// General settings widget. MainWindow has the ownership
70 /// General settings widget. MainWindow has the ownership
71 SqpSettingsGeneralWidget *m_GeneralSettingsWidget;
71 SqpSettingsGeneralWidget *m_GeneralSettingsWidget;
72 /// Settings dialog. MainWindow has the ownership
72 /// Settings dialog. MainWindow has the ownership
73 SqpSettingsDialog *m_SettingsDialog;
73 SqpSettingsDialog *m_SettingsDialog;
74 };
74 };
75
75
76 MainWindow::MainWindow(QWidget *parent)
76 MainWindow::MainWindow(QWidget *parent)
77 : QMainWindow{parent},
77 : QMainWindow{parent},
78 m_Ui{new Ui::MainWindow},
78 m_Ui{new Ui::MainWindow},
79 impl{spimpl::make_unique_impl<MainWindowPrivate>(this)}
79 impl{spimpl::make_unique_impl<MainWindowPrivate>(this)}
80 {
80 {
81 m_Ui->setupUi(this);
81 m_Ui->setupUi(this);
82
82
83 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
83 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
84 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
84 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
85
85
86
86
87 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
87 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
88 auto openLeftInspectorAction = new QAction{QIcon{
88 auto openLeftInspectorAction = new QAction{QIcon{
89 ":/icones/previous.png",
89 ":/icones/previous.png",
90 },
90 },
91 tr("Show/hide the left inspector"), this};
91 tr("Show/hide the left inspector"), this};
92
92
93
93
94 auto spacerLeftTop = new QWidget{};
94 auto spacerLeftTop = new QWidget{};
95 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
95 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
96
96
97 auto spacerLeftBottom = new QWidget{};
97 auto spacerLeftBottom = new QWidget{};
98 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
98 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
99
99
100 leftSidePane->addWidget(spacerLeftTop);
100 leftSidePane->addWidget(spacerLeftTop);
101 leftSidePane->addAction(openLeftInspectorAction);
101 leftSidePane->addAction(openLeftInspectorAction);
102 leftSidePane->addWidget(spacerLeftBottom);
102 leftSidePane->addWidget(spacerLeftBottom);
103
103
104
104
105 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
105 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
106 auto openRightInspectorAction = new QAction{QIcon{
106 auto openRightInspectorAction = new QAction{QIcon{
107 ":/icones/next.png",
107 ":/icones/next.png",
108 },
108 },
109 tr("Show/hide the right inspector"), this};
109 tr("Show/hide the right inspector"), this};
110
110
111 auto spacerRightTop = new QWidget{};
111 auto spacerRightTop = new QWidget{};
112 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
112 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113
113
114 auto spacerRightBottom = new QWidget{};
114 auto spacerRightBottom = new QWidget{};
115 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
115 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
116
116
117 rightSidePane->addWidget(spacerRightTop);
117 rightSidePane->addWidget(spacerRightTop);
118 rightSidePane->addAction(openRightInspectorAction);
118 rightSidePane->addAction(openRightInspectorAction);
119 rightSidePane->addWidget(spacerRightBottom);
119 rightSidePane->addWidget(spacerRightBottom);
120
120
121 openLeftInspectorAction->setCheckable(true);
121 openLeftInspectorAction->setCheckable(true);
122 openRightInspectorAction->setCheckable(true);
122 openRightInspectorAction->setCheckable(true);
123
123
124 auto openInspector = [this](bool checked, bool right, auto action) {
124 auto openInspector = [this](bool checked, bool right, auto action) {
125
125
126 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
126 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
127
127
128 auto &lastInspectorSize
128 auto &lastInspectorSize
129 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
129 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
130
130
131 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
131 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
132 : m_Ui->leftMainInspectorWidget->size();
132 : m_Ui->leftMainInspectorWidget->size();
133
133
134 // Update of the last opened geometry
134 // Update of the last opened geometry
135 if (checked) {
135 if (checked) {
136 lastInspectorSize = nextInspectorSize;
136 lastInspectorSize = nextInspectorSize;
137 }
137 }
138
138
139 auto startSize = lastInspectorSize;
139 auto startSize = lastInspectorSize;
140 auto endSize = startSize;
140 auto endSize = startSize;
141 endSize.setWidth(0);
141 endSize.setWidth(0);
142
142
143 auto splitterInspectorIndex
143 auto splitterInspectorIndex
144 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
144 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
145
145
146 auto currentSizes = m_Ui->splitter->sizes();
146 auto currentSizes = m_Ui->splitter->sizes();
147 if (checked) {
147 if (checked) {
148 // adjust sizes individually here, e.g.
148 // adjust sizes individually here, e.g.
149 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
149 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
150 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
150 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
151 m_Ui->splitter->setSizes(currentSizes);
151 m_Ui->splitter->setSizes(currentSizes);
152 }
152 }
153 else {
153 else {
154 // adjust sizes individually here, e.g.
154 // adjust sizes individually here, e.g.
155 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
155 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
156 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
156 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
157 m_Ui->splitter->setSizes(currentSizes);
157 m_Ui->splitter->setSizes(currentSizes);
158 }
158 }
159
159
160 };
160 };
161
161
162
162
163 connect(openLeftInspectorAction, &QAction::triggered,
163 connect(openLeftInspectorAction, &QAction::triggered,
164 [openInspector, openLeftInspectorAction](bool checked) {
164 [openInspector, openLeftInspectorAction](bool checked) {
165 openInspector(checked, false, openLeftInspectorAction);
165 openInspector(checked, false, openLeftInspectorAction);
166 });
166 });
167 connect(openRightInspectorAction, &QAction::triggered,
167 connect(openRightInspectorAction, &QAction::triggered,
168 [openInspector, openRightInspectorAction](bool checked) {
168 [openInspector, openRightInspectorAction](bool checked) {
169 openInspector(checked, true, openRightInspectorAction);
169 openInspector(checked, true, openRightInspectorAction);
170 });
170 });
171
171
172 // //// //
172 // //// //
173 // Menu //
173 // Menu //
174 // //// //
174 // //// //
175 this->menuBar()->addAction(tr("File"));
175 this->menuBar()->addAction(tr("File"));
176 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
176 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
177 toolsMenu->addAction(tr("Settings..."), [this]() {
177 toolsMenu->addAction(tr("Settings..."), [this]() {
178 impl->m_SettingsDialog->exec();
178 // Loads settings
179 impl->m_SettingsDialog->loadSettings();
180
181 // Open settings dialog and save settings if the dialog is accepted
182 if (impl->m_SettingsDialog->exec() == QDialog::Accepted) {
183 impl->m_SettingsDialog->saveSettings();
184 }
185
179 });
186 });
180
187
181 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
188 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
182
189
183 auto timeWidget = new TimeWidget{};
190 auto timeWidget = new TimeWidget{};
184 mainToolBar->addWidget(timeWidget);
191 mainToolBar->addWidget(timeWidget);
185
192
186 // //////// //
193 // //////// //
187 // Settings //
194 // Settings //
188 // //////// //
195 // //////// //
189
196
190 // Registers "general settings" widget to the settings dialog
197 // Registers "general settings" widget to the settings dialog
191 impl->m_SettingsDialog->registerWidget(QStringLiteral("General"),
198 impl->m_SettingsDialog->registerWidget(QStringLiteral("General"),
192 impl->m_GeneralSettingsWidget);
199 impl->m_GeneralSettingsWidget);
193
200
194 // /////////// //
201 // /////////// //
195 // Connections //
202 // Connections //
196 // /////////// //
203 // /////////// //
197
204
198 // Controllers / controllers connections
205 // Controllers / controllers connections
199 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
206 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
200 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
207 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
201
208
202 // Widgets / controllers connections
209 // Widgets / controllers connections
203
210
204 // DataSource
211 // DataSource
205 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
212 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
206 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
213 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
207
214
208 // Time
215 // Time
209 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
216 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
210 SLOT(onTimeToUpdate(SqpDateTime)));
217 SLOT(onTimeToUpdate(SqpDateTime)));
211
218
212 // Visualization
219 // Visualization
213 connect(&sqpApp->visualizationController(),
220 connect(&sqpApp->visualizationController(),
214 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
221 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
215 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
222 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
216
223
217 connect(&sqpApp->visualizationController(),
224 connect(&sqpApp->visualizationController(),
218 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view,
225 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view,
219 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
226 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
220
227
221 // Widgets / widgets connections
228 // Widgets / widgets connections
222
229
223 // For the following connections, we use DirectConnection to allow each widget that can
230 // For the following connections, we use DirectConnection to allow each widget that can
224 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
231 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
225 // The order of connections is also important, since it determines the order in which each
232 // The order of connections is also important, since it determines the order in which each
226 // widget will attach its menu
233 // widget will attach its menu
227 connect(
234 connect(
228 m_Ui->variableInspectorWidget,
235 m_Ui->variableInspectorWidget,
229 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
236 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
230 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
237 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
231 Qt::DirectConnection);
238 Qt::DirectConnection);
232 }
239 }
233
240
234 MainWindow::~MainWindow()
241 MainWindow::~MainWindow()
235 {
242 {
236 }
243 }
237
244
238 void MainWindow::changeEvent(QEvent *e)
245 void MainWindow::changeEvent(QEvent *e)
239 {
246 {
240 QMainWindow::changeEvent(e);
247 QMainWindow::changeEvent(e);
241 switch (e->type()) {
248 switch (e->type()) {
242 case QEvent::LanguageChange:
249 case QEvent::LanguageChange:
243 m_Ui->retranslateUi(this);
250 m_Ui->retranslateUi(this);
244 break;
251 break;
245 default:
252 default:
246 break;
253 break;
247 }
254 }
248 }
255 }
General Comments 0
You need to be logged in to leave comments. Login now