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