##// END OF EJS Templates
drop of zone on the time widget
trabillard -
r977:672c298824bc
parent child
Show More
@@ -23,7 +23,7 signals:
23 23 void dropOccuredOnWidget(VisualizationDragWidget *dragWidget, const QMimeData *mimeData);
24 24
25 25 public:
26 enum class DropBehavior { Inserted, Merged, InsertedAndMerged };
26 enum class DropBehavior { Inserted, Merged, InsertedAndMerged, Forbidden };
27 27 using AcceptMimeDataFunction = std::function<bool(const QMimeData *mimeData)>;
28 28
29 29 VisualizationDragDropContainer(QWidget *parent = nullptr);
@@ -31,7 +31,7 public:
31 31 void addDragWidget(VisualizationDragWidget *dragWidget);
32 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 36 int countDragWidget() const;
37 37
@@ -36,13 +36,28 struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate {
36 36
37 37 bool acceptMimeData(const QMimeData *data) const
38 38 {
39 for (const auto &type : m_AcceptedMimeTypes.keys()) {
40 if (data->hasFormat(type) && m_AcceptMimeDataFun(data)) {
41 return true;
39 auto accepted = false;
40 for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd();
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 63 bool allowMergeForMimeData(const QMimeData *data) const
@@ -153,7 +168,7 void VisualizationDragDropContainer::insertDragWidget(int index,
153 168 &VisualizationDragDropContainer::startDrag);
154 169 }
155 170
156 void VisualizationDragDropContainer::addAcceptedMimeType(
171 void VisualizationDragDropContainer::setMimeType(
157 172 const QString &mimeType, VisualizationDragDropContainer::DropBehavior behavior)
158 173 {
159 174 impl->m_AcceptedMimeTypes[mimeType] = behavior;
@@ -80,12 +80,12 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par
80 80
81 81 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone");
82 82 ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5);
83 ui->dragDropContainer->addAcceptedMimeType(
84 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
85 ui->dragDropContainer->addAcceptedMimeType(
86 MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted);
87 ui->dragDropContainer->addAcceptedMimeType(
88 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted);
83 ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH,
84 VisualizationDragDropContainer::DropBehavior::Inserted);
85 ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE,
86 VisualizationDragDropContainer::DropBehavior::Inserted);
87 ui->dragDropContainer->setMimeType(MIME_TYPE_VARIABLE_LIST,
88 VisualizationDragDropContainer::DropBehavior::Inserted);
89 89
90 90 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
91 91 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
@@ -102,12 +102,14 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *p
102 102 ui->zoneNameLabel->setText(name);
103 103
104 104 ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Graph);
105 ui->dragDropContainer->addAcceptedMimeType(
106 MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted);
107 ui->dragDropContainer->addAcceptedMimeType(
105 ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH,
106 VisualizationDragDropContainer::DropBehavior::Inserted);
107 ui->dragDropContainer->setMimeType(
108 108 MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged);
109 ui->dragDropContainer->addAcceptedMimeType(
110 MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged);
109 ui->dragDropContainer->setMimeType(MIME_TYPE_TIME_RANGE,
110 VisualizationDragDropContainer::DropBehavior::Merged);
111 ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE,
112 VisualizationDragDropContainer::DropBehavior::Forbidden);
111 113 ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) {
112 114 return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData,
113 115 ui->dragDropContainer);
@@ -332,6 +334,11 QMimeData *VisualizationZoneWidget::mimeData() const
332 334 auto mimeData = new QMimeData;
333 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 342 return mimeData;
336 343 }
337 344
General Comments 1
Under Review
author

Auto status change to "Under Review"

You need to be logged in to leave comments. Login now