@@ -1,254 +1,256 | |||
|
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 | 185 | // Widgets / widgets connections |
|
186 | 186 | qRegisterMetaType<std::shared_ptr<Variable> >(); |
|
187 | 187 | |
|
188 | 188 | // For the following connections, we use DirectConnection to allow each widget that can |
|
189 | 189 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. |
|
190 | 190 | // The order of connections is also important, since it determines the order in which each |
|
191 | 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); | |
|
192 | connect( | |
|
193 | m_Ui->variableInspectorWidget, | |
|
194 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
|
195 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | |
|
196 | Qt::DirectConnection); | |
|
195 | 197 | |
|
196 | 198 | /* QLopGUI::registerMenuBar(menuBar()); |
|
197 | 199 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); |
|
198 | 200 | this->m_progressWidget = new QWidget(); |
|
199 | 201 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); |
|
200 | 202 | this->m_progressWidget->setLayout(this->m_progressLayout); |
|
201 | 203 | this->m_progressWidget->setWindowModality(Qt::WindowModal); |
|
202 | 204 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
203 | 205 | for(int i=0;i<OMP_THREADS;i++) |
|
204 | 206 | { |
|
205 | 207 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); |
|
206 | 208 | this->m_progress.last()->setMinimum(0); |
|
207 | 209 | this->m_progress.last()->setMaximum(100); |
|
208 | 210 | this->m_progressLayout->addWidget(this->m_progress.last()); |
|
209 | 211 | this->m_progressWidget->hide(); |
|
210 | 212 | this->m_progressThreadIds[i] = -1; |
|
211 | 213 | } |
|
212 | 214 | this->m_progressWidget->setWindowTitle("Loading File"); |
|
213 | 215 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
214 | 216 | << QLopCore::self() |
|
215 | 217 | << QLopPlotManager::self() |
|
216 | 218 | << QLopCodecManager::self() |
|
217 | 219 | << FileDownloader::self() |
|
218 | 220 | << QLopDataBase::self() |
|
219 | 221 | << SpaceData::self(); |
|
220 | 222 | |
|
221 | 223 | CDFCodec::registerToManager(); |
|
222 | 224 | AMDATXTCodec::registerToManager(); |
|
223 | 225 | |
|
224 | 226 | |
|
225 | 227 | for(int i=0;i<ServicesToLoad.count();i++) |
|
226 | 228 | { |
|
227 | 229 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
228 | 230 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI |
|
229 | 231 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
230 | 232 | if(wdgt) |
|
231 | 233 | { |
|
232 | 234 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
233 | 235 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
234 | 236 | } |
|
235 | 237 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
236 | 238 | }*/ |
|
237 | 239 | } |
|
238 | 240 | |
|
239 | 241 | MainWindow::~MainWindow() |
|
240 | 242 | { |
|
241 | 243 | } |
|
242 | 244 | |
|
243 | 245 | |
|
244 | 246 | void MainWindow::changeEvent(QEvent *e) |
|
245 | 247 | { |
|
246 | 248 | QMainWindow::changeEvent(e); |
|
247 | 249 | switch (e->type()) { |
|
248 | 250 | case QEvent::LanguageChange: |
|
249 | 251 | m_Ui->retranslateUi(this); |
|
250 | 252 | break; |
|
251 | 253 | default: |
|
252 | 254 | break; |
|
253 | 255 | } |
|
254 | 256 | } |
@@ -1,49 +1,50 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
2 | 2 | #define SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <QLoggingCategory> |
|
5 | 5 | #include <QMenu> |
|
6 | 6 | #include <QWidget> |
|
7 | 7 | |
|
8 | 8 | #include <memory> |
|
9 | 9 | |
|
10 | 10 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableInspectorWidget) |
|
11 | 11 | |
|
12 | 12 | class Variable; |
|
13 | 13 | |
|
14 | 14 | namespace Ui { |
|
15 | 15 | class VariableInspectorWidget; |
|
16 | 16 | } // Ui |
|
17 | 17 | |
|
18 | 18 | /** |
|
19 | 19 | * @brief The VariableInspectorWidget class representes represents the variable inspector, from |
|
20 | 20 | * which it is possible to view the loaded variables, handle them or trigger their display in |
|
21 | 21 | * visualization |
|
22 | 22 | */ |
|
23 | 23 | class VariableInspectorWidget : public QWidget { |
|
24 | 24 | Q_OBJECT |
|
25 | 25 | |
|
26 | 26 | public: |
|
27 | 27 | explicit VariableInspectorWidget(QWidget *parent = 0); |
|
28 | 28 | virtual ~VariableInspectorWidget(); |
|
29 | 29 | |
|
30 | 30 | signals: |
|
31 | 31 | /** |
|
32 |
* Signal emitted before a menu concerning |
|
|
32 | * Signal emitted before a menu concerning variables is displayed. It is used for other widgets | |
|
33 | 33 | * to complete the menu. |
|
34 | 34 | * @param tableMenu the menu to be completed |
|
35 | * @param variable the variable concerned by the menu | |
|
35 | * @param variables the variables concerned by the menu | |
|
36 | 36 | * @remarks To make the dynamic addition of menus work, the connections to this signal must be |
|
37 | 37 | * in Qt :: DirectConnection |
|
38 | 38 | */ |
|
39 |
void tableMenuAboutToBeDisplayed(QMenu *tableMenu, |
|
|
39 | void tableMenuAboutToBeDisplayed(QMenu *tableMenu, | |
|
40 | const QVector<std::shared_ptr<Variable> > &variables); | |
|
40 | 41 | |
|
41 | 42 | private: |
|
42 | 43 | Ui::VariableInspectorWidget *ui; |
|
43 | 44 | |
|
44 | 45 | private slots: |
|
45 | 46 | /// Slot called when right clicking on an variable in the table (displays a menu) |
|
46 | 47 | void onTableMenuRequested(const QPoint &pos) noexcept; |
|
47 | 48 | }; |
|
48 | 49 | |
|
49 | 50 | #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H |
@@ -1,43 +1,44 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | 5 | |
|
6 | 6 | #include <QLoggingCategory> |
|
7 | 7 | #include <QWidget> |
|
8 | 8 | |
|
9 | 9 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) |
|
10 | 10 | |
|
11 | 11 | class QMenu; |
|
12 | 12 | class Variable; |
|
13 | 13 | class VisualizationTabWidget; |
|
14 | 14 | |
|
15 | 15 | namespace Ui { |
|
16 | 16 | class VisualizationWidget; |
|
17 | 17 | } // namespace Ui |
|
18 | 18 | |
|
19 | 19 | class VisualizationWidget : public QWidget, public IVisualizationWidget { |
|
20 | 20 | Q_OBJECT |
|
21 | 21 | |
|
22 | 22 | public: |
|
23 | 23 | explicit VisualizationWidget(QWidget *parent = 0); |
|
24 | 24 | virtual ~VisualizationWidget(); |
|
25 | 25 | |
|
26 | 26 | // IVisualizationWidget interface |
|
27 | 27 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
28 | 28 | bool canDrop(const Variable &variable) const override; |
|
29 | 29 | QString name() const override; |
|
30 | 30 | |
|
31 | 31 | public slots: |
|
32 | 32 | /** |
|
33 |
* Attaches to a menu the menu relati |
|
|
33 | * Attaches to a menu the menu relative to the visualization of variables | |
|
34 | 34 | * @param menu the parent menu of the generated menu |
|
35 | * @param variable the variable for which to generate the menu | |
|
35 | * @param variables the variables for which to generate the menu | |
|
36 | 36 | */ |
|
37 |
void attachVariableMenu(QMenu *menu, |
|
|
37 | void attachVariableMenu(QMenu *menu, | |
|
38 | const QVector<std::shared_ptr<Variable> > &variables) noexcept; | |
|
38 | 39 | |
|
39 | 40 | private: |
|
40 | 41 | Ui::VisualizationWidget *ui; |
|
41 | 42 | }; |
|
42 | 43 | |
|
43 | 44 | #endif // VISUALIZATIONWIDGET_H |
@@ -1,70 +1,69 | |||
|
1 | 1 | #include <Variable/VariableController.h> |
|
2 | 2 | #include <Variable/VariableInspectorWidget.h> |
|
3 | 3 | #include <Variable/VariableModel.h> |
|
4 | 4 | |
|
5 | 5 | #include <ui_VariableInspectorWidget.h> |
|
6 | 6 | |
|
7 | 7 | #include <QSortFilterProxyModel> |
|
8 | 8 | |
|
9 | 9 | #include <SqpApplication.h> |
|
10 | 10 | |
|
11 | 11 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") |
|
12 | 12 | |
|
13 | 13 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
14 | 14 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} |
|
15 | 15 | { |
|
16 | 16 | ui->setupUi(this); |
|
17 | 17 | |
|
18 | 18 | // Sets model for table |
|
19 | 19 | auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
20 | 20 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
21 | 21 | |
|
22 | 22 | ui->tableView->setModel(sortFilterModel); |
|
23 | 23 | |
|
24 | 24 | // Fixes column sizes |
|
25 | 25 | auto model = ui->tableView->model(); |
|
26 | 26 | const auto count = model->columnCount(); |
|
27 | 27 | for (auto i = 0; i < count; ++i) { |
|
28 | 28 | ui->tableView->setColumnWidth( |
|
29 | 29 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | // Sets selection options |
|
33 | 33 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); |
|
34 | 34 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); |
|
35 | 35 | |
|
36 | 36 | // Connection to show a menu when right clicking on the tree |
|
37 | 37 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
38 | 38 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, |
|
39 | 39 | &VariableInspectorWidget::onTableMenuRequested); |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | VariableInspectorWidget::~VariableInspectorWidget() |
|
43 | 43 | { |
|
44 | 44 | delete ui; |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept |
|
48 | 48 | { |
|
49 | 49 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); |
|
50 | 50 | |
|
51 | 51 | // Gets the model to retrieve the underlying selected variables |
|
52 | 52 | auto model = sqpApp->variableController().variableModel(); |
|
53 | 53 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; |
|
54 | 54 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
55 | 55 | if (auto selectedVariable = model->variable(selectedRow.row())) { |
|
56 | 56 | selectedVariables.push_back(selectedVariable); |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | QMenu tableMenu{}; |
|
61 | 61 | |
|
62 | 62 | // Emits a signal so that potential receivers can populate the menu before displaying it |
|
63 | /// @todo ALX : handles list of variables in the signal | |
|
64 | 63 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); |
|
65 | 64 | |
|
66 | 65 | if (!tableMenu.isEmpty()) { |
|
67 | 66 | // Displays menu |
|
68 | 67 | tableMenu.exec(mapToGlobal(pos)); |
|
69 | 68 | } |
|
70 | 69 | } |
@@ -1,115 +1,129 | |||
|
1 | 1 | #include "Visualization/VisualizationWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "Visualization/VisualizationGraphWidget.h" |
|
4 | 4 | #include "Visualization/VisualizationTabWidget.h" |
|
5 | 5 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | 6 | #include "Visualization/operations/GenerateVariableMenuOperation.h" |
|
7 | 7 | #include "Visualization/qcustomplot.h" |
|
8 | 8 | |
|
9 | 9 | #include "ui_VisualizationWidget.h" |
|
10 | 10 | |
|
11 | 11 | #include <QToolButton> |
|
12 | 12 | |
|
13 | 13 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
14 | 14 | |
|
15 | 15 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
16 | 16 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
17 | 17 | { |
|
18 | 18 | ui->setupUi(this); |
|
19 | 19 | |
|
20 | 20 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
21 | 21 | addTabViewButton->setText(tr("Add View")); |
|
22 | 22 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
23 | 23 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
24 | 24 | |
|
25 | 25 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
26 | 26 | |
|
27 | 27 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
28 | 28 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
29 | 29 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
30 | 30 | tabViewCornerWidget->setMinimumHeight(height); |
|
31 | 31 | tabViewCornerWidget->setMinimumWidth(width); |
|
32 | 32 | ui->tabWidget->setMinimumHeight(height); |
|
33 | 33 | ui->tabWidget->setMinimumWidth(width); |
|
34 | 34 | }; |
|
35 | 35 | |
|
36 | 36 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
37 | 37 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
38 | 38 | ui->tabWidget}; |
|
39 | 39 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
40 | 40 | if (ui->tabWidget->count() > 0) { |
|
41 | 41 | enableMinimumCornerWidgetSize(false); |
|
42 | 42 | } |
|
43 | 43 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
44 | 44 | }; |
|
45 | 45 | |
|
46 | 46 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
47 | 47 | if (ui->tabWidget->count() == 1) { |
|
48 | 48 | enableMinimumCornerWidgetSize(true); |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | // Removes widget from tab and closes it |
|
52 | 52 | auto widget = ui->tabWidget->widget(index); |
|
53 | 53 | ui->tabWidget->removeTab(index); |
|
54 | 54 | if (widget) { |
|
55 | 55 | widget->close(); |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
59 | 59 | |
|
60 | 60 | }; |
|
61 | 61 | |
|
62 | 62 | ui->tabWidget->setTabsClosable(true); |
|
63 | 63 | |
|
64 | 64 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
65 | 65 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
66 | 66 | |
|
67 | 67 | // Adds default tab |
|
68 | 68 | addTabView(); |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | VisualizationWidget::~VisualizationWidget() |
|
72 | 72 | { |
|
73 | 73 | delete ui; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
77 | 77 | { |
|
78 | 78 | if (visitor) { |
|
79 | 79 | visitor->visitEnter(this); |
|
80 | 80 | |
|
81 | 81 | // Apply visitor for tab children |
|
82 | 82 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
83 | 83 | // Widgets different from tabs are not visited (no action) |
|
84 | 84 | if (auto visualizationTabWidget |
|
85 | 85 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
86 | 86 | visualizationTabWidget->accept(visitor); |
|
87 | 87 | } |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | visitor->visitLeave(this); |
|
91 | 91 | } |
|
92 | 92 | else { |
|
93 | 93 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); |
|
94 | 94 | } |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | bool VisualizationWidget::canDrop(const Variable &variable) const |
|
98 | 98 | { |
|
99 | 99 | // The main widget can never accomodate a variable |
|
100 | 100 | Q_UNUSED(variable); |
|
101 | 101 | return false; |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | QString VisualizationWidget::name() const |
|
105 | 105 | { |
|
106 | 106 | return QStringLiteral("MainView"); |
|
107 | 107 | } |
|
108 | 108 | |
|
109 |
void VisualizationWidget::attachVariableMenu( |
|
|
110 |
|
|
|
109 | void VisualizationWidget::attachVariableMenu( | |
|
110 | QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
|
111 | 111 | { |
|
112 | // Generates the actions that make it possible to visualize the variable | |
|
113 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |
|
114 | accept(&generateVariableMenuOperation); | |
|
112 | // Menu is generated only if there is a single variable | |
|
113 | if (variables.size() == 1) { | |
|
114 | if (auto variable = variables.first()) { | |
|
115 | // Generates the actions that make it possible to visualize the variable | |
|
116 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |
|
117 | accept(&generateVariableMenuOperation); | |
|
118 | } | |
|
119 | else { | |
|
120 | qCCritical(LOG_VisualizationWidget()) << tr( | |
|
121 | "Can't generate the menu relative to the visualization: the variable is null"); | |
|
122 | } | |
|
123 | } | |
|
124 | else { | |
|
125 | qCDebug(LOG_VisualizationWidget()) | |
|
126 | << tr("No generation of the menu related to the visualization: several variables are " | |
|
127 | "selected"); | |
|
128 | } | |
|
115 | 129 | } |
General Comments 0
You need to be logged in to leave comments.
Login now