@@ -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 | } |
@@ -1,49 +1,51 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLEMODEL_H |
|
2 | 2 | #define SCIQLOP_VARIABLEMODEL_H |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | #include <Data/SqpDateTime.h> |
|
6 | 6 | |
|
7 | 7 | #include <QAbstractTableModel> |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | |
|
10 | 10 | #include <Common/spimpl.h> |
|
11 | 11 | |
|
12 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) |
|
13 | 13 | |
|
14 | 14 | class IDataSeries; |
|
15 | 15 | class Variable; |
|
16 | 16 | |
|
17 | 17 | /** |
|
18 | 18 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
|
19 | 19 | */ |
|
20 | 20 | class VariableModel : public QAbstractTableModel { |
|
21 | 21 | public: |
|
22 | 22 | explicit VariableModel(QObject *parent = nullptr); |
|
23 | 23 | |
|
24 | 24 | /** |
|
25 | 25 | * Creates a new variable in the model |
|
26 | 26 | * @param name the name of the new variable |
|
27 | 27 | * @param dateTime the dateTime of the new variable |
|
28 | 28 | * @param defaultDataSeries the default data of the new variable |
|
29 | 29 | * @return the pointer to the new variable |
|
30 | 30 | */ |
|
31 | 31 | std::shared_ptr<Variable> |
|
32 | 32 | createVariable(const QString &name, const SqpDateTime &dateTime, |
|
33 | 33 | std::unique_ptr<IDataSeries> defaultDataSeries) noexcept; |
|
34 | 34 | |
|
35 | std::shared_ptr<Variable> variable(int index) const; | |
|
36 | ||
|
35 | 37 | // /////////////////////////// // |
|
36 | 38 | // QAbstractTableModel methods // |
|
37 | 39 | // /////////////////////////// // |
|
38 | 40 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
39 | 41 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
40 | 42 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
41 | 43 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
42 | 44 | int role = Qt::DisplayRole) const override; |
|
43 | 45 | |
|
44 | 46 | private: |
|
45 | 47 | class VariableModelPrivate; |
|
46 | 48 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; |
|
47 | 49 | }; |
|
48 | 50 | |
|
49 | 51 | #endif // SCIQLOP_VARIABLEMODEL_H |
@@ -1,120 +1,125 | |||
|
1 | 1 | #include <Variable/Variable.h> |
|
2 | 2 | #include <Variable/VariableModel.h> |
|
3 | 3 | |
|
4 | 4 | #include <Data/IDataSeries.h> |
|
5 | 5 | |
|
6 | 6 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") |
|
7 | 7 | |
|
8 | 8 | namespace { |
|
9 | 9 | |
|
10 | 10 | // Column indexes |
|
11 | 11 | const auto NAME_COLUMN = 0; |
|
12 | 12 | const auto UNIT_COLUMN = 1; |
|
13 | 13 | const auto MISSION_COLUMN = 2; |
|
14 | 14 | const auto NB_COLUMNS = 3; |
|
15 | 15 | |
|
16 | 16 | } // namespace |
|
17 | 17 | |
|
18 | 18 | struct VariableModel::VariableModelPrivate { |
|
19 | 19 | /// Variables created in SciQlop |
|
20 | 20 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
21 | 21 | }; |
|
22 | 22 | |
|
23 | 23 | VariableModel::VariableModel(QObject *parent) |
|
24 | 24 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
25 | 25 | { |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | std::shared_ptr<Variable> |
|
29 | 29 | VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime, |
|
30 | 30 | std::unique_ptr<IDataSeries> defaultDataSeries) noexcept |
|
31 | 31 | { |
|
32 | 32 | auto insertIndex = rowCount(); |
|
33 | 33 | beginInsertRows({}, insertIndex, insertIndex); |
|
34 | 34 | |
|
35 | 35 | /// @todo For the moment, the other data of the variable is initialized with default values |
|
36 | 36 | auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"), |
|
37 | 37 | QStringLiteral("mission"), dateTime); |
|
38 | 38 | variable->setDataSeries(std::move(defaultDataSeries)); |
|
39 | 39 | |
|
40 | 40 | impl->m_Variables.push_back(variable); |
|
41 | 41 | |
|
42 | 42 | endInsertRows(); |
|
43 | 43 | |
|
44 | 44 | return variable; |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | std::shared_ptr<Variable> VariableModel::variable(int index) const | |
|
48 | { | |
|
49 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables.at(index) : nullptr; | |
|
50 | } | |
|
51 | ||
|
47 | 52 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
48 | 53 | { |
|
49 | 54 | Q_UNUSED(parent); |
|
50 | 55 | |
|
51 | 56 | return NB_COLUMNS; |
|
52 | 57 | } |
|
53 | 58 | |
|
54 | 59 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
55 | 60 | { |
|
56 | 61 | Q_UNUSED(parent); |
|
57 | 62 | |
|
58 | 63 | return impl->m_Variables.size(); |
|
59 | 64 | } |
|
60 | 65 | |
|
61 | 66 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
62 | 67 | { |
|
63 | 68 | if (!index.isValid()) { |
|
64 | 69 | return QVariant{}; |
|
65 | 70 | } |
|
66 | 71 | |
|
67 | 72 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
68 | 73 | return QVariant{}; |
|
69 | 74 | } |
|
70 | 75 | |
|
71 | 76 | if (role == Qt::DisplayRole) { |
|
72 | 77 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
73 | 78 | switch (index.column()) { |
|
74 | 79 | case NAME_COLUMN: |
|
75 | 80 | return variable->name(); |
|
76 | 81 | case UNIT_COLUMN: |
|
77 | 82 | return variable->unit(); |
|
78 | 83 | case MISSION_COLUMN: |
|
79 | 84 | return variable->mission(); |
|
80 | 85 | default: |
|
81 | 86 | // No action |
|
82 | 87 | break; |
|
83 | 88 | } |
|
84 | 89 | |
|
85 | 90 | qWarning(LOG_VariableModel()) |
|
86 | 91 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
87 | 92 | } |
|
88 | 93 | else { |
|
89 | 94 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
90 | 95 | } |
|
91 | 96 | } |
|
92 | 97 | |
|
93 | 98 | return QVariant{}; |
|
94 | 99 | } |
|
95 | 100 | |
|
96 | 101 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
97 | 102 | { |
|
98 | 103 | if (role != Qt::DisplayRole) { |
|
99 | 104 | return QVariant{}; |
|
100 | 105 | } |
|
101 | 106 | |
|
102 | 107 | if (orientation == Qt::Horizontal) { |
|
103 | 108 | switch (section) { |
|
104 | 109 | case NAME_COLUMN: |
|
105 | 110 | return tr("Name"); |
|
106 | 111 | case UNIT_COLUMN: |
|
107 | 112 | return tr("Unit"); |
|
108 | 113 | case MISSION_COLUMN: |
|
109 | 114 | return tr("Mission"); |
|
110 | 115 | default: |
|
111 | 116 | // No action |
|
112 | 117 | break; |
|
113 | 118 | } |
|
114 | 119 | |
|
115 | 120 | qWarning(LOG_VariableModel()) |
|
116 | 121 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
117 | 122 | } |
|
118 | 123 | |
|
119 | 124 | return QVariant{}; |
|
120 | 125 | } |
@@ -1,26 +1,46 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
2 | 2 | #define SCIQLOP_VARIABLEINSPECTORWIDGET_H |
|
3 | 3 | |
|
4 | #include <QMenu> | |
|
4 | 5 | #include <QWidget> |
|
5 | 6 | |
|
7 | #include <memory> | |
|
8 | ||
|
9 | class Variable; | |
|
10 | ||
|
6 | 11 | namespace Ui { |
|
7 | 12 | class VariableInspectorWidget; |
|
8 | 13 | } // Ui |
|
9 | 14 | |
|
10 | 15 | /** |
|
11 | 16 | * @brief The VariableInspectorWidget class representes represents the variable inspector, from |
|
12 | 17 | * which it is possible to view the loaded variables, handle them or trigger their display in |
|
13 | 18 | * visualization |
|
14 | 19 | */ |
|
15 | 20 | class VariableInspectorWidget : public QWidget { |
|
16 | 21 | Q_OBJECT |
|
17 | 22 | |
|
18 | 23 | public: |
|
19 | 24 | explicit VariableInspectorWidget(QWidget *parent = 0); |
|
20 | 25 | virtual ~VariableInspectorWidget(); |
|
21 | 26 | |
|
27 | signals: | |
|
28 | /** | |
|
29 | * Signal emitted before a menu concerning a variable is displayed. It is used for other widgets | |
|
30 | * to complete the menu. | |
|
31 | * @param tableMenu the menu to be completed | |
|
32 | * @param variable the variable concerned by the menu | |
|
33 | * @remarks To make the dynamic addition of menus work, the connections to this signal must be | |
|
34 | * in Qt :: DirectConnection | |
|
35 | */ | |
|
36 | void tableMenuAboutToBeDisplayed(QMenu *tableMenu, std::shared_ptr<Variable> variable); | |
|
37 | ||
|
22 | 38 | private: |
|
23 | 39 | Ui::VariableInspectorWidget *ui; |
|
40 | ||
|
41 | private slots: | |
|
42 | /// Slot called when right clicking on an variable in the table (displays a menu) | |
|
43 | void onTableMenuRequested(const QPoint &pos) noexcept; | |
|
24 | 44 | }; |
|
25 | 45 | |
|
26 | 46 | #endif // SCIQLOP_VARIABLEINSPECTORWIDGET_H |
@@ -1,53 +1,53 | |||
|
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 | class QMenu; | |
|
11 | 12 | class Variable; |
|
12 | 13 | class VisualizationTabWidget; |
|
13 | 14 | |
|
14 | 15 | namespace Ui { |
|
15 | 16 | class VisualizationWidget; |
|
16 | 17 | } // namespace Ui |
|
17 | 18 | |
|
18 | 19 | class VisualizationWidget : public QWidget, public IVisualizationWidget { |
|
19 | 20 | Q_OBJECT |
|
20 | 21 | |
|
21 | 22 | public: |
|
22 | 23 | explicit VisualizationWidget(QWidget *parent = 0); |
|
23 | 24 | virtual ~VisualizationWidget(); |
|
24 | 25 | |
|
25 | 26 | /// Add a zone widget |
|
26 | 27 | virtual void addTab(VisualizationTabWidget *tabWidget); |
|
27 | 28 | |
|
28 | 29 | /// Create a tab using a Variable |
|
29 | 30 | VisualizationTabWidget *createTab(); |
|
30 | 31 | |
|
31 | 32 | /// Remove a tab |
|
32 | 33 | void removeTab(VisualizationTabWidget *tab); |
|
33 | 34 | |
|
34 | 35 | // IVisualizationWidget interface |
|
35 | 36 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
36 | 37 | bool canDrop(const Variable &variable) const override; |
|
37 | 38 | void close() override; |
|
38 | 39 | QString name() const override; |
|
39 | 40 | |
|
40 | 41 | public slots: |
|
41 | 42 | /** |
|
42 | * Displays a variable in a new graph of a new zone of the current tab | |
|
43 | * @param variable the variable to display | |
|
44 | * @todo this is a temporary method that will be replaced by own actions for each type of | |
|
45 | * visualization widget | |
|
43 | * Attaches to a menu the menu relating to the visualization of a variable | |
|
44 | * @param menu the parent menu of the generated menu | |
|
45 | * @param variable the variable for which to generate the menu | |
|
46 | 46 | */ |
|
47 |
void |
|
|
47 | void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept; | |
|
48 | 48 | |
|
49 | 49 | private: |
|
50 | 50 | Ui::VisualizationWidget *ui; |
|
51 | 51 | }; |
|
52 | 52 | |
|
53 | 53 | #endif // VISUALIZATIONWIDGET_H |
@@ -1,26 +1,50 | |||
|
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 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
12 | 12 | : QWidget{parent}, ui{new Ui::VariableInspectorWidget} |
|
13 | 13 | { |
|
14 | 14 | ui->setupUi(this); |
|
15 | 15 | |
|
16 | 16 | // Sets model for table |
|
17 | 17 | auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
18 | 18 | sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
19 | 19 | |
|
20 | 20 | ui->tableView->setModel(sortFilterModel); |
|
21 | ||
|
22 | // Connection to show a menu when right clicking on the tree | |
|
23 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | |
|
24 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, | |
|
25 | &VariableInspectorWidget::onTableMenuRequested); | |
|
21 | 26 | } |
|
22 | 27 | |
|
23 | 28 | VariableInspectorWidget::~VariableInspectorWidget() |
|
24 | 29 | { |
|
25 | 30 | delete ui; |
|
26 | 31 | } |
|
32 | ||
|
33 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | |
|
34 | { | |
|
35 | auto selectedIndex = ui->tableView->indexAt(pos); | |
|
36 | if (selectedIndex.isValid()) { | |
|
37 | // Gets the model to retrieve the underlying selected variable | |
|
38 | auto model = sqpApp->variableController().variableModel(); | |
|
39 | if (auto selectedVariable = model->variable(selectedIndex.row())) { | |
|
40 | QMenu tableMenu{}; | |
|
41 | ||
|
42 | // Emit a signal so that potential receivers can populate the menu before displaying it | |
|
43 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariable); | |
|
44 | ||
|
45 | if (!tableMenu.isEmpty()) { | |
|
46 | tableMenu.exec(mapToGlobal(pos)); | |
|
47 | } | |
|
48 | } | |
|
49 | } | |
|
50 | } |
@@ -1,136 +1,131 | |||
|
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 | #include "Visualization/operations/GenerateVariableMenuOperation.h" | |
|
6 | 7 | #include "Visualization/qcustomplot.h" |
|
7 | 8 | |
|
8 | 9 | #include "ui_VisualizationWidget.h" |
|
9 | 10 | |
|
10 | 11 | #include <QToolButton> |
|
11 | 12 | |
|
12 | 13 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
13 | 14 | |
|
14 | 15 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
15 | 16 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
16 | 17 | { |
|
17 | 18 | ui->setupUi(this); |
|
18 | 19 | |
|
19 | 20 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
20 | 21 | addTabViewButton->setText(tr("Add View")); |
|
21 | 22 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
22 | 23 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
23 | 24 | |
|
24 | 25 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
25 | 26 | |
|
26 | 27 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
27 | 28 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
28 | 29 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
29 | 30 | tabViewCornerWidget->setMinimumHeight(height); |
|
30 | 31 | tabViewCornerWidget->setMinimumWidth(width); |
|
31 | 32 | ui->tabWidget->setMinimumHeight(height); |
|
32 | 33 | ui->tabWidget->setMinimumWidth(width); |
|
33 | 34 | }; |
|
34 | 35 | |
|
35 | 36 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
36 | 37 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
37 | 38 | ui->tabWidget}; |
|
38 | 39 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
39 | 40 | if (ui->tabWidget->count() > 0) { |
|
40 | 41 | enableMinimumCornerWidgetSize(false); |
|
41 | 42 | } |
|
42 | 43 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
43 | 44 | }; |
|
44 | 45 | |
|
45 | 46 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
46 | 47 | if (ui->tabWidget->count() == 1) { |
|
47 | 48 | enableMinimumCornerWidgetSize(true); |
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | ui->tabWidget->removeTab(index); |
|
51 | 52 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
52 | 53 | |
|
53 | 54 | }; |
|
54 | 55 | |
|
55 | 56 | ui->tabWidget->setTabsClosable(true); |
|
56 | 57 | |
|
57 | 58 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
58 | 59 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
59 | 60 | |
|
60 | 61 | // Adds default tab |
|
61 | 62 | addTabView(); |
|
62 | 63 | } |
|
63 | 64 | |
|
64 | 65 | VisualizationWidget::~VisualizationWidget() |
|
65 | 66 | { |
|
66 | 67 | delete ui; |
|
67 | 68 | } |
|
68 | 69 | |
|
69 | 70 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
70 | 71 | { |
|
71 | 72 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
72 | 73 | // lambda function (in the constructor) |
|
73 | 74 | } |
|
74 | 75 | |
|
75 | 76 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
76 | 77 | { |
|
77 | 78 | } |
|
78 | 79 | |
|
79 | 80 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
80 | 81 | { |
|
81 | 82 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
82 | 83 | // lambda function (in the constructor) |
|
83 | 84 | } |
|
84 | 85 | |
|
85 | 86 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
86 | 87 | { |
|
87 | 88 | if (visitor) { |
|
88 | 89 | visitor->visitEnter(this); |
|
89 | 90 | |
|
90 | 91 | // Apply visitor for tab children |
|
91 | 92 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
92 | 93 | // Widgets different from tabs are not visited (no action) |
|
93 | 94 | if (auto visualizationTabWidget |
|
94 | 95 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
95 | 96 | visualizationTabWidget->accept(visitor); |
|
96 | 97 | } |
|
97 | 98 | } |
|
98 | 99 | |
|
99 | 100 | visitor->visitLeave(this); |
|
100 | 101 | } |
|
101 | 102 | else { |
|
102 | 103 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); |
|
103 | 104 | } |
|
104 | 105 | } |
|
105 | 106 | |
|
106 | 107 | bool VisualizationWidget::canDrop(const Variable &variable) const |
|
107 | 108 | { |
|
108 | 109 | // The main widget can never accomodate a variable |
|
109 | 110 | Q_UNUSED(variable); |
|
110 | 111 | return false; |
|
111 | 112 | } |
|
112 | 113 | |
|
113 | 114 | void VisualizationWidget::close() |
|
114 | 115 | { |
|
115 | 116 | // The main view cannot be directly closed. |
|
116 | 117 | return; |
|
117 | 118 | } |
|
118 | 119 | |
|
119 | 120 | QString VisualizationWidget::name() const |
|
120 | 121 | { |
|
121 | 122 | return QStringLiteral("MainView"); |
|
122 | 123 | } |
|
123 | 124 | |
|
124 | void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept | |
|
125 | void VisualizationWidget::attachVariableMenu(QMenu *menu, | |
|
126 | std::shared_ptr<Variable> variable) noexcept | |
|
125 | 127 | { |
|
126 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { | |
|
127 | if (!currentTab->createZone(variable)) { | |
|
128 | qCCritical(LOG_VisualizationWidget()) | |
|
129 | << tr("Can't display the variable : can't create a new zone in the current tab"); | |
|
130 | } | |
|
131 | } | |
|
132 | else { | |
|
133 | qCCritical(LOG_VisualizationWidget()) | |
|
134 | << tr("Can't display the variable : there is no current tab"); | |
|
135 | } | |
|
128 | // Generates the actions that make it possible to visualize the variable | |
|
129 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |
|
130 | accept(&generateVariableMenuOperation); | |
|
136 | 131 | } |
General Comments 0
You need to be logged in to leave comments.
Login now