##// END OF EJS Templates
drop of zone on the time widget
trabillard -
r936:672c298824bc
parent child
Show More
@@ -23,7 +23,7 signals:
23 void dropOccuredOnWidget(VisualizationDragWidget *dragWidget, const QMimeData *mimeData);
23 void dropOccuredOnWidget(VisualizationDragWidget *dragWidget, const QMimeData *mimeData);
24
24
25 public:
25 public:
26 enum class DropBehavior { Inserted, Merged, InsertedAndMerged };
26 enum class DropBehavior { Inserted, Merged, InsertedAndMerged, Forbidden };
27 using AcceptMimeDataFunction = std::function<bool(const QMimeData *mimeData)>;
27 using AcceptMimeDataFunction = std::function<bool(const QMimeData *mimeData)>;
28
28
29 VisualizationDragDropContainer(QWidget *parent = nullptr);
29 VisualizationDragDropContainer(QWidget *parent = nullptr);
@@ -31,7 +31,7 public:
31 void addDragWidget(VisualizationDragWidget *dragWidget);
31 void addDragWidget(VisualizationDragWidget *dragWidget);
32 void insertDragWidget(int index, VisualizationDragWidget *dragWidget);
32 void insertDragWidget(int index, VisualizationDragWidget *dragWidget);
33
33
34 void addAcceptedMimeType(const QString &mimeType, DropBehavior behavior);
34 void setMimeType(const QString &mimeType, DropBehavior behavior);
35
35
36 int countDragWidget() const;
36 int countDragWidget() const;
37
37
@@ -36,13 +36,28 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
36
36
37 bool acceptMimeData(const QMimeData *data) const
37 bool acceptMimeData(const QMimeData *data) const
38 {
38 {
39 for (const auto &type : m_AcceptedMimeTypes.keys()) {
39 auto accepted = false;
40 if (data->hasFormat(type) && m_AcceptMimeDataFun(data)) {
40 for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd();
41 return true;
41 ++it) {
42 const auto &type = it.key();
43 const auto &behavior = it.value();
44
45 if (data->hasFormat(type)) {
46 if (behavior != DropBehavior::Forbidden) {
47 accepted = true;
48 }
49 else {
50 accepted = false;
51 break;
52 }
42 }
53 }
43 }
54 }
44
55
45 return false;
56 if (accepted) {
57 accepted = m_AcceptMimeDataFun(data);
58 }
59
60 return accepted;
46 }
61 }
47
62
48 bool allowMergeForMimeData(const QMimeData *data) const
63 bool allowMergeForMimeData(const QMimeData *data) const
@@ -153,7 +168,7 void VisualizationDragDropContainer::insertDragWidget(int index,
153 &VisualizationDragDropContainer::startDrag);
168 &VisualizationDragDropContainer::startDrag);
154 }
169 }
155
170
156 void VisualizationDragDropContainer::addAcceptedMimeType(
171 void VisualizationDragDropContainer::setMimeType(
157 const QString &mimeType, VisualizationDragDropContainer::DropBehavior behavior)
172 const QString &mimeType, VisualizationDragDropContainer::DropBehavior behavior)
158 {
173 {
159 impl->m_AcceptedMimeTypes[mimeType] = behavior;
174 impl->m_AcceptedMimeTypes[mimeType] = behavior;
@@ -80,12 +80,12 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par
80
80
81 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone");
81 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone");
82 ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5);
82 ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5);
83 ui->dragDropContainer->addAcceptedMimeType(
83 ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH,
84 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
84 VisualizationDragDropContainer::DropBehavior::Inserted);
85 ui->dragDropContainer->addAcceptedMimeType(
85 ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE,
86 MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted);
86 VisualizationDragDropContainer::DropBehavior::Inserted);
87 ui->dragDropContainer->addAcceptedMimeType(
87 ui->dragDropContainer->setMimeType(MIME_TYPE_VARIABLE_LIST,
88 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted);
88 VisualizationDragDropContainer::DropBehavior::Inserted);
89
89
90 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
90 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
91 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
91 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
@@ -102,12 +102,14 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
102 ui->zoneNameLabel->setText(name);
102 ui->zoneNameLabel->setText(name);
103
103
104 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Graph);
104 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Graph);
105 ui->dragDropContainer->addAcceptedMimeType(
105 ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH,
106 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
106 VisualizationDragDropContainer::DropBehavior::Inserted);
107 ui->dragDropContainer->addAcceptedMimeType(
107 ui->dragDropContainer->setMimeType(
108 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
108 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
109 ui->dragDropContainer->addAcceptedMimeType(
109 ui->dragDropContainer->setMimeType(MIME_TYPE_TIME_RANGE,
110 MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged);
110 VisualizationDragDropContainer::DropBehavior::Merged);
111 ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE,
112 VisualizationDragDropContainer::DropBehavior::Forbidden);
111 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
113 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
112 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
114 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
113 ui->dragDropContainer);
115 ui->dragDropContainer);
@@ -332,6 +334,11 QMimeData *VisualizationZoneWidget::mimeData() const
332 auto mimeData = new QMimeData;
334 auto mimeData = new QMimeData;
333 mimeData->setData(MIME_TYPE_ZONE, QByteArray{});
335 mimeData->setData(MIME_TYPE_ZONE, QByteArray{});
334
336
337 if (auto firstGraph = impl->firstGraph(this)) {
338 auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange());
339 mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData);
340 }
341
335 return mimeData;
342 return mimeData;
336 }
343 }
337
344
General Comments 0
You need to be logged in to leave comments. Login now