##// END OF EJS Templates
Drop of variable, graph and zones on the time widget
trabillard -
r884:e439cb403ff9
parent child
Show More
@@ -64,8 +64,11 public:
64 64 */
65 65 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
66 66
67 QByteArray mimeDataForProductsData(const QVariantList &productsData) const;
68 QVariantList productsDataForMimeData(const QByteArray &mimeData) const;
67 /// Returns the MIME data associated to a list of product meta data
68 static QByteArray mimeDataForProductsData(const QVariantList &productsData);
69
70 /// Returns the list of meta data contained in a MIME data
71 static QVariantList productsDataForMimeData(const QByteArray &mimeData);
69 72
70 73 public slots:
71 74 /// Manage init/end of the controller
@@ -23,6 +23,12 public:
23 23
24 24 SqpRange dateTime() const noexcept;
25 25
26 /// Returns the MIME data associated to a time range
27 static QByteArray mimeDataForTimeRange(const SqpRange &timeRange);
28
29 /// Returns the time range contained in a MIME data
30 static SqpRange timeRangeForMimeData(const QByteArray &mimeData);
31
26 32 signals:
27 33 /// Signal emitted to notify that time parameters has beed updated
28 34 void timeUpdated(SqpRange time);
@@ -68,7 +68,10 public:
68 68 */
69 69 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
70 70
71 /// Returns the MIME data associated to a list of variables
71 72 QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const;
73
74 /// Returns the list of variables contained in a MIME data
72 75 QList<std::shared_ptr<Variable> > variablesForMimeData(const QByteArray &mimeData) const;
73 76
74 77 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
@@ -139,7 +139,7 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
139 139 }
140 140 }
141 141
142 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
142 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData)
143 143 {
144 144 QByteArray encodedData;
145 145 QDataStream stream{&encodedData, QIODevice::WriteOnly};
@@ -149,7 +149,7 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &pro
149 149 return encodedData;
150 150 }
151 151
152 QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData) const
152 QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData)
153 153 {
154 154 QDataStream stream{mimeData};
155 155
@@ -1,5 +1,7
1 1 #include "Time/TimeController.h"
2 2
3 #include <QDataStream>
4
3 5 Q_LOGGING_CATEGORY(LOG_TimeController, "TimeController")
4 6
5 7 struct TimeController::TimeControllerPrivate {
@@ -18,6 +20,26 SqpRange TimeController::dateTime() const noexcept
18 20 return impl->m_DateTime;
19 21 }
20 22
23 QByteArray TimeController::mimeDataForTimeRange(const SqpRange &timeRange)
24 {
25 QByteArray encodedData;
26 QDataStream stream{&encodedData, QIODevice::WriteOnly};
27
28 stream << timeRange.m_TStart << timeRange.m_TEnd;
29
30 return encodedData;
31 }
32
33 SqpRange TimeController::timeRangeForMimeData(const QByteArray &mimeData)
34 {
35 QDataStream stream{mimeData};
36
37 SqpRange timeRange;
38 stream >> timeRange.m_TStart >> timeRange.m_TEnd;
39
40 return timeRange;
41 }
42
21 43 void TimeController::onTimeToUpdate(SqpRange dateTime)
22 44 {
23 45 impl->m_DateTime = dateTime;
@@ -8,7 +8,9
8 8
9 9 #include <Data/IDataSeries.h>
10 10
11 #include <QDataStream>
11 #include <DataSource/DataSourceController.h>
12 #include <Time/TimeController.h>
13
12 14 #include <QMimeData>
13 15 #include <QSize>
14 16 #include <unordered_map>
@@ -278,7 +280,7 Qt::DropActions VariableModel::supportedDragActions() const
278 280
279 281 QStringList VariableModel::mimeTypes() const
280 282 {
281 return {MIME_TYPE_VARIABLE_LIST};
283 return {MIME_TYPE_VARIABLE_LIST, MIME_TYPE_TIME_RANGE};
282 284 }
283 285
284 286 QMimeData *VariableModel::mimeData(const QModelIndexList &indexes) const
@@ -287,17 +289,31 QMimeData *VariableModel::mimeData(const QModelIndexList &indexes) const
287 289
288 290 QList<std::shared_ptr<Variable> > variableList;
289 291
292
293 SqpRange firstTimeRange;
290 294 for (const auto &index : indexes) {
291 295 if (index.column() == 0) { // only the first column
292 296 auto variable = impl->m_Variables.at(index.row());
293 297 if (variable.get() && index.isValid()) {
298
299 if (variableList.isEmpty()) {
300 // Gets the range of the first variable
301 firstTimeRange = std::move(variable->range());
302 }
303
294 304 variableList << variable;
295 305 }
296 306 }
297 307 }
298 308
299 auto encodedData = impl->m_VariableController->mimeDataForVariables(variableList);
300 mimeData->setData(MIME_TYPE_VARIABLE_LIST, encodedData);
309 auto variablesEncodedData = impl->m_VariableController->mimeDataForVariables(variableList);
310 mimeData->setData(MIME_TYPE_VARIABLE_LIST, variablesEncodedData);
311
312 if (variableList.count() == 1) {
313 // No time range MIME data if multiple variables are dragged
314 auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange);
315 mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData);
316 }
301 317
302 318 return mimeData;
303 319 }
@@ -315,10 +331,9 bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, i
315 331 auto dropDone = false;
316 332
317 333 if (data->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
318 QDataStream stream(data->data(MIME_TYPE_PRODUCT_LIST));
319 334
320 QVariantList productList;
321 stream >> productList;
335 auto productList
336 = DataSourceController::productsDataForMimeData(data->data(MIME_TYPE_PRODUCT_LIST));
322 337
323 338 for (auto metaData : productList) {
324 339 emit requestVariable(metaData.toHash());
@@ -16,6 +16,8 public:
16 16 explicit TimeWidget(QWidget *parent = 0);
17 17 virtual ~TimeWidget();
18 18
19 void setTimeRange(SqpRange time);
20
19 21 signals:
20 22 /// Signal emitted when the time parameters has beed updated
21 23 void timeUpdated(SqpRange time);
@@ -24,6 +26,11 public slots:
24 26 /// slot called when time parameters update has ben requested
25 27 void onTimeUpdateRequested();
26 28
29 protected:
30 void dragEnterEvent(QDragEnterEvent *event) override;
31 void dragLeaveEvent(QDragLeaveEvent *event) override;
32 void dropEvent(QDropEvent *event) override;
33
27 34
28 35 private:
29 36 Ui::TimeWidget *ui;
@@ -2,9 +2,15
2 2 #include "ui_TimeWidget.h"
3 3
4 4 #include <Common/DateUtils.h>
5 #include <Common/MimeTypesDef.h>
6
5 7 #include <SqpApplication.h>
6 8 #include <Time/TimeController.h>
7 9
10 #include <QDragEnterEvent>
11 #include <QDropEvent>
12 #include <QMimeData>
13
8 14 TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget}
9 15 {
10 16 ui->setupUi(this);
@@ -41,6 +47,15 TimeWidget::~TimeWidget()
41 47 delete ui;
42 48 }
43 49
50 void TimeWidget::setTimeRange(SqpRange time)
51 {
52 auto startDateTime = DateUtils::dateTime(time.m_TStart);
53 auto endDateTime = DateUtils::dateTime(time.m_TEnd);
54
55 ui->startDateTimeEdit->setDateTime(startDateTime);
56 ui->endDateTimeEdit->setDateTime(endDateTime);
57 }
58
44 59 void TimeWidget::onTimeUpdateRequested()
45 60 {
46 61 auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()),
@@ -48,3 +63,34 void TimeWidget::onTimeUpdateRequested()
48 63
49 64 emit timeUpdated(std::move(dateTime));
50 65 }
66
67 void TimeWidget::dragEnterEvent(QDragEnterEvent *event)
68 {
69 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
70 event->acceptProposedAction();
71 setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}");
72 }
73 else {
74 event->ignore();
75 }
76 }
77
78 void TimeWidget::dragLeaveEvent(QDragLeaveEvent *event)
79 {
80 setStyleSheet(QString());
81 }
82
83 void TimeWidget::dropEvent(QDropEvent *event)
84 {
85 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
86 auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE);
87 auto timeRange = TimeController::timeRangeForMimeData(mimeData);
88
89 setTimeRange(timeRange);
90 }
91 else {
92 event->ignore();
93 }
94
95 setStyleSheet(QString());
96 }
@@ -12,6 +12,7
12 12 #include <DragDropHelper.h>
13 13 #include <Settings/SqpSettingsDefs.h>
14 14 #include <SqpApplication.h>
15 #include <Time/TimeController.h>
15 16 #include <Variable/Variable.h>
16 17 #include <Variable/VariableController.h>
17 18
@@ -235,6 +236,9 QMimeData *VisualizationGraphWidget::mimeData() const
235 236 auto mimeData = new QMimeData;
236 237 mimeData->setData(MIME_TYPE_GRAPH, QByteArray{});
237 238
239 auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange());
240 mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData);
241
238 242 return mimeData;
239 243 }
240 244
@@ -10,6 +10,7
10 10 #include "Common/VisualizationDef.h"
11 11
12 12 #include <Data/SqpRange.h>
13 #include <Time/TimeController.h>
13 14 #include <Variable/Variable.h>
14 15 #include <Variable/VariableController.h>
15 16
@@ -71,6 +72,21 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
71 72 QUuid m_SynchronisationGroupId;
72 73 std::unique_ptr<IGraphSynchronizer> m_Synchronizer;
73 74
75 // Returns the first graph in the zone or nullptr if there is no graph inside
76 VisualizationGraphWidget *firstGraph(const VisualizationZoneWidget *zoneWidget) const
77 {
78 VisualizationGraphWidget *firstGraph = nullptr;
79 auto layout = zoneWidget->ui->dragDropContainer->layout();
80 if (layout->count() > 0) {
81 if (auto visualizationGraphWidget
82 = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
83 firstGraph = visualizationGraphWidget;
84 }
85 }
86
87 return firstGraph;
88 }
89
74 90 void dropGraph(int index, VisualizationZoneWidget *zoneWidget);
75 91 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
76 92 VisualizationZoneWidget *zoneWidget);
@@ -238,15 +254,9 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
238 254 &VisualizationZoneWidget::onVariableAboutToBeRemoved);
239 255
240 256 auto range = SqpRange{};
241
242 // Apply visitor to graph children
243 auto layout = ui->dragDropContainer->layout();
244 if (layout->count() > 0) {
257 if (auto firstGraph = impl->firstGraph(this)) {
245 258 // Case of a new graph in a existant zone
246 if (auto visualizationGraphWidget
247 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
248 range = visualizationGraphWidget->graphRange();
249 }
259 range = firstGraph->graphRange();
250 260 }
251 261 else {
252 262 // Case of a new graph as the first of the zone
@@ -333,6 +343,11 QMimeData *VisualizationZoneWidget::mimeData() const
333 343 auto mimeData = new QMimeData;
334 344 mimeData->setData(MIME_TYPE_ZONE, QByteArray{});
335 345
346 if (const auto firstGraph = impl->firstGraph(this)) {
347 auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange());
348 mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData);
349 }
350
336 351 return mimeData;
337 352 }
338 353
@@ -16,9 +16,15
16 16 <verstretch>0</verstretch>
17 17 </sizepolicy>
18 18 </property>
19 <property name="acceptDrops">
20 <bool>true</bool>
21 </property>
19 22 <property name="windowTitle">
20 23 <string>Form</string>
21 24 </property>
25 <property name="styleSheet">
26 <string notr="true">b</string>
27 </property>
22 28 <layout class="QHBoxLayout" name="horizontalLayout_2">
23 29 <item>
24 30 <widget class="QLabel" name="label">
General Comments 3
Under Review
author

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * A core/tests/meson.build
You need to be logged in to leave comments. Login now