@@ -0,0 +1,32 | |||
|
1 | #ifndef SCIQLOP_DRAGDROPSCROLLER_H | |
|
2 | #define SCIQLOP_DRAGDROPSCROLLER_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QScrollArea> | |
|
6 | ||
|
7 | /** | |
|
8 | * @brief Event filter class which manage the scroll of QScrollArea during a drag&drop operation. | |
|
9 | * @note A QScrollArea inside an other QScrollArea is not fully supported. | |
|
10 | */ | |
|
11 | class DragDropScroller : public QObject { | |
|
12 | Q_OBJECT | |
|
13 | ||
|
14 | public: | |
|
15 | DragDropScroller(QObject *parent = nullptr); | |
|
16 | ||
|
17 | void addScrollArea(QScrollArea *scrollArea); | |
|
18 | void removeScrollArea(QScrollArea *scrollArea); | |
|
19 | ||
|
20 | protected: | |
|
21 | bool eventFilter(QObject *obj, QEvent *event); | |
|
22 | ||
|
23 | private: | |
|
24 | class DragDropScrollerPrivate; | |
|
25 | spimpl::unique_impl_ptr<DragDropScrollerPrivate> impl; | |
|
26 | ||
|
27 | private slots: | |
|
28 | void onTimer(); | |
|
29 | }; | |
|
30 | ||
|
31 | ||
|
32 | #endif // SCIQLOP_DRAGDROPSCROLLER_H |
@@ -0,0 +1,29 | |||
|
1 | #ifndef SCIQLOP_DRAGDROPTABSWITCHER_H | |
|
2 | #define SCIQLOP_DRAGDROPTABSWITCHER_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | ||
|
6 | #include <QLoggingCategory> | |
|
7 | #include <QTabBar> | |
|
8 | ||
|
9 | Q_DECLARE_LOGGING_CATEGORY(LOG_DragDropTabSwitcher) | |
|
10 | ||
|
11 | class DragDropTabSwitcher : public QObject { | |
|
12 | Q_OBJECT | |
|
13 | ||
|
14 | public: | |
|
15 | DragDropTabSwitcher(QObject *parent = nullptr); | |
|
16 | ||
|
17 | void addTabBar(QTabBar *tabBar); | |
|
18 | void removeTabBar(QTabBar *tabBar); | |
|
19 | ||
|
20 | protected: | |
|
21 | bool eventFilter(QObject *obj, QEvent *event); | |
|
22 | ||
|
23 | private: | |
|
24 | class DragDropTabSwitcherPrivate; | |
|
25 | spimpl::unique_impl_ptr<DragDropTabSwitcherPrivate> impl; | |
|
26 | }; | |
|
27 | ||
|
28 | ||
|
29 | #endif // SCIQLOP_DRAGDROPTABSWITCHER_H |
@@ -0,0 +1,14 | |||
|
1 | #ifndef SCIQLOP_VARIABLEINSPECTORTABLEVIEW_H | |
|
2 | #define SCIQLOP_VARIABLEINSPECTORTABLEVIEW_H | |
|
3 | ||
|
4 | #include <QTableView> | |
|
5 | ||
|
6 | class VariableInspectorTableView : public QTableView { | |
|
7 | public: | |
|
8 | VariableInspectorTableView(QWidget *parent = nullptr); | |
|
9 | ||
|
10 | protected: | |
|
11 | void startDrag(Qt::DropActions supportedActions); | |
|
12 | }; | |
|
13 | ||
|
14 | #endif // SCIQLOP_VARIABLEINSPECTORTABLEVIEW_H |
@@ -0,0 +1,275 | |||
|
1 | #include "DragAndDrop/DragDropHelper.h" | |
|
2 | #include "DragAndDrop/DragDropScroller.h" | |
|
3 | #include "DragAndDrop/DragDropTabSwitcher.h" | |
|
4 | #include "SqpApplication.h" | |
|
5 | #include "Visualization/VisualizationDragDropContainer.h" | |
|
6 | #include "Visualization/VisualizationDragWidget.h" | |
|
7 | #include "Visualization/VisualizationWidget.h" | |
|
8 | #include "Visualization/operations/FindVariableOperation.h" | |
|
9 | ||
|
10 | #include "Variable/Variable.h" | |
|
11 | #include "Variable/VariableController.h" | |
|
12 | ||
|
13 | #include "Common/MimeTypesDef.h" | |
|
14 | #include "Common/VisualizationDef.h" | |
|
15 | ||
|
16 | #include <QDir> | |
|
17 | #include <QLabel> | |
|
18 | #include <QUrl> | |
|
19 | #include <QVBoxLayout> | |
|
20 | ||
|
21 | ||
|
22 | Q_LOGGING_CATEGORY(LOG_DragDropHelper, "DragDropHelper") | |
|
23 | ||
|
24 | ||
|
25 | struct DragDropHelper::DragDropHelperPrivate { | |
|
26 | ||
|
27 | VisualizationDragWidget *m_CurrentDragWidget = nullptr; | |
|
28 | std::unique_ptr<QWidget> m_PlaceHolder = nullptr; | |
|
29 | QLabel *m_PlaceHolderLabel; | |
|
30 | QWidget *m_PlaceBackground; | |
|
31 | std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr; | |
|
32 | std::unique_ptr<DragDropTabSwitcher> m_DragDropTabSwitcher = nullptr; | |
|
33 | QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using | |
|
34 | // QTemporaryFile to have a name which is not generated. | |
|
35 | ||
|
36 | VisualizationDragWidget *m_HighlightedDragWidget = nullptr; | |
|
37 | ||
|
38 | QMetaObject::Connection m_DragWidgetDestroyedConnection; | |
|
39 | QMetaObject::Connection m_HighlightedWidgetDestroyedConnection; | |
|
40 | ||
|
41 | explicit DragDropHelperPrivate() | |
|
42 | : m_PlaceHolder{std::make_unique<QWidget>()}, | |
|
43 | m_DragDropScroller{std::make_unique<DragDropScroller>()}, | |
|
44 | m_DragDropTabSwitcher{std::make_unique<DragDropTabSwitcher>()} | |
|
45 | { | |
|
46 | ||
|
47 | auto layout = new QVBoxLayout{m_PlaceHolder.get()}; | |
|
48 | layout->setSpacing(0); | |
|
49 | layout->setContentsMargins(0, 0, 0, 0); | |
|
50 | ||
|
51 | m_PlaceHolderLabel = new QLabel{"", m_PlaceHolder.get()}; | |
|
52 | m_PlaceHolderLabel->setMinimumHeight(25); | |
|
53 | layout->addWidget(m_PlaceHolderLabel); | |
|
54 | ||
|
55 | m_PlaceBackground = new QWidget{m_PlaceHolder.get()}; | |
|
56 | m_PlaceBackground->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
|
57 | layout->addWidget(m_PlaceBackground); | |
|
58 | ||
|
59 | sqpApp->installEventFilter(m_DragDropScroller.get()); | |
|
60 | sqpApp->installEventFilter(m_DragDropTabSwitcher.get()); | |
|
61 | ||
|
62 | m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png"); | |
|
63 | } | |
|
64 | ||
|
65 | void preparePlaceHolder(DragDropHelper::PlaceHolderType type, const QString &topLabelText) const | |
|
66 | { | |
|
67 | if (m_CurrentDragWidget) { | |
|
68 | m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size()); | |
|
69 | m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy()); | |
|
70 | } | |
|
71 | else { | |
|
72 | // Configuration of the placeHolder when there is no dragWidget | |
|
73 | // (for instance with a drag from a variable) | |
|
74 | ||
|
75 | m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT); | |
|
76 | m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
|
77 | } | |
|
78 | ||
|
79 | switch (type) { | |
|
80 | case DragDropHelper::PlaceHolderType::Graph: | |
|
81 | m_PlaceBackground->setStyleSheet( | |
|
82 | "background-color: #BBD5EE; border: 1px solid #2A7FD4"); | |
|
83 | break; | |
|
84 | case DragDropHelper::PlaceHolderType::Zone: | |
|
85 | case DragDropHelper::PlaceHolderType::Default: | |
|
86 | m_PlaceBackground->setStyleSheet( | |
|
87 | "background-color: #BBD5EE; border: 2px solid #2A7FD4"); | |
|
88 | m_PlaceHolderLabel->setStyleSheet("color: #2A7FD4"); | |
|
89 | break; | |
|
90 | } | |
|
91 | ||
|
92 | m_PlaceHolderLabel->setText(topLabelText); | |
|
93 | m_PlaceHolderLabel->setVisible(!topLabelText.isEmpty()); | |
|
94 | } | |
|
95 | }; | |
|
96 | ||
|
97 | ||
|
98 | DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()} {} | |
|
99 | ||
|
100 | DragDropHelper::~DragDropHelper() | |
|
101 | { | |
|
102 | QFile::remove(impl->m_ImageTempUrl); | |
|
103 | } | |
|
104 | ||
|
105 | void DragDropHelper::resetDragAndDrop() | |
|
106 | { | |
|
107 | setCurrentDragWidget(nullptr); | |
|
108 | impl->m_HighlightedDragWidget = nullptr; | |
|
109 | } | |
|
110 | ||
|
111 | void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget) | |
|
112 | { | |
|
113 | if (impl->m_CurrentDragWidget) { | |
|
114 | ||
|
115 | QObject::disconnect(impl->m_DragWidgetDestroyedConnection); | |
|
116 | } | |
|
117 | ||
|
118 | if (dragWidget) { | |
|
119 | // ensures the impl->m_CurrentDragWidget is reset when the widget is destroyed | |
|
120 | impl->m_DragWidgetDestroyedConnection | |
|
121 | = QObject::connect(dragWidget, &VisualizationDragWidget::destroyed, | |
|
122 | [this]() { impl->m_CurrentDragWidget = nullptr; }); | |
|
123 | } | |
|
124 | ||
|
125 | impl->m_CurrentDragWidget = dragWidget; | |
|
126 | } | |
|
127 | ||
|
128 | VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const | |
|
129 | { | |
|
130 | return impl->m_CurrentDragWidget; | |
|
131 | } | |
|
132 | ||
|
133 | QWidget &DragDropHelper::placeHolder() const | |
|
134 | { | |
|
135 | return *impl->m_PlaceHolder; | |
|
136 | } | |
|
137 | ||
|
138 | void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type, | |
|
139 | const QString &topLabelText) | |
|
140 | { | |
|
141 | removePlaceHolder(); | |
|
142 | impl->preparePlaceHolder(type, topLabelText); | |
|
143 | layout->insertWidget(index, impl->m_PlaceHolder.get()); | |
|
144 | impl->m_PlaceHolder->show(); | |
|
145 | } | |
|
146 | ||
|
147 | void DragDropHelper::removePlaceHolder() | |
|
148 | { | |
|
149 | auto parentWidget = impl->m_PlaceHolder->parentWidget(); | |
|
150 | if (parentWidget) { | |
|
151 | parentWidget->layout()->removeWidget(impl->m_PlaceHolder.get()); | |
|
152 | impl->m_PlaceHolder->setParent(nullptr); | |
|
153 | impl->m_PlaceHolder->hide(); | |
|
154 | } | |
|
155 | } | |
|
156 | ||
|
157 | bool DragDropHelper::isPlaceHolderSet() const | |
|
158 | { | |
|
159 | return impl->m_PlaceHolder->parentWidget(); | |
|
160 | } | |
|
161 | ||
|
162 | void DragDropHelper::addDragDropScrollArea(QScrollArea *scrollArea) | |
|
163 | { | |
|
164 | impl->m_DragDropScroller->addScrollArea(scrollArea); | |
|
165 | } | |
|
166 | ||
|
167 | void DragDropHelper::removeDragDropScrollArea(QScrollArea *scrollArea) | |
|
168 | { | |
|
169 | impl->m_DragDropScroller->removeScrollArea(scrollArea); | |
|
170 | } | |
|
171 | ||
|
172 | void DragDropHelper::addDragDropTabBar(QTabBar *tabBar) | |
|
173 | { | |
|
174 | impl->m_DragDropTabSwitcher->addTabBar(tabBar); | |
|
175 | } | |
|
176 | ||
|
177 | void DragDropHelper::removeDragDropTabBar(QTabBar *tabBar) | |
|
178 | { | |
|
179 | impl->m_DragDropTabSwitcher->removeTabBar(tabBar); | |
|
180 | } | |
|
181 | ||
|
182 | QUrl DragDropHelper::imageTemporaryUrl(const QImage &image) const | |
|
183 | { | |
|
184 | image.save(impl->m_ImageTempUrl); | |
|
185 | return QUrl::fromLocalFile(impl->m_ImageTempUrl); | |
|
186 | } | |
|
187 | ||
|
188 | void DragDropHelper::setHightlightedDragWidget(VisualizationDragWidget *dragWidget) | |
|
189 | { | |
|
190 | if (impl->m_HighlightedDragWidget) { | |
|
191 | impl->m_HighlightedDragWidget->highlightForMerge(false); | |
|
192 | QObject::disconnect(impl->m_HighlightedWidgetDestroyedConnection); | |
|
193 | } | |
|
194 | ||
|
195 | if (dragWidget) { | |
|
196 | dragWidget->highlightForMerge(true); | |
|
197 | ||
|
198 | // ensures the impl->m_HighlightedDragWidget is reset when the widget is destroyed | |
|
199 | impl->m_DragWidgetDestroyedConnection | |
|
200 | = QObject::connect(dragWidget, &VisualizationDragWidget::destroyed, | |
|
201 | [this]() { impl->m_HighlightedDragWidget = nullptr; }); | |
|
202 | } | |
|
203 | ||
|
204 | impl->m_HighlightedDragWidget = dragWidget; | |
|
205 | } | |
|
206 | ||
|
207 | VisualizationDragWidget *DragDropHelper::getHightlightedDragWidget() const | |
|
208 | { | |
|
209 | return impl->m_HighlightedDragWidget; | |
|
210 | } | |
|
211 | ||
|
212 | bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData, | |
|
213 | VisualizationDragDropContainer *dropContainer) | |
|
214 | { | |
|
215 | if (!mimeData || !dropContainer) { | |
|
216 | qCWarning(LOG_DragDropHelper()) << QObject::tr( | |
|
217 | "DragDropHelper::checkMimeDataForVisualization, invalid input parameters."); | |
|
218 | Q_ASSERT(false); | |
|
219 | return false; | |
|
220 | } | |
|
221 | ||
|
222 | auto result = false; | |
|
223 | ||
|
224 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
|
225 | auto variables = sqpApp->variableController().variablesForMimeData( | |
|
226 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
|
227 | ||
|
228 | if (variables.count() == 1) { | |
|
229 | ||
|
230 | auto variable = variables.first(); | |
|
231 | if (variable->dataSeries() != nullptr) { | |
|
232 | ||
|
233 | // Check that the variable is not already in a graph | |
|
234 | ||
|
235 | auto parent = dropContainer->parentWidget(); | |
|
236 | while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) { | |
|
237 | parent = parent->parentWidget(); // Search for the top level VisualizationWidget | |
|
238 | } | |
|
239 | ||
|
240 | if (parent) { | |
|
241 | auto visualizationWidget = static_cast<VisualizationWidget *>(parent); | |
|
242 | ||
|
243 | FindVariableOperation findVariableOperation{variable}; | |
|
244 | visualizationWidget->accept(&findVariableOperation); | |
|
245 | auto variableContainers = findVariableOperation.result(); | |
|
246 | if (variableContainers.empty()) { | |
|
247 | result = true; | |
|
248 | } | |
|
249 | else { | |
|
250 | // result = false: the variable already exist in the visualisation | |
|
251 | } | |
|
252 | } | |
|
253 | else { | |
|
254 | qCWarning(LOG_DragDropHelper()) << QObject::tr( | |
|
255 | "DragDropHelper::checkMimeDataForVisualization, the parent " | |
|
256 | "VisualizationWidget cannot be found. Cannot check if the variable is " | |
|
257 | "already used or not."); | |
|
258 | } | |
|
259 | } | |
|
260 | else { | |
|
261 | // result = false: the variable is not fully loaded | |
|
262 | } | |
|
263 | } | |
|
264 | else { | |
|
265 | // result = false: cannot drop multiple variables in the visualisation | |
|
266 | } | |
|
267 | } | |
|
268 | else { | |
|
269 | // Other MIME data | |
|
270 | // no special rules, accepted by default | |
|
271 | result = true; | |
|
272 | } | |
|
273 | ||
|
274 | return result; | |
|
275 | } |
@@ -0,0 +1,180 | |||
|
1 | #include "DragAndDrop/DragDropTabSwitcher.h" | |
|
2 | ||
|
3 | #include <QAbstractButton> | |
|
4 | #include <QDragEnterEvent> | |
|
5 | #include <QDragMoveEvent> | |
|
6 | #include <QTimer> | |
|
7 | ||
|
8 | #include "SqpApplication.h" | |
|
9 | ||
|
10 | Q_LOGGING_CATEGORY(LOG_DragDropTabSwitcher, "DragDropTabSwitcher") | |
|
11 | ||
|
12 | const int CHANGE_TAB_INTERVAL = 400; // time necessary over a tab to accept the switch | |
|
13 | const int SCROLL_BUTTON_AUTO_CLICK_INTERVAL | |
|
14 | = 500; // time between 2 auto clicks on a scroll button of the tab bar | |
|
15 | ||
|
16 | struct DragDropTabSwitcher::DragDropTabSwitcherPrivate { | |
|
17 | ||
|
18 | QList<QTabBar *> m_TabBarList; | |
|
19 | QTabBar *m_CurrentTabBar = nullptr; | |
|
20 | ||
|
21 | int m_HoveredTabIndex = -1; | |
|
22 | std::unique_ptr<QTimer> m_TabSwitchTimer = nullptr; | |
|
23 | ||
|
24 | QAbstractButton *m_HoveredScrollButton = nullptr; | |
|
25 | std::unique_ptr<QTimer> m_ScrollButtonsTimer = nullptr; | |
|
26 | ||
|
27 | explicit DragDropTabSwitcherPrivate() | |
|
28 | : m_TabSwitchTimer{std::make_unique<QTimer>()}, | |
|
29 | m_ScrollButtonsTimer{std::make_unique<QTimer>()} | |
|
30 | { | |
|
31 | m_TabSwitchTimer->setSingleShot(true); | |
|
32 | m_TabSwitchTimer->setInterval(CHANGE_TAB_INTERVAL); | |
|
33 | QObject::connect(m_TabSwitchTimer.get(), &QTimer::timeout, [this]() { | |
|
34 | if (m_CurrentTabBar) { | |
|
35 | m_CurrentTabBar->setCurrentIndex(m_HoveredTabIndex); | |
|
36 | } | |
|
37 | else { | |
|
38 | qCWarning(LOG_DragDropTabSwitcher()) << "DragDropTabSwitcherPrivate::timeout: " | |
|
39 | "Cannot select a new tab: unknown current " | |
|
40 | "tab bar."; | |
|
41 | } | |
|
42 | }); | |
|
43 | ||
|
44 | m_ScrollButtonsTimer->setInterval(SCROLL_BUTTON_AUTO_CLICK_INTERVAL); | |
|
45 | QObject::connect(m_ScrollButtonsTimer.get(), &QTimer::timeout, [this]() { | |
|
46 | if (m_HoveredScrollButton) { | |
|
47 | m_HoveredScrollButton->animateClick(); | |
|
48 | } | |
|
49 | else { | |
|
50 | qCWarning(LOG_DragDropTabSwitcher()) | |
|
51 | << "DragDropTabSwitcherPrivate::timeoutScroll: " | |
|
52 | "Unknown scroll button"; | |
|
53 | } | |
|
54 | }); | |
|
55 | } | |
|
56 | ||
|
57 | bool isScrollTabButton(QAbstractButton *button, QTabBar *tabBar) | |
|
58 | { | |
|
59 | auto isNextOrPreviousTabButton = true; | |
|
60 | ||
|
61 | if (tabBar->isAncestorOf(button)) { | |
|
62 | for (auto i = 0; i < tabBar->count(); ++i) { | |
|
63 | if (tabBar->tabButton(i, QTabBar::RightSide) == button | |
|
64 | || tabBar->tabButton(i, QTabBar::LeftSide) == button) { | |
|
65 | isNextOrPreviousTabButton = false; | |
|
66 | break; | |
|
67 | } | |
|
68 | } | |
|
69 | } | |
|
70 | else { | |
|
71 | isNextOrPreviousTabButton = false; | |
|
72 | } | |
|
73 | ||
|
74 | return isNextOrPreviousTabButton; | |
|
75 | } | |
|
76 | ||
|
77 | QAbstractButton *tabScrollButtonAt(const QPoint &pos, QTabBar *tabBar) | |
|
78 | { | |
|
79 | ||
|
80 | auto globalPos = tabBar->mapToGlobal(pos); | |
|
81 | ||
|
82 | auto widgetUnderMouse = sqpApp->widgetAt(globalPos); | |
|
83 | if (auto btn = qobject_cast<QAbstractButton *>(widgetUnderMouse)) { | |
|
84 | ||
|
85 | if (isScrollTabButton(btn, tabBar)) { | |
|
86 | return btn; | |
|
87 | } | |
|
88 | } | |
|
89 | ||
|
90 | return nullptr; | |
|
91 | } | |
|
92 | }; | |
|
93 | ||
|
94 | DragDropTabSwitcher::DragDropTabSwitcher(QObject *parent) | |
|
95 | : QObject(parent), impl{spimpl::make_unique_impl<DragDropTabSwitcherPrivate>()} | |
|
96 | { | |
|
97 | } | |
|
98 | ||
|
99 | void DragDropTabSwitcher::addTabBar(QTabBar *tabBar) | |
|
100 | { | |
|
101 | impl->m_TabBarList << tabBar; | |
|
102 | tabBar->setAcceptDrops(true); | |
|
103 | } | |
|
104 | ||
|
105 | void DragDropTabSwitcher::removeTabBar(QTabBar *tabBar) | |
|
106 | { | |
|
107 | impl->m_TabBarList.removeAll(tabBar); | |
|
108 | tabBar->setAcceptDrops(false); | |
|
109 | } | |
|
110 | ||
|
111 | bool DragDropTabSwitcher::eventFilter(QObject *obj, QEvent *event) | |
|
112 | { | |
|
113 | if (event->type() == QEvent::DragMove) { | |
|
114 | ||
|
115 | if (impl->m_CurrentTabBar) { | |
|
116 | ||
|
117 | QWidget *w = static_cast<QWidget *>(obj); | |
|
118 | if (!impl->m_CurrentTabBar->isAncestorOf(w)) { | |
|
119 | return false; | |
|
120 | } | |
|
121 | ||
|
122 | auto moveEvent = static_cast<QDragMoveEvent *>(event); | |
|
123 | ||
|
124 | auto scrollButton = impl->tabScrollButtonAt(moveEvent->pos(), impl->m_CurrentTabBar); | |
|
125 | ||
|
126 | if (!scrollButton) { | |
|
127 | ||
|
128 | auto tabIndex = impl->m_CurrentTabBar->tabAt(moveEvent->pos()); | |
|
129 | if (tabIndex >= 0 && tabIndex != impl->m_CurrentTabBar->currentIndex()) { | |
|
130 | // The mouse is over an unselected tab | |
|
131 | if (!impl->m_TabSwitchTimer->isActive() | |
|
132 | || tabIndex != impl->m_HoveredTabIndex) { | |
|
133 | impl->m_HoveredTabIndex = tabIndex; | |
|
134 | impl->m_TabSwitchTimer->start(); | |
|
135 | } | |
|
136 | else { | |
|
137 | // do nothing, timer already running | |
|
138 | } | |
|
139 | } | |
|
140 | else { | |
|
141 | impl->m_TabSwitchTimer->stop(); | |
|
142 | } | |
|
143 | ||
|
144 | impl->m_ScrollButtonsTimer->stop(); | |
|
145 | } | |
|
146 | else { | |
|
147 | // The mouse is over a scroll button | |
|
148 | // click it in a loop with a timer | |
|
149 | if (!impl->m_ScrollButtonsTimer->isActive() | |
|
150 | || impl->m_HoveredScrollButton != scrollButton) { | |
|
151 | impl->m_HoveredScrollButton = scrollButton; | |
|
152 | impl->m_ScrollButtonsTimer->start(); | |
|
153 | } | |
|
154 | } | |
|
155 | } | |
|
156 | } | |
|
157 | else if (event->type() == QEvent::DragEnter) { | |
|
158 | QWidget *w = static_cast<QWidget *>(obj); | |
|
159 | ||
|
160 | for (auto tabBar : impl->m_TabBarList) { | |
|
161 | if (w == tabBar) { | |
|
162 | auto enterEvent = static_cast<QDragEnterEvent *>(event); | |
|
163 | enterEvent->acceptProposedAction(); | |
|
164 | enterEvent->setDropAction(Qt::IgnoreAction); | |
|
165 | impl->m_CurrentTabBar = tabBar; | |
|
166 | break; | |
|
167 | } | |
|
168 | } | |
|
169 | } | |
|
170 | else if (event->type() == QEvent::DragLeave || event->type() == QEvent::Drop) { | |
|
171 | if (impl->m_CurrentTabBar) { | |
|
172 | impl->m_HoveredTabIndex = -1; | |
|
173 | impl->m_TabSwitchTimer->stop(); | |
|
174 | impl->m_CurrentTabBar = nullptr; | |
|
175 | impl->m_ScrollButtonsTimer->stop(); | |
|
176 | } | |
|
177 | } | |
|
178 | ||
|
179 | return false; | |
|
180 | } |
@@ -0,0 +1,13 | |||
|
1 | #include "Variable/VariableInspectorTableView.h" | |
|
2 | ||
|
3 | #include "DragAndDrop/DragDropHelper.h" | |
|
4 | #include "SqpApplication.h" | |
|
5 | ||
|
6 | VariableInspectorTableView::VariableInspectorTableView(QWidget *parent) : QTableView(parent) {} | |
|
7 | ||
|
8 | void VariableInspectorTableView::startDrag(Qt::DropActions supportedActions) | |
|
9 | { | |
|
10 | // Resets the drag&drop operations before it's starting | |
|
11 | sqpApp->dragDropHelper().resetDragAndDrop(); | |
|
12 | QTableView::startDrag(supportedActions); | |
|
13 | } |
@@ -1,99 +1,102 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASOURCECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_DATASOURCECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <QLoggingCategory> |
|
7 | 7 | #include <QObject> |
|
8 | 8 | #include <QUuid> |
|
9 | 9 | |
|
10 | 10 | #include <Common/spimpl.h> |
|
11 | 11 | |
|
12 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController) |
|
13 | 13 | |
|
14 | 14 | class DataSourceItem; |
|
15 | 15 | class IDataProvider; |
|
16 | 16 | |
|
17 | 17 | /** |
|
18 | 18 | * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This |
|
19 | 19 | * is the intermediate class that SciQlop has to use in the way to connect a data source. Please |
|
20 | 20 | * first use register method to initialize a plugin specified by its metadata name (JSON plugin |
|
21 | 21 | * source) then others specifics method will be able to access it. You can load a data source driver |
|
22 | 22 | * plugin then create a data source. |
|
23 | 23 | */ |
|
24 | 24 | class SCIQLOP_CORE_EXPORT DataSourceController : public QObject { |
|
25 | 25 | Q_OBJECT |
|
26 | 26 | public: |
|
27 | 27 | explicit DataSourceController(QObject *parent = 0); |
|
28 | 28 | virtual ~DataSourceController(); |
|
29 | 29 | |
|
30 | 30 | /** |
|
31 | 31 | * Registers a data source. The method delivers a unique id that can be used afterwards to |
|
32 | 32 | * access to the data source properties (structure, connection parameters, data provider, etc.) |
|
33 | 33 | * @param dataSourceName the name of the data source |
|
34 | 34 | * @return the unique id with which the data source has been registered |
|
35 | 35 | */ |
|
36 | 36 | QUuid registerDataSource(const QString &dataSourceName) noexcept; |
|
37 | 37 | |
|
38 | 38 | /** |
|
39 | 39 | * Sets the structure of a data source. The controller takes ownership of the structure. |
|
40 | 40 | * @param dataSourceUid the unique id with which the data source has been registered into the |
|
41 | 41 | * controller. If it is invalid, the method has no effect. |
|
42 | 42 | * @param dataSourceItem the structure of the data source. It must be not null to be registered |
|
43 | 43 | * @sa registerDataSource() |
|
44 | 44 | */ |
|
45 | 45 | void setDataSourceItem(const QUuid &dataSourceUid, |
|
46 | 46 | std::unique_ptr<DataSourceItem> dataSourceItem) noexcept; |
|
47 | 47 | |
|
48 | 48 | /** |
|
49 | 49 | * Sets the data provider used to retrieve data from of a data source. The controller takes |
|
50 | 50 | * ownership of the provider. |
|
51 | 51 | * @param dataSourceUid the unique id with which the data source has been registered into the |
|
52 | 52 | * controller. If it is invalid, the method has no effect. |
|
53 | 53 | * @param dataProvider the provider of the data source |
|
54 | 54 | * @sa registerDataSource() |
|
55 | 55 | */ |
|
56 | 56 | void setDataProvider(const QUuid &dataSourceUid, |
|
57 | 57 | std::unique_ptr<IDataProvider> dataProvider) noexcept; |
|
58 | 58 | |
|
59 | 59 | /** |
|
60 | 60 | * Loads an item (product) as a variable in SciQlop |
|
61 | 61 | * @param dataSourceUid the unique id of the data source containing the item. It is used to get |
|
62 | 62 | * the data provider associated to the data source, and pass it to for the variable creation |
|
63 | 63 | * @param productItem the item to load |
|
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 |
|
72 | 75 | void initialize(); |
|
73 | 76 | void finalize(); |
|
74 | 77 | |
|
75 | 78 | void requestVariable(const QVariantHash &productData); |
|
76 | 79 | |
|
77 | 80 | signals: |
|
78 | 81 | /// Signal emitted when a structure has been set for a data source |
|
79 | 82 | void dataSourceItemSet(DataSourceItem *dataSourceItem); |
|
80 | 83 | |
|
81 | 84 | /** |
|
82 | 85 | * Signal emitted when a variable creation is asked for a product |
|
83 | 86 | * @param variableName the name of the variable |
|
84 | 87 | * @param variableMetadata the metadata of the variable |
|
85 | 88 | * @param variableProvider the provider that will be used to retrieve the data of the variable |
|
86 | 89 | * (can be null) |
|
87 | 90 | */ |
|
88 | 91 | void variableCreationRequested(const QString &variableName, |
|
89 | 92 | const QVariantHash &variableMetadata, |
|
90 | 93 | std::shared_ptr<IDataProvider> variableProvider); |
|
91 | 94 | |
|
92 | 95 | private: |
|
93 | 96 | void waitForFinish(); |
|
94 | 97 | |
|
95 | 98 | class DataSourceControllerPrivate; |
|
96 | 99 | spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl; |
|
97 | 100 | }; |
|
98 | 101 | |
|
99 | 102 | #endif // SCIQLOP_DATASOURCECONTROLLER_H |
@@ -1,42 +1,48 | |||
|
1 | 1 | #ifndef SCIQLOP_TIMECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_TIMECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/SqpRange.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | #include <QObject> |
|
10 | 10 | |
|
11 | 11 | #include <Common/spimpl.h> |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | Q_DECLARE_LOGGING_CATEGORY(LOG_TimeController) |
|
15 | 15 | |
|
16 | 16 | /** |
|
17 | 17 | * @brief The TimeController class aims to handle the Time parameters notification in SciQlop. |
|
18 | 18 | */ |
|
19 | 19 | class SCIQLOP_CORE_EXPORT TimeController : public QObject { |
|
20 | 20 | Q_OBJECT |
|
21 | 21 | public: |
|
22 | 22 | explicit TimeController(QObject *parent = 0); |
|
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); |
|
29 | 35 | |
|
30 | 36 | public slots: |
|
31 | 37 | /// Slot called when a new dateTime has been defined. |
|
32 | 38 | void onTimeToUpdate(SqpRange dateTime); |
|
33 | 39 | |
|
34 | 40 | /// Slot called when the dateTime has to be notified. Call timeUpdated signal |
|
35 | 41 | void onTimeNotify(); |
|
36 | 42 | |
|
37 | 43 | private: |
|
38 | 44 | class TimeControllerPrivate; |
|
39 | 45 | spimpl::unique_impl_ptr<TimeControllerPrivate> impl; |
|
40 | 46 | }; |
|
41 | 47 | |
|
42 | 48 | #endif // SCIQLOP_TIMECONTROLLER_H |
@@ -1,132 +1,135 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/AcquisitionDataPacket.h> |
|
7 | 7 | #include <Data/SqpRange.h> |
|
8 | 8 | |
|
9 | 9 | #include <QLoggingCategory> |
|
10 | 10 | #include <QObject> |
|
11 | 11 | #include <QUuid> |
|
12 | 12 | |
|
13 | 13 | #include <Common/spimpl.h> |
|
14 | 14 | |
|
15 | 15 | class IDataProvider; |
|
16 | 16 | class QItemSelectionModel; |
|
17 | 17 | class TimeController; |
|
18 | 18 | class Variable; |
|
19 | 19 | class VariableModel; |
|
20 | 20 | |
|
21 | 21 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | /** |
|
25 | 25 | * Possible types of zoom operation |
|
26 | 26 | */ |
|
27 | 27 | enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | /** |
|
31 | 31 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
32 | 32 | */ |
|
33 | 33 | class SCIQLOP_CORE_EXPORT VariableController : public QObject { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | public: |
|
36 | 36 | explicit VariableController(QObject *parent = 0); |
|
37 | 37 | virtual ~VariableController(); |
|
38 | 38 | |
|
39 | 39 | VariableModel *variableModel() noexcept; |
|
40 | 40 | QItemSelectionModel *variableSelectionModel() noexcept; |
|
41 | 41 | |
|
42 | 42 | void setTimeController(TimeController *timeController) noexcept; |
|
43 | 43 | |
|
44 | 44 | /** |
|
45 | 45 | * Clones the variable passed in parameter and adds the duplicate to the controller |
|
46 | 46 | * @param variable the variable to duplicate |
|
47 | 47 | * @return the duplicate created, nullptr if the variable couldn't be created |
|
48 | 48 | */ |
|
49 | 49 | std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept; |
|
50 | 50 | |
|
51 | 51 | /** |
|
52 | 52 | * Deletes from the controller the variable passed in parameter. |
|
53 | 53 | * |
|
54 | 54 | * Delete a variable includes: |
|
55 | 55 | * - the deletion of the various references to the variable in SciQlop |
|
56 | 56 | * - the deletion of the model variable |
|
57 | 57 | * - the deletion of the provider associated with the variable |
|
58 | 58 | * - removing the cache associated with the variable |
|
59 | 59 | * |
|
60 | 60 | * @param variable the variable to delete from the controller. |
|
61 | 61 | */ |
|
62 | 62 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
63 | 63 | |
|
64 | 64 | /** |
|
65 | 65 | * Deletes from the controller the variables passed in parameter. |
|
66 | 66 | * @param variables the variables to delete from the controller. |
|
67 | 67 | * @sa deleteVariable() |
|
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); |
|
75 | 78 | signals: |
|
76 | 79 | /// Signal emitted when a variable is about to be deleted from the controller |
|
77 | 80 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
78 | 81 | |
|
79 | 82 | /// Signal emitted when a data acquisition is requested on a range for a variable |
|
80 | 83 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
81 | 84 | |
|
82 | 85 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed |
|
83 | 86 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
84 | 87 | |
|
85 | 88 | public slots: |
|
86 | 89 | /// Request the data loading of the variable whithin range |
|
87 | 90 | void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range, |
|
88 | 91 | bool synchronise); |
|
89 | 92 | /** |
|
90 | 93 | * Creates a new variable and adds it to the model |
|
91 | 94 | * @param name the name of the new variable |
|
92 | 95 | * @param metadata the metadata of the new variable |
|
93 | 96 | * @param provider the data provider for the new variable |
|
94 | 97 | * @return the pointer to the new variable or nullptr if the creation failed |
|
95 | 98 | */ |
|
96 | 99 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, |
|
97 | 100 | std::shared_ptr<IDataProvider> provider) noexcept; |
|
98 | 101 | |
|
99 | 102 | /// Update the temporal parameters of every selected variable to dateTime |
|
100 | 103 | void onDateTimeOnSelection(const SqpRange &dateTime); |
|
101 | 104 | |
|
102 | 105 | |
|
103 | 106 | void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
104 | 107 | const SqpRange &cacheRangeRequested, |
|
105 | 108 | QVector<AcquisitionDataPacket> dataAcquired); |
|
106 | 109 | |
|
107 | 110 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); |
|
108 | 111 | |
|
109 | 112 | /// Cancel the current request for the variable |
|
110 | 113 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); |
|
111 | 114 | void onAbortAcquisitionRequested(QUuid vIdentifier); |
|
112 | 115 | |
|
113 | 116 | // synchronization group methods |
|
114 | 117 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); |
|
115 | 118 | void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId); |
|
116 | 119 | void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); |
|
117 | 120 | |
|
118 | 121 | /// Desynchronizes the variable of the group whose identifier is passed in parameter |
|
119 | 122 | /// @remarks the method does nothing if the variable is not part of the group |
|
120 | 123 | void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); |
|
121 | 124 | |
|
122 | 125 | void initialize(); |
|
123 | 126 | void finalize(); |
|
124 | 127 | |
|
125 | 128 | private: |
|
126 | 129 | void waitForFinish(); |
|
127 | 130 | |
|
128 | 131 | class VariableControllerPrivate; |
|
129 | 132 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
130 | 133 | }; |
|
131 | 134 | |
|
132 | 135 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,67 +1,65 | |||
|
1 | 1 | |
|
2 | 2 | core_moc_headers = [ |
|
3 | 3 | 'include/Data/IDataProvider.h', |
|
4 | 4 | 'include/DataSource/DataSourceController.h', |
|
5 | 5 | 'include/DataSource/DataSourceItemAction.h', |
|
6 | 'include/DataSource/DataSourceWidget.h', | |
|
7 | 6 | 'include/Network/NetworkController.h', |
|
8 | 7 | 'include/Time/TimeController.h', |
|
9 | 8 | 'include/Variable/Variable.h', |
|
10 | 9 | 'include/Variable/VariableCacheController.h', |
|
11 | 10 | 'include/Variable/VariableController.h', |
|
12 | 11 | 'include/Variable/VariableAcquisitionWorker.h', |
|
13 | 12 | 'include/Variable/VariableCacheStrategy.h', |
|
14 | 13 | 'include/Variable/VariableSynchronizationGroup.h', |
|
15 | 14 | 'include/Variable/VariableModel.h', |
|
16 | 15 | 'include/Visualization/VisualizationController.h' |
|
17 | 16 | ] |
|
18 | 17 | |
|
19 | 18 | |
|
20 | 19 | core_moc_files = qt5.preprocess(moc_headers : core_moc_headers) |
|
21 | 20 | |
|
22 | 21 | core_sources = [ |
|
23 | 22 | 'src/Common/DateUtils.cpp', |
|
24 | 23 | 'src/Common/StringUtils.cpp', |
|
25 | 24 | 'src/Common/MimeTypesDef.cpp', |
|
26 | 25 | 'src/Data/ScalarSeries.cpp', |
|
27 | 26 | 'src/Data/SpectrogramSeries.cpp', |
|
28 | 27 | 'src/Data/DataSeriesIterator.cpp', |
|
29 | 28 | 'src/Data/ArrayDataIterator.cpp', |
|
30 | 29 | 'src/Data/VectorSeries.cpp', |
|
31 | 30 | 'src/Data/OptionalAxis.cpp', |
|
32 | 31 | 'src/DataSource/DataSourceController.cpp', |
|
33 | 32 | 'src/DataSource/DataSourceItem.cpp', |
|
34 | 33 | 'src/DataSource/DataSourceItemAction.cpp', |
|
35 | 'src/DataSource/DataSourceWidget.cpp', | |
|
36 | 34 | 'src/Network/NetworkController.cpp', |
|
37 | 35 | 'src/Plugin/PluginManager.cpp', |
|
38 | 36 | 'src/Settings/SqpSettingsDefs.cpp', |
|
39 | 37 | 'src/Time/TimeController.cpp', |
|
40 | 38 | 'src/Variable/Variable.cpp', |
|
41 | 39 | 'src/Variable/VariableCacheController.cpp', |
|
42 | 40 | 'src/Variable/VariableController.cpp', |
|
43 | 41 | 'src/Variable/VariableAcquisitionWorker.cpp', |
|
44 | 42 | 'src/Variable/VariableSynchronizationGroup.cpp', |
|
45 | 43 | 'src/Variable/VariableModel.cpp', |
|
46 | 44 | 'src/Visualization/VisualizationController.cpp' |
|
47 | 45 | ] |
|
48 | 46 | |
|
49 | 47 | core_inc = include_directories(['include', '../plugin/include']) |
|
50 | 48 | |
|
51 | 49 | sciqlop_core_lib = library('sciqlopcore', |
|
52 | 50 | core_sources, |
|
53 | 51 | core_moc_files, |
|
54 | 52 | cpp_args : '-DCORE_LIB', |
|
55 | 53 | include_directories : core_inc, |
|
56 | 54 | dependencies : [qt5core, qt5network], |
|
57 | 55 | install : true |
|
58 | 56 | ) |
|
59 | 57 | |
|
60 | 58 | |
|
61 | 59 | sciqlop_core = declare_dependency(link_with : sciqlop_core_lib, |
|
62 | 60 | include_directories : core_inc, |
|
63 | 61 | dependencies : [qt5core, qt5network]) |
|
64 | 62 | |
|
65 | 63 | |
|
66 | 64 | subdir('tests') |
|
67 | 65 |
@@ -1,192 +1,192 | |||
|
1 | 1 | #include "DataSource/DataSourceController.h" |
|
2 | 2 | #include "DataSource/DataSourceItem.h" |
|
3 | 3 | |
|
4 | 4 | #include <Data/IDataProvider.h> |
|
5 | 5 | |
|
6 | 6 | #include <QMutex> |
|
7 | 7 | #include <QThread> |
|
8 | 8 | |
|
9 | 9 | #include <QDataStream> |
|
10 | 10 | #include <QDir> |
|
11 | 11 | #include <QStandardPaths> |
|
12 | 12 | |
|
13 | 13 | Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") |
|
14 | 14 | |
|
15 | 15 | namespace { |
|
16 | 16 | |
|
17 | 17 | /** |
|
18 | 18 | * Builds the metadata of the variable that will be generated from the loading of an item |
|
19 | 19 | * @param dataSourceItem the data source item from which to generate the metadata |
|
20 | 20 | * @return the metadata of the variable |
|
21 | 21 | */ |
|
22 | 22 | QVariantHash variableMetadata(const DataSourceItem &dataSourceItem) |
|
23 | 23 | { |
|
24 | 24 | // Variable metadata contains... |
|
25 | 25 | |
|
26 | 26 | // ... all metadata of the item |
|
27 | 27 | auto result = dataSourceItem.data(); |
|
28 | 28 | |
|
29 | 29 | // ... and the name of the plugin, recovered from root item |
|
30 | 30 | result.insert(QStringLiteral("plugin"), dataSourceItem.rootItem().name()); |
|
31 | 31 | |
|
32 | 32 | return result; |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | } // namespace |
|
36 | 36 | |
|
37 | 37 | class DataSourceController::DataSourceControllerPrivate { |
|
38 | 38 | public: |
|
39 | 39 | QMutex m_WorkingMutex; |
|
40 | 40 | /// Data sources registered |
|
41 | 41 | QHash<QUuid, QString> m_DataSources; |
|
42 | 42 | /// Data sources structures |
|
43 | 43 | std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems; |
|
44 | 44 | /// Data providers registered |
|
45 | 45 | /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and |
|
46 | 46 | /// continue to live without necessarily the data source controller |
|
47 | 47 | std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders; |
|
48 | 48 | |
|
49 | 49 | // Search for the first datasource item matching the specified data |
|
50 | 50 | DataSourceItem *findDataSourceItem(const QVariantHash &data) |
|
51 | 51 | { |
|
52 | 52 | DataSourceItem *sourceItem = nullptr; |
|
53 | 53 | for (const auto &item : m_DataSourceItems) { |
|
54 | 54 | sourceItem = item.second->findItem(data, true); |
|
55 | 55 | if (sourceItem) { |
|
56 | 56 | break; |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | return sourceItem; |
|
61 | 61 | } |
|
62 | 62 | }; |
|
63 | 63 | |
|
64 | 64 | DataSourceController::DataSourceController(QObject *parent) |
|
65 | 65 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} |
|
66 | 66 | { |
|
67 | 67 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction") |
|
68 | 68 | << QThread::currentThread(); |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | DataSourceController::~DataSourceController() |
|
72 | 72 | { |
|
73 | 73 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction") |
|
74 | 74 | << QThread::currentThread(); |
|
75 | 75 | this->waitForFinish(); |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept |
|
79 | 79 | { |
|
80 | 80 | auto dataSourceUid = QUuid::createUuid(); |
|
81 | 81 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); |
|
82 | 82 | |
|
83 | 83 | return dataSourceUid; |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | void DataSourceController::setDataSourceItem( |
|
87 | 87 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept |
|
88 | 88 | { |
|
89 | 89 | if (!dataSourceItem) { |
|
90 | 90 | qCWarning(LOG_DataSourceController()) |
|
91 | 91 | << tr("Data source item can't be registered (null item)"); |
|
92 | 92 | return; |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
96 | 96 | // The data provider is implicitly converted to a shared_ptr |
|
97 | 97 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); |
|
98 | 98 | |
|
99 | 99 | // Retrieves the data source item to emit the signal with it |
|
100 | 100 | auto it = impl->m_DataSourceItems.find(dataSourceUid); |
|
101 | 101 | if (it != impl->m_DataSourceItems.end()) { |
|
102 | 102 | emit dataSourceItemSet(it->second.get()); |
|
103 | 103 | } |
|
104 | 104 | } |
|
105 | 105 | else { |
|
106 | 106 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " |
|
107 | 107 | "data source has been registered with the uid") |
|
108 | 108 | .arg(dataSourceUid.toString()); |
|
109 | 109 | } |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, |
|
113 | 113 | std::unique_ptr<IDataProvider> dataProvider) noexcept |
|
114 | 114 | { |
|
115 | 115 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
116 | 116 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); |
|
117 | 117 | } |
|
118 | 118 | else { |
|
119 | 119 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " |
|
120 | 120 | "source has been registered with the uid") |
|
121 | 121 | .arg(dataSourceUid.toString()); |
|
122 | 122 | } |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | void DataSourceController::loadProductItem(const QUuid &dataSourceUid, |
|
126 | 126 | const DataSourceItem &productItem) noexcept |
|
127 | 127 | { |
|
128 | 128 | if (productItem.type() == DataSourceItemType::PRODUCT |
|
129 | 129 | || productItem.type() == DataSourceItemType::COMPONENT) { |
|
130 | 130 | /// Retrieves the data provider of the data source (if any) |
|
131 | 131 | auto it = impl->m_DataProviders.find(dataSourceUid); |
|
132 | 132 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; |
|
133 | 133 | |
|
134 | 134 | emit variableCreationRequested(productItem.name(), variableMetadata(productItem), |
|
135 | 135 | dataProvider); |
|
136 | 136 | } |
|
137 | 137 | else { |
|
138 | 138 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); |
|
139 | 139 | } |
|
140 | 140 | } |
|
141 | 141 | |
|
142 |
QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) |
|
|
142 | QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) | |
|
143 | 143 | { |
|
144 | 144 | QByteArray encodedData; |
|
145 | 145 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; |
|
146 | 146 | |
|
147 | 147 | stream << productsData; |
|
148 | 148 | |
|
149 | 149 | return encodedData; |
|
150 | 150 | } |
|
151 | 151 | |
|
152 |
QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData) |
|
|
152 | QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData) | |
|
153 | 153 | { |
|
154 | 154 | QDataStream stream{mimeData}; |
|
155 | 155 | |
|
156 | 156 | QVariantList productList; |
|
157 | 157 | stream >> productList; |
|
158 | 158 | |
|
159 | 159 | return productList; |
|
160 | 160 | } |
|
161 | 161 | |
|
162 | 162 | void DataSourceController::initialize() |
|
163 | 163 | { |
|
164 | 164 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
|
165 | 165 | << QThread::currentThread(); |
|
166 | 166 | impl->m_WorkingMutex.lock(); |
|
167 | 167 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | void DataSourceController::finalize() |
|
171 | 171 | { |
|
172 | 172 | impl->m_WorkingMutex.unlock(); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | void DataSourceController::requestVariable(const QVariantHash &productData) |
|
176 | 176 | { |
|
177 |
|
|
|
177 | auto sourceItem = impl->findDataSourceItem(productData); | |
|
178 | 178 | |
|
179 | 179 | if (sourceItem) { |
|
180 | 180 | auto sourceName = sourceItem->rootItem().name(); |
|
181 | 181 | auto sourceId = impl->m_DataSources.key(sourceName); |
|
182 | 182 | loadProductItem(sourceId, *sourceItem); |
|
183 | 183 | } |
|
184 | 184 | else { |
|
185 | 185 | qCWarning(LOG_DataSourceController()) << tr("requestVariable, product data not found"); |
|
186 | 186 | } |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | void DataSourceController::waitForFinish() |
|
190 | 190 | { |
|
191 | 191 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
192 | 192 | } |
@@ -1,163 +1,162 | |||
|
1 | 1 | #include <DataSource/DataSourceItem.h> |
|
2 | 2 | #include <DataSource/DataSourceItemAction.h> |
|
3 | 3 | |
|
4 | 4 | #include <QVector> |
|
5 | 5 | |
|
6 | 6 | const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name"); |
|
7 | 7 | |
|
8 | 8 | struct DataSourceItem::DataSourceItemPrivate { |
|
9 | 9 | explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data) |
|
10 | 10 | : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{} |
|
11 | 11 | { |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | DataSourceItem *m_Parent; |
|
15 | 15 | std::vector<std::unique_ptr<DataSourceItem> > m_Children; |
|
16 | 16 | DataSourceItemType m_Type; |
|
17 | 17 | QVariantHash m_Data; |
|
18 | 18 | std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions; |
|
19 | 19 | }; |
|
20 | 20 | |
|
21 | 21 | DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name) |
|
22 | 22 | : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}} |
|
23 | 23 | { |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data) |
|
27 | 27 | : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))} |
|
28 | 28 | { |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept |
|
32 | 32 | { |
|
33 | 33 | auto result = QVector<DataSourceItemAction *>{}; |
|
34 | 34 | |
|
35 | 35 | std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions), |
|
36 | 36 | std::back_inserter(result), [](const auto &action) { return action.get(); }); |
|
37 | 37 | |
|
38 | 38 | return result; |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept |
|
42 | 42 | { |
|
43 | 43 | action->setDataSourceItem(this); |
|
44 | 44 | impl->m_Actions.push_back(std::move(action)); |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept |
|
48 | 48 | { |
|
49 | 49 | child->impl->m_Parent = this; |
|
50 | 50 | impl->m_Children.push_back(std::move(child)); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | DataSourceItem *DataSourceItem::child(int childIndex) const noexcept |
|
54 | 54 | { |
|
55 | 55 | if (childIndex < 0 || childIndex >= childCount()) { |
|
56 | 56 | return nullptr; |
|
57 | 57 | } |
|
58 | 58 | else { |
|
59 | 59 | return impl->m_Children.at(childIndex).get(); |
|
60 | 60 | } |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | int DataSourceItem::childCount() const noexcept |
|
64 | 64 | { |
|
65 | 65 | return impl->m_Children.size(); |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | QVariant DataSourceItem::data(const QString &key) const noexcept |
|
69 | 69 | { |
|
70 | 70 | return impl->m_Data.value(key); |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | QVariantHash DataSourceItem::data() const noexcept |
|
74 | 74 | { |
|
75 | 75 | return impl->m_Data; |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | bool DataSourceItem::isRoot() const noexcept |
|
79 | 79 | { |
|
80 | 80 | return impl->m_Parent == nullptr; |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | QString DataSourceItem::name() const noexcept |
|
84 | 84 | { |
|
85 | 85 | return data(NAME_DATA_KEY).toString(); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
|
89 | 89 | { |
|
90 | 90 | return impl->m_Parent; |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | const DataSourceItem &DataSourceItem::rootItem() const noexcept |
|
94 | 94 | { |
|
95 | 95 | return isRoot() ? *this : parentItem()->rootItem(); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept |
|
99 | 99 | { |
|
100 | 100 | auto it = impl->m_Data.constFind(key); |
|
101 | 101 | if (append && it != impl->m_Data.constEnd()) { |
|
102 | 102 | // Case of an existing value to which we want to add to the new value |
|
103 | 103 | if (it->canConvert<QVariantList>()) { |
|
104 | 104 | auto variantList = it->value<QVariantList>(); |
|
105 | 105 | variantList.append(value); |
|
106 | 106 | |
|
107 | 107 | impl->m_Data.insert(key, variantList); |
|
108 | 108 | } |
|
109 | 109 | else { |
|
110 | 110 | impl->m_Data.insert(key, QVariantList{*it, value}); |
|
111 | 111 | } |
|
112 | 112 | } |
|
113 | 113 | else { |
|
114 | 114 | // Other cases : |
|
115 | 115 | // - new value in map OR |
|
116 | 116 | // - replacement of an existing value (not appending) |
|
117 | 117 | impl->m_Data.insert(key, value); |
|
118 | 118 | } |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | DataSourceItemType DataSourceItem::type() const noexcept |
|
122 | 122 | { |
|
123 | 123 | return impl->m_Type; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive) |
|
127 | 127 | { |
|
128 | 128 | for (const auto &child : impl->m_Children) { |
|
129 | 129 | if (child->impl->m_Data == data) { |
|
130 | 130 | return child.get(); |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | if (recursive) { |
|
134 |
auto foundItem = child->findItem(data, true) |
|
|
135 | if (foundItem) { | |
|
134 | if (auto foundItem = child->findItem(data, true)) { | |
|
136 | 135 | return foundItem; |
|
137 | 136 | } |
|
138 | 137 | } |
|
139 | 138 | } |
|
140 | 139 | |
|
141 | 140 | return nullptr; |
|
142 | 141 | } |
|
143 | 142 | |
|
144 | 143 | bool DataSourceItem::operator==(const DataSourceItem &other) |
|
145 | 144 | { |
|
146 | 145 | // Compares items' attributes |
|
147 | 146 | if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { |
|
148 | 147 | // Compares contents of items' children |
|
149 | 148 | return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), |
|
150 | 149 | std::cbegin(other.impl->m_Children), |
|
151 | 150 | [](const auto &itemChild, const auto &otherChild) { |
|
152 | 151 | return *itemChild == *otherChild; |
|
153 | 152 | }); |
|
154 | 153 | } |
|
155 | 154 | else { |
|
156 | 155 | return false; |
|
157 | 156 | } |
|
158 | 157 | } |
|
159 | 158 | |
|
160 | 159 | bool DataSourceItem::operator!=(const DataSourceItem &other) |
|
161 | 160 | { |
|
162 | 161 | return !(*this == other); |
|
163 | 162 | } |
@@ -1,29 +1,51 | |||
|
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 { |
|
6 | 8 | |
|
7 | 9 | SqpRange m_DateTime; |
|
8 | 10 | }; |
|
9 | 11 | |
|
10 | 12 | TimeController::TimeController(QObject *parent) |
|
11 | 13 | : QObject{parent}, impl{spimpl::make_unique_impl<TimeControllerPrivate>()} |
|
12 | 14 | { |
|
13 | 15 | qCDebug(LOG_TimeController()) << tr("TimeController construction"); |
|
14 | 16 | } |
|
15 | 17 | |
|
16 | 18 | SqpRange TimeController::dateTime() const noexcept |
|
17 | 19 | { |
|
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; |
|
24 | 46 | } |
|
25 | 47 | |
|
26 | 48 | void TimeController::onTimeNotify() |
|
27 | 49 | { |
|
28 | 50 | emit timeUpdated(impl->m_DateTime); |
|
29 | 51 | } |
@@ -1,368 +1,383 | |||
|
1 | 1 | #include <Variable/Variable.h> |
|
2 | 2 | #include <Variable/VariableController.h> |
|
3 | 3 | #include <Variable/VariableModel.h> |
|
4 | 4 | |
|
5 | 5 | #include <Common/DateUtils.h> |
|
6 | 6 | #include <Common/MimeTypesDef.h> |
|
7 | 7 | #include <Common/StringUtils.h> |
|
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> |
|
15 | 17 | |
|
16 | 18 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") |
|
17 | 19 | |
|
18 | 20 | namespace { |
|
19 | 21 | |
|
20 | 22 | // Column indexes |
|
21 | 23 | const auto NAME_COLUMN = 0; |
|
22 | 24 | const auto TSTART_COLUMN = 1; |
|
23 | 25 | const auto TEND_COLUMN = 2; |
|
24 | 26 | const auto NBPOINTS_COLUMN = 3; |
|
25 | 27 | const auto UNIT_COLUMN = 4; |
|
26 | 28 | const auto MISSION_COLUMN = 5; |
|
27 | 29 | const auto PLUGIN_COLUMN = 6; |
|
28 | 30 | const auto NB_COLUMNS = 7; |
|
29 | 31 | |
|
30 | 32 | // Column properties |
|
31 | 33 | const auto DEFAULT_HEIGHT = 25; |
|
32 | 34 | const auto DEFAULT_WIDTH = 100; |
|
33 | 35 | |
|
34 | 36 | struct ColumnProperties { |
|
35 | 37 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, |
|
36 | 38 | int height = DEFAULT_HEIGHT) |
|
37 | 39 | : m_Name{name}, m_Width{width}, m_Height{height} |
|
38 | 40 | { |
|
39 | 41 | } |
|
40 | 42 | |
|
41 | 43 | QString m_Name; |
|
42 | 44 | int m_Width; |
|
43 | 45 | int m_Height; |
|
44 | 46 | }; |
|
45 | 47 | |
|
46 | 48 | const auto COLUMN_PROPERTIES = QHash<int, ColumnProperties>{ |
|
47 | 49 | {NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, |
|
48 | 50 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {NBPOINTS_COLUMN, {QObject::tr("Nb points")}}, |
|
49 | 51 | {UNIT_COLUMN, {QObject::tr("Unit")}}, {MISSION_COLUMN, {QObject::tr("Mission")}}, |
|
50 | 52 | {PLUGIN_COLUMN, {QObject::tr("Plugin")}}}; |
|
51 | 53 | |
|
52 | 54 | /// Format for datetimes |
|
53 | 55 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); |
|
54 | 56 | |
|
55 | 57 | QString uniqueName(const QString &defaultName, |
|
56 | 58 | const std::vector<std::shared_ptr<Variable> > &variables) |
|
57 | 59 | { |
|
58 | 60 | auto forbiddenNames = std::vector<QString>(variables.size()); |
|
59 | 61 | std::transform(variables.cbegin(), variables.cend(), forbiddenNames.begin(), |
|
60 | 62 | [](const auto &variable) { return variable->name(); }); |
|
61 | 63 | auto uniqueName = StringUtils::uniqueName(defaultName, forbiddenNames); |
|
62 | 64 | Q_ASSERT(!uniqueName.isEmpty()); |
|
63 | 65 | |
|
64 | 66 | return uniqueName; |
|
65 | 67 | } |
|
66 | 68 | |
|
67 | 69 | } // namespace |
|
68 | 70 | |
|
69 | 71 | struct VariableModel::VariableModelPrivate { |
|
70 | 72 | /// Variables created in SciQlop |
|
71 | 73 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
72 | 74 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; |
|
73 | 75 | VariableController *m_VariableController; |
|
74 | 76 | |
|
75 | 77 | /// Return the row index of the variable. -1 if it's not found |
|
76 | 78 | int indexOfVariable(Variable *variable) const noexcept; |
|
77 | 79 | }; |
|
78 | 80 | |
|
79 | 81 | VariableModel::VariableModel(VariableController *parent) |
|
80 | 82 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
81 | 83 | { |
|
82 | 84 | impl->m_VariableController = parent; |
|
83 | 85 | } |
|
84 | 86 | |
|
85 | 87 | void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept |
|
86 | 88 | { |
|
87 | 89 | auto insertIndex = rowCount(); |
|
88 | 90 | beginInsertRows({}, insertIndex, insertIndex); |
|
89 | 91 | |
|
90 | 92 | // Generates unique name for the variable |
|
91 | 93 | variable->setName(uniqueName(variable->name(), impl->m_Variables)); |
|
92 | 94 | |
|
93 | 95 | impl->m_Variables.push_back(variable); |
|
94 | 96 | connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated); |
|
95 | 97 | |
|
96 | 98 | endInsertRows(); |
|
97 | 99 | } |
|
98 | 100 | |
|
99 | 101 | bool VariableModel::containsVariable(std::shared_ptr<Variable> variable) const noexcept |
|
100 | 102 | { |
|
101 | 103 | auto end = impl->m_Variables.cend(); |
|
102 | 104 | return std::find(impl->m_Variables.cbegin(), end, variable) != end; |
|
103 | 105 | } |
|
104 | 106 | |
|
105 | 107 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, |
|
106 | 108 | const QVariantHash &metadata) noexcept |
|
107 | 109 | { |
|
108 | 110 | auto variable = std::make_shared<Variable>(name, metadata); |
|
109 | 111 | addVariable(variable); |
|
110 | 112 | |
|
111 | 113 | return variable; |
|
112 | 114 | } |
|
113 | 115 | |
|
114 | 116 | void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
115 | 117 | { |
|
116 | 118 | if (!variable) { |
|
117 | 119 | qCCritical(LOG_Variable()) << "Can't delete a null variable from the model"; |
|
118 | 120 | return; |
|
119 | 121 | } |
|
120 | 122 | |
|
121 | 123 | // Finds variable in the model |
|
122 | 124 | auto begin = impl->m_Variables.cbegin(); |
|
123 | 125 | auto end = impl->m_Variables.cend(); |
|
124 | 126 | auto it = std::find(begin, end, variable); |
|
125 | 127 | if (it != end) { |
|
126 | 128 | auto removeIndex = std::distance(begin, it); |
|
127 | 129 | |
|
128 | 130 | // Deletes variable |
|
129 | 131 | beginRemoveRows({}, removeIndex, removeIndex); |
|
130 | 132 | impl->m_Variables.erase(it); |
|
131 | 133 | endRemoveRows(); |
|
132 | 134 | } |
|
133 | 135 | else { |
|
134 | 136 | qCritical(LOG_VariableModel()) |
|
135 | 137 | << tr("Can't delete variable %1 from the model: the variable is not in the model") |
|
136 | 138 | .arg(variable->name()); |
|
137 | 139 | } |
|
138 | 140 | |
|
139 | 141 | // Removes variable from progress map |
|
140 | 142 | impl->m_VariableToProgress.erase(variable); |
|
141 | 143 | } |
|
142 | 144 | |
|
143 | 145 | |
|
144 | 146 | std::shared_ptr<Variable> VariableModel::variable(int index) const |
|
145 | 147 | { |
|
146 | 148 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; |
|
147 | 149 | } |
|
148 | 150 | |
|
149 | 151 | std::vector<std::shared_ptr<Variable> > VariableModel::variables() const |
|
150 | 152 | { |
|
151 | 153 | return impl->m_Variables; |
|
152 | 154 | } |
|
153 | 155 | |
|
154 | 156 | void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress) |
|
155 | 157 | { |
|
156 | 158 | if (progress > 0.0) { |
|
157 | 159 | impl->m_VariableToProgress[variable] = progress; |
|
158 | 160 | } |
|
159 | 161 | else { |
|
160 | 162 | impl->m_VariableToProgress.erase(variable); |
|
161 | 163 | } |
|
162 | 164 | auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); |
|
163 | 165 | |
|
164 | 166 | emit dataChanged(modelIndex, modelIndex); |
|
165 | 167 | } |
|
166 | 168 | |
|
167 | 169 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
168 | 170 | { |
|
169 | 171 | Q_UNUSED(parent); |
|
170 | 172 | |
|
171 | 173 | return NB_COLUMNS; |
|
172 | 174 | } |
|
173 | 175 | |
|
174 | 176 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
175 | 177 | { |
|
176 | 178 | Q_UNUSED(parent); |
|
177 | 179 | |
|
178 | 180 | return impl->m_Variables.size(); |
|
179 | 181 | } |
|
180 | 182 | |
|
181 | 183 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
182 | 184 | { |
|
183 | 185 | if (!index.isValid()) { |
|
184 | 186 | return QVariant{}; |
|
185 | 187 | } |
|
186 | 188 | |
|
187 | 189 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
188 | 190 | return QVariant{}; |
|
189 | 191 | } |
|
190 | 192 | |
|
191 | 193 | if (role == Qt::DisplayRole) { |
|
192 | 194 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
193 | 195 | switch (index.column()) { |
|
194 | 196 | case NAME_COLUMN: |
|
195 | 197 | return variable->name(); |
|
196 | 198 | case TSTART_COLUMN: { |
|
197 | 199 | auto range = variable->realRange(); |
|
198 | 200 | return range != INVALID_RANGE |
|
199 | 201 | ? DateUtils::dateTime(range.m_TStart).toString(DATETIME_FORMAT) |
|
200 | 202 | : QVariant{}; |
|
201 | 203 | } |
|
202 | 204 | case TEND_COLUMN: { |
|
203 | 205 | auto range = variable->realRange(); |
|
204 | 206 | return range != INVALID_RANGE |
|
205 | 207 | ? DateUtils::dateTime(range.m_TEnd).toString(DATETIME_FORMAT) |
|
206 | 208 | : QVariant{}; |
|
207 | 209 | } |
|
208 | 210 | case NBPOINTS_COLUMN: |
|
209 | 211 | return variable->nbPoints(); |
|
210 | 212 | case UNIT_COLUMN: |
|
211 | 213 | return variable->metadata().value(QStringLiteral("units")); |
|
212 | 214 | case MISSION_COLUMN: |
|
213 | 215 | return variable->metadata().value(QStringLiteral("mission")); |
|
214 | 216 | case PLUGIN_COLUMN: |
|
215 | 217 | return variable->metadata().value(QStringLiteral("plugin")); |
|
216 | 218 | default: |
|
217 | 219 | // No action |
|
218 | 220 | break; |
|
219 | 221 | } |
|
220 | 222 | |
|
221 | 223 | qWarning(LOG_VariableModel()) |
|
222 | 224 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
223 | 225 | } |
|
224 | 226 | else { |
|
225 | 227 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
226 | 228 | } |
|
227 | 229 | } |
|
228 | 230 | else if (role == VariableRoles::ProgressRole) { |
|
229 | 231 | if (auto variable = impl->m_Variables.at(index.row())) { |
|
230 | 232 | |
|
231 | 233 | auto it = impl->m_VariableToProgress.find(variable); |
|
232 | 234 | if (it != impl->m_VariableToProgress.cend()) { |
|
233 | 235 | return it->second; |
|
234 | 236 | } |
|
235 | 237 | } |
|
236 | 238 | } |
|
237 | 239 | |
|
238 | 240 | return QVariant{}; |
|
239 | 241 | } |
|
240 | 242 | |
|
241 | 243 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
242 | 244 | { |
|
243 | 245 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { |
|
244 | 246 | return QVariant{}; |
|
245 | 247 | } |
|
246 | 248 | |
|
247 | 249 | if (orientation == Qt::Horizontal) { |
|
248 | 250 | auto propertiesIt = COLUMN_PROPERTIES.find(section); |
|
249 | 251 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { |
|
250 | 252 | // Role is either DisplayRole or SizeHintRole |
|
251 | 253 | return (role == Qt::DisplayRole) |
|
252 | 254 | ? QVariant{propertiesIt->m_Name} |
|
253 | 255 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; |
|
254 | 256 | } |
|
255 | 257 | else { |
|
256 | 258 | qWarning(LOG_VariableModel()) |
|
257 | 259 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
258 | 260 | } |
|
259 | 261 | } |
|
260 | 262 | |
|
261 | 263 | return QVariant{}; |
|
262 | 264 | } |
|
263 | 265 | |
|
264 | 266 | Qt::ItemFlags VariableModel::flags(const QModelIndex &index) const |
|
265 | 267 | { |
|
266 | 268 | return QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; |
|
267 | 269 | } |
|
268 | 270 | |
|
269 | 271 | Qt::DropActions VariableModel::supportedDropActions() const |
|
270 | 272 | { |
|
271 | 273 | return Qt::CopyAction | Qt::MoveAction; |
|
272 | 274 | } |
|
273 | 275 | |
|
274 | 276 | Qt::DropActions VariableModel::supportedDragActions() const |
|
275 | 277 | { |
|
276 | 278 | return Qt::CopyAction | Qt::MoveAction; |
|
277 | 279 | } |
|
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 |
|
285 | 287 | { |
|
286 | 288 | auto mimeData = new QMimeData; |
|
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 | } |
|
304 | 320 | |
|
305 | 321 | bool VariableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, |
|
306 | 322 | int column, const QModelIndex &parent) const |
|
307 | 323 | { |
|
308 | 324 | // drop of a product |
|
309 | 325 | return data->hasFormat(MIME_TYPE_PRODUCT_LIST); |
|
310 | 326 | } |
|
311 | 327 | |
|
312 | 328 | bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, |
|
313 | 329 | const QModelIndex &parent) |
|
314 | 330 | { |
|
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 |
|
|
|
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()); |
|
325 | 340 | } |
|
326 | 341 | |
|
327 | 342 | dropDone = true; |
|
328 | 343 | } |
|
329 | 344 | |
|
330 | 345 | return dropDone; |
|
331 | 346 | } |
|
332 | 347 | |
|
333 | 348 | void VariableModel::abortProgress(const QModelIndex &index) |
|
334 | 349 | { |
|
335 | 350 | if (auto variable = impl->m_Variables.at(index.row())) { |
|
336 | 351 | emit abortProgessRequested(variable); |
|
337 | 352 | } |
|
338 | 353 | } |
|
339 | 354 | |
|
340 | 355 | void VariableModel::onVariableUpdated() noexcept |
|
341 | 356 | { |
|
342 | 357 | // Finds variable that has been updated in the model |
|
343 | 358 | if (auto updatedVariable = dynamic_cast<Variable *>(sender())) { |
|
344 | 359 | auto updatedVariableIndex = impl->indexOfVariable(updatedVariable); |
|
345 | 360 | |
|
346 | 361 | if (updatedVariableIndex > -1) { |
|
347 | 362 | emit dataChanged(createIndex(updatedVariableIndex, 0), |
|
348 | 363 | createIndex(updatedVariableIndex, columnCount() - 1)); |
|
349 | 364 | } |
|
350 | 365 | } |
|
351 | 366 | } |
|
352 | 367 | |
|
353 | 368 | int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept |
|
354 | 369 | { |
|
355 | 370 | auto begin = std::cbegin(m_Variables); |
|
356 | 371 | auto end = std::cend(m_Variables); |
|
357 | 372 | auto it |
|
358 | 373 | = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; }); |
|
359 | 374 | |
|
360 | 375 | if (it != end) { |
|
361 | 376 | // Gets the index of the variable in the model: we assume here that views have the same |
|
362 | 377 | // order as the model |
|
363 | 378 | return std::distance(begin, it); |
|
364 | 379 | } |
|
365 | 380 | else { |
|
366 | 381 | return -1; |
|
367 | 382 | } |
|
368 | 383 | } |
@@ -1,23 +1,31 | |||
|
1 | 1 | |
|
2 | 2 | |
|
3 | 3 | tests = [ |
|
4 | 4 | [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'], |
|
5 | 5 | [['Data/TestScalarSeries.cpp'],'test_scalar','ScalarSeries test'], |
|
6 | 6 | [['Data/TestSpectrogramSeries.cpp'],'test_spectrogram','SpectrogramSeries test'], |
|
7 | 7 | [['Data/TestVectorSeries.cpp'],'test_vector','VectorSeries test'], |
|
8 | 8 | [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'], |
|
9 | 9 | [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'], |
|
10 | 10 | [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'], |
|
11 | 11 | [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'], |
|
12 | 12 | [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'], |
|
13 | 13 | [['Variable/TestVariable.cpp'],'test_variable','Variable test'], |
|
14 | 14 | [['Variable/TestVariableSync.cpp'],'test_variable_sync','Variable synchronization test'] |
|
15 | 15 | ] |
|
16 | 16 | |
|
17 | amdatest_sources = [ | |
|
18 | 'Data/DataSeriesBuilders.h', | |
|
19 | 'Data/DataSeriesBuilders.cpp', | |
|
20 | 'Data/DataSeriesUtils.h', | |
|
21 | 'Data/DataSeriesUtils.cpp' | |
|
22 | ] | |
|
23 | ||
|
17 | 24 | foreach unit_test : tests |
|
18 | 25 | test_moc_files = qt5.preprocess(moc_sources : unit_test[0]) |
|
19 | 26 | test_exe = executable(unit_test[1],unit_test[0] , test_moc_files, |
|
20 |
dependencies : [sciqlop_core, qt5test] |
|
|
27 | dependencies : [sciqlop_core, qt5test], | |
|
28 | sources : [amdatest_sources]) | |
|
21 | 29 | test(unit_test[2], test_exe, args: ['-teamcity', '-o', '@0@.teamcity.txt'.format(unit_test[1])]) |
|
22 | 30 | endforeach |
|
23 | 31 |
@@ -1,14 +1,15 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASOURCETREEWIDGET_H |
|
2 | 2 | #define SCIQLOP_DATASOURCETREEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <QTreeWidget> |
|
5 | 5 | |
|
6 | 6 | class DataSourceTreeWidget : public QTreeWidget { |
|
7 | 7 | public: |
|
8 | 8 | DataSourceTreeWidget(QWidget *parent); |
|
9 | 9 | |
|
10 | 10 | protected: |
|
11 | 11 | QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const override; |
|
12 | void startDrag(Qt::DropActions supportedActions) override; | |
|
12 | 13 | }; |
|
13 | 14 | |
|
14 | 15 | #endif // SCIQLOP_DATASOURCETREEWIDGET_H |
@@ -1,85 +1,71 | |||
|
1 | 1 | #ifndef SCIQLOP_DRAGDROPHELPER_H |
|
2 | 2 | #define SCIQLOP_DRAGDROPHELPER_H |
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 | 5 | #include <QLoggingCategory> |
|
6 | 6 | #include <QWidget> |
|
7 | 7 | |
|
8 | 8 | class QVBoxLayout; |
|
9 | 9 | class QScrollArea; |
|
10 | class QTabBar; | |
|
10 | 11 | class VisualizationDragWidget; |
|
11 | 12 | class VisualizationDragDropContainer; |
|
12 | 13 | class QMimeData; |
|
13 | 14 | |
|
14 | 15 | Q_DECLARE_LOGGING_CATEGORY(LOG_DragDropHelper) |
|
15 | 16 | |
|
16 | 17 | /** |
|
17 | 18 | * @brief Helper class for drag&drop operations. |
|
18 | 19 | * @note The helper is accessible from the sqpApp singleton and has the same life as the whole |
|
19 | 20 | * application (like a controller). But contrary to a controller, it doesn't live in a thread and |
|
20 | 21 | * can interect with the gui. |
|
21 | 22 | * @see SqpApplication |
|
22 | 23 | */ |
|
23 | 24 | class DragDropHelper { |
|
24 | 25 | public: |
|
25 | 26 | static const QString MIME_TYPE_GRAPH; |
|
26 | 27 | static const QString MIME_TYPE_ZONE; |
|
27 | 28 | |
|
29 | enum class PlaceHolderType { Default, Graph, Zone }; | |
|
30 | ||
|
28 | 31 | DragDropHelper(); |
|
29 | 32 | virtual ~DragDropHelper(); |
|
30 | 33 | |
|
31 | 34 | /// Resets some internal variables. Must be called before any new drag&drop operation. |
|
32 | 35 | void resetDragAndDrop(); |
|
33 | 36 | |
|
34 | 37 | /// Sets the visualization widget currently being drag on the visualization. |
|
35 | 38 | void setCurrentDragWidget(VisualizationDragWidget *dragWidget); |
|
36 | 39 | |
|
37 | 40 | /// Returns the visualization widget currently being drag on the visualization. |
|
38 | 41 | /// Can be null if a new visualization widget is intended to be created by the drag&drop |
|
39 | 42 | /// operation. |
|
40 | 43 | VisualizationDragWidget *getCurrentDragWidget() const; |
|
41 | 44 | |
|
42 | 45 | QWidget &placeHolder() const; |
|
43 |
void insertPlaceHolder(QVBoxLayout *layout, int index |
|
|
46 | void insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type, | |
|
47 | const QString &topLabelText); | |
|
44 | 48 | void removePlaceHolder(); |
|
45 | 49 | bool isPlaceHolderSet() const; |
|
46 | 50 | |
|
47 | 51 | /// Checks if the specified mime data is valid for a drop in the visualization |
|
48 | 52 | bool checkMimeDataForVisualization(const QMimeData *mimeData, |
|
49 | 53 | VisualizationDragDropContainer *dropContainer); |
|
50 | 54 | |
|
51 | 55 | void addDragDropScrollArea(QScrollArea *scrollArea); |
|
52 | 56 | void removeDragDropScrollArea(QScrollArea *scrollArea); |
|
53 | 57 | |
|
58 | void addDragDropTabBar(QTabBar *tabBar); | |
|
59 | void removeDragDropTabBar(QTabBar *tabBar); | |
|
60 | ||
|
54 | 61 | QUrl imageTemporaryUrl(const QImage &image) const; |
|
55 | 62 | |
|
63 | void setHightlightedDragWidget(VisualizationDragWidget *dragWidget); | |
|
64 | VisualizationDragWidget *getHightlightedDragWidget() const; | |
|
65 | ||
|
56 | 66 | private: |
|
57 | 67 | class DragDropHelperPrivate; |
|
58 | 68 | spimpl::unique_impl_ptr<DragDropHelperPrivate> impl; |
|
59 | 69 | }; |
|
60 | 70 | |
|
61 | /** | |
|
62 | * @brief Event filter class which manage the scroll of QScrollArea during a drag&drop operation. | |
|
63 | * @note A QScrollArea inside an other QScrollArea is not fully supported. | |
|
64 | */ | |
|
65 | class DragDropScroller : public QObject { | |
|
66 | Q_OBJECT | |
|
67 | ||
|
68 | public: | |
|
69 | DragDropScroller(QObject *parent = nullptr); | |
|
70 | ||
|
71 | void addScrollArea(QScrollArea *scrollArea); | |
|
72 | void removeScrollArea(QScrollArea *scrollArea); | |
|
73 | ||
|
74 | protected: | |
|
75 | bool eventFilter(QObject *obj, QEvent *event); | |
|
76 | ||
|
77 | private: | |
|
78 | class DragDropScrollerPrivate; | |
|
79 | spimpl::unique_impl_ptr<DragDropScrollerPrivate> impl; | |
|
80 | ||
|
81 | private slots: | |
|
82 | void onTimer(); | |
|
83 | }; | |
|
84 | ||
|
85 | 71 | #endif // SCIQLOP_DRAGDROPHELPER_H |
@@ -1,32 +1,47 | |||
|
1 | 1 | #ifndef SCIQLOP_TIMEWIDGET_H |
|
2 | 2 | #define SCIQLOP_TIMEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <QWidget> |
|
5 | 5 | |
|
6 | 6 | #include <Data/SqpRange.h> |
|
7 | 7 | |
|
8 | #include <Common/spimpl.h> | |
|
9 | ||
|
8 | 10 | namespace Ui { |
|
9 | 11 | class TimeWidget; |
|
10 | 12 | } // Ui |
|
11 | 13 | |
|
12 | 14 | class TimeWidget : public QWidget { |
|
13 | 15 | Q_OBJECT |
|
14 | 16 | |
|
15 | 17 | public: |
|
16 | 18 | explicit TimeWidget(QWidget *parent = 0); |
|
17 | 19 | virtual ~TimeWidget(); |
|
18 | 20 | |
|
21 | void setTimeRange(SqpRange time); | |
|
22 | SqpRange timeRange() const; | |
|
23 | ||
|
19 | 24 | signals: |
|
20 | 25 | /// Signal emitted when the time parameters has beed updated |
|
21 | 26 | void timeUpdated(SqpRange time); |
|
22 | 27 | |
|
23 | 28 | public slots: |
|
24 | 29 | /// slot called when time parameters update has ben requested |
|
25 | 30 | void onTimeUpdateRequested(); |
|
26 | 31 | |
|
32 | protected: | |
|
33 | void dragEnterEvent(QDragEnterEvent *event) override; | |
|
34 | void dragLeaveEvent(QDragLeaveEvent *event) override; | |
|
35 | void dropEvent(QDropEvent *event) override; | |
|
36 | ||
|
37 | void mousePressEvent(QMouseEvent *event) override; | |
|
38 | void mouseMoveEvent(QMouseEvent *event) override; | |
|
27 | 39 | |
|
28 | 40 | private: |
|
29 | 41 | Ui::TimeWidget *ui; |
|
42 | ||
|
43 | class TimeWidgetPrivate; | |
|
44 | spimpl::unique_impl_ptr<TimeWidgetPrivate> impl; | |
|
30 | 45 | }; |
|
31 | 46 | |
|
32 | 47 | #endif // SCIQLOP_ SQPSIDEPANE_H |
@@ -1,51 +1,57 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONDRAGDROPCONTAINER_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONDRAGDROPCONTAINER_H |
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 | #include <QFrame> | |
|
5 | 6 | #include <QLoggingCategory> |
|
6 | 7 | #include <QMimeData> |
|
7 | 8 | #include <QVBoxLayout> |
|
8 | #include <QWidget> | |
|
9 | 9 | |
|
10 | 10 | #include <functional> |
|
11 | 11 | |
|
12 | #include <DragAndDrop/DragDropHelper.h> | |
|
13 | ||
|
12 | 14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer) |
|
13 | 15 | |
|
14 | 16 | class VisualizationDragWidget; |
|
15 | 17 | |
|
16 |
class VisualizationDragDropContainer : public Q |
|
|
18 | class VisualizationDragDropContainer : public QFrame { | |
|
17 | 19 | Q_OBJECT |
|
18 | 20 | |
|
19 | 21 | signals: |
|
20 | void dropOccured(int dropIndex, const QMimeData *mimeData); | |
|
22 | void dropOccuredInContainer(int dropIndex, const QMimeData *mimeData); | |
|
23 | void dropOccuredOnWidget(VisualizationDragWidget *dragWidget, const QMimeData *mimeData); | |
|
21 | 24 | |
|
22 | 25 | public: |
|
26 | enum class DropBehavior { Inserted, Merged, InsertedAndMerged }; | |
|
23 | 27 | using AcceptMimeDataFunction = std::function<bool(const QMimeData *mimeData)>; |
|
24 | 28 | |
|
25 | 29 | VisualizationDragDropContainer(QWidget *parent = nullptr); |
|
26 | 30 | |
|
27 | 31 | void addDragWidget(VisualizationDragWidget *dragWidget); |
|
28 | 32 | void insertDragWidget(int index, VisualizationDragWidget *dragWidget); |
|
29 | 33 | |
|
30 |
void |
|
|
31 | void setMergeAllowedMimeTypes(const QStringList &mimeTypes); | |
|
34 | void addAcceptedMimeType(const QString &mimeType, DropBehavior behavior); | |
|
32 | 35 | |
|
33 | 36 | int countDragWidget() const; |
|
34 | 37 | |
|
35 | 38 | void setAcceptMimeDataFunction(AcceptMimeDataFunction fun); |
|
36 | 39 | |
|
40 | void setPlaceHolderType(DragDropHelper::PlaceHolderType type, | |
|
41 | const QString &placeHolderText = QString()); | |
|
42 | ||
|
37 | 43 | protected: |
|
38 | 44 | void dragEnterEvent(QDragEnterEvent *event); |
|
39 | 45 | void dragLeaveEvent(QDragLeaveEvent *event); |
|
40 | 46 | void dragMoveEvent(QDragMoveEvent *event); |
|
41 | 47 | void dropEvent(QDropEvent *event); |
|
42 | 48 | |
|
43 | 49 | private: |
|
44 | 50 | class VisualizationDragDropContainerPrivate; |
|
45 | 51 | spimpl::unique_impl_ptr<VisualizationDragDropContainerPrivate> impl; |
|
46 | 52 | |
|
47 | 53 | private slots: |
|
48 | 54 | void startDrag(VisualizationDragWidget *dragWidget, const QPoint &dragPosition); |
|
49 | 55 | }; |
|
50 | 56 | |
|
51 | 57 | #endif // SCIQLOP_VISUALIZATIONDRAGDROPCONTAINER_H |
@@ -1,29 +1,30 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONDRAGWIDGET_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONDRAGWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 | 5 | #include <QMimeData> |
|
6 | 6 | #include <QWidget> |
|
7 | 7 | |
|
8 | 8 | class VisualizationDragWidget : public QWidget { |
|
9 | 9 | Q_OBJECT |
|
10 | 10 | |
|
11 | 11 | public: |
|
12 | 12 | VisualizationDragWidget(QWidget *parent = nullptr); |
|
13 | 13 | |
|
14 | 14 | virtual QMimeData *mimeData() const = 0; |
|
15 | 15 | virtual bool isDragAllowed() const = 0; |
|
16 | virtual void highlightForMerge(bool highlighted) { Q_UNUSED(highlighted); }; | |
|
16 | 17 | |
|
17 | 18 | protected: |
|
18 | 19 | virtual void mousePressEvent(QMouseEvent *event) override; |
|
19 | 20 | virtual void mouseMoveEvent(QMouseEvent *event) override; |
|
20 | 21 | |
|
21 | 22 | private: |
|
22 | 23 | class VisualizationDragWidgetPrivate; |
|
23 | 24 | spimpl::unique_impl_ptr<VisualizationDragWidgetPrivate> impl; |
|
24 | 25 | |
|
25 | 26 | signals: |
|
26 | 27 | void dragDetected(VisualizationDragWidget *dragWidget, const QPoint &dragPosition); |
|
27 | 28 | }; |
|
28 | 29 | |
|
29 | 30 | #endif // SCIQLOP_VISUALIZATIONDRAGWIDGET_H |
@@ -1,107 +1,108 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | 5 | #include "Visualization/VisualizationDragWidget.h" |
|
6 | 6 | |
|
7 | 7 | #include <QLoggingCategory> |
|
8 | 8 | #include <QWidget> |
|
9 | 9 | |
|
10 | 10 | #include <memory> |
|
11 | 11 | |
|
12 | 12 | #include <Common/spimpl.h> |
|
13 | 13 | |
|
14 | 14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
15 | 15 | |
|
16 | 16 | class QCPRange; |
|
17 | 17 | class QCustomPlot; |
|
18 | 18 | class SqpRange; |
|
19 | 19 | class Variable; |
|
20 | 20 | class VisualizationZoneWidget; |
|
21 | 21 | |
|
22 | 22 | namespace Ui { |
|
23 | 23 | class VisualizationGraphWidget; |
|
24 | 24 | } // namespace Ui |
|
25 | 25 | |
|
26 | 26 | class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget { |
|
27 | 27 | Q_OBJECT |
|
28 | 28 | |
|
29 | 29 | friend class QCustomPlotSynchronizer; |
|
30 | 30 | friend class VisualizationGraphRenderingDelegate; |
|
31 | 31 | |
|
32 | 32 | public: |
|
33 | 33 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
34 | 34 | virtual ~VisualizationGraphWidget(); |
|
35 | 35 | |
|
36 | 36 | VisualizationZoneWidget *parentZoneWidget() const noexcept; |
|
37 | 37 | |
|
38 | 38 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
39 | 39 | void enableAcquisition(bool enable); |
|
40 | 40 | |
|
41 | 41 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); |
|
42 | 42 | |
|
43 | 43 | /// Removes a variable from the graph |
|
44 | 44 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
45 | 45 | |
|
46 | 46 | /// Returns the list of all variables used in the graph |
|
47 | 47 | QList<std::shared_ptr<Variable> > variables() const; |
|
48 | 48 | |
|
49 | 49 | void setYRange(const SqpRange &range); |
|
50 | 50 | SqpRange graphRange() const noexcept; |
|
51 | 51 | void setGraphRange(const SqpRange &range); |
|
52 | 52 | |
|
53 | 53 | // IVisualizationWidget interface |
|
54 | 54 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
55 | 55 | bool canDrop(const Variable &variable) const override; |
|
56 | 56 | bool contains(const Variable &variable) const override; |
|
57 | 57 | QString name() const override; |
|
58 | 58 | |
|
59 | 59 | // VisualisationDragWidget |
|
60 | 60 | QMimeData *mimeData() const override; |
|
61 | 61 | bool isDragAllowed() const override; |
|
62 | void highlightForMerge(bool highlighted) override; | |
|
62 | 63 | |
|
63 | 64 | signals: |
|
64 | 65 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
|
65 | 66 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, |
|
66 | 67 | bool synchronise); |
|
67 | 68 | |
|
68 | 69 | /// Signal emitted when the variable is about to be removed from the graph |
|
69 | 70 | void variableAboutToBeRemoved(std::shared_ptr<Variable> var); |
|
70 | 71 | /// Signal emitted when the variable has been added to the graph |
|
71 | 72 | void variableAdded(std::shared_ptr<Variable> var); |
|
72 | 73 | |
|
73 | 74 | protected: |
|
74 | 75 | void closeEvent(QCloseEvent *event) override; |
|
75 | 76 | void enterEvent(QEvent *event) override; |
|
76 | 77 | void leaveEvent(QEvent *event) override; |
|
77 | 78 | |
|
78 | 79 | QCustomPlot &plot() noexcept; |
|
79 | 80 | |
|
80 | 81 | private: |
|
81 | 82 | Ui::VisualizationGraphWidget *ui; |
|
82 | 83 | |
|
83 | 84 | class VisualizationGraphWidgetPrivate; |
|
84 | 85 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
85 | 86 | |
|
86 | 87 | private slots: |
|
87 | 88 | /// Slot called when right clicking on the graph (displays a menu) |
|
88 | 89 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
89 | 90 | |
|
90 | 91 | /// Rescale the X axe to range parameter |
|
91 | 92 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); |
|
92 | 93 | |
|
93 | 94 | /// Slot called when a mouse move was made |
|
94 | 95 | void onMouseMove(QMouseEvent *event) noexcept; |
|
95 | 96 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
96 | 97 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
97 | 98 | /// Slot called when a mouse press was made, to activate the calibration of a graph |
|
98 | 99 | void onMousePress(QMouseEvent *event) noexcept; |
|
99 | 100 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph |
|
100 | 101 | void onMouseRelease(QMouseEvent *event) noexcept; |
|
101 | 102 | |
|
102 | 103 | void onDataCacheVariableUpdated(); |
|
103 | 104 | |
|
104 | 105 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
105 | 106 | }; |
|
106 | 107 | |
|
107 | 108 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,90 +1,91 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | 5 | #include "Visualization/VisualizationDragWidget.h" |
|
6 | 6 | |
|
7 | 7 | #include <QLoggingCategory> |
|
8 | 8 | #include <QWidget> |
|
9 | 9 | |
|
10 | 10 | #include <memory> |
|
11 | 11 | |
|
12 | 12 | #include <Common/spimpl.h> |
|
13 | 13 | |
|
14 | 14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget) |
|
15 | 15 | |
|
16 | 16 | namespace Ui { |
|
17 | 17 | class VisualizationZoneWidget; |
|
18 | 18 | } // namespace Ui |
|
19 | 19 | |
|
20 | 20 | class Variable; |
|
21 | 21 | class VisualizationGraphWidget; |
|
22 | 22 | |
|
23 | 23 | class VisualizationZoneWidget : public VisualizationDragWidget, public IVisualizationWidget { |
|
24 | 24 | Q_OBJECT |
|
25 | 25 | |
|
26 | 26 | public: |
|
27 | 27 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); |
|
28 | 28 | virtual ~VisualizationZoneWidget(); |
|
29 | 29 | |
|
30 | 30 | /// Adds a graph widget |
|
31 | 31 | void addGraph(VisualizationGraphWidget *graphWidget); |
|
32 | 32 | |
|
33 | 33 | /// Inserts a graph widget |
|
34 | 34 | void insertGraph(int index, VisualizationGraphWidget *graphWidget); |
|
35 | 35 | |
|
36 | 36 | /** |
|
37 | 37 | * Creates a graph using a variable. The variable will be displayed in the new graph. |
|
38 | 38 | * The graph is added at the end. |
|
39 | 39 | * @param variable the variable for which to create the graph |
|
40 | 40 | * @return the pointer to the created graph |
|
41 | 41 | */ |
|
42 | 42 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable); |
|
43 | 43 | |
|
44 | 44 | /** |
|
45 | 45 | * Creates a graph using a variable. The variable will be displayed in the new graph. |
|
46 | 46 | * The graph is inserted at the specified index. |
|
47 | 47 | * @param variable the variable for which to create the graph |
|
48 | 48 | * @param index The index where the graph should be inserted in the layout |
|
49 | 49 | * @return the pointer to the created graph |
|
50 | 50 | */ |
|
51 | 51 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable, int index); |
|
52 | 52 | |
|
53 | 53 | /** |
|
54 | 54 | * Creates a graph using a list of variables. The variables will be displayed in the new graph. |
|
55 | 55 | * The graph is inserted at the specified index. |
|
56 | 56 | * @param variables List of variables to be added to the graph |
|
57 | 57 | * @param index The index where the graph should be inserted in the layout |
|
58 | 58 | * @return the pointer to the created graph |
|
59 | 59 | */ |
|
60 | 60 | VisualizationGraphWidget *createGraph(const QList<std::shared_ptr<Variable> > variables, |
|
61 | 61 | int index); |
|
62 | 62 | |
|
63 | 63 | // IVisualizationWidget interface |
|
64 | 64 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
65 | 65 | bool canDrop(const Variable &variable) const override; |
|
66 | 66 | bool contains(const Variable &variable) const override; |
|
67 | 67 | QString name() const override; |
|
68 | 68 | |
|
69 | 69 | // VisualisationDragWidget |
|
70 | 70 | QMimeData *mimeData() const override; |
|
71 | 71 | bool isDragAllowed() const override; |
|
72 | 72 | |
|
73 | 73 | protected: |
|
74 | 74 | void closeEvent(QCloseEvent *event) override; |
|
75 | 75 | |
|
76 | 76 | private: |
|
77 | 77 | Ui::VisualizationZoneWidget *ui; |
|
78 | 78 | |
|
79 | 79 | class VisualizationZoneWidgetPrivate; |
|
80 | 80 | spimpl::unique_impl_ptr<VisualizationZoneWidgetPrivate> impl; |
|
81 | 81 | |
|
82 | 82 | private slots: |
|
83 | 83 | void onVariableAdded(std::shared_ptr<Variable> variable); |
|
84 | 84 | /// Slot called when a variable is about to be removed from a graph contained in the zone |
|
85 | 85 | void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable); |
|
86 | 86 | |
|
87 | 87 | void dropMimeData(int index, const QMimeData *mimeData); |
|
88 | void dropMimeDataOnGraph(VisualizationDragWidget *dragWidget, const QMimeData *mimeData); | |
|
88 | 89 | }; |
|
89 | 90 | |
|
90 | 91 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -1,87 +1,95 | |||
|
1 | 1 | |
|
2 | 2 | gui_moc_headers = [ |
|
3 | 3 | 'include/DataSource/DataSourceWidget.h', |
|
4 | 'include/DataSource/DataSourceTreeWidget.h', | |
|
4 | 5 | 'include/Settings/SqpSettingsDialog.h', |
|
5 | 6 | 'include/Settings/SqpSettingsGeneralWidget.h', |
|
6 | 7 | 'include/SidePane/SqpSidePane.h', |
|
7 | 8 | 'include/SqpApplication.h', |
|
8 | 'include/DragDropHelper.h', | |
|
9 | 'include/DragAndDrop/DragDropHelper.h', | |
|
10 | 'include/DragAndDrop/DragDropScroller.h', | |
|
11 | 'include/DragAndDrop/DragDropTabSwitcher.h', | |
|
9 | 12 | 'include/TimeWidget/TimeWidget.h', |
|
10 | 13 | 'include/Variable/VariableInspectorWidget.h', |
|
14 | 'include/Variable/VariableInspectorTableView.h', | |
|
11 | 15 | 'include/Variable/RenameVariableDialog.h', |
|
12 | 16 | 'include/Visualization/qcustomplot.h', |
|
13 | 17 | 'include/Visualization/VisualizationGraphWidget.h', |
|
14 | 18 | 'include/Visualization/VisualizationTabWidget.h', |
|
15 | 19 | 'include/Visualization/VisualizationWidget.h', |
|
16 | 20 | 'include/Visualization/VisualizationZoneWidget.h', |
|
17 | 21 | 'include/Visualization/VisualizationDragDropContainer.h', |
|
18 | 22 | 'include/Visualization/VisualizationDragWidget.h' |
|
19 | 23 | ] |
|
20 | 24 | |
|
21 | 25 | gui_ui_files = [ |
|
22 | 26 | 'ui/DataSource/DataSourceWidget.ui', |
|
23 | 27 | 'ui/Settings/SqpSettingsDialog.ui', |
|
24 | 28 | 'ui/Settings/SqpSettingsGeneralWidget.ui', |
|
25 | 29 | 'ui/SidePane/SqpSidePane.ui', |
|
26 | 30 | 'ui/TimeWidget/TimeWidget.ui', |
|
27 | 31 | 'ui/Variable/VariableInspectorWidget.ui', |
|
28 | 32 | 'ui/Variable/RenameVariableDialog.ui', |
|
29 | 33 | 'ui/Variable/VariableMenuHeaderWidget.ui', |
|
30 | 34 | 'ui/Visualization/VisualizationGraphWidget.ui', |
|
31 | 35 | 'ui/Visualization/VisualizationTabWidget.ui', |
|
32 | 36 | 'ui/Visualization/VisualizationWidget.ui', |
|
33 | 37 | 'ui/Visualization/VisualizationZoneWidget.ui' |
|
34 | 38 | ] |
|
35 | 39 | |
|
36 | 40 | gui_qresources = ['resources/sqpguiresources.qrc'] |
|
37 | 41 | |
|
38 | 42 | gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers, |
|
39 | 43 | ui_files : gui_ui_files, |
|
40 | 44 | qresources : gui_qresources) |
|
41 | 45 | |
|
42 | 46 | gui_sources = [ |
|
43 | 47 | 'src/SqpApplication.cpp', |
|
44 | 'src/DragDropHelper.cpp', | |
|
48 | 'src/DragAndDrop/DragDropHelper.cpp', | |
|
49 | 'src/DragAndDrop/DragDropScroller.cpp', | |
|
50 | 'src/DragAndDrop/DragDropTabSwitcher.cpp', | |
|
45 | 51 | 'src/Common/ColorUtils.cpp', |
|
46 | 52 | 'src/Common/VisualizationDef.cpp', |
|
47 | 53 | 'src/DataSource/DataSourceTreeWidgetItem.cpp', |
|
48 | 54 | 'src/DataSource/DataSourceTreeWidgetHelper.cpp', |
|
49 | 55 | 'src/DataSource/DataSourceWidget.cpp', |
|
56 | 'src/DataSource/DataSourceTreeWidget.cpp', | |
|
50 | 57 | 'src/Settings/SqpSettingsDialog.cpp', |
|
51 | 58 | 'src/Settings/SqpSettingsGeneralWidget.cpp', |
|
52 | 59 | 'src/SidePane/SqpSidePane.cpp', |
|
53 | 60 | 'src/TimeWidget/TimeWidget.cpp', |
|
54 | 61 | 'src/Variable/VariableInspectorWidget.cpp', |
|
62 | 'src/Variable/VariableInspectorTableView.cpp', | |
|
55 | 63 | 'src/Variable/VariableMenuHeaderWidget.cpp', |
|
56 | 64 | 'src/Variable/RenameVariableDialog.cpp', |
|
57 | 65 | 'src/Visualization/VisualizationGraphHelper.cpp', |
|
58 | 66 | 'src/Visualization/VisualizationGraphRenderingDelegate.cpp', |
|
59 | 67 | 'src/Visualization/VisualizationGraphWidget.cpp', |
|
60 | 68 | 'src/Visualization/VisualizationTabWidget.cpp', |
|
61 | 69 | 'src/Visualization/VisualizationWidget.cpp', |
|
62 | 70 | 'src/Visualization/VisualizationZoneWidget.cpp', |
|
63 | 71 | 'src/Visualization/qcustomplot.cpp', |
|
64 | 72 | 'src/Visualization/QCustomPlotSynchronizer.cpp', |
|
65 | 73 | 'src/Visualization/operations/FindVariableOperation.cpp', |
|
66 | 74 | 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', |
|
67 | 75 | 'src/Visualization/operations/MenuBuilder.cpp', |
|
68 | 76 | 'src/Visualization/operations/RemoveVariableOperation.cpp', |
|
69 | 77 | 'src/Visualization/operations/RescaleAxeOperation.cpp', |
|
70 | 78 | 'src/Visualization/VisualizationDragDropContainer.cpp', |
|
71 | 79 | 'src/Visualization/VisualizationDragWidget.cpp' |
|
72 | 80 | ] |
|
73 | 81 | |
|
74 | 82 | gui_inc = include_directories(['include']) |
|
75 | 83 | |
|
76 | 84 | sciqlop_gui_lib = library('sciqlopgui', |
|
77 | 85 | gui_sources, |
|
78 | 86 | gui_moc_files, |
|
79 | 87 | include_directories : [gui_inc], |
|
80 | 88 | dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core], |
|
81 | 89 | install : true |
|
82 | 90 | ) |
|
83 | 91 | |
|
84 | 92 | sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, |
|
85 | 93 | include_directories : gui_inc, |
|
86 | 94 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core]) |
|
87 | 95 |
@@ -1,37 +1,45 | |||
|
1 | 1 | #include "DataSource/DataSourceTreeWidget.h" |
|
2 | 2 | #include "Common/MimeTypesDef.h" |
|
3 | 3 | #include "DataSource/DataSourceController.h" |
|
4 | 4 | #include "DataSource/DataSourceItem.h" |
|
5 | 5 | #include "DataSource/DataSourceTreeWidgetItem.h" |
|
6 | 6 | |
|
7 | #include "DragAndDrop/DragDropHelper.h" | |
|
7 | 8 | #include "SqpApplication.h" |
|
8 | 9 | |
|
9 | 10 | #include <QMimeData> |
|
10 | 11 | |
|
11 | 12 | DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {} |
|
12 | 13 | |
|
13 | 14 | QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const |
|
14 | 15 | { |
|
15 | 16 | auto mimeData = new QMimeData; |
|
16 | 17 | |
|
17 | 18 | // Basic check to ensure the item are correctly typed |
|
18 | 19 | Q_ASSERT(items.isEmpty() || dynamic_cast<DataSourceTreeWidgetItem *>(items.first()) != nullptr); |
|
19 | 20 | |
|
20 | 21 | QVariantList productData; |
|
21 | 22 | |
|
22 | 23 | for (auto item : items) { |
|
23 | 24 | auto dataSourceTreeItem = static_cast<DataSourceTreeWidgetItem *>(item); |
|
24 | 25 | auto dataSource = dataSourceTreeItem->data(); |
|
25 | 26 | |
|
26 | 27 | if (dataSource->type() == DataSourceItemType::COMPONENT |
|
27 | 28 | || dataSource->type() == DataSourceItemType::PRODUCT) { |
|
28 | 29 | auto metaData = dataSource->data(); |
|
29 | 30 | productData << metaData; |
|
30 | 31 | } |
|
31 | 32 | } |
|
32 | 33 | |
|
33 | 34 | auto encodedData = sqpApp->dataSourceController().mimeDataForProductsData(productData); |
|
34 | 35 | mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData); |
|
35 | 36 | |
|
36 | 37 | return mimeData; |
|
37 | 38 | } |
|
39 | ||
|
40 | void DataSourceTreeWidget::startDrag(Qt::DropActions supportedActions) | |
|
41 | { | |
|
42 | // Resets the drag&drop operations before it's starting | |
|
43 | sqpApp->dragDropHelper().resetDragAndDrop(); | |
|
44 | QTreeWidget::startDrag(supportedActions); | |
|
45 | } |
@@ -1,295 +1,125 | |||
|
1 |
#include "Drag |
|
|
2 | #include "SqpApplication.h" | |
|
3 | #include "Visualization/VisualizationDragDropContainer.h" | |
|
4 | #include "Visualization/VisualizationDragWidget.h" | |
|
5 | #include "Visualization/VisualizationWidget.h" | |
|
6 | #include "Visualization/operations/FindVariableOperation.h" | |
|
1 | #include "DragAndDrop/DragDropScroller.h" | |
|
7 | 2 | |
|
8 | #include "Variable/VariableController.h" | |
|
9 | ||
|
10 | #include "Common/MimeTypesDef.h" | |
|
11 | #include "Common/VisualizationDef.h" | |
|
12 | ||
|
13 | #include <QDir> | |
|
14 | 3 | #include <QDragEnterEvent> |
|
15 | 4 | #include <QDragMoveEvent> |
|
16 | #include <QScrollArea> | |
|
17 | 5 | #include <QScrollBar> |
|
18 | 6 | #include <QTimer> |
|
19 | #include <QVBoxLayout> | |
|
20 | 7 | |
|
21 | 8 | const int SCROLL_SPEED = 5; |
|
22 | 9 | const int SCROLL_ZONE_SIZE = 50; |
|
23 | 10 | |
|
24 | Q_LOGGING_CATEGORY(LOG_DragDropHelper, "DragDrophelper") | |
|
25 | ||
|
26 | 11 | struct DragDropScroller::DragDropScrollerPrivate { |
|
27 | 12 | |
|
28 | 13 | QList<QScrollArea *> m_ScrollAreas; |
|
29 | 14 | QScrollArea *m_CurrentScrollArea = nullptr; |
|
30 | 15 | std::unique_ptr<QTimer> m_Timer = nullptr; |
|
31 | 16 | |
|
32 | ||
|
33 | 17 | enum class ScrollDirection { up, down, unknown }; |
|
34 | 18 | ScrollDirection m_Direction = ScrollDirection::unknown; |
|
35 | 19 | |
|
36 | 20 | explicit DragDropScrollerPrivate() : m_Timer{std::make_unique<QTimer>()} |
|
37 | 21 | { |
|
38 | 22 | m_Timer->setInterval(0); |
|
39 | 23 | } |
|
40 | 24 | }; |
|
41 | 25 | |
|
42 | 26 | DragDropScroller::DragDropScroller(QObject *parent) |
|
43 | 27 | : QObject{parent}, impl{spimpl::make_unique_impl<DragDropScrollerPrivate>()} |
|
44 | 28 | { |
|
45 | 29 | connect(impl->m_Timer.get(), &QTimer::timeout, this, &DragDropScroller::onTimer); |
|
46 | 30 | } |
|
47 | 31 | |
|
48 | 32 | void DragDropScroller::addScrollArea(QScrollArea *scrollArea) |
|
49 | 33 | { |
|
50 | 34 | impl->m_ScrollAreas << scrollArea; |
|
51 | 35 | scrollArea->viewport()->setAcceptDrops(true); |
|
52 | 36 | } |
|
53 | 37 | |
|
54 | 38 | void DragDropScroller::removeScrollArea(QScrollArea *scrollArea) |
|
55 | 39 | { |
|
56 | 40 | impl->m_ScrollAreas.removeAll(scrollArea); |
|
57 | 41 | scrollArea->viewport()->setAcceptDrops(false); |
|
58 | 42 | } |
|
59 | 43 | |
|
60 | 44 | bool DragDropScroller::eventFilter(QObject *obj, QEvent *event) |
|
61 | 45 | { |
|
62 | 46 | if (event->type() == QEvent::DragMove) { |
|
63 | 47 | auto w = static_cast<QWidget *>(obj); |
|
64 | 48 | |
|
65 | 49 | if (impl->m_CurrentScrollArea && impl->m_CurrentScrollArea->isAncestorOf(w)) { |
|
66 | 50 | auto moveEvent = static_cast<QDragMoveEvent *>(event); |
|
67 | 51 | |
|
68 | 52 | auto pos = moveEvent->pos(); |
|
69 | 53 | if (impl->m_CurrentScrollArea->viewport() != w) { |
|
70 | 54 | auto globalPos = w->mapToGlobal(moveEvent->pos()); |
|
71 | 55 | pos = impl->m_CurrentScrollArea->viewport()->mapFromGlobal(globalPos); |
|
72 | 56 | } |
|
73 | 57 | |
|
74 | 58 | auto isInTopZone = pos.y() > impl->m_CurrentScrollArea->viewport()->size().height() |
|
75 | 59 | - SCROLL_ZONE_SIZE; |
|
76 | 60 | auto isInBottomZone = pos.y() < SCROLL_ZONE_SIZE; |
|
77 | 61 | |
|
78 | 62 | if (!isInTopZone && !isInBottomZone) { |
|
79 | 63 | impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown; |
|
80 | 64 | impl->m_Timer->stop(); |
|
81 | 65 | } |
|
82 | 66 | else if (!impl->m_Timer->isActive()) { |
|
83 | 67 | impl->m_Direction = isInTopZone ? DragDropScrollerPrivate::ScrollDirection::up |
|
84 | 68 | : DragDropScrollerPrivate::ScrollDirection::down; |
|
85 | 69 | impl->m_Timer->start(); |
|
86 | 70 | } |
|
87 | 71 | } |
|
88 | 72 | } |
|
89 | 73 | else if (event->type() == QEvent::DragEnter) { |
|
90 | 74 | auto w = static_cast<QWidget *>(obj); |
|
91 | 75 | |
|
92 | 76 | for (auto scrollArea : impl->m_ScrollAreas) { |
|
93 | 77 | if (impl->m_CurrentScrollArea != scrollArea && scrollArea->isAncestorOf(w)) { |
|
94 | 78 | auto enterEvent = static_cast<QDragEnterEvent *>(event); |
|
95 | 79 | enterEvent->acceptProposedAction(); |
|
96 | 80 | enterEvent->setDropAction(Qt::IgnoreAction); |
|
97 | 81 | impl->m_CurrentScrollArea = scrollArea; |
|
98 | 82 | break; |
|
99 | 83 | } |
|
100 | 84 | } |
|
101 | 85 | } |
|
102 | 86 | else if (event->type() == QEvent::DragLeave) { |
|
103 | 87 | if (impl->m_CurrentScrollArea) { |
|
104 | 88 | if (!QRect(QPoint(), impl->m_CurrentScrollArea->size()) |
|
105 | 89 | .contains(impl->m_CurrentScrollArea->mapFromGlobal(QCursor::pos()))) { |
|
106 | 90 | impl->m_CurrentScrollArea = nullptr; |
|
107 | 91 | impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown; |
|
108 | 92 | impl->m_Timer->stop(); |
|
109 | 93 | } |
|
110 | 94 | } |
|
111 | 95 | } |
|
112 | 96 | else if (event->type() == QEvent::Drop) { |
|
113 | 97 | if (impl->m_CurrentScrollArea) { |
|
114 | 98 | impl->m_CurrentScrollArea = nullptr; |
|
115 | 99 | impl->m_Direction = DragDropScrollerPrivate::ScrollDirection::unknown; |
|
116 | 100 | impl->m_Timer->stop(); |
|
117 | 101 | } |
|
118 | 102 | } |
|
119 | 103 | |
|
120 | 104 | return false; |
|
121 | 105 | } |
|
122 | 106 | |
|
123 | 107 | void DragDropScroller::onTimer() |
|
124 | 108 | { |
|
125 | 109 | if (impl->m_CurrentScrollArea) { |
|
126 | 110 | auto mvt = 0; |
|
127 | 111 | switch (impl->m_Direction) { |
|
128 | 112 | case DragDropScrollerPrivate::ScrollDirection::up: |
|
129 | 113 | mvt = SCROLL_SPEED; |
|
130 | 114 | break; |
|
131 | 115 | case DragDropScrollerPrivate::ScrollDirection::down: |
|
132 | 116 | mvt = -SCROLL_SPEED; |
|
133 | 117 | break; |
|
134 | 118 | default: |
|
135 | 119 | break; |
|
136 | 120 | } |
|
137 | 121 | |
|
138 | 122 | impl->m_CurrentScrollArea->verticalScrollBar()->setValue( |
|
139 | 123 | impl->m_CurrentScrollArea->verticalScrollBar()->value() + mvt); |
|
140 | 124 | } |
|
141 | 125 | } |
|
142 | ||
|
143 | struct DragDropHelper::DragDropHelperPrivate { | |
|
144 | ||
|
145 | VisualizationDragWidget *m_CurrentDragWidget = nullptr; | |
|
146 | std::unique_ptr<QWidget> m_PlaceHolder = nullptr; | |
|
147 | std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr; | |
|
148 | QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using | |
|
149 | // QTemporaryFile to have a name which is not generated. | |
|
150 | ||
|
151 | explicit DragDropHelperPrivate() | |
|
152 | : m_PlaceHolder{std::make_unique<QWidget>()}, | |
|
153 | m_DragDropScroller{std::make_unique<DragDropScroller>()} | |
|
154 | { | |
|
155 | m_PlaceHolder->setStyleSheet("background-color: #BBD5EE; border:2px solid #2A7FD4"); | |
|
156 | sqpApp->installEventFilter(m_DragDropScroller.get()); | |
|
157 | ||
|
158 | ||
|
159 | m_ImageTempUrl = QDir::temp().absoluteFilePath("Scqlop_graph.png"); | |
|
160 | } | |
|
161 | ||
|
162 | void preparePlaceHolder() const | |
|
163 | { | |
|
164 | if (m_CurrentDragWidget) { | |
|
165 | m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size()); | |
|
166 | m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy()); | |
|
167 | } | |
|
168 | else { | |
|
169 | // Configuration of the placeHolder when there is no dragWidget | |
|
170 | // (for instance with a drag from a variable) | |
|
171 | ||
|
172 | m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT); | |
|
173 | m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
|
174 | } | |
|
175 | } | |
|
176 | }; | |
|
177 | ||
|
178 | ||
|
179 | DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()} | |
|
180 | { | |
|
181 | } | |
|
182 | ||
|
183 | DragDropHelper::~DragDropHelper() | |
|
184 | { | |
|
185 | QFile::remove(impl->m_ImageTempUrl); | |
|
186 | } | |
|
187 | ||
|
188 | void DragDropHelper::resetDragAndDrop() | |
|
189 | { | |
|
190 | setCurrentDragWidget(nullptr); | |
|
191 | } | |
|
192 | ||
|
193 | void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget) | |
|
194 | { | |
|
195 | impl->m_CurrentDragWidget = dragWidget; | |
|
196 | } | |
|
197 | ||
|
198 | VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const | |
|
199 | { | |
|
200 | return impl->m_CurrentDragWidget; | |
|
201 | } | |
|
202 | ||
|
203 | ||
|
204 | QWidget &DragDropHelper::placeHolder() const | |
|
205 | { | |
|
206 | return *impl->m_PlaceHolder; | |
|
207 | } | |
|
208 | ||
|
209 | void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index) | |
|
210 | { | |
|
211 | removePlaceHolder(); | |
|
212 | impl->preparePlaceHolder(); | |
|
213 | layout->insertWidget(index, impl->m_PlaceHolder.get()); | |
|
214 | impl->m_PlaceHolder->show(); | |
|
215 | } | |
|
216 | ||
|
217 | void DragDropHelper::removePlaceHolder() | |
|
218 | { | |
|
219 | auto parentWidget = impl->m_PlaceHolder->parentWidget(); | |
|
220 | if (parentWidget) { | |
|
221 | parentWidget->layout()->removeWidget(impl->m_PlaceHolder.get()); | |
|
222 | impl->m_PlaceHolder->setParent(nullptr); | |
|
223 | impl->m_PlaceHolder->hide(); | |
|
224 | } | |
|
225 | } | |
|
226 | ||
|
227 | bool DragDropHelper::isPlaceHolderSet() const | |
|
228 | { | |
|
229 | return impl->m_PlaceHolder->parentWidget(); | |
|
230 | } | |
|
231 | ||
|
232 | void DragDropHelper::addDragDropScrollArea(QScrollArea *scrollArea) | |
|
233 | { | |
|
234 | impl->m_DragDropScroller->addScrollArea(scrollArea); | |
|
235 | } | |
|
236 | ||
|
237 | void DragDropHelper::removeDragDropScrollArea(QScrollArea *scrollArea) | |
|
238 | { | |
|
239 | impl->m_DragDropScroller->removeScrollArea(scrollArea); | |
|
240 | } | |
|
241 | ||
|
242 | QUrl DragDropHelper::imageTemporaryUrl(const QImage &image) const | |
|
243 | { | |
|
244 | image.save(impl->m_ImageTempUrl); | |
|
245 | return QUrl::fromLocalFile(impl->m_ImageTempUrl); | |
|
246 | } | |
|
247 | ||
|
248 | bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData, | |
|
249 | VisualizationDragDropContainer *dropContainer) | |
|
250 | { | |
|
251 | if (!mimeData || !dropContainer) { | |
|
252 | qCWarning(LOG_DragDropHelper()) << QObject::tr( | |
|
253 | "DragDropHelper::checkMimeDataForVisualization, invalid input parameters."); | |
|
254 | Q_ASSERT(false); | |
|
255 | } | |
|
256 | ||
|
257 | auto result = true; | |
|
258 | ||
|
259 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
|
260 | auto variables = sqpApp->variableController().variablesForMimeData( | |
|
261 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
|
262 | ||
|
263 | if (variables.count() == 1) { | |
|
264 | // Check that the viariable is not already in a graph | |
|
265 | ||
|
266 | // Search for the top level VisualizationWidget | |
|
267 | auto parent = dropContainer->parentWidget(); | |
|
268 | while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) { | |
|
269 | parent = parent->parentWidget(); | |
|
270 | } | |
|
271 | ||
|
272 | if (parent) { | |
|
273 | auto visualizationWidget = static_cast<VisualizationWidget *>(parent); | |
|
274 | ||
|
275 | FindVariableOperation findVariableOperation{variables.first()}; | |
|
276 | visualizationWidget->accept(&findVariableOperation); | |
|
277 | auto variableContainers = findVariableOperation.result(); | |
|
278 | if (!variableContainers.empty()) { | |
|
279 | result = false; | |
|
280 | } | |
|
281 | } | |
|
282 | else { | |
|
283 | qCWarning(LOG_DragDropHelper()) << QObject::tr( | |
|
284 | "DragDropHelper::checkMimeDataForVisualization, the parent " | |
|
285 | "VisualizationWidget cannot be found."); | |
|
286 | result = false; | |
|
287 | } | |
|
288 | } | |
|
289 | else { | |
|
290 | result = false; | |
|
291 | } | |
|
292 | } | |
|
293 | ||
|
294 | return result; | |
|
295 | } |
@@ -1,163 +1,163 | |||
|
1 | 1 | #include "SqpApplication.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/IDataProvider.h> |
|
4 | 4 | #include <DataSource/DataSourceController.h> |
|
5 | #include <DragDropHelper.h> | |
|
5 | #include <DragAndDrop/DragDropHelper.h> | |
|
6 | 6 | #include <Network/NetworkController.h> |
|
7 | 7 | #include <QThread> |
|
8 | 8 | #include <Time/TimeController.h> |
|
9 | 9 | #include <Variable/Variable.h> |
|
10 | 10 | #include <Variable/VariableController.h> |
|
11 | 11 | #include <Variable/VariableModel.h> |
|
12 | 12 | #include <Visualization/VisualizationController.h> |
|
13 | 13 | |
|
14 | 14 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
15 | 15 | |
|
16 | 16 | class SqpApplication::SqpApplicationPrivate { |
|
17 | 17 | public: |
|
18 | 18 | SqpApplicationPrivate() |
|
19 | 19 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
20 | 20 | m_NetworkController{std::make_unique<NetworkController>()}, |
|
21 | 21 | m_TimeController{std::make_unique<TimeController>()}, |
|
22 | 22 | m_VariableController{std::make_unique<VariableController>()}, |
|
23 | 23 | m_VisualizationController{std::make_unique<VisualizationController>()}, |
|
24 | 24 | m_DragDropHelper{std::make_unique<DragDropHelper>()} |
|
25 | 25 | { |
|
26 | 26 | // /////////////////////////////// // |
|
27 | 27 | // Connections between controllers // |
|
28 | 28 | // /////////////////////////////// // |
|
29 | 29 | |
|
30 | 30 | // VariableController <-> DataSourceController |
|
31 | 31 | connect(m_DataSourceController.get(), |
|
32 | 32 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, |
|
33 | 33 | std::shared_ptr<IDataProvider>)), |
|
34 | 34 | m_VariableController.get(), |
|
35 | 35 | SLOT(createVariable(const QString &, const QVariantHash &, |
|
36 | 36 | std::shared_ptr<IDataProvider>))); |
|
37 | 37 | |
|
38 | 38 | connect(m_VariableController->variableModel(), &VariableModel::requestVariable, |
|
39 | 39 | m_DataSourceController.get(), &DataSourceController::requestVariable); |
|
40 | 40 | |
|
41 | 41 | // VariableController <-> VisualizationController |
|
42 | 42 | connect(m_VariableController.get(), |
|
43 | 43 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
44 | 44 | m_VisualizationController.get(), |
|
45 | 45 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
46 | 46 | |
|
47 | 47 | connect(m_VariableController.get(), |
|
48 | 48 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), |
|
49 | 49 | m_VisualizationController.get(), |
|
50 | 50 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &))); |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
54 | 54 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); |
|
55 | 55 | m_NetworkController->moveToThread(&m_NetworkControllerThread); |
|
56 | 56 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); |
|
57 | 57 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
58 | 58 | m_VariableControllerThread.setObjectName("VariableControllerThread"); |
|
59 | 59 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
60 | 60 | m_VisualizationControllerThread.setObjectName("VsualizationControllerThread"); |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | // Additionnal init |
|
64 | 64 | m_VariableController->setTimeController(m_TimeController.get()); |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | virtual ~SqpApplicationPrivate() |
|
68 | 68 | { |
|
69 | 69 | m_DataSourceControllerThread.quit(); |
|
70 | 70 | m_DataSourceControllerThread.wait(); |
|
71 | 71 | |
|
72 | 72 | m_NetworkControllerThread.quit(); |
|
73 | 73 | m_NetworkControllerThread.wait(); |
|
74 | 74 | |
|
75 | 75 | m_VariableControllerThread.quit(); |
|
76 | 76 | m_VariableControllerThread.wait(); |
|
77 | 77 | |
|
78 | 78 | m_VisualizationControllerThread.quit(); |
|
79 | 79 | m_VisualizationControllerThread.wait(); |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
83 | 83 | std::unique_ptr<VariableController> m_VariableController; |
|
84 | 84 | std::unique_ptr<TimeController> m_TimeController; |
|
85 | 85 | std::unique_ptr<NetworkController> m_NetworkController; |
|
86 | 86 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
87 | 87 | QThread m_DataSourceControllerThread; |
|
88 | 88 | QThread m_NetworkControllerThread; |
|
89 | 89 | QThread m_VariableControllerThread; |
|
90 | 90 | QThread m_VisualizationControllerThread; |
|
91 | 91 | |
|
92 | 92 | std::unique_ptr<DragDropHelper> m_DragDropHelper; |
|
93 | 93 | }; |
|
94 | 94 | |
|
95 | 95 | |
|
96 | 96 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
97 | 97 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
98 | 98 | { |
|
99 | 99 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); |
|
100 | 100 | |
|
101 | 101 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
102 | 102 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
103 | 103 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
104 | 104 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
105 | 105 | |
|
106 | 106 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), |
|
107 | 107 | &NetworkController::initialize); |
|
108 | 108 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), |
|
109 | 109 | &NetworkController::finalize); |
|
110 | 110 | |
|
111 | 111 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
112 | 112 | &VariableController::initialize); |
|
113 | 113 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
114 | 114 | &VariableController::finalize); |
|
115 | 115 | |
|
116 | 116 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
117 | 117 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
118 | 118 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
119 | 119 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
120 | 120 | |
|
121 | 121 | impl->m_DataSourceControllerThread.start(); |
|
122 | 122 | impl->m_NetworkControllerThread.start(); |
|
123 | 123 | impl->m_VariableControllerThread.start(); |
|
124 | 124 | impl->m_VisualizationControllerThread.start(); |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | SqpApplication::~SqpApplication() |
|
128 | 128 | { |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void SqpApplication::initialize() |
|
132 | 132 | { |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
136 | 136 | { |
|
137 | 137 | return *impl->m_DataSourceController; |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | NetworkController &SqpApplication::networkController() noexcept |
|
141 | 141 | { |
|
142 | 142 | return *impl->m_NetworkController; |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | TimeController &SqpApplication::timeController() noexcept |
|
146 | 146 | { |
|
147 | 147 | return *impl->m_TimeController; |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | VariableController &SqpApplication::variableController() noexcept |
|
151 | 151 | { |
|
152 | 152 | return *impl->m_VariableController; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
156 | 156 | { |
|
157 | 157 | return *impl->m_VisualizationController; |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | DragDropHelper &SqpApplication::dragDropHelper() noexcept |
|
161 | 161 | { |
|
162 | 162 | return *impl->m_DragDropHelper; |
|
163 | 163 | } |
@@ -1,50 +1,156 | |||
|
1 | 1 | #include "TimeWidget/TimeWidget.h" |
|
2 | 2 | #include "ui_TimeWidget.h" |
|
3 | 3 | |
|
4 | 4 | #include <Common/DateUtils.h> |
|
5 | #include <Common/MimeTypesDef.h> | |
|
6 | ||
|
7 | #include <DragAndDrop/DragDropHelper.h> | |
|
5 | 8 | #include <SqpApplication.h> |
|
6 | 9 | #include <Time/TimeController.h> |
|
7 | 10 | |
|
8 | TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget} | |
|
11 | #include <QDrag> | |
|
12 | #include <QDragEnterEvent> | |
|
13 | #include <QDropEvent> | |
|
14 | #include <QMimeData> | |
|
15 | ||
|
16 | ||
|
17 | struct TimeWidget::TimeWidgetPrivate { | |
|
18 | ||
|
19 | explicit TimeWidgetPrivate() {} | |
|
20 | ||
|
21 | QPoint m_DragStartPosition; | |
|
22 | }; | |
|
23 | ||
|
24 | TimeWidget::TimeWidget(QWidget *parent) | |
|
25 | : QWidget{parent}, | |
|
26 | ui{new Ui::TimeWidget}, | |
|
27 | impl{spimpl::make_unique_impl<TimeWidgetPrivate>()} | |
|
9 | 28 | { |
|
10 | 29 | ui->setupUi(this); |
|
11 | 30 | |
|
12 | 31 | ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton)); |
|
13 | 32 | |
|
14 | 33 | // Connection |
|
15 | 34 | connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, |
|
16 | 35 | &TimeWidget::onTimeUpdateRequested); |
|
17 | 36 | |
|
18 | 37 | connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, |
|
19 | 38 | &TimeWidget::onTimeUpdateRequested); |
|
20 | 39 | |
|
21 | 40 | |
|
22 | 41 | connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(), |
|
23 | 42 | &TimeController::onTimeNotify); |
|
24 | 43 | |
|
25 | 44 | // Initialisation |
|
26 | 45 | auto endDateTime = QDateTime::currentDateTimeUtc(); |
|
27 | 46 | auto startDateTime = endDateTime.addSecs(-3600); // one hour before |
|
28 | 47 | |
|
29 | 48 | ui->startDateTimeEdit->setDateTime(startDateTime); |
|
30 | 49 | ui->endDateTimeEdit->setDateTime(endDateTime); |
|
31 | 50 | |
|
32 | 51 | auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(startDateTime), |
|
33 | 52 | DateUtils::secondsSinceEpoch(endDateTime)}; |
|
34 | 53 | |
|
35 | 54 | sqpApp->timeController().onTimeToUpdate(dateTime); |
|
36 | 55 | } |
|
37 | 56 | |
|
38 | 57 | |
|
39 | 58 | TimeWidget::~TimeWidget() |
|
40 | 59 | { |
|
41 | 60 | delete ui; |
|
42 | 61 | } |
|
43 | 62 | |
|
44 |
void TimeWidget:: |
|
|
63 | void TimeWidget::setTimeRange(SqpRange time) | |
|
64 | { | |
|
65 | auto startDateTime = DateUtils::dateTime(time.m_TStart); | |
|
66 | auto endDateTime = DateUtils::dateTime(time.m_TEnd); | |
|
67 | ||
|
68 | ui->startDateTimeEdit->setDateTime(startDateTime); | |
|
69 | ui->endDateTimeEdit->setDateTime(endDateTime); | |
|
70 | } | |
|
71 | ||
|
72 | SqpRange TimeWidget::timeRange() const | |
|
45 | 73 | { |
|
46 |
|
|
|
47 |
|
|
|
74 | return SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()), | |
|
75 | DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime())}; | |
|
76 | } | |
|
48 | 77 | |
|
78 | void TimeWidget::onTimeUpdateRequested() | |
|
79 | { | |
|
80 | auto dateTime = timeRange(); | |
|
49 | 81 | emit timeUpdated(std::move(dateTime)); |
|
50 | 82 | } |
|
83 | ||
|
84 | void TimeWidget::dragEnterEvent(QDragEnterEvent *event) | |
|
85 | { | |
|
86 | if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) { | |
|
87 | event->acceptProposedAction(); | |
|
88 | setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}"); | |
|
89 | } | |
|
90 | else { | |
|
91 | event->ignore(); | |
|
92 | } | |
|
93 | } | |
|
94 | ||
|
95 | void TimeWidget::dragLeaveEvent(QDragLeaveEvent *event) | |
|
96 | { | |
|
97 | setStyleSheet(QString()); | |
|
98 | } | |
|
99 | ||
|
100 | void TimeWidget::dropEvent(QDropEvent *event) | |
|
101 | { | |
|
102 | if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) { | |
|
103 | auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE); | |
|
104 | auto timeRange = TimeController::timeRangeForMimeData(mimeData); | |
|
105 | ||
|
106 | setTimeRange(timeRange); | |
|
107 | } | |
|
108 | else { | |
|
109 | event->ignore(); | |
|
110 | } | |
|
111 | ||
|
112 | setStyleSheet(QString()); | |
|
113 | } | |
|
114 | ||
|
115 | ||
|
116 | void TimeWidget::mousePressEvent(QMouseEvent *event) | |
|
117 | { | |
|
118 | if (event->button() == Qt::LeftButton) { | |
|
119 | impl->m_DragStartPosition = event->pos(); | |
|
120 | } | |
|
121 | ||
|
122 | QWidget::mousePressEvent(event); | |
|
123 | } | |
|
124 | ||
|
125 | void TimeWidget::mouseMoveEvent(QMouseEvent *event) | |
|
126 | { | |
|
127 | if (!(event->buttons() & Qt::LeftButton)) { | |
|
128 | return; | |
|
129 | } | |
|
130 | ||
|
131 | if ((event->pos() - impl->m_DragStartPosition).manhattanLength() | |
|
132 | < QApplication::startDragDistance()) { | |
|
133 | return; | |
|
134 | } | |
|
135 | ||
|
136 | // Note: The management of the drag object is done by Qt | |
|
137 | auto drag = new QDrag{this}; | |
|
138 | ||
|
139 | auto mimeData = new QMimeData; | |
|
140 | auto timeData = TimeController::mimeDataForTimeRange(timeRange()); | |
|
141 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeData); | |
|
142 | ||
|
143 | drag->setMimeData(mimeData); | |
|
144 | ||
|
145 | auto pixmap = QPixmap(size()); | |
|
146 | render(&pixmap); | |
|
147 | drag->setPixmap(pixmap); | |
|
148 | drag->setHotSpot(impl->m_DragStartPosition); | |
|
149 | ||
|
150 | sqpApp->dragDropHelper().resetDragAndDrop(); | |
|
151 | ||
|
152 | // Note: The exec() is blocking on windows but not on linux and macOS | |
|
153 | drag->exec(Qt::MoveAction | Qt::CopyAction); | |
|
154 | ||
|
155 | QWidget::mouseMoveEvent(event); | |
|
156 | } |
@@ -1,245 +1,240 | |||
|
1 | 1 | #include <Variable/RenameVariableDialog.h> |
|
2 | 2 | #include <Variable/Variable.h> |
|
3 | 3 | #include <Variable/VariableController.h> |
|
4 | 4 | #include <Variable/VariableInspectorWidget.h> |
|
5 | 5 | #include <Variable/VariableMenuHeaderWidget.h> |
|
6 | 6 | #include <Variable/VariableModel.h> |
|
7 | 7 | |
|
8 | 8 | #include <ui_VariableInspectorWidget.h> |
|
9 | 9 | |
|
10 | 10 | #include <QMouseEvent> |
|
11 | 11 | #include <QSortFilterProxyModel> |
|
12 | 12 | #include <QStyledItemDelegate> |
|
13 | 13 | #include <QWidgetAction> |
|
14 | 14 | |
|
15 | #include <DragDropHelper.h> | |
|
15 | #include <DragAndDrop/DragDropHelper.h> | |
|
16 | 16 | #include <SqpApplication.h> |
|
17 | 17 | |
|
18 | 18 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | class QProgressBarItemDelegate : public QStyledItemDelegate { |
|
22 | 22 | |
|
23 | 23 | public: |
|
24 | 24 | QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {} |
|
25 | 25 | |
|
26 | 26 | void paint(QPainter *painter, const QStyleOptionViewItem &option, |
|
27 | 27 | const QModelIndex &index) const |
|
28 | 28 | { |
|
29 | 29 | auto data = index.data(Qt::DisplayRole); |
|
30 | 30 | auto progressData = index.data(VariableRoles::ProgressRole); |
|
31 | 31 | if (data.isValid() && progressData.isValid()) { |
|
32 | 32 | auto name = data.value<QString>(); |
|
33 | 33 | auto progress = progressData.value<double>(); |
|
34 | 34 | if (progress > 0) { |
|
35 | 35 | auto cancelButtonWidth = 20; |
|
36 | 36 | auto progressBarOption = QStyleOptionProgressBar{}; |
|
37 | 37 | auto progressRect = option.rect; |
|
38 | 38 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); |
|
39 | 39 | progressBarOption.rect = progressRect; |
|
40 | 40 | progressBarOption.minimum = 0; |
|
41 | 41 | progressBarOption.maximum = 100; |
|
42 | 42 | progressBarOption.progress = progress; |
|
43 | 43 | progressBarOption.text |
|
44 | 44 | = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%"); |
|
45 | 45 | progressBarOption.textVisible = true; |
|
46 | 46 | progressBarOption.textAlignment = Qt::AlignCenter; |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, |
|
50 | 50 | painter); |
|
51 | 51 | |
|
52 | 52 | // Cancel button |
|
53 | 53 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, |
|
54 | 54 | option.rect.height()); |
|
55 | 55 | auto buttonOption = QStyleOptionButton{}; |
|
56 | 56 | buttonOption.rect = buttonRect; |
|
57 | 57 | buttonOption.text = "X"; |
|
58 | 58 | |
|
59 | 59 | QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter); |
|
60 | 60 | } |
|
61 | 61 | else { |
|
62 | 62 | QStyledItemDelegate::paint(painter, option, index); |
|
63 | 63 | } |
|
64 | 64 | } |
|
65 | 65 | else { |
|
66 | 66 | QStyledItemDelegate::paint(painter, option, index); |
|
67 | 67 | } |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, |
|
71 | 71 | const QModelIndex &index) |
|
72 | 72 | { |
|
73 | 73 | if (event->type() == QEvent::MouseButtonRelease) { |
|
74 | 74 | auto data = index.data(Qt::DisplayRole); |
|
75 | 75 | auto progressData = index.data(VariableRoles::ProgressRole); |
|
76 | 76 | if (data.isValid() && progressData.isValid()) { |
|
77 | 77 | auto cancelButtonWidth = 20; |
|
78 | 78 | auto progressRect = option.rect; |
|
79 | 79 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); |
|
80 | 80 | // Cancel button |
|
81 | 81 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, |
|
82 | 82 | option.rect.height()); |
|
83 | 83 | |
|
84 | 84 | auto e = (QMouseEvent *)event; |
|
85 | 85 | auto clickX = e->x(); |
|
86 | 86 | auto clickY = e->y(); |
|
87 | 87 | |
|
88 | 88 | auto x = buttonRect.left(); // the X coordinate |
|
89 | 89 | auto y = buttonRect.top(); // the Y coordinate |
|
90 | 90 | auto w = buttonRect.width(); // button width |
|
91 | 91 | auto h = buttonRect.height(); // button height |
|
92 | 92 | |
|
93 | 93 | if (clickX > x && clickX < x + w) { |
|
94 | 94 | if (clickY > y && clickY < y + h) { |
|
95 | 95 | auto variableModel = sqpApp->variableController().variableModel(); |
|
96 | 96 | variableModel->abortProgress(index); |
|
97 | 97 | } |
|
98 | 98 | return true; |
|
99 | 99 | } |
|
100 | 100 | else { |
|
101 | 101 | return QStyledItemDelegate::editorEvent(event, model, option, index); |
|
102 | 102 | } |
|
103 | 103 | } |
|
104 | 104 | else { |
|
105 | 105 | return QStyledItemDelegate::editorEvent(event, model, option, index); |
|
106 | 106 | } |
|
107 | 107 | } |
|
108 | 108 | else { |
|
109 | 109 | return QStyledItemDelegate::editorEvent(event, model, option, index); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | return QStyledItemDelegate::editorEvent(event, model, option, index); |
|
114 | 114 | } |
|
115 | 115 | }; |
|
116 | 116 | |
|
117 | 117 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
118 | 118 | : QWidget{parent}, |
|
119 | 119 | ui{new Ui::VariableInspectorWidget}, |
|
120 | 120 | m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}} |
|
121 | 121 | { |
|
122 | 122 | ui->setupUi(this); |
|
123 | 123 | |
|
124 | 124 | // Sets model for table |
|
125 | 125 | // auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
126 | 126 | // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
127 | 127 | |
|
128 | 128 | auto variableModel = sqpApp->variableController().variableModel(); |
|
129 | 129 | ui->tableView->setModel(variableModel); |
|
130 | 130 | |
|
131 | 131 | // Adds extra signal/slot between view and model, so the view can be updated instantly when |
|
132 | 132 | // there is a change of data in the model |
|
133 | 133 | connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, |
|
134 | 134 | SLOT(refresh())); |
|
135 | 135 | |
|
136 | 136 | ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); |
|
137 | 137 | ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate); |
|
138 | 138 | |
|
139 | 139 | // Fixes column sizes |
|
140 | 140 | auto model = ui->tableView->model(); |
|
141 | 141 | const auto count = model->columnCount(); |
|
142 | 142 | for (auto i = 0; i < count; ++i) { |
|
143 | 143 | ui->tableView->setColumnWidth( |
|
144 | 144 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); |
|
145 | 145 | } |
|
146 | 146 | |
|
147 | 147 | // Sets selection options |
|
148 | 148 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); |
|
149 | 149 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); |
|
150 | 150 | |
|
151 | 151 | // Connection to show a menu when right clicking on the tree |
|
152 | 152 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
153 | 153 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, |
|
154 | 154 | &VariableInspectorWidget::onTableMenuRequested); |
|
155 | ||
|
156 | // Resets the drag&drop operation on a left-click (the drag&drop is also started by a left | |
|
157 | // click). | |
|
158 | connect(ui->tableView, &QTableView::clicked, | |
|
159 | [](const auto &modelIndex) { sqpApp->dragDropHelper().resetDragAndDrop(); }); | |
|
160 | 155 | } |
|
161 | 156 | |
|
162 | 157 | VariableInspectorWidget::~VariableInspectorWidget() |
|
163 | 158 | { |
|
164 | 159 | delete ui; |
|
165 | 160 | } |
|
166 | 161 | |
|
167 | 162 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept |
|
168 | 163 | { |
|
169 | 164 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); |
|
170 | 165 | |
|
171 | 166 | // Gets the model to retrieve the underlying selected variables |
|
172 | 167 | auto model = sqpApp->variableController().variableModel(); |
|
173 | 168 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; |
|
174 | 169 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
175 | 170 | if (auto selectedVariable = model->variable(selectedRow.row())) { |
|
176 | 171 | selectedVariables.push_back(selectedVariable); |
|
177 | 172 | } |
|
178 | 173 | } |
|
179 | 174 | |
|
180 | 175 | QMenu tableMenu{}; |
|
181 | 176 | |
|
182 | 177 | // Emits a signal so that potential receivers can populate the menu before displaying it |
|
183 | 178 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); |
|
184 | 179 | |
|
185 | 180 | // Adds menu-specific actions |
|
186 | 181 | if (!selectedVariables.isEmpty()) { |
|
187 | 182 | tableMenu.addSeparator(); |
|
188 | 183 | |
|
189 | 184 | // 'Rename' and 'Duplicate' actions (only if one variable selected) |
|
190 | 185 | if (selectedVariables.size() == 1) { |
|
191 | 186 | auto selectedVariable = selectedVariables.front(); |
|
192 | 187 | |
|
193 | 188 | auto duplicateFun = [varW = std::weak_ptr<Variable>(selectedVariable)]() |
|
194 | 189 | { |
|
195 | 190 | if (auto var = varW.lock()) { |
|
196 | 191 | sqpApp->variableController().cloneVariable(var); |
|
197 | 192 | } |
|
198 | 193 | }; |
|
199 | 194 | |
|
200 | 195 | tableMenu.addAction(tr("Duplicate"), duplicateFun); |
|
201 | 196 | |
|
202 | 197 | auto renameFun = [ varW = std::weak_ptr<Variable>(selectedVariable), &model, this ]() |
|
203 | 198 | { |
|
204 | 199 | if (auto var = varW.lock()) { |
|
205 | 200 | // Generates forbidden names (names associated to existing variables) |
|
206 | 201 | auto allVariables = model->variables(); |
|
207 | 202 | auto forbiddenNames = QVector<QString>(allVariables.size()); |
|
208 | 203 | std::transform(allVariables.cbegin(), allVariables.cend(), |
|
209 | 204 | forbiddenNames.begin(), |
|
210 | 205 | [](const auto &variable) { return variable->name(); }); |
|
211 | 206 | |
|
212 | 207 | RenameVariableDialog dialog{var->name(), forbiddenNames, this}; |
|
213 | 208 | if (dialog.exec() == QDialog::Accepted) { |
|
214 | 209 | var->setName(dialog.name()); |
|
215 | 210 | } |
|
216 | 211 | } |
|
217 | 212 | }; |
|
218 | 213 | |
|
219 | 214 | tableMenu.addAction(tr("Rename..."), renameFun); |
|
220 | 215 | } |
|
221 | 216 | |
|
222 | 217 | // 'Delete' action |
|
223 | 218 | auto deleteFun = [&selectedVariables]() { |
|
224 | 219 | sqpApp->variableController().deleteVariables(selectedVariables); |
|
225 | 220 | }; |
|
226 | 221 | |
|
227 | 222 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); |
|
228 | 223 | } |
|
229 | 224 | |
|
230 | 225 | if (!tableMenu.isEmpty()) { |
|
231 | 226 | // Generates menu header (inserted before first action) |
|
232 | 227 | auto firstAction = tableMenu.actions().first(); |
|
233 | 228 | auto headerAction = new QWidgetAction{&tableMenu}; |
|
234 | 229 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); |
|
235 | 230 | tableMenu.insertAction(firstAction, headerAction); |
|
236 | 231 | |
|
237 | 232 | // Displays menu |
|
238 | 233 | tableMenu.exec(QCursor::pos()); |
|
239 | 234 | } |
|
240 | 235 | } |
|
241 | 236 | |
|
242 | 237 | void VariableInspectorWidget::refresh() noexcept |
|
243 | 238 | { |
|
244 | 239 | ui->tableView->viewport()->update(); |
|
245 | 240 | } |
@@ -1,362 +1,453 | |||
|
1 | 1 | #include "Visualization/VisualizationDragDropContainer.h" |
|
2 | #include "DragDropHelper.h" | |
|
2 | #include "DragAndDrop/DragDropHelper.h" | |
|
3 | 3 | #include "SqpApplication.h" |
|
4 | 4 | #include "Visualization/VisualizationDragWidget.h" |
|
5 | 5 | |
|
6 | 6 | #include "Common/VisualizationDef.h" |
|
7 | 7 | |
|
8 | 8 | #include <QDrag> |
|
9 | 9 | #include <QDragEnterEvent> |
|
10 | 10 | #include <QVBoxLayout> |
|
11 | 11 | |
|
12 | 12 | #include <cmath> |
|
13 | 13 | #include <memory> |
|
14 | 14 | |
|
15 | 15 | Q_LOGGING_CATEGORY(LOG_VisualizationDragDropContainer, "VisualizationDragDropContainer") |
|
16 | 16 | |
|
17 | 17 | struct VisualizationDragDropContainer::VisualizationDragDropContainerPrivate { |
|
18 | 18 | |
|
19 | 19 | QVBoxLayout *m_Layout; |
|
20 | QStringList m_AcceptedMimeTypes; | |
|
21 | QStringList m_MergeAllowedMimeTypes; | |
|
20 | QHash<QString, VisualizationDragDropContainer::DropBehavior> m_AcceptedMimeTypes; | |
|
21 | QString m_PlaceHolderText; | |
|
22 | DragDropHelper::PlaceHolderType m_PlaceHolderType = DragDropHelper::PlaceHolderType::Graph; | |
|
23 | ||
|
22 | 24 | VisualizationDragDropContainer::AcceptMimeDataFunction m_AcceptMimeDataFun |
|
23 | 25 | = [](auto mimeData) { return true; }; |
|
24 | 26 | |
|
27 | int m_MinContainerHeight = 0; | |
|
28 | ||
|
25 | 29 | explicit VisualizationDragDropContainerPrivate(QWidget *widget) |
|
26 | 30 | { |
|
27 | 31 | m_Layout = new QVBoxLayout(widget); |
|
28 | 32 | m_Layout->setContentsMargins(0, 0, 0, 0); |
|
29 | 33 | } |
|
30 | 34 | |
|
31 | 35 | bool acceptMimeData(const QMimeData *data) const |
|
32 | 36 | { |
|
33 | for (const auto &type : m_AcceptedMimeTypes) { | |
|
37 | for (const auto &type : m_AcceptedMimeTypes.keys()) { | |
|
34 | 38 | if (data->hasFormat(type) && m_AcceptMimeDataFun(data)) { |
|
35 | 39 | return true; |
|
36 | 40 | } |
|
37 | 41 | } |
|
38 | 42 | |
|
39 | 43 | return false; |
|
40 | 44 | } |
|
41 | 45 | |
|
42 | bool allowMergeMimeData(const QMimeData *data) const | |
|
46 | bool allowMergeForMimeData(const QMimeData *data) const | |
|
47 | { | |
|
48 | bool result = false; | |
|
49 | for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd(); | |
|
50 | ++it) { | |
|
51 | ||
|
52 | if (data->hasFormat(it.key()) | |
|
53 | && (it.value() == VisualizationDragDropContainer::DropBehavior::Merged | |
|
54 | || it.value() | |
|
55 | == VisualizationDragDropContainer::DropBehavior::InsertedAndMerged)) { | |
|
56 | result = true; | |
|
57 | } | |
|
58 | else if (data->hasFormat(it.key()) | |
|
59 | && it.value() == VisualizationDragDropContainer::DropBehavior::Inserted) { | |
|
60 | // Merge is forbidden if the mime data contain an acceptable type which cannot be | |
|
61 | // merged | |
|
62 | result = false; | |
|
63 | break; | |
|
64 | } | |
|
65 | } | |
|
66 | ||
|
67 | return result; | |
|
68 | } | |
|
69 | ||
|
70 | bool allowInsertForMimeData(const QMimeData *data) const | |
|
43 | 71 | { |
|
44 | for (const auto &type : m_MergeAllowedMimeTypes) { | |
|
45 | if (data->hasFormat(type)) { | |
|
72 | for (auto it = m_AcceptedMimeTypes.constBegin(); it != m_AcceptedMimeTypes.constEnd(); | |
|
73 | ++it) { | |
|
74 | if (data->hasFormat(it.key()) | |
|
75 | && (it.value() == VisualizationDragDropContainer::DropBehavior::Inserted | |
|
76 | || it.value() | |
|
77 | == VisualizationDragDropContainer::DropBehavior::InsertedAndMerged)) { | |
|
46 | 78 | return true; |
|
47 | 79 | } |
|
48 | 80 | } |
|
49 | 81 | |
|
50 | 82 | return false; |
|
51 | 83 | } |
|
52 | 84 | |
|
53 | 85 | bool hasPlaceHolder() const |
|
54 | 86 | { |
|
55 | 87 | return sqpApp->dragDropHelper().placeHolder().parentWidget() == m_Layout->parentWidget(); |
|
56 | 88 | } |
|
57 | 89 | |
|
58 | VisualizationDragWidget *getChildDragWidgetAt(QWidget *parent, const QPoint &pos) const | |
|
90 | VisualizationDragWidget *getChildDragWidgetAt(const QWidget *parent, const QPoint &pos) const | |
|
59 | 91 | { |
|
60 | 92 | VisualizationDragWidget *dragWidget = nullptr; |
|
61 | 93 | |
|
62 | 94 | for (auto child : parent->children()) { |
|
63 | 95 | auto widget = qobject_cast<VisualizationDragWidget *>(child); |
|
64 | 96 | if (widget && widget->isVisible()) { |
|
65 | 97 | if (widget->frameGeometry().contains(pos)) { |
|
66 | 98 | dragWidget = widget; |
|
67 | 99 | break; |
|
68 | 100 | } |
|
69 | 101 | } |
|
70 | 102 | } |
|
71 | 103 | |
|
72 | 104 | return dragWidget; |
|
73 | 105 | } |
|
74 | 106 | |
|
75 | 107 | bool cursorIsInContainer(QWidget *container) const |
|
76 | 108 | { |
|
77 | auto adustNum = 18; // to be safe, in case of scrollbar on the side | |
|
78 | auto containerRect = QRect(QPoint(), container->contentsRect().size()) | |
|
79 | .adjusted(adustNum, adustNum, -adustNum, -adustNum); | |
|
80 | return containerRect.contains(container->mapFromGlobal(QCursor::pos())); | |
|
109 | return container->isAncestorOf(sqpApp->widgetAt(QCursor::pos())); | |
|
110 | } | |
|
111 | ||
|
112 | int countDragWidget(const QWidget *parent, bool onlyVisible = false) const | |
|
113 | { | |
|
114 | auto nbGraph = 0; | |
|
115 | for (auto child : parent->children()) { | |
|
116 | if (qobject_cast<VisualizationDragWidget *>(child)) { | |
|
117 | if (!onlyVisible || qobject_cast<VisualizationDragWidget *>(child)->isVisible()) { | |
|
118 | nbGraph += 1; | |
|
119 | } | |
|
120 | } | |
|
121 | } | |
|
122 | ||
|
123 | return nbGraph; | |
|
81 | 124 | } |
|
125 | ||
|
126 | void findPlaceHolderPosition(const QPoint &pos, bool canInsert, bool canMerge, | |
|
127 | const VisualizationDragDropContainer *container); | |
|
82 | 128 | }; |
|
83 | 129 | |
|
84 | 130 | VisualizationDragDropContainer::VisualizationDragDropContainer(QWidget *parent) |
|
85 |
: Q |
|
|
131 | : QFrame{parent}, | |
|
86 | 132 | impl{spimpl::make_unique_impl<VisualizationDragDropContainerPrivate>(this)} |
|
87 | 133 | { |
|
88 | 134 | setAcceptDrops(true); |
|
89 | 135 | } |
|
90 | 136 | |
|
91 | 137 | void VisualizationDragDropContainer::addDragWidget(VisualizationDragWidget *dragWidget) |
|
92 | 138 | { |
|
93 | 139 | impl->m_Layout->addWidget(dragWidget); |
|
94 | 140 | disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr); |
|
95 | 141 | connect(dragWidget, &VisualizationDragWidget::dragDetected, this, |
|
96 | 142 | &VisualizationDragDropContainer::startDrag); |
|
97 | 143 | } |
|
98 | 144 | |
|
99 | 145 | void VisualizationDragDropContainer::insertDragWidget(int index, |
|
100 | 146 | VisualizationDragWidget *dragWidget) |
|
101 | 147 | { |
|
102 | 148 | impl->m_Layout->insertWidget(index, dragWidget); |
|
103 | 149 | disconnect(dragWidget, &VisualizationDragWidget::dragDetected, nullptr, nullptr); |
|
104 | 150 | connect(dragWidget, &VisualizationDragWidget::dragDetected, this, |
|
105 | 151 | &VisualizationDragDropContainer::startDrag); |
|
106 | 152 | } |
|
107 | 153 | |
|
108 |
void VisualizationDragDropContainer:: |
|
|
109 | { | |
|
110 | impl->m_AcceptedMimeTypes = mimeTypes; | |
|
111 | } | |
|
112 | ||
|
113 | void VisualizationDragDropContainer::setMergeAllowedMimeTypes(const QStringList &mimeTypes) | |
|
154 | void VisualizationDragDropContainer::addAcceptedMimeType( | |
|
155 | const QString &mimeType, VisualizationDragDropContainer::DropBehavior behavior) | |
|
114 | 156 | { |
|
115 |
impl->m_ |
|
|
157 | impl->m_AcceptedMimeTypes[mimeType] = behavior; | |
|
116 | 158 | } |
|
117 | 159 | |
|
118 | 160 | int VisualizationDragDropContainer::countDragWidget() const |
|
119 | 161 | { |
|
120 | auto nbGraph = 0; | |
|
121 | for (auto child : children()) { | |
|
122 | if (qobject_cast<VisualizationDragWidget *>(child)) { | |
|
123 | nbGraph += 1; | |
|
124 | } | |
|
125 | } | |
|
126 | ||
|
127 | return nbGraph; | |
|
162 | return impl->countDragWidget(this); | |
|
128 | 163 | } |
|
129 | 164 | |
|
130 | 165 | void VisualizationDragDropContainer::setAcceptMimeDataFunction( |
|
131 | 166 | VisualizationDragDropContainer::AcceptMimeDataFunction fun) |
|
132 | 167 | { |
|
133 | 168 | impl->m_AcceptMimeDataFun = fun; |
|
134 | 169 | } |
|
135 | 170 | |
|
171 | void VisualizationDragDropContainer::setPlaceHolderType(DragDropHelper::PlaceHolderType type, | |
|
172 | const QString &placeHolderText) | |
|
173 | { | |
|
174 | impl->m_PlaceHolderType = type; | |
|
175 | impl->m_PlaceHolderText = placeHolderText; | |
|
176 | } | |
|
177 | ||
|
136 | 178 | void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidget, |
|
137 | 179 | const QPoint &dragPosition) |
|
138 | 180 | { |
|
139 | 181 | auto &helper = sqpApp->dragDropHelper(); |
|
140 | 182 | helper.resetDragAndDrop(); |
|
141 | 183 | |
|
142 | 184 | // Note: The management of the drag object is done by Qt |
|
143 | 185 | auto drag = new QDrag{dragWidget}; |
|
144 | 186 | drag->setHotSpot(dragPosition); |
|
145 | 187 | |
|
146 | 188 | auto mimeData = dragWidget->mimeData(); |
|
147 | 189 | drag->setMimeData(mimeData); |
|
148 | 190 | |
|
149 | 191 | auto pixmap = QPixmap(dragWidget->size()); |
|
150 | 192 | dragWidget->render(&pixmap); |
|
151 | 193 | drag->setPixmap(pixmap); |
|
152 | 194 | |
|
153 | 195 | auto image = pixmap.toImage(); |
|
154 | 196 | mimeData->setImageData(image); |
|
155 | 197 | mimeData->setUrls({helper.imageTemporaryUrl(image)}); |
|
156 | 198 | |
|
157 | 199 | if (impl->m_Layout->indexOf(dragWidget) >= 0) { |
|
158 | 200 | helper.setCurrentDragWidget(dragWidget); |
|
159 | 201 | |
|
160 | 202 | if (impl->cursorIsInContainer(this)) { |
|
161 | 203 | auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget); |
|
162 |
helper.insertPlaceHolder(impl->m_Layout, dragWidgetIndex |
|
|
204 | helper.insertPlaceHolder(impl->m_Layout, dragWidgetIndex, impl->m_PlaceHolderType, | |
|
205 | impl->m_PlaceHolderText); | |
|
163 | 206 | dragWidget->setVisible(false); |
|
164 | 207 | } |
|
208 | else { | |
|
209 | // The drag starts directly outside the drop zone | |
|
210 | // do not add the placeHolder | |
|
211 | } | |
|
165 | 212 | |
|
166 | 213 | // Note: The exec() is blocking on windows but not on linux and macOS |
|
167 | 214 | drag->exec(Qt::MoveAction | Qt::CopyAction); |
|
168 | 215 | } |
|
169 | 216 | else { |
|
170 | 217 | qCWarning(LOG_VisualizationDragDropContainer()) |
|
171 | 218 | << tr("VisualizationDragDropContainer::startDrag, drag aborted, the specified " |
|
172 | 219 | "VisualizationDragWidget is not found in this container."); |
|
173 | 220 | } |
|
174 | 221 | } |
|
175 | 222 | |
|
176 | 223 | void VisualizationDragDropContainer::dragEnterEvent(QDragEnterEvent *event) |
|
177 | 224 | { |
|
178 | 225 | if (impl->acceptMimeData(event->mimeData())) { |
|
179 | 226 | event->acceptProposedAction(); |
|
180 | 227 | |
|
181 | 228 | auto &helper = sqpApp->dragDropHelper(); |
|
182 | 229 | |
|
183 | 230 | if (!impl->hasPlaceHolder()) { |
|
184 | 231 | auto dragWidget = helper.getCurrentDragWidget(); |
|
185 | 232 | |
|
186 | 233 | if (dragWidget) { |
|
187 | 234 | // If the drag&drop is internal to the visualization, entering the container hide |
|
188 |
// the dragWidget which was |
|
|
235 | // the dragWidget which was made visible by the dragLeaveEvent | |
|
189 | 236 | auto parentWidget |
|
190 | 237 | = qobject_cast<VisualizationDragDropContainer *>(dragWidget->parentWidget()); |
|
191 | 238 | if (parentWidget) { |
|
192 | 239 | dragWidget->setVisible(false); |
|
193 | 240 | } |
|
194 | 241 | } |
|
195 | 242 | |
|
196 | auto dragWidgetHovered = impl->getChildDragWidgetAt(this, event->pos()); | |
|
197 | ||
|
198 | if (dragWidgetHovered) { | |
|
199 | auto hoveredWidgetIndex = impl->m_Layout->indexOf(dragWidgetHovered); | |
|
200 | ||
|
201 | if (dragWidget) { | |
|
202 | auto dragWidgetIndex = impl->m_Layout->indexOf(helper.getCurrentDragWidget()); | |
|
203 | if (dragWidgetIndex >= 0 && dragWidgetIndex <= hoveredWidgetIndex) { | |
|
204 | // Correction of the index if the drop occurs in the same container | |
|
205 | // and if the drag is started from the visualization (in that case, the | |
|
206 | // dragWidget is hidden) | |
|
207 | hoveredWidgetIndex += 1; | |
|
208 | } | |
|
209 | } | |
|
210 | ||
|
211 | helper.insertPlaceHolder(impl->m_Layout, hoveredWidgetIndex); | |
|
212 | } | |
|
213 | else { | |
|
214 | helper.insertPlaceHolder(impl->m_Layout, 0); | |
|
215 | } | |
|
243 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); | |
|
244 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); | |
|
245 | impl->findPlaceHolderPosition(event->pos(), canInsert, canMerge, this); | |
|
216 | 246 | } |
|
217 | 247 | else { |
|
218 | 248 | // do nothing |
|
219 | 249 | } |
|
220 | 250 | } |
|
221 | 251 | else { |
|
222 | 252 | event->ignore(); |
|
223 | 253 | } |
|
224 | 254 | |
|
225 | 255 | QWidget::dragEnterEvent(event); |
|
226 | 256 | } |
|
227 | 257 | |
|
228 | 258 | void VisualizationDragDropContainer::dragLeaveEvent(QDragLeaveEvent *event) |
|
229 | 259 | { |
|
230 | 260 | Q_UNUSED(event); |
|
231 | 261 | |
|
232 | 262 | auto &helper = sqpApp->dragDropHelper(); |
|
233 | 263 | |
|
234 | 264 | if (!impl->cursorIsInContainer(this)) { |
|
235 | 265 | helper.removePlaceHolder(); |
|
266 | helper.setHightlightedDragWidget(nullptr); | |
|
267 | impl->m_MinContainerHeight = 0; | |
|
236 | 268 | |
|
237 | 269 | auto dragWidget = helper.getCurrentDragWidget(); |
|
238 | 270 | if (dragWidget) { |
|
239 | 271 | // dragWidget has a value only if the drag is started from the visualization |
|
240 | 272 | // In that case, shows the drag widget at its original place |
|
241 | 273 | // So the drag widget doesn't stay hidden if the drop occurs outside the visualization |
|
242 | 274 | // drop zone (It is not possible to catch a drop event outside of the application) |
|
243 | 275 | |
|
244 | 276 | if (dragWidget) { |
|
245 | 277 | dragWidget->setVisible(true); |
|
246 | 278 | } |
|
247 | 279 | } |
|
248 | 280 | } |
|
249 | 281 | else { |
|
250 | 282 | // Leave event probably received for a child widget. |
|
251 | 283 | // Do nothing. |
|
252 | 284 | // Note: The DragLeave event, doesn't have any mean to determine who sent it. |
|
253 | 285 | } |
|
254 | 286 | |
|
255 | 287 | QWidget::dragLeaveEvent(event); |
|
256 | 288 | } |
|
257 | 289 | |
|
258 | 290 | void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event) |
|
259 | 291 | { |
|
260 | 292 | if (impl->acceptMimeData(event->mimeData())) { |
|
261 | auto dragWidgetHovered = impl->getChildDragWidgetAt(this, event->pos()); | |
|
262 | if (dragWidgetHovered) { | |
|
263 | auto canMerge = impl->allowMergeMimeData(event->mimeData()); | |
|
264 | ||
|
265 | auto nbDragWidget = countDragWidget(); | |
|
266 | if (nbDragWidget > 0) { | |
|
267 | auto graphHeight = qMax(size().height() / nbDragWidget, GRAPH_MINIMUM_HEIGHT); | |
|
293 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); | |
|
294 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); | |
|
295 | impl->findPlaceHolderPosition(event->pos(), canInsert, canMerge, this); | |
|
296 | } | |
|
297 | else { | |
|
298 | event->ignore(); | |
|
299 | } | |
|
268 | 300 | |
|
269 | auto dropIndex = floor(event->pos().y() / graphHeight); | |
|
270 | auto zoneSize = qMin(graphHeight / 3.0, 150.0); | |
|
301 | QWidget::dragMoveEvent(event); | |
|
302 | } | |
|
271 | 303 | |
|
272 | auto isOnTop = event->pos().y() < dropIndex * graphHeight + zoneSize; | |
|
273 | auto isOnBottom = event->pos().y() > (dropIndex + 1) * graphHeight - zoneSize; | |
|
304 | void VisualizationDragDropContainer::dropEvent(QDropEvent *event) | |
|
305 | { | |
|
306 | auto &helper = sqpApp->dragDropHelper(); | |
|
274 | 307 | |
|
275 | auto &helper = sqpApp->dragDropHelper(); | |
|
276 | auto placeHolderIndex = impl->m_Layout->indexOf(&(helper.placeHolder())); | |
|
308 | if (impl->acceptMimeData(event->mimeData())) { | |
|
309 | auto dragWidget = helper.getCurrentDragWidget(); | |
|
310 | if (impl->hasPlaceHolder()) { | |
|
311 | // drop where the placeHolder is located | |
|
277 | 312 | |
|
278 | if (isOnTop || isOnBottom) { | |
|
279 |
|
|
|
280 | dropIndex += 1; | |
|
281 | } | |
|
313 | auto canInsert = impl->allowInsertForMimeData(event->mimeData()); | |
|
314 | if (canInsert) { | |
|
315 | auto droppedIndex = impl->m_Layout->indexOf(&helper.placeHolder()); | |
|
282 | 316 | |
|
283 |
|
|
|
284 |
|
|
|
285 | = impl->m_Layout->indexOf(helper.getCurrentDragWidget()); | |
|
286 | if (dragWidgetIndex >= 0 && dragWidgetIndex <= dropIndex) { | |
|
287 | // Correction of the index if the drop occurs in the same container | |
|
288 | // and if the drag is started from the visualization (in that case, the | |
|
289 |
|
|
|
290 | dropIndex += 1; | |
|
291 | } | |
|
317 | if (dragWidget) { | |
|
318 | auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget); | |
|
319 | if (dragWidgetIndex >= 0 && dragWidgetIndex < droppedIndex) { | |
|
320 | // Correction of the index if the drop occurs in the same container | |
|
321 | // and if the drag is started from the visualization (in that case, the | |
|
322 | // dragWidget is hidden) | |
|
323 | droppedIndex -= 1; | |
|
292 | 324 | } |
|
293 | 325 | |
|
294 | if (dropIndex != placeHolderIndex) { | |
|
295 | helper.insertPlaceHolder(impl->m_Layout, dropIndex); | |
|
296 | } | |
|
297 | } | |
|
298 | else if (canMerge) { | |
|
299 | // drop on the middle -> merge | |
|
300 | if (impl->hasPlaceHolder()) { | |
|
301 | helper.removePlaceHolder(); | |
|
302 | } | |
|
326 | dragWidget->setVisible(true); | |
|
303 | 327 | } |
|
328 | ||
|
329 | event->acceptProposedAction(); | |
|
330 | ||
|
331 | helper.removePlaceHolder(); | |
|
332 | ||
|
333 | emit dropOccuredInContainer(droppedIndex, event->mimeData()); | |
|
304 | 334 | } |
|
305 | 335 | else { |
|
306 | qCWarning(LOG_VisualizationDragDropContainer()) | |
|
307 |
|
|
|
308 |
|
|
|
336 | qCWarning(LOG_VisualizationDragDropContainer()) << tr( | |
|
337 | "VisualizationDragDropContainer::dropEvent, dropping on the placeHolder, but " | |
|
338 | "the insertion is forbidden."); | |
|
339 | Q_ASSERT(false); | |
|
309 | 340 | } |
|
310 | 341 | } |
|
311 | else { | |
|
312 | // No hovered drag widget, the mouse is probably hover the placeHolder | |
|
313 | // Do nothing | |
|
342 | else if (helper.getHightlightedDragWidget()) { | |
|
343 | // drop on the highlighted widget | |
|
344 | ||
|
345 | auto canMerge = impl->allowMergeForMimeData(event->mimeData()); | |
|
346 | if (canMerge) { | |
|
347 | event->acceptProposedAction(); | |
|
348 | emit dropOccuredOnWidget(helper.getHightlightedDragWidget(), event->mimeData()); | |
|
349 | } | |
|
350 | else { | |
|
351 | qCWarning(LOG_VisualizationDragDropContainer()) | |
|
352 | << tr("VisualizationDragDropContainer::dropEvent, dropping on a widget, but " | |
|
353 | "the merge is forbidden."); | |
|
354 | Q_ASSERT(false); | |
|
355 | } | |
|
314 | 356 | } |
|
315 | 357 | } |
|
316 | 358 | else { |
|
317 | 359 | event->ignore(); |
|
318 | 360 | } |
|
319 | 361 | |
|
320 | QWidget::dragMoveEvent(event); | |
|
362 | sqpApp->dragDropHelper().setHightlightedDragWidget(nullptr); | |
|
363 | impl->m_MinContainerHeight = 0; | |
|
364 | ||
|
365 | QWidget::dropEvent(event); | |
|
321 | 366 | } |
|
322 | 367 | |
|
323 | void VisualizationDragDropContainer::dropEvent(QDropEvent *event) | |
|
368 | ||
|
369 | void VisualizationDragDropContainer::VisualizationDragDropContainerPrivate::findPlaceHolderPosition( | |
|
370 | const QPoint &pos, bool canInsert, bool canMerge, | |
|
371 | const VisualizationDragDropContainer *container) | |
|
324 | 372 | { |
|
325 | if (impl->acceptMimeData(event->mimeData())) { | |
|
326 | auto dragWidget = sqpApp->dragDropHelper().getCurrentDragWidget(); | |
|
327 | if (impl->hasPlaceHolder()) { | |
|
328 | auto &helper = sqpApp->dragDropHelper(); | |
|
373 | auto &helper = sqpApp->dragDropHelper(); | |
|
329 | 374 | |
|
330 | auto droppedIndex = impl->m_Layout->indexOf(&helper.placeHolder()); | |
|
375 | auto absPos = container->mapToGlobal(pos); | |
|
376 | auto isOnPlaceHolder = sqpApp->widgetAt(absPos) == &(helper.placeHolder()); | |
|
331 | 377 | |
|
332 | if (dragWidget) { | |
|
333 | auto dragWidgetIndex = impl->m_Layout->indexOf(dragWidget); | |
|
334 | if (dragWidgetIndex >= 0 && dragWidgetIndex < droppedIndex) { | |
|
335 | // Correction of the index if the drop occurs in the same container | |
|
336 | // and if the drag is started from the visualization (in that case, the | |
|
337 | // dragWidget is hidden) | |
|
338 | droppedIndex -= 1; | |
|
339 | } | |
|
378 | if (countDragWidget(container, true) == 0) { | |
|
379 | // Drop on an empty container, just add the placeHolder at the top | |
|
380 | helper.insertPlaceHolder(m_Layout, 0, m_PlaceHolderType, m_PlaceHolderText); | |
|
381 | } | |
|
382 | else if (!isOnPlaceHolder) { | |
|
383 | auto nbDragWidget = countDragWidget(container); | |
|
384 | if (nbDragWidget > 0) { | |
|
340 | 385 | |
|
341 | dragWidget->setVisible(true); | |
|
386 | if (m_MinContainerHeight == 0) { | |
|
387 | m_MinContainerHeight = container->size().height(); | |
|
342 | 388 | } |
|
343 | 389 | |
|
344 | event->acceptProposedAction(); | |
|
390 | m_MinContainerHeight = qMin(m_MinContainerHeight, container->size().height()); | |
|
391 | auto graphHeight = qMax(m_MinContainerHeight / nbDragWidget, GRAPH_MINIMUM_HEIGHT); | |
|
392 | ||
|
393 | auto posY = pos.y(); | |
|
394 | auto dropIndex = floor(posY / graphHeight); | |
|
395 | auto zoneSize = qMin(graphHeight / 4.0, 75.0); | |
|
396 | ||
|
397 | ||
|
398 | auto isOnTop = posY < dropIndex * graphHeight + zoneSize; | |
|
399 | auto isOnBottom = posY > (dropIndex + 1) * graphHeight - zoneSize; | |
|
400 | ||
|
401 | auto placeHolderIndex = m_Layout->indexOf(&(helper.placeHolder())); | |
|
402 | ||
|
403 | auto dragWidgetHovered = getChildDragWidgetAt(container, pos); | |
|
345 | 404 | |
|
346 | helper.removePlaceHolder(); | |
|
405 | if (canInsert && (isOnTop || isOnBottom || !canMerge)) { | |
|
406 | if (isOnBottom) { | |
|
407 | dropIndex += 1; | |
|
408 | } | |
|
347 | 409 | |
|
348 | emit dropOccured(droppedIndex, event->mimeData()); | |
|
410 | if (helper.getCurrentDragWidget()) { | |
|
411 | auto dragWidgetIndex = m_Layout->indexOf(helper.getCurrentDragWidget()); | |
|
412 | if (dragWidgetIndex >= 0 && dragWidgetIndex <= dropIndex) { | |
|
413 | // Correction of the index if the drop occurs in the same container | |
|
414 | // and if the drag is started from the visualization (in that case, the | |
|
415 | // dragWidget is hidden) | |
|
416 | dropIndex += 1; | |
|
417 | } | |
|
418 | } | |
|
419 | ||
|
420 | if (dropIndex != placeHolderIndex) { | |
|
421 | helper.insertPlaceHolder(m_Layout, dropIndex, m_PlaceHolderType, | |
|
422 | m_PlaceHolderText); | |
|
423 | } | |
|
424 | ||
|
425 | helper.setHightlightedDragWidget(nullptr); | |
|
426 | } | |
|
427 | else if (canMerge && dragWidgetHovered) { | |
|
428 | // drop on the middle -> merge | |
|
429 | if (hasPlaceHolder()) { | |
|
430 | helper.removePlaceHolder(); | |
|
431 | } | |
|
432 | ||
|
433 | helper.setHightlightedDragWidget(dragWidgetHovered); | |
|
434 | } | |
|
435 | else { | |
|
436 | qCWarning(LOG_VisualizationDragDropContainer()) | |
|
437 | << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no valid drop " | |
|
438 | "action."); | |
|
439 | Q_ASSERT(false); | |
|
440 | } | |
|
349 | 441 | } |
|
350 | 442 | else { |
|
351 | 443 | qCWarning(LOG_VisualizationDragDropContainer()) |
|
352 |
<< tr("VisualizationDragDropContainer:: |
|
|
353 |
" |
|
|
354 | Q_ASSERT(false); | |
|
444 | << tr("VisualizationDragDropContainer::findPlaceHolderPosition, no widget " | |
|
445 | "found in the " | |
|
446 | "container"); | |
|
355 | 447 | } |
|
356 | 448 | } |
|
357 | 449 | else { |
|
358 | event->ignore(); | |
|
450 | // the mouse is hover the placeHolder | |
|
451 | // Do nothing | |
|
359 | 452 | } |
|
360 | ||
|
361 | QWidget::dropEvent(event); | |
|
362 | 453 | } |
@@ -1,385 +1,401 | |||
|
1 | 1 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "Visualization/VisualizationDefs.h" |
|
4 | 4 | #include "Visualization/VisualizationGraphHelper.h" |
|
5 | 5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
6 | 6 | #include "Visualization/VisualizationZoneWidget.h" |
|
7 | 7 | #include "ui_VisualizationGraphWidget.h" |
|
8 | 8 | |
|
9 | 9 | #include <Common/MimeTypesDef.h> |
|
10 | 10 | #include <Data/ArrayData.h> |
|
11 | 11 | #include <Data/IDataSeries.h> |
|
12 | #include <DragDropHelper.h> | |
|
12 | #include <DragAndDrop/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 | |
|
18 | 19 | #include <unordered_map> |
|
19 | 20 | |
|
20 | 21 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
21 | 22 | |
|
22 | 23 | namespace { |
|
23 | 24 | |
|
24 | 25 | /// Key pressed to enable zoom on horizontal axis |
|
25 | 26 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
26 | 27 | |
|
27 | 28 | /// Key pressed to enable zoom on vertical axis |
|
28 | 29 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
29 | 30 | |
|
30 | 31 | } // namespace |
|
31 | 32 | |
|
32 | 33 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
33 | 34 | |
|
34 | 35 | explicit VisualizationGraphWidgetPrivate(const QString &name) |
|
35 | 36 | : m_Name{name}, |
|
36 | 37 | m_DoAcquisition{true}, |
|
37 | 38 | m_IsCalibration{false}, |
|
38 | 39 | m_RenderingDelegate{nullptr} |
|
39 | 40 | { |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | QString m_Name; |
|
43 | 44 | // 1 variable -> n qcpplot |
|
44 | 45 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
45 | 46 | bool m_DoAcquisition; |
|
46 | 47 | bool m_IsCalibration; |
|
47 | 48 | QCPItemTracer *m_TextTracer; |
|
48 | 49 | /// Delegate used to attach rendering features to the plot |
|
49 | 50 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
50 | 51 | }; |
|
51 | 52 | |
|
52 | 53 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
53 | 54 | : VisualizationDragWidget{parent}, |
|
54 | 55 | ui{new Ui::VisualizationGraphWidget}, |
|
55 | 56 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
56 | 57 | { |
|
57 | 58 | ui->setupUi(this); |
|
58 | 59 | |
|
59 | 60 | // 'Close' options : widget is deleted when closed |
|
60 | 61 | setAttribute(Qt::WA_DeleteOnClose); |
|
61 | 62 | |
|
62 | 63 | // Set qcpplot properties : |
|
63 | 64 | // - Drag (on x-axis) and zoom are enabled |
|
64 | 65 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
65 | 66 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectItems); |
|
66 | 67 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
67 | 68 | |
|
68 | 69 | // The delegate must be initialized after the ui as it uses the plot |
|
69 | 70 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
70 | 71 | |
|
71 | 72 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
72 | 73 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
73 | 74 | &VisualizationGraphWidget::onMouseRelease); |
|
74 | 75 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
75 | 76 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
76 | 77 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
77 | 78 | &QCPAxis::rangeChanged), |
|
78 | 79 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
79 | 80 | |
|
80 | 81 | // Activates menu when right clicking on the graph |
|
81 | 82 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
82 | 83 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
83 | 84 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
84 | 85 | |
|
85 | 86 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
86 | 87 | &VariableController::onRequestDataLoading); |
|
87 | 88 | |
|
88 | 89 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
89 | 90 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | |
|
93 | 94 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
94 | 95 | { |
|
95 | 96 | delete ui; |
|
96 | 97 | } |
|
97 | 98 | |
|
98 | 99 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
99 | 100 | { |
|
100 | 101 | auto parent = parentWidget(); |
|
101 | 102 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { |
|
102 | 103 | parent = parent->parentWidget(); |
|
103 | 104 | } |
|
104 | 105 | |
|
105 | 106 | return qobject_cast<VisualizationZoneWidget *>(parent); |
|
106 | 107 | } |
|
107 | 108 | |
|
108 | 109 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
109 | 110 | { |
|
110 | 111 | impl->m_DoAcquisition = enable; |
|
111 | 112 | } |
|
112 | 113 | |
|
113 | 114 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
114 | 115 | { |
|
115 | 116 | // Uses delegate to create the qcpplot components according to the variable |
|
116 | 117 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
117 | 118 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
118 | 119 | |
|
119 | 120 | // Set axes properties according to the units of the data series |
|
120 | 121 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers |
|
121 | 122 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph |
|
122 | 123 | auto xAxisUnit = Unit{}; |
|
123 | 124 | auto valuesUnit = Unit{}; |
|
124 | 125 | |
|
125 | 126 | if (auto dataSeries = variable->dataSeries()) { |
|
126 | 127 | dataSeries->lockRead(); |
|
127 | 128 | xAxisUnit = dataSeries->xAxisUnit(); |
|
128 | 129 | valuesUnit = dataSeries->valuesUnit(); |
|
129 | 130 | dataSeries->unlock(); |
|
130 | 131 | } |
|
131 | 132 | impl->m_RenderingDelegate->setAxesProperties(xAxisUnit, valuesUnit); |
|
132 | 133 | |
|
133 | 134 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
134 | 135 | |
|
135 | 136 | this->enableAcquisition(false); |
|
136 | 137 | this->setGraphRange(range); |
|
137 | 138 | this->enableAcquisition(true); |
|
138 | 139 | |
|
139 | 140 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false); |
|
140 | 141 | |
|
141 | 142 | emit variableAdded(variable); |
|
142 | 143 | } |
|
143 | 144 | |
|
144 | 145 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
145 | 146 | { |
|
146 | 147 | // Each component associated to the variable : |
|
147 | 148 | // - is removed from qcpplot (which deletes it) |
|
148 | 149 | // - is no longer referenced in the map |
|
149 | 150 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
150 | 151 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
151 | 152 | emit variableAboutToBeRemoved(variable); |
|
152 | 153 | |
|
153 | 154 | auto &plottablesMap = variableIt->second; |
|
154 | 155 | |
|
155 | 156 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
156 | 157 | plottableIt != plottableEnd;) { |
|
157 | 158 | ui->widget->removePlottable(plottableIt->second); |
|
158 | 159 | plottableIt = plottablesMap.erase(plottableIt); |
|
159 | 160 | } |
|
160 | 161 | |
|
161 | 162 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
162 | 163 | } |
|
163 | 164 | |
|
164 | 165 | // Updates graph |
|
165 | 166 | ui->widget->replot(); |
|
166 | 167 | } |
|
167 | 168 | |
|
168 | 169 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const |
|
169 | 170 | { |
|
170 | 171 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
171 | 172 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
172 | 173 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { |
|
173 | 174 | variables << it->first; |
|
174 | 175 | } |
|
175 | 176 | |
|
176 | 177 | return variables; |
|
177 | 178 | } |
|
178 | 179 | |
|
179 | 180 | void VisualizationGraphWidget::setYRange(const SqpRange &range) |
|
180 | 181 | { |
|
181 | 182 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
|
182 | 183 | } |
|
183 | 184 | |
|
184 | 185 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
185 | 186 | { |
|
186 | 187 | auto graphRange = ui->widget->xAxis->range(); |
|
187 | 188 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
188 | 189 | } |
|
189 | 190 | |
|
190 | 191 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) |
|
191 | 192 | { |
|
192 | 193 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
193 | 194 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
194 | 195 | ui->widget->replot(); |
|
195 | 196 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
196 | 197 | } |
|
197 | 198 | |
|
198 | 199 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
199 | 200 | { |
|
200 | 201 | if (visitor) { |
|
201 | 202 | visitor->visit(this); |
|
202 | 203 | } |
|
203 | 204 | else { |
|
204 | 205 | qCCritical(LOG_VisualizationGraphWidget()) |
|
205 | 206 | << tr("Can't visit widget : the visitor is null"); |
|
206 | 207 | } |
|
207 | 208 | } |
|
208 | 209 | |
|
209 | 210 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
210 | 211 | { |
|
211 | 212 | /// @todo : for the moment, a graph can always accomodate a variable |
|
212 | 213 | Q_UNUSED(variable); |
|
213 | 214 | return true; |
|
214 | 215 | } |
|
215 | 216 | |
|
216 | 217 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
217 | 218 | { |
|
218 | 219 | // Finds the variable among the keys of the map |
|
219 | 220 | auto variablePtr = &variable; |
|
220 | 221 | auto findVariable |
|
221 | 222 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
222 | 223 | |
|
223 | 224 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
224 | 225 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
225 | 226 | return it != end; |
|
226 | 227 | } |
|
227 | 228 | |
|
228 | 229 | QString VisualizationGraphWidget::name() const |
|
229 | 230 | { |
|
230 | 231 | return impl->m_Name; |
|
231 | 232 | } |
|
232 | 233 | |
|
233 | 234 | QMimeData *VisualizationGraphWidget::mimeData() const |
|
234 | 235 | { |
|
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 | |
|
241 | 245 | bool VisualizationGraphWidget::isDragAllowed() const |
|
242 | 246 | { |
|
243 | 247 | return true; |
|
244 | 248 | } |
|
245 | 249 | |
|
250 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
|
251 | { | |
|
252 | if (highlighted) { | |
|
253 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
|
254 | } | |
|
255 | else { | |
|
256 | plot().setBackground(QBrush(Qt::white)); | |
|
257 | } | |
|
258 | ||
|
259 | plot().update(); | |
|
260 | } | |
|
261 | ||
|
246 | 262 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
247 | 263 | { |
|
248 | 264 | Q_UNUSED(event); |
|
249 | 265 | |
|
250 | 266 | // Prevents that all variables will be removed from graph when it will be closed |
|
251 | 267 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
252 | 268 | emit variableAboutToBeRemoved(variableEntry.first); |
|
253 | 269 | } |
|
254 | 270 | } |
|
255 | 271 | |
|
256 | 272 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
257 | 273 | { |
|
258 | 274 | Q_UNUSED(event); |
|
259 | 275 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
260 | 276 | } |
|
261 | 277 | |
|
262 | 278 | void VisualizationGraphWidget::leaveEvent(QEvent *event) |
|
263 | 279 | { |
|
264 | 280 | Q_UNUSED(event); |
|
265 | 281 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
266 | 282 | } |
|
267 | 283 | |
|
268 | 284 | QCustomPlot &VisualizationGraphWidget::plot() noexcept |
|
269 | 285 | { |
|
270 | 286 | return *ui->widget; |
|
271 | 287 | } |
|
272 | 288 | |
|
273 | 289 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
274 | 290 | { |
|
275 | 291 | QMenu graphMenu{}; |
|
276 | 292 | |
|
277 | 293 | // Iterates on variables (unique keys) |
|
278 | 294 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
279 | 295 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
280 | 296 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
281 | 297 | // 'Remove variable' action |
|
282 | 298 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
283 | 299 | [ this, var = it->first ]() { removeVariable(var); }); |
|
284 | 300 | } |
|
285 | 301 | |
|
286 | 302 | if (!graphMenu.isEmpty()) { |
|
287 | 303 | graphMenu.exec(QCursor::pos()); |
|
288 | 304 | } |
|
289 | 305 | } |
|
290 | 306 | |
|
291 | 307 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
292 | 308 | { |
|
293 | 309 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
294 | 310 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
295 | 311 | << impl->m_DoAcquisition; |
|
296 | 312 | |
|
297 | 313 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
298 | 314 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
299 | 315 | |
|
300 | 316 | if (impl->m_DoAcquisition) { |
|
301 | 317 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
302 | 318 | |
|
303 | 319 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
304 | 320 | end = impl->m_VariableToPlotMultiMap.end(); |
|
305 | 321 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
306 | 322 | variableUnderGraphVector.push_back(it->first); |
|
307 | 323 | } |
|
308 | 324 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, |
|
309 | 325 | !impl->m_IsCalibration); |
|
310 | 326 | |
|
311 | 327 | if (!impl->m_IsCalibration) { |
|
312 | 328 | qCDebug(LOG_VisualizationGraphWidget()) |
|
313 | 329 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
314 | 330 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
315 | 331 | emit synchronize(graphRange, oldGraphRange); |
|
316 | 332 | } |
|
317 | 333 | } |
|
318 | 334 | } |
|
319 | 335 | |
|
320 | 336 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
321 | 337 | { |
|
322 | 338 | // Handles plot rendering when mouse is moving |
|
323 | 339 | impl->m_RenderingDelegate->onMouseMove(event); |
|
324 | 340 | |
|
325 | 341 | VisualizationDragWidget::mouseMoveEvent(event); |
|
326 | 342 | } |
|
327 | 343 | |
|
328 | 344 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
329 | 345 | { |
|
330 | 346 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
331 | 347 | |
|
332 | 348 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
333 | 349 | // has |
|
334 | 350 | // been pressed |
|
335 | 351 | auto enableOrientation |
|
336 | 352 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
337 | 353 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
338 | 354 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
339 | 355 | }; |
|
340 | 356 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
341 | 357 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
342 | 358 | |
|
343 | 359 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
344 | 360 | } |
|
345 | 361 | |
|
346 | 362 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
347 | 363 | { |
|
348 | 364 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); |
|
349 | 365 | |
|
350 | 366 | plot().setInteraction(QCP::iRangeDrag, !event->modifiers().testFlag(Qt::AltModifier)); |
|
351 | 367 | |
|
352 | 368 | VisualizationDragWidget::mousePressEvent(event); |
|
353 | 369 | } |
|
354 | 370 | |
|
355 | 371 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
356 | 372 | { |
|
357 | 373 | impl->m_IsCalibration = false; |
|
358 | 374 | } |
|
359 | 375 | |
|
360 | 376 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
361 | 377 | { |
|
362 | 378 | auto graphRange = ui->widget->xAxis->range(); |
|
363 | 379 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
364 | 380 | |
|
365 | 381 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
366 | 382 | auto variable = variableEntry.first; |
|
367 | 383 | qCDebug(LOG_VisualizationGraphWidget()) |
|
368 | 384 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
369 | 385 | qCDebug(LOG_VisualizationGraphWidget()) |
|
370 | 386 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
371 | 387 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
372 | 388 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(), |
|
373 | 389 | variable->range()); |
|
374 | 390 | } |
|
375 | 391 | } |
|
376 | 392 | } |
|
377 | 393 | |
|
378 | 394 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
379 | 395 | const SqpRange &range) |
|
380 | 396 | { |
|
381 | 397 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
382 | 398 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
383 | 399 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range); |
|
384 | 400 | } |
|
385 | 401 | } |
@@ -1,300 +1,309 | |||
|
1 | 1 | #include "Visualization/VisualizationTabWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "ui_VisualizationTabWidget.h" |
|
4 | 4 | |
|
5 | 5 | #include "Visualization/VisualizationGraphWidget.h" |
|
6 | 6 | #include "Visualization/VisualizationZoneWidget.h" |
|
7 | 7 | |
|
8 | 8 | #include "Variable/VariableController.h" |
|
9 | 9 | |
|
10 | 10 | #include "Common/MimeTypesDef.h" |
|
11 | 11 | |
|
12 | #include "DragDropHelper.h" | |
|
12 | #include "DragAndDrop/DragDropHelper.h" | |
|
13 | 13 | #include "SqpApplication.h" |
|
14 | 14 | |
|
15 | 15 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") |
|
16 | 16 | |
|
17 | 17 | namespace { |
|
18 | 18 | |
|
19 | 19 | /// Generates a default name for a new zone, according to the number of zones already displayed in |
|
20 | 20 | /// the tab |
|
21 | 21 | QString defaultZoneName(const QLayout &layout) |
|
22 | 22 | { |
|
23 | 23 | auto count = 0; |
|
24 | 24 | for (auto i = 0; i < layout.count(); ++i) { |
|
25 | 25 | if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) { |
|
26 | 26 | count++; |
|
27 | 27 | } |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | return QObject::tr("Zone %1").arg(count + 1); |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | /** |
|
34 | 34 | * Applies a function to all zones of the tab represented by its layout |
|
35 | 35 | * @param layout the layout that contains zones |
|
36 | 36 | * @param fun the function to apply to each zone |
|
37 | 37 | */ |
|
38 | 38 | template <typename Fun> |
|
39 | 39 | void processZones(QLayout &layout, Fun fun) |
|
40 | 40 | { |
|
41 | 41 | for (auto i = 0; i < layout.count(); ++i) { |
|
42 | 42 | if (auto item = layout.itemAt(i)) { |
|
43 | 43 | if (auto visualizationZoneWidget |
|
44 | 44 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { |
|
45 | 45 | fun(*visualizationZoneWidget); |
|
46 | 46 | } |
|
47 | 47 | } |
|
48 | 48 | } |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | } // namespace |
|
52 | 52 | |
|
53 | 53 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { |
|
54 | 54 | explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} |
|
55 | 55 | |
|
56 | 56 | QString m_Name; |
|
57 | 57 | |
|
58 | 58 | void dropGraph(int index, VisualizationTabWidget *tabWidget); |
|
59 | 59 | void dropZone(int index, VisualizationTabWidget *tabWidget); |
|
60 | 60 | void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index, |
|
61 | 61 | VisualizationTabWidget *tabWidget); |
|
62 | 62 | }; |
|
63 | 63 | |
|
64 | 64 | VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) |
|
65 | 65 | : QWidget{parent}, |
|
66 | 66 | ui{new Ui::VisualizationTabWidget}, |
|
67 | 67 | impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} |
|
68 | 68 | { |
|
69 | 69 | ui->setupUi(this); |
|
70 | 70 | |
|
71 | ui->dragDropContainer->setAcceptedMimeTypes( | |
|
72 | {MIME_TYPE_GRAPH, MIME_TYPE_ZONE, MIME_TYPE_VARIABLE_LIST}); | |
|
73 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, | |
|
74 | &VisualizationTabWidget::dropMimeData); | |
|
71 | ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone"); | |
|
72 | ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5); | |
|
73 | ui->dragDropContainer->addAcceptedMimeType( | |
|
74 | MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted); | |
|
75 | ui->dragDropContainer->addAcceptedMimeType( | |
|
76 | MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted); | |
|
77 | ui->dragDropContainer->addAcceptedMimeType( | |
|
78 | MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted); | |
|
79 | ||
|
75 | 80 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { |
|
76 | 81 | return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData, |
|
77 | 82 | ui->dragDropContainer); |
|
78 | 83 | }); |
|
84 | ||
|
85 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, | |
|
86 | &VisualizationTabWidget::dropMimeData); | |
|
87 | ||
|
79 | 88 | sqpApp->dragDropHelper().addDragDropScrollArea(ui->scrollArea); |
|
80 | 89 | |
|
81 | 90 | // Widget is deleted when closed |
|
82 | 91 | setAttribute(Qt::WA_DeleteOnClose); |
|
83 | 92 | } |
|
84 | 93 | |
|
85 | 94 | VisualizationTabWidget::~VisualizationTabWidget() |
|
86 | 95 | { |
|
87 | 96 | sqpApp->dragDropHelper().removeDragDropScrollArea(ui->scrollArea); |
|
88 | 97 | delete ui; |
|
89 | 98 | } |
|
90 | 99 | |
|
91 | 100 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) |
|
92 | 101 | { |
|
93 | 102 | ui->dragDropContainer->addDragWidget(zoneWidget); |
|
94 | 103 | } |
|
95 | 104 | |
|
96 | 105 | void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget) |
|
97 | 106 | { |
|
98 | 107 | ui->dragDropContainer->insertDragWidget(index, zoneWidget); |
|
99 | 108 | } |
|
100 | 109 | |
|
101 | 110 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
102 | 111 | { |
|
103 | 112 | return createZone({variable}, -1); |
|
104 | 113 | } |
|
105 | 114 | |
|
106 | 115 | VisualizationZoneWidget * |
|
107 | 116 | VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) |
|
108 | 117 | { |
|
109 | 118 | auto zoneWidget = createEmptyZone(index); |
|
110 | 119 | |
|
111 | 120 | // Creates a new graph into the zone |
|
112 | 121 | zoneWidget->createGraph(variables, index); |
|
113 | 122 | |
|
114 | 123 | return zoneWidget; |
|
115 | 124 | } |
|
116 | 125 | |
|
117 | 126 | VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index) |
|
118 | 127 | { |
|
119 | 128 | auto zoneWidget |
|
120 | 129 | = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; |
|
121 | 130 | this->insertZone(index, zoneWidget); |
|
122 | 131 | |
|
123 | 132 | return zoneWidget; |
|
124 | 133 | } |
|
125 | 134 | |
|
126 | 135 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
127 | 136 | { |
|
128 | 137 | if (visitor) { |
|
129 | 138 | visitor->visitEnter(this); |
|
130 | 139 | |
|
131 | 140 | // Apply visitor to zone children: widgets different from zones are not visited (no action) |
|
132 | 141 | processZones(tabLayout(), [visitor](VisualizationZoneWidget &zoneWidget) { |
|
133 | 142 | zoneWidget.accept(visitor); |
|
134 | 143 | }); |
|
135 | 144 | |
|
136 | 145 | visitor->visitLeave(this); |
|
137 | 146 | } |
|
138 | 147 | else { |
|
139 | 148 | qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); |
|
140 | 149 | } |
|
141 | 150 | } |
|
142 | 151 | |
|
143 | 152 | bool VisualizationTabWidget::canDrop(const Variable &variable) const |
|
144 | 153 | { |
|
145 | 154 | // A tab can always accomodate a variable |
|
146 | 155 | Q_UNUSED(variable); |
|
147 | 156 | return true; |
|
148 | 157 | } |
|
149 | 158 | |
|
150 | 159 | bool VisualizationTabWidget::contains(const Variable &variable) const |
|
151 | 160 | { |
|
152 | 161 | Q_UNUSED(variable); |
|
153 | 162 | return false; |
|
154 | 163 | } |
|
155 | 164 | |
|
156 | 165 | QString VisualizationTabWidget::name() const |
|
157 | 166 | { |
|
158 | 167 | return impl->m_Name; |
|
159 | 168 | } |
|
160 | 169 | |
|
161 | 170 | void VisualizationTabWidget::closeEvent(QCloseEvent *event) |
|
162 | 171 | { |
|
163 | 172 | // Closes zones in the tab |
|
164 | 173 | processZones(tabLayout(), [](VisualizationZoneWidget &zoneWidget) { zoneWidget.close(); }); |
|
165 | 174 | |
|
166 | 175 | QWidget::closeEvent(event); |
|
167 | 176 | } |
|
168 | 177 | |
|
169 | 178 | QLayout &VisualizationTabWidget::tabLayout() const noexcept |
|
170 | 179 | { |
|
171 | 180 | return *ui->dragDropContainer->layout(); |
|
172 | 181 | } |
|
173 | 182 | |
|
174 | 183 | void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) |
|
175 | 184 | { |
|
176 | 185 | if (mimeData->hasFormat(MIME_TYPE_GRAPH)) { |
|
177 | 186 | impl->dropGraph(index, this); |
|
178 | 187 | } |
|
179 | 188 | else if (mimeData->hasFormat(MIME_TYPE_ZONE)) { |
|
180 | 189 | impl->dropZone(index, this); |
|
181 | 190 | } |
|
182 | 191 | else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { |
|
183 | 192 | auto variables = sqpApp->variableController().variablesForMimeData( |
|
184 | 193 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); |
|
185 | 194 | impl->dropVariables(variables, index, this); |
|
186 | 195 | } |
|
187 | 196 | else { |
|
188 | 197 | qCWarning(LOG_VisualizationZoneWidget()) |
|
189 | 198 | << tr("VisualizationTabWidget::dropMimeData, unknown MIME data received."); |
|
190 | 199 | } |
|
191 | 200 | } |
|
192 | 201 | |
|
193 | 202 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph( |
|
194 | 203 | int index, VisualizationTabWidget *tabWidget) |
|
195 | 204 | { |
|
196 | 205 | auto &helper = sqpApp->dragDropHelper(); |
|
197 | 206 | |
|
198 | 207 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); |
|
199 | 208 | if (!graphWidget) { |
|
200 | 209 | qCWarning(LOG_VisualizationZoneWidget()) |
|
201 | 210 | << tr("VisualizationTabWidget::dropGraph, drop aborted, the dropped graph is not " |
|
202 | 211 | "found or invalid."); |
|
203 | 212 | Q_ASSERT(false); |
|
204 | 213 | return; |
|
205 | 214 | } |
|
206 | 215 | |
|
207 | 216 | auto parentDragDropContainer |
|
208 | 217 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); |
|
209 | 218 | if (!parentDragDropContainer) { |
|
210 | 219 | qCWarning(LOG_VisualizationZoneWidget()) |
|
211 | 220 | << tr("VisualizationTabWidget::dropGraph, drop aborted, the parent container of " |
|
212 | 221 | "the dropped graph is not found."); |
|
213 | 222 | Q_ASSERT(false); |
|
214 | 223 | return; |
|
215 | 224 | } |
|
216 | 225 | |
|
217 | 226 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
218 | 227 | |
|
219 | 228 | const auto &variables = graphWidget->variables(); |
|
220 | 229 | |
|
221 | 230 | if (!variables.isEmpty()) { |
|
222 | 231 | // Abort the requests for the variables (if any) |
|
223 | 232 | // Commented, because it's not sure if it's needed or not |
|
224 | 233 | // for (const auto& var : variables) |
|
225 | 234 | //{ |
|
226 | 235 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
227 | 236 | //} |
|
228 | 237 | |
|
229 | 238 | if (nbGraph == 1) { |
|
230 | 239 | // This is the only graph in the previous zone, close the zone |
|
231 | 240 | graphWidget->parentZoneWidget()->close(); |
|
232 | 241 | } |
|
233 | 242 | else { |
|
234 | 243 | // Close the graph |
|
235 | 244 | graphWidget->close(); |
|
236 | 245 | } |
|
237 | 246 | |
|
238 | 247 | tabWidget->createZone(variables, index); |
|
239 | 248 | } |
|
240 | 249 | else { |
|
241 | 250 | // The graph is empty, create an empty zone and move the graph inside |
|
242 | 251 | |
|
243 | 252 | auto parentZoneWidget = graphWidget->parentZoneWidget(); |
|
244 | 253 | |
|
245 | 254 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
246 | 255 | |
|
247 | 256 | auto zoneWidget = tabWidget->createEmptyZone(index); |
|
248 | 257 | zoneWidget->addGraph(graphWidget); |
|
249 | 258 | |
|
250 | 259 | // Close the old zone if it was the only graph inside |
|
251 | 260 | if (nbGraph == 1) { |
|
252 | 261 | parentZoneWidget->close(); |
|
253 | 262 | } |
|
254 | 263 | } |
|
255 | 264 | } |
|
256 | 265 | |
|
257 | 266 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropZone( |
|
258 | 267 | int index, VisualizationTabWidget *tabWidget) |
|
259 | 268 | { |
|
260 | 269 | auto &helper = sqpApp->dragDropHelper(); |
|
261 | 270 | |
|
262 | 271 | auto zoneWidget = qobject_cast<VisualizationZoneWidget *>(helper.getCurrentDragWidget()); |
|
263 | 272 | if (!zoneWidget) { |
|
264 | 273 | qCWarning(LOG_VisualizationZoneWidget()) |
|
265 | 274 | << tr("VisualizationTabWidget::dropZone, drop aborted, the dropped zone is not " |
|
266 | 275 | "found or invalid."); |
|
267 | 276 | Q_ASSERT(false); |
|
268 | 277 | return; |
|
269 | 278 | } |
|
270 | 279 | |
|
271 | 280 | auto parentDragDropContainer |
|
272 | 281 | = qobject_cast<VisualizationDragDropContainer *>(zoneWidget->parentWidget()); |
|
273 | 282 | if (!parentDragDropContainer) { |
|
274 | 283 | qCWarning(LOG_VisualizationZoneWidget()) |
|
275 | 284 | << tr("VisualizationTabWidget::dropZone, drop aborted, the parent container of " |
|
276 | 285 | "the dropped zone is not found."); |
|
277 | 286 | Q_ASSERT(false); |
|
278 | 287 | return; |
|
279 | 288 | } |
|
280 | 289 | |
|
281 | 290 | // Simple move of the zone, no variable operation associated |
|
282 | 291 | parentDragDropContainer->layout()->removeWidget(zoneWidget); |
|
283 | 292 | tabWidget->ui->dragDropContainer->insertDragWidget(index, zoneWidget); |
|
284 | 293 | } |
|
285 | 294 | |
|
286 | 295 | void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropVariables( |
|
287 | 296 | const QList<std::shared_ptr<Variable> > &variables, int index, |
|
288 | 297 | VisualizationTabWidget *tabWidget) |
|
289 | 298 | { |
|
290 | 299 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and |
|
291 | 300 | // compatible variable here |
|
292 | 301 | if (variables.count() > 1) { |
|
293 | 302 | qCWarning(LOG_VisualizationZoneWidget()) |
|
294 | 303 | << tr("VisualizationTabWidget::dropVariables, dropping multiple variables, operation " |
|
295 | 304 | "aborted."); |
|
296 | 305 | return; |
|
297 | 306 | } |
|
298 | 307 | |
|
299 | 308 | tabWidget->createZone(variables, index); |
|
300 | 309 | } |
@@ -1,172 +1,178 | |||
|
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/FindVariableOperation.h" |
|
7 | 7 | #include "Visualization/operations/GenerateVariableMenuOperation.h" |
|
8 | 8 | #include "Visualization/operations/RemoveVariableOperation.h" |
|
9 | 9 | #include "Visualization/operations/RescaleAxeOperation.h" |
|
10 | 10 | #include "Visualization/qcustomplot.h" |
|
11 | 11 | |
|
12 | 12 | #include "ui_VisualizationWidget.h" |
|
13 | 13 | |
|
14 | #include "DragAndDrop/DragDropHelper.h" | |
|
15 | #include "SqpApplication.h" | |
|
16 | ||
|
14 | 17 | #include <QToolButton> |
|
15 | 18 | |
|
16 | 19 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
17 | 20 | |
|
18 | 21 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
19 | 22 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
20 | 23 | { |
|
21 | 24 | ui->setupUi(this); |
|
22 | 25 | |
|
23 | 26 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
24 | 27 | addTabViewButton->setText(tr("Add View")); |
|
25 | 28 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
26 | 29 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
27 | 30 | |
|
28 | 31 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
29 | 32 | |
|
30 | 33 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
31 | 34 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
32 | 35 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
33 | 36 | tabViewCornerWidget->setMinimumHeight(height); |
|
34 | 37 | tabViewCornerWidget->setMinimumWidth(width); |
|
35 | 38 | ui->tabWidget->setMinimumHeight(height); |
|
36 | 39 | ui->tabWidget->setMinimumWidth(width); |
|
37 | 40 | }; |
|
38 | 41 | |
|
39 | 42 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
40 | 43 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
41 | 44 | ui->tabWidget}; |
|
42 | 45 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
43 | 46 | if (ui->tabWidget->count() > 0) { |
|
44 | 47 | enableMinimumCornerWidgetSize(false); |
|
45 | 48 | } |
|
46 | 49 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
47 | 50 | }; |
|
48 | 51 | |
|
49 | 52 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
50 | 53 | if (ui->tabWidget->count() == 1) { |
|
51 | 54 | enableMinimumCornerWidgetSize(true); |
|
52 | 55 | } |
|
53 | 56 | |
|
54 | 57 | // Removes widget from tab and closes it |
|
55 | 58 | auto widget = ui->tabWidget->widget(index); |
|
56 | 59 | ui->tabWidget->removeTab(index); |
|
57 | 60 | if (widget) { |
|
58 | 61 | widget->close(); |
|
59 | 62 | } |
|
60 | 63 | |
|
61 | 64 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
62 | 65 | |
|
63 | 66 | }; |
|
64 | 67 | |
|
65 | 68 | ui->tabWidget->setTabsClosable(true); |
|
66 | 69 | |
|
67 | 70 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
68 | 71 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
69 | 72 | |
|
73 | sqpApp->dragDropHelper().addDragDropTabBar(ui->tabWidget->tabBar()); | |
|
74 | ||
|
70 | 75 | // Adds default tab |
|
71 | 76 | addTabView(); |
|
72 | 77 | } |
|
73 | 78 | |
|
74 | 79 | VisualizationWidget::~VisualizationWidget() |
|
75 | 80 | { |
|
81 | sqpApp->dragDropHelper().removeDragDropTabBar(ui->tabWidget->tabBar()); | |
|
76 | 82 | delete ui; |
|
77 | 83 | } |
|
78 | 84 | |
|
79 | 85 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
80 | 86 | { |
|
81 | 87 | if (visitor) { |
|
82 | 88 | visitor->visitEnter(this); |
|
83 | 89 | |
|
84 | 90 | // Apply visitor for tab children |
|
85 | 91 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
86 | 92 | // Widgets different from tabs are not visited (no action) |
|
87 | 93 | if (auto visualizationTabWidget |
|
88 | 94 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
89 | 95 | visualizationTabWidget->accept(visitor); |
|
90 | 96 | } |
|
91 | 97 | } |
|
92 | 98 | |
|
93 | 99 | visitor->visitLeave(this); |
|
94 | 100 | } |
|
95 | 101 | else { |
|
96 | 102 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); |
|
97 | 103 | } |
|
98 | 104 | } |
|
99 | 105 | |
|
100 | 106 | bool VisualizationWidget::canDrop(const Variable &variable) const |
|
101 | 107 | { |
|
102 | 108 | // The main widget can never accomodate a variable |
|
103 | 109 | Q_UNUSED(variable); |
|
104 | 110 | return false; |
|
105 | 111 | } |
|
106 | 112 | |
|
107 | 113 | bool VisualizationWidget::contains(const Variable &variable) const |
|
108 | 114 | { |
|
109 | 115 | Q_UNUSED(variable); |
|
110 | 116 | return false; |
|
111 | 117 | } |
|
112 | 118 | |
|
113 | 119 | QString VisualizationWidget::name() const |
|
114 | 120 | { |
|
115 | 121 | return QStringLiteral("MainView"); |
|
116 | 122 | } |
|
117 | 123 | |
|
118 | 124 | void VisualizationWidget::attachVariableMenu( |
|
119 | 125 | QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
120 | 126 | { |
|
121 | 127 | // Menu is generated only if there is a single variable |
|
122 | 128 | if (variables.size() == 1) { |
|
123 | 129 | if (auto variable = variables.first()) { |
|
124 | 130 | // Gets the containers of the variable |
|
125 | 131 | FindVariableOperation findVariableOperation{variable}; |
|
126 | 132 | accept(&findVariableOperation); |
|
127 | 133 | auto variableContainers = findVariableOperation.result(); |
|
128 | 134 | |
|
129 | 135 | // Generates the actions that make it possible to visualize the variable |
|
130 | 136 | GenerateVariableMenuOperation generateVariableMenuOperation{ |
|
131 | 137 | menu, variable, std::move(variableContainers)}; |
|
132 | 138 | accept(&generateVariableMenuOperation); |
|
133 | 139 | } |
|
134 | 140 | else { |
|
135 | 141 | qCCritical(LOG_VisualizationWidget()) << tr( |
|
136 | 142 | "Can't generate the menu relative to the visualization: the variable is null"); |
|
137 | 143 | } |
|
138 | 144 | } |
|
139 | 145 | else { |
|
140 | 146 | qCDebug(LOG_VisualizationWidget()) |
|
141 | 147 | << tr("No generation of the menu related to the visualization: several variables are " |
|
142 | 148 | "selected"); |
|
143 | 149 | } |
|
144 | 150 | } |
|
145 | 151 | |
|
146 | 152 | void VisualizationWidget::onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept |
|
147 | 153 | { |
|
148 | 154 | // Calls the operation of removing all references to the variable in the visualization |
|
149 | 155 | auto removeVariableOperation = RemoveVariableOperation{variable}; |
|
150 | 156 | accept(&removeVariableOperation); |
|
151 | 157 | } |
|
152 | 158 | |
|
153 | 159 | void VisualizationWidget::onRangeChanged(std::shared_ptr<Variable> variable, |
|
154 | 160 | const SqpRange &range) noexcept |
|
155 | 161 | { |
|
156 | 162 | // Calls the operation of rescaling all graph that contrains variable in the visualization |
|
157 | 163 | auto rescaleVariableOperation = RescaleAxeOperation{variable, range}; |
|
158 | 164 | accept(&rescaleVariableOperation); |
|
159 | 165 | } |
|
160 | 166 | |
|
161 | 167 | void VisualizationWidget::closeEvent(QCloseEvent *event) |
|
162 | 168 | { |
|
163 | 169 | // Closes tabs in the widget |
|
164 | 170 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
165 | 171 | if (auto visualizationTabWidget |
|
166 | 172 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
167 | 173 | visualizationTabWidget->close(); |
|
168 | 174 | } |
|
169 | 175 | } |
|
170 | 176 | |
|
171 | 177 | QWidget::closeEvent(event); |
|
172 | 178 | } |
@@ -1,468 +1,516 | |||
|
1 | 1 | #include "Visualization/VisualizationZoneWidget.h" |
|
2 | 2 | |
|
3 | 3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
4 | 4 | #include "Visualization/QCustomPlotSynchronizer.h" |
|
5 | 5 | #include "Visualization/VisualizationGraphWidget.h" |
|
6 | 6 | #include "Visualization/VisualizationWidget.h" |
|
7 | 7 | #include "ui_VisualizationZoneWidget.h" |
|
8 | 8 | |
|
9 | 9 | #include "Common/MimeTypesDef.h" |
|
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 | |
|
16 | 17 | #include <Visualization/operations/FindVariableOperation.h> |
|
17 | 18 | |
|
18 | #include <DragDropHelper.h> | |
|
19 | #include <DragAndDrop/DragDropHelper.h> | |
|
19 | 20 | #include <QUuid> |
|
20 | 21 | #include <SqpApplication.h> |
|
21 | 22 | #include <cmath> |
|
22 | 23 | |
|
23 | 24 | #include <QLayout> |
|
24 | 25 | |
|
25 | 26 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
26 | 27 | |
|
27 | 28 | namespace { |
|
28 | 29 | |
|
29 | 30 | |
|
30 | 31 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
31 | 32 | /// the zone |
|
32 | 33 | QString defaultGraphName(const QLayout &layout) |
|
33 | 34 | { |
|
34 | 35 | auto count = 0; |
|
35 | 36 | for (auto i = 0; i < layout.count(); ++i) { |
|
36 | 37 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
37 | 38 | count++; |
|
38 | 39 | } |
|
39 | 40 | } |
|
40 | 41 | |
|
41 | 42 | return QObject::tr("Graph %1").arg(count + 1); |
|
42 | 43 | } |
|
43 | 44 | |
|
44 | 45 | /** |
|
45 | 46 | * Applies a function to all graphs of the zone represented by its layout |
|
46 | 47 | * @param layout the layout that contains graphs |
|
47 | 48 | * @param fun the function to apply to each graph |
|
48 | 49 | */ |
|
49 | 50 | template <typename Fun> |
|
50 | 51 | void processGraphs(QLayout &layout, Fun fun) |
|
51 | 52 | { |
|
52 | 53 | for (auto i = 0; i < layout.count(); ++i) { |
|
53 | 54 | if (auto item = layout.itemAt(i)) { |
|
54 | 55 | if (auto visualizationGraphWidget |
|
55 | 56 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
56 | 57 | fun(*visualizationGraphWidget); |
|
57 | 58 | } |
|
58 | 59 | } |
|
59 | 60 | } |
|
60 | 61 | } |
|
61 | 62 | |
|
62 | 63 | } // namespace |
|
63 | 64 | |
|
64 | 65 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { |
|
65 | 66 | |
|
66 | 67 | explicit VisualizationZoneWidgetPrivate() |
|
67 | 68 | : m_SynchronisationGroupId{QUuid::createUuid()}, |
|
68 | 69 | m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()} |
|
69 | 70 | { |
|
70 | 71 | } |
|
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); |
|
77 | 93 | }; |
|
78 | 94 | |
|
79 | 95 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
80 | 96 | : VisualizationDragWidget{parent}, |
|
81 | 97 | ui{new Ui::VisualizationZoneWidget}, |
|
82 | 98 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
83 | 99 | { |
|
84 | 100 | ui->setupUi(this); |
|
85 | 101 | |
|
86 | 102 | ui->zoneNameLabel->setText(name); |
|
87 | 103 | |
|
88 | ui->dragDropContainer->setAcceptedMimeTypes({MIME_TYPE_GRAPH, MIME_TYPE_VARIABLE_LIST}); | |
|
104 | ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Graph); | |
|
105 | ui->dragDropContainer->addAcceptedMimeType( | |
|
106 | MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted); | |
|
107 | ui->dragDropContainer->addAcceptedMimeType( | |
|
108 | MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); | |
|
109 | ui->dragDropContainer->addAcceptedMimeType( | |
|
110 | MIME_TYPE_TIME_RANGE, VisualizationDragDropContainer::DropBehavior::Merged); | |
|
89 | 111 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { |
|
90 | 112 | return sqpApp->dragDropHelper().checkMimeDataForVisualization(mimeData, |
|
91 | 113 | ui->dragDropContainer); |
|
92 | 114 | }); |
|
93 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, | |
|
115 | ||
|
116 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, | |
|
94 | 117 | &VisualizationZoneWidget::dropMimeData); |
|
118 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, | |
|
119 | &VisualizationZoneWidget::dropMimeDataOnGraph); | |
|
95 | 120 | |
|
96 | 121 | // 'Close' options : widget is deleted when closed |
|
97 | 122 | setAttribute(Qt::WA_DeleteOnClose); |
|
98 | 123 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
99 | 124 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
100 | 125 | |
|
101 | 126 | // Synchronisation id |
|
102 | 127 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", |
|
103 | 128 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
104 | 129 | } |
|
105 | 130 | |
|
106 | 131 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
107 | 132 | { |
|
108 | 133 | delete ui; |
|
109 | 134 | } |
|
110 | 135 | |
|
111 | 136 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
112 | 137 | { |
|
113 | 138 | // Synchronize new graph with others in the zone |
|
114 | 139 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
115 | 140 | |
|
116 | 141 | ui->dragDropContainer->addDragWidget(graphWidget); |
|
117 | 142 | } |
|
118 | 143 | |
|
119 | 144 | void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget *graphWidget) |
|
120 | 145 | { |
|
121 | 146 | // Synchronize new graph with others in the zone |
|
122 | 147 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
123 | 148 | |
|
124 | 149 | ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
125 | 150 | } |
|
126 | 151 | |
|
127 | 152 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
128 | 153 | { |
|
129 | 154 | return createGraph(variable, -1); |
|
130 | 155 | } |
|
131 | 156 | |
|
132 | 157 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable, |
|
133 | 158 | int index) |
|
134 | 159 | { |
|
135 | 160 | auto graphWidget |
|
136 | 161 | = new VisualizationGraphWidget{defaultGraphName(*ui->dragDropContainer->layout()), this}; |
|
137 | 162 | |
|
138 | 163 | |
|
139 | 164 | // Set graph properties |
|
140 | 165 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
141 | 166 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
|
142 | 167 | |
|
143 | 168 | |
|
144 | 169 | // Lambda to synchronize zone widget |
|
145 | 170 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, |
|
146 | 171 | const SqpRange &oldGraphRange) { |
|
147 | 172 | |
|
148 | 173 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
149 | 174 | auto frameLayout = ui->dragDropContainer->layout(); |
|
150 | 175 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
151 | 176 | auto graphChild |
|
152 | 177 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
153 | 178 | if (graphChild && (graphChild != graphWidget)) { |
|
154 | 179 | |
|
155 | 180 | auto graphChildRange = graphChild->graphRange(); |
|
156 | 181 | switch (zoomType) { |
|
157 | 182 | case AcquisitionZoomType::ZoomIn: { |
|
158 | 183 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
159 | 184 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
160 | 185 | graphChildRange.m_TStart += deltaLeft; |
|
161 | 186 | graphChildRange.m_TEnd -= deltaRight; |
|
162 | 187 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); |
|
163 | 188 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
164 | 189 | << deltaLeft; |
|
165 | 190 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
166 | 191 | << deltaRight; |
|
167 | 192 | qCDebug(LOG_VisualizationZoneWidget()) |
|
168 | 193 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
169 | 194 | |
|
170 | 195 | break; |
|
171 | 196 | } |
|
172 | 197 | |
|
173 | 198 | case AcquisitionZoomType::ZoomOut: { |
|
174 | 199 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); |
|
175 | 200 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
176 | 201 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
177 | 202 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
178 | 203 | << deltaLeft; |
|
179 | 204 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
180 | 205 | << deltaRight; |
|
181 | 206 | qCDebug(LOG_VisualizationZoneWidget()) |
|
182 | 207 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
183 | 208 | graphChildRange.m_TStart -= deltaLeft; |
|
184 | 209 | graphChildRange.m_TEnd += deltaRight; |
|
185 | 210 | break; |
|
186 | 211 | } |
|
187 | 212 | case AcquisitionZoomType::PanRight: { |
|
188 | 213 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); |
|
189 | 214 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
190 | 215 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
191 | 216 | graphChildRange.m_TStart += deltaLeft; |
|
192 | 217 | graphChildRange.m_TEnd += deltaRight; |
|
193 | 218 | qCDebug(LOG_VisualizationZoneWidget()) |
|
194 | 219 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
195 | 220 | break; |
|
196 | 221 | } |
|
197 | 222 | case AcquisitionZoomType::PanLeft: { |
|
198 | 223 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); |
|
199 | 224 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
200 | 225 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
201 | 226 | graphChildRange.m_TStart -= deltaLeft; |
|
202 | 227 | graphChildRange.m_TEnd -= deltaRight; |
|
203 | 228 | break; |
|
204 | 229 | } |
|
205 | 230 | case AcquisitionZoomType::Unknown: { |
|
206 | 231 | qCDebug(LOG_VisualizationZoneWidget()) |
|
207 | 232 | << tr("Impossible to synchronize: zoom type unknown"); |
|
208 | 233 | break; |
|
209 | 234 | } |
|
210 | 235 | default: |
|
211 | 236 | qCCritical(LOG_VisualizationZoneWidget()) |
|
212 | 237 | << tr("Impossible to synchronize: zoom type not take into account"); |
|
213 | 238 | // No action |
|
214 | 239 | break; |
|
215 | 240 | } |
|
216 | 241 | graphChild->enableAcquisition(false); |
|
217 | 242 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") |
|
218 | 243 | << graphChild->graphRange(); |
|
219 | 244 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") |
|
220 | 245 | << graphChildRange; |
|
221 | 246 | qCDebug(LOG_VisualizationZoneWidget()) |
|
222 | 247 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
223 | 248 | graphChild->setGraphRange(graphChildRange); |
|
224 | 249 | graphChild->enableAcquisition(true); |
|
225 | 250 | } |
|
226 | 251 | } |
|
227 | 252 | }; |
|
228 | 253 | |
|
229 | 254 | // connection for synchronization |
|
230 | 255 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); |
|
231 | 256 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, |
|
232 | 257 | &VisualizationZoneWidget::onVariableAdded); |
|
233 | 258 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, |
|
234 | 259 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); |
|
235 | 260 | |
|
236 | 261 | auto range = SqpRange{}; |
|
237 | ||
|
238 | // Apply visitor to graph children | |
|
239 | auto layout = ui->dragDropContainer->layout(); | |
|
240 | if (layout->count() > 0) { | |
|
262 | if (auto firstGraph = impl->firstGraph(this)) { | |
|
241 | 263 | // Case of a new graph in a existant zone |
|
242 | if (auto visualizationGraphWidget | |
|
243 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
|
244 | range = visualizationGraphWidget->graphRange(); | |
|
245 | } | |
|
264 | range = firstGraph->graphRange(); | |
|
246 | 265 | } |
|
247 | 266 | else { |
|
248 | 267 | // Case of a new graph as the first of the zone |
|
249 | 268 | range = variable->range(); |
|
250 | 269 | } |
|
251 | 270 | |
|
252 | 271 | this->insertGraph(index, graphWidget); |
|
253 | 272 | |
|
254 | 273 | graphWidget->addVariable(variable, range); |
|
255 | 274 | |
|
256 | 275 | // get y using variable range |
|
257 | 276 | if (auto dataSeries = variable->dataSeries()) { |
|
258 | 277 | dataSeries->lockRead(); |
|
259 | 278 | auto valuesBounds |
|
260 | 279 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); |
|
261 | 280 | auto end = dataSeries->cend(); |
|
262 | 281 | if (valuesBounds.first != end && valuesBounds.second != end) { |
|
263 | 282 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; |
|
264 | 283 | |
|
265 | 284 | auto minValue = rangeValue(valuesBounds.first->minValue()); |
|
266 | 285 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); |
|
267 | 286 | |
|
268 | 287 | graphWidget->setYRange(SqpRange{minValue, maxValue}); |
|
269 | 288 | } |
|
270 | 289 | dataSeries->unlock(); |
|
271 | 290 | } |
|
272 | 291 | |
|
273 | 292 | return graphWidget; |
|
274 | 293 | } |
|
275 | 294 | |
|
276 | 295 | VisualizationGraphWidget * |
|
277 | 296 | VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > variables, int index) |
|
278 | 297 | { |
|
279 | 298 | if (variables.isEmpty()) { |
|
280 | 299 | return nullptr; |
|
281 | 300 | } |
|
282 | 301 | |
|
283 | 302 | auto graphWidget = createGraph(variables.first(), index); |
|
284 | 303 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) { |
|
285 | 304 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); |
|
286 | 305 | } |
|
287 | 306 | |
|
288 | 307 | return graphWidget; |
|
289 | 308 | } |
|
290 | 309 | |
|
291 | 310 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
292 | 311 | { |
|
293 | 312 | if (visitor) { |
|
294 | 313 | visitor->visitEnter(this); |
|
295 | 314 | |
|
296 | 315 | // Apply visitor to graph children: widgets different from graphs are not visited (no |
|
297 | 316 | // action) |
|
298 | 317 | processGraphs( |
|
299 | 318 | *ui->dragDropContainer->layout(), |
|
300 | 319 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); |
|
301 | 320 | |
|
302 | 321 | visitor->visitLeave(this); |
|
303 | 322 | } |
|
304 | 323 | else { |
|
305 | 324 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
306 | 325 | } |
|
307 | 326 | } |
|
308 | 327 | |
|
309 | 328 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
310 | 329 | { |
|
311 | 330 | // A tab can always accomodate a variable |
|
312 | 331 | Q_UNUSED(variable); |
|
313 | 332 | return true; |
|
314 | 333 | } |
|
315 | 334 | |
|
316 | 335 | bool VisualizationZoneWidget::contains(const Variable &variable) const |
|
317 | 336 | { |
|
318 | 337 | Q_UNUSED(variable); |
|
319 | 338 | return false; |
|
320 | 339 | } |
|
321 | 340 | |
|
322 | 341 | QString VisualizationZoneWidget::name() const |
|
323 | 342 | { |
|
324 | 343 | return ui->zoneNameLabel->text(); |
|
325 | 344 | } |
|
326 | 345 | |
|
327 | 346 | QMimeData *VisualizationZoneWidget::mimeData() const |
|
328 | 347 | { |
|
329 | 348 | auto mimeData = new QMimeData; |
|
330 | 349 | mimeData->setData(MIME_TYPE_ZONE, QByteArray{}); |
|
331 | 350 | |
|
332 | 351 | return mimeData; |
|
333 | 352 | } |
|
334 | 353 | |
|
335 | 354 | bool VisualizationZoneWidget::isDragAllowed() const |
|
336 | 355 | { |
|
337 | 356 | return true; |
|
338 | 357 | } |
|
339 | 358 | |
|
340 | 359 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) |
|
341 | 360 | { |
|
342 | 361 | // Closes graphs in the zone |
|
343 | 362 | processGraphs(*ui->dragDropContainer->layout(), |
|
344 | 363 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); |
|
345 | 364 | |
|
346 | 365 | // Delete synchronization group from variable controller |
|
347 | 366 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId", |
|
348 | 367 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
349 | 368 | |
|
350 | 369 | QWidget::closeEvent(event); |
|
351 | 370 | } |
|
352 | 371 | |
|
353 | 372 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) |
|
354 | 373 | { |
|
355 | 374 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
|
356 | 375 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), |
|
357 | 376 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
358 | 377 | } |
|
359 | 378 | |
|
360 | 379 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable) |
|
361 | 380 | { |
|
362 | 381 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, |
|
363 | 382 | Q_ARG(std::shared_ptr<Variable>, variable), |
|
364 | 383 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
365 | 384 | } |
|
366 | 385 | |
|
367 | 386 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) |
|
368 | 387 | { |
|
369 | 388 | if (mimeData->hasFormat(MIME_TYPE_GRAPH)) { |
|
370 | 389 | impl->dropGraph(index, this); |
|
371 | 390 | } |
|
372 | 391 | else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { |
|
373 | 392 | auto variables = sqpApp->variableController().variablesForMimeData( |
|
374 | 393 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); |
|
375 | 394 | impl->dropVariables(variables, index, this); |
|
376 | 395 | } |
|
377 | 396 | else { |
|
378 | 397 | qCWarning(LOG_VisualizationZoneWidget()) |
|
379 | 398 | << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received."); |
|
380 | 399 | } |
|
381 | 400 | } |
|
382 | 401 | |
|
402 | void VisualizationZoneWidget::dropMimeDataOnGraph(VisualizationDragWidget *dragWidget, | |
|
403 | const QMimeData *mimeData) | |
|
404 | { | |
|
405 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(dragWidget); | |
|
406 | if (!graphWidget) { | |
|
407 | qCWarning(LOG_VisualizationZoneWidget()) | |
|
408 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, dropping in an unknown widget, " | |
|
409 | "drop aborted"); | |
|
410 | Q_ASSERT(false); | |
|
411 | return; | |
|
412 | } | |
|
413 | ||
|
414 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
|
415 | auto variables = sqpApp->variableController().variablesForMimeData( | |
|
416 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
|
417 | for (const auto &var : variables) { | |
|
418 | graphWidget->addVariable(var, graphWidget->graphRange()); | |
|
419 | } | |
|
420 | } | |
|
421 | else if (mimeData->hasFormat(MIME_TYPE_TIME_RANGE)) { | |
|
422 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE)); | |
|
423 | graphWidget->setGraphRange(range); | |
|
424 | } | |
|
425 | else { | |
|
426 | qCWarning(LOG_VisualizationZoneWidget()) | |
|
427 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, unknown MIME data received."); | |
|
428 | } | |
|
429 | } | |
|
430 | ||
|
383 | 431 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph( |
|
384 | 432 | int index, VisualizationZoneWidget *zoneWidget) |
|
385 | 433 | { |
|
386 | 434 | auto &helper = sqpApp->dragDropHelper(); |
|
387 | 435 | |
|
388 | 436 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); |
|
389 | 437 | if (!graphWidget) { |
|
390 | 438 | qCWarning(LOG_VisualizationZoneWidget()) |
|
391 | 439 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the dropped graph is not " |
|
392 | 440 | "found or invalid."); |
|
393 | 441 | Q_ASSERT(false); |
|
394 | 442 | return; |
|
395 | 443 | } |
|
396 | 444 | |
|
397 | 445 | auto parentDragDropContainer |
|
398 | 446 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); |
|
399 | 447 | if (!parentDragDropContainer) { |
|
400 | 448 | qCWarning(LOG_VisualizationZoneWidget()) |
|
401 | 449 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the parent container of " |
|
402 | 450 | "the dropped graph is not found."); |
|
403 | 451 | Q_ASSERT(false); |
|
404 | 452 | return; |
|
405 | 453 | } |
|
406 | 454 | |
|
407 | 455 | const auto &variables = graphWidget->variables(); |
|
408 | 456 | |
|
409 | 457 | if (parentDragDropContainer != zoneWidget->ui->dragDropContainer && !variables.isEmpty()) { |
|
410 | 458 | // The drop didn't occur in the same zone |
|
411 | 459 | |
|
412 | 460 | // Abort the requests for the variables (if any) |
|
413 | 461 | // Commented, because it's not sure if it's needed or not |
|
414 | 462 | // for (const auto& var : variables) |
|
415 | 463 | //{ |
|
416 | 464 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
417 | 465 | //} |
|
418 | 466 | |
|
419 | 467 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); |
|
420 | 468 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
421 | 469 | if (nbGraph == 1) { |
|
422 | 470 | // This is the only graph in the previous zone, close the zone |
|
423 | 471 | previousParentZoneWidget->close(); |
|
424 | 472 | } |
|
425 | 473 | else { |
|
426 | 474 | // Close the graph |
|
427 | 475 | graphWidget->close(); |
|
428 | 476 | } |
|
429 | 477 | |
|
430 | 478 | // Creates the new graph in the zone |
|
431 | 479 | zoneWidget->createGraph(variables, index); |
|
432 | 480 | } |
|
433 | 481 | else { |
|
434 | 482 | // The drop occurred in the same zone or the graph is empty |
|
435 | 483 | // Simple move of the graph, no variable operation associated |
|
436 | 484 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
437 | 485 | |
|
438 | 486 | if (variables.isEmpty() && parentDragDropContainer != zoneWidget->ui->dragDropContainer) { |
|
439 | 487 | // The graph is empty and dropped in a different zone. |
|
440 | 488 | // Take the range of the first graph in the zone (if existing). |
|
441 | 489 | auto layout = zoneWidget->ui->dragDropContainer->layout(); |
|
442 | 490 | if (layout->count() > 0) { |
|
443 | 491 | if (auto visualizationGraphWidget |
|
444 | 492 | = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
445 | 493 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); |
|
446 | 494 | } |
|
447 | 495 | } |
|
448 | 496 | } |
|
449 | 497 | |
|
450 | 498 | zoneWidget->ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
451 | 499 | } |
|
452 | 500 | } |
|
453 | 501 | |
|
454 | 502 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables( |
|
455 | 503 | const QList<std::shared_ptr<Variable> > &variables, int index, |
|
456 | 504 | VisualizationZoneWidget *zoneWidget) |
|
457 | 505 | { |
|
458 | 506 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and |
|
459 | 507 | // compatible variable here |
|
460 | 508 | if (variables.count() > 1) { |
|
461 | 509 | qCWarning(LOG_VisualizationZoneWidget()) |
|
462 | 510 | << tr("VisualizationZoneWidget::dropVariables, dropping multiple variables, operation " |
|
463 | 511 | "aborted."); |
|
464 | 512 | return; |
|
465 | 513 | } |
|
466 | 514 | |
|
467 | 515 | zoneWidget->createGraph(variables, index); |
|
468 | 516 | } |
@@ -1,98 +1,104 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>TimeWidget</class> |
|
4 | 4 | <widget class="QWidget" name="TimeWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>716</width> |
|
10 | 10 | <height>48</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="sizePolicy"> |
|
14 | 14 | <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> |
|
15 | 15 | <horstretch>0</horstretch> |
|
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"> |
|
25 | 31 | <property name="sizePolicy"> |
|
26 | 32 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> |
|
27 | 33 | <horstretch>0</horstretch> |
|
28 | 34 | <verstretch>0</verstretch> |
|
29 | 35 | </sizepolicy> |
|
30 | 36 | </property> |
|
31 | 37 | <property name="text"> |
|
32 | 38 | <string>TStart :</string> |
|
33 | 39 | </property> |
|
34 | 40 | </widget> |
|
35 | 41 | </item> |
|
36 | 42 | <item> |
|
37 | 43 | <widget class="QDateTimeEdit" name="startDateTimeEdit"> |
|
38 | 44 | <property name="sizePolicy"> |
|
39 | 45 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
|
40 | 46 | <horstretch>0</horstretch> |
|
41 | 47 | <verstretch>0</verstretch> |
|
42 | 48 | </sizepolicy> |
|
43 | 49 | </property> |
|
44 | 50 | <property name="displayFormat"> |
|
45 | 51 | <string>dd/MM/yyyy HH:mm:ss:zzz</string> |
|
46 | 52 | </property> |
|
47 | 53 | <property name="calendarPopup"> |
|
48 | 54 | <bool>true</bool> |
|
49 | 55 | </property> |
|
50 | 56 | <property name="timeSpec"> |
|
51 | 57 | <enum>Qt::UTC</enum> |
|
52 | 58 | </property> |
|
53 | 59 | </widget> |
|
54 | 60 | </item> |
|
55 | 61 | <item> |
|
56 | 62 | <widget class="QLabel" name="label_2"> |
|
57 | 63 | <property name="sizePolicy"> |
|
58 | 64 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> |
|
59 | 65 | <horstretch>0</horstretch> |
|
60 | 66 | <verstretch>0</verstretch> |
|
61 | 67 | </sizepolicy> |
|
62 | 68 | </property> |
|
63 | 69 | <property name="text"> |
|
64 | 70 | <string>TEnd :</string> |
|
65 | 71 | </property> |
|
66 | 72 | </widget> |
|
67 | 73 | </item> |
|
68 | 74 | <item> |
|
69 | 75 | <widget class="QDateTimeEdit" name="endDateTimeEdit"> |
|
70 | 76 | <property name="sizePolicy"> |
|
71 | 77 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> |
|
72 | 78 | <horstretch>0</horstretch> |
|
73 | 79 | <verstretch>0</verstretch> |
|
74 | 80 | </sizepolicy> |
|
75 | 81 | </property> |
|
76 | 82 | <property name="displayFormat"> |
|
77 | 83 | <string>dd/MM/yyyy HH:mm:ss:zzz</string> |
|
78 | 84 | </property> |
|
79 | 85 | <property name="calendarPopup"> |
|
80 | 86 | <bool>true</bool> |
|
81 | 87 | </property> |
|
82 | 88 | <property name="timeSpec"> |
|
83 | 89 | <enum>Qt::UTC</enum> |
|
84 | 90 | </property> |
|
85 | 91 | </widget> |
|
86 | 92 | </item> |
|
87 | 93 | <item> |
|
88 | 94 | <widget class="QToolButton" name="applyToolButton"> |
|
89 | 95 | <property name="text"> |
|
90 | 96 | <string>...</string> |
|
91 | 97 | </property> |
|
92 | 98 | </widget> |
|
93 | 99 | </item> |
|
94 | 100 | </layout> |
|
95 | 101 | </widget> |
|
96 | 102 | <resources/> |
|
97 | 103 | <connections/> |
|
98 | 104 | </ui> |
@@ -1,40 +1,47 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>VariableInspectorWidget</class> |
|
4 | 4 | <widget class="QWidget" name="VariableInspectorWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>400</width> |
|
10 | 10 | <height>300</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
|
14 | 14 | <string>Variables</string> |
|
15 | 15 | </property> |
|
16 | 16 | <layout class="QGridLayout" name="gridLayout"> |
|
17 | 17 | <item row="0" column="0"> |
|
18 |
<widget class=" |
|
|
18 | <widget class="VariableInspectorTableView" name="tableView"> | |
|
19 | 19 | <property name="acceptDrops"> |
|
20 | 20 | <bool>true</bool> |
|
21 | 21 | </property> |
|
22 | 22 | <property name="dragEnabled"> |
|
23 | 23 | <bool>true</bool> |
|
24 | 24 | </property> |
|
25 | 25 | <property name="dragDropMode"> |
|
26 | 26 | <enum>QAbstractItemView::DragDrop</enum> |
|
27 | 27 | </property> |
|
28 | 28 | <property name="sortingEnabled"> |
|
29 | 29 | <bool>true</bool> |
|
30 | 30 | </property> |
|
31 | 31 | <attribute name="horizontalHeaderStretchLastSection"> |
|
32 | 32 | <bool>true</bool> |
|
33 | 33 | </attribute> |
|
34 | 34 | </widget> |
|
35 | 35 | </item> |
|
36 | 36 | </layout> |
|
37 | 37 | </widget> |
|
38 | <customwidgets> | |
|
39 | <customwidget> | |
|
40 | <class>VariableInspectorTableView</class> | |
|
41 | <extends>QTableView</extends> | |
|
42 | <header>Variable/VariableInspectorTableView.h</header> | |
|
43 | </customwidget> | |
|
44 | </customwidgets> | |
|
38 | 45 | <resources/> |
|
39 | 46 | <connections/> |
|
40 | 47 | </ui> |
@@ -1,84 +1,88 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>VisualizationTabWidget</class> |
|
4 | 4 | <widget class="QWidget" name="VisualizationTabWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>400</width> |
|
10 | 10 | <height>300</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
|
14 | 14 | <string>Form</string> |
|
15 | 15 | </property> |
|
16 | 16 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
17 | 17 | <property name="leftMargin"> |
|
18 | 18 | <number>0</number> |
|
19 | 19 | </property> |
|
20 | 20 | <property name="topMargin"> |
|
21 | 21 | <number>0</number> |
|
22 | 22 | </property> |
|
23 | 23 | <property name="rightMargin"> |
|
24 | 24 | <number>0</number> |
|
25 | 25 | </property> |
|
26 | 26 | <property name="bottomMargin"> |
|
27 | 27 | <number>0</number> |
|
28 | 28 | </property> |
|
29 | 29 | <item> |
|
30 | 30 | <widget class="QScrollArea" name="scrollArea"> |
|
31 | 31 | <property name="frameShape"> |
|
32 | 32 | <enum>QFrame::NoFrame</enum> |
|
33 | 33 | </property> |
|
34 | 34 | <property name="frameShadow"> |
|
35 | 35 | <enum>QFrame::Sunken</enum> |
|
36 | 36 | </property> |
|
37 | 37 | <property name="widgetResizable"> |
|
38 | 38 | <bool>true</bool> |
|
39 | 39 | </property> |
|
40 | 40 | <widget class="QWidget" name="scrollAreaWidgetContents"> |
|
41 | 41 | <property name="geometry"> |
|
42 | 42 | <rect> |
|
43 | 43 | <x>0</x> |
|
44 | 44 | <y>0</y> |
|
45 | 45 | <width>400</width> |
|
46 | 46 | <height>300</height> |
|
47 | 47 | </rect> |
|
48 | 48 | </property> |
|
49 | 49 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
|
50 | 50 | <property name="spacing"> |
|
51 | 51 | <number>3</number> |
|
52 | 52 | </property> |
|
53 | 53 | <property name="leftMargin"> |
|
54 | 54 | <number>0</number> |
|
55 | 55 | </property> |
|
56 | 56 | <property name="topMargin"> |
|
57 | 57 | <number>0</number> |
|
58 | 58 | </property> |
|
59 | 59 | <property name="rightMargin"> |
|
60 | 60 | <number>0</number> |
|
61 | 61 | </property> |
|
62 | 62 | <property name="bottomMargin"> |
|
63 | 63 | <number>0</number> |
|
64 | 64 | </property> |
|
65 | 65 | <item> |
|
66 |
<widget class="VisualizationDragDropContainer" name="dragDropContainer" |
|
|
66 | <widget class="VisualizationDragDropContainer" name="dragDropContainer"> | |
|
67 | <property name="lineWidth"> | |
|
68 | <number>0</number> | |
|
69 | </property> | |
|
70 | </widget> | |
|
67 | 71 | </item> |
|
68 | 72 | </layout> |
|
69 | 73 | </widget> |
|
70 | 74 | </widget> |
|
71 | 75 | </item> |
|
72 | 76 | </layout> |
|
73 | 77 | </widget> |
|
74 | 78 | <customwidgets> |
|
75 | 79 | <customwidget> |
|
76 | 80 | <class>VisualizationDragDropContainer</class> |
|
77 |
<extends>Q |
|
|
81 | <extends>QFrame</extends> | |
|
78 | 82 | <header>Visualization/VisualizationDragDropContainer.h</header> |
|
79 | 83 | <container>1</container> |
|
80 | 84 | </customwidget> |
|
81 | 85 | </customwidgets> |
|
82 | 86 | <resources/> |
|
83 | 87 | <connections/> |
|
84 | 88 | </ui> |
@@ -1,128 +1,125 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>VisualizationZoneWidget</class> |
|
4 | 4 | <widget class="QWidget" name="VisualizationZoneWidget"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 | 9 | <width>400</width> |
|
10 | 10 | <height>300</height> |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
|
14 | 14 | <string>Form</string> |
|
15 | 15 | </property> |
|
16 | 16 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
|
17 | 17 | <property name="spacing"> |
|
18 | 18 | <number>0</number> |
|
19 | 19 | </property> |
|
20 | 20 | <property name="leftMargin"> |
|
21 | 21 | <number>0</number> |
|
22 | 22 | </property> |
|
23 | 23 | <property name="topMargin"> |
|
24 | 24 | <number>0</number> |
|
25 | 25 | </property> |
|
26 | 26 | <property name="rightMargin"> |
|
27 | 27 | <number>0</number> |
|
28 | 28 | </property> |
|
29 | 29 | <property name="bottomMargin"> |
|
30 | 30 | <number>0</number> |
|
31 | 31 | </property> |
|
32 | 32 | <item> |
|
33 | 33 | <widget class="QWidget" name="infobar" native="true"> |
|
34 | 34 | <property name="sizePolicy"> |
|
35 | 35 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> |
|
36 | 36 | <horstretch>0</horstretch> |
|
37 | 37 | <verstretch>0</verstretch> |
|
38 | 38 | </sizepolicy> |
|
39 | 39 | </property> |
|
40 | 40 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
41 | 41 | <property name="spacing"> |
|
42 | 42 | <number>0</number> |
|
43 | 43 | </property> |
|
44 | 44 | <property name="leftMargin"> |
|
45 | 45 | <number>0</number> |
|
46 | 46 | </property> |
|
47 | 47 | <property name="topMargin"> |
|
48 | 48 | <number>0</number> |
|
49 | 49 | </property> |
|
50 | 50 | <property name="rightMargin"> |
|
51 | 51 | <number>0</number> |
|
52 | 52 | </property> |
|
53 | 53 | <property name="bottomMargin"> |
|
54 | 54 | <number>0</number> |
|
55 | 55 | </property> |
|
56 | 56 | <item> |
|
57 | 57 | <widget class="QLabel" name="zoneNameLabel"> |
|
58 | 58 | <property name="styleSheet"> |
|
59 | 59 | <string notr="true">color: rgb(127, 127, 127); |
|
60 | 60 | </string> |
|
61 | 61 | </property> |
|
62 | 62 | <property name="text"> |
|
63 | 63 | <string>TextLabel</string> |
|
64 | 64 | </property> |
|
65 | 65 | </widget> |
|
66 | 66 | </item> |
|
67 | 67 | <item> |
|
68 | 68 | <widget class="QToolButton" name="closeButton"> |
|
69 | 69 | <property name="styleSheet"> |
|
70 | 70 | <string notr="true">background-color: transparent;</string> |
|
71 | 71 | </property> |
|
72 | 72 | <property name="text"> |
|
73 | 73 | <string>Close</string> |
|
74 | 74 | </property> |
|
75 | 75 | </widget> |
|
76 | 76 | </item> |
|
77 | 77 | </layout> |
|
78 | 78 | </widget> |
|
79 | 79 | </item> |
|
80 | 80 | <item> |
|
81 |
<widget class=" |
|
|
81 | <widget class="VisualizationDragDropContainer" name="dragDropContainer"> | |
|
82 | 82 | <property name="sizePolicy"> |
|
83 | 83 | <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> |
|
84 | 84 | <horstretch>0</horstretch> |
|
85 | 85 | <verstretch>0</verstretch> |
|
86 | 86 | </sizepolicy> |
|
87 | 87 | </property> |
|
88 | 88 | <property name="frameShape"> |
|
89 | 89 | <enum>QFrame::Box</enum> |
|
90 | 90 | </property> |
|
91 | 91 | <property name="frameShadow"> |
|
92 | 92 | <enum>QFrame::Raised</enum> |
|
93 | 93 | </property> |
|
94 | 94 | <property name="lineWidth"> |
|
95 | 95 | <number>1</number> |
|
96 | 96 | </property> |
|
97 | 97 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
98 | 98 | <property name="leftMargin"> |
|
99 | 99 | <number>0</number> |
|
100 | 100 | </property> |
|
101 | 101 | <property name="topMargin"> |
|
102 | 102 | <number>0</number> |
|
103 | 103 | </property> |
|
104 | 104 | <property name="rightMargin"> |
|
105 | 105 | <number>0</number> |
|
106 | 106 | </property> |
|
107 | 107 | <property name="bottomMargin"> |
|
108 | 108 | <number>0</number> |
|
109 | 109 | </property> |
|
110 | <item> | |
|
111 | <widget class="VisualizationDragDropContainer" name="dragDropContainer" native="true"/> | |
|
112 | </item> | |
|
113 | 110 | </layout> |
|
114 | 111 | </widget> |
|
115 | 112 | </item> |
|
116 | 113 | </layout> |
|
117 | 114 | </widget> |
|
118 | 115 | <customwidgets> |
|
119 | 116 | <customwidget> |
|
120 | 117 | <class>VisualizationDragDropContainer</class> |
|
121 |
<extends>Q |
|
|
118 | <extends>QFrame</extends> | |
|
122 | 119 | <header>Visualization/VisualizationDragDropContainer.h</header> |
|
123 | 120 | <container>1</container> |
|
124 | 121 | </customwidget> |
|
125 | 122 | </customwidgets> |
|
126 | 123 | <resources/> |
|
127 | 124 | <connections/> |
|
128 | 125 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now