Auto status change to "Under Review"
@@ -0,0 +1,42 | |||
|
1 | #ifndef DRAGDROPHELPER_H | |
|
2 | #define DRAGDROPHELPER_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QWidget> | |
|
6 | ||
|
7 | class QVBoxLayout; | |
|
8 | class QScrollArea; | |
|
9 | class VisualizationDragWidget; | |
|
10 | class QMimeData; | |
|
11 | ||
|
12 | /** | |
|
13 | * @brief Helper class for drag&drop operations. | |
|
14 | */ | |
|
15 | class DragDropHelper | |
|
16 | { | |
|
17 | public: | |
|
18 | DragDropHelper(); | |
|
19 | ~DragDropHelper(); | |
|
20 | ||
|
21 | static const QString MIME_TYPE_GRAPH; | |
|
22 | static const QString MIME_TYPE_ZONE; | |
|
23 | ||
|
24 | void setCurrentDragWidget(VisualizationDragWidget* dragWidget); | |
|
25 | VisualizationDragWidget* getCurrentDragWidget() const; | |
|
26 | ||
|
27 | QWidget &placeHolder() const; | |
|
28 | void insertPlaceHolder(QVBoxLayout* layout, int index); | |
|
29 | void removePlaceHolder(); | |
|
30 | bool isPlaceHolderSet() const; | |
|
31 | ||
|
32 | void addDragDropScrollArea(QScrollArea* scrollArea); | |
|
33 | void removeDragDropScrollArea(QScrollArea* scrollArea); | |
|
34 | ||
|
35 | QUrl imageTemporaryUrl(const QImage& image) const; | |
|
36 | ||
|
37 | private: | |
|
38 | class DragDropHelperPrivate; | |
|
39 | spimpl::unique_impl_ptr<DragDropHelperPrivate> impl; | |
|
40 | }; | |
|
41 | ||
|
42 | #endif // DRAGDROPHELPER_H |
@@ -0,0 +1,105 | |||
|
1 | #include "DragDropHelper.h" | |
|
2 | #include "Visualization/VisualizationDragWidget.h" | |
|
3 | #include "SqpApplication.h" | |
|
4 | ||
|
5 | #include <QDragMoveEvent> | |
|
6 | #include <QDragEnterEvent> | |
|
7 | #include <QScrollBar> | |
|
8 | #include <QScrollArea> | |
|
9 | #include <QVBoxLayout> | |
|
10 | #include <QTimer> | |
|
11 | #include <QDir> | |
|
12 | ||
|
13 | const QString DragDropHelper::MIME_TYPE_GRAPH = "scqlop/graph"; | |
|
14 | const QString DragDropHelper::MIME_TYPE_ZONE = "scqlop/zone"; | |
|
15 | ||
|
16 | ||
|
17 | struct DragDropHelper::DragDropHelperPrivate { | |
|
18 | ||
|
19 | VisualizationDragWidget* m_currentDragWidget = nullptr; | |
|
20 | std::unique_ptr<QWidget> m_placeHolder = nullptr; | |
|
21 | std::unique_ptr<DragDropScroller> m_dragDropScroller = nullptr; | |
|
22 | QString m_imageTempUrl; //Temporary file for image url generated by the drag & drop. Not using QTemporaryFile to have a name which is not generated. | |
|
23 | ||
|
24 | explicit DragDropHelperPrivate() | |
|
25 | : m_placeHolder{std::make_unique<QWidget>()}, | |
|
26 | m_dragDropScroller{std::make_unique<DragDropScroller>()} | |
|
27 | { | |
|
28 | m_placeHolder->setStyleSheet("background-color: #BBD5EE; border:2px solid #2A7FD4"); | |
|
29 | sqpApp->installEventFilter(m_dragDropScroller.get()); | |
|
30 | ||
|
31 | ||
|
32 | m_imageTempUrl = QDir::temp().absoluteFilePath("Scqlop_graph.png"); | |
|
33 | } | |
|
34 | ||
|
35 | void preparePlaceHolder() const | |
|
36 | { | |
|
37 | if (m_currentDragWidget) | |
|
38 | { | |
|
39 | m_placeHolder->setMinimumSize(m_currentDragWidget->size()); | |
|
40 | m_placeHolder->setSizePolicy(m_currentDragWidget->sizePolicy()); | |
|
41 | } | |
|
42 | else | |
|
43 | { | |
|
44 | m_placeHolder->setMinimumSize(200, 200); | |
|
45 | } | |
|
46 | } | |
|
47 | }; | |
|
48 | ||
|
49 | ||
|
50 | DragDropHelper::DragDropHelper() : | |
|
51 | impl{spimpl::make_unique_impl<DragDropHelperPrivate>()} | |
|
52 | { | |
|
53 | } | |
|
54 | ||
|
55 | DragDropHelper::~DragDropHelper() | |
|
56 | { | |
|
57 | QFile::remove(impl->m_imageTempUrl); | |
|
58 | } | |
|
59 | ||
|
60 | void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget) | |
|
61 | { | |
|
62 | impl->m_currentDragWidget = dragWidget; | |
|
63 | } | |
|
64 | ||
|
65 | VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const | |
|
66 | { | |
|
67 | return impl->m_currentDragWidget; | |
|
68 | } | |
|
69 | ||
|
70 | ||
|
71 | QWidget& DragDropHelper::placeHolder() const | |
|
72 | { | |
|
73 | return *impl->m_placeHolder; | |
|
74 | } | |
|
75 | ||
|
76 | void DragDropHelper::insertPlaceHolder(QVBoxLayout *layout, int index) | |
|
77 | { | |
|
78 | removePlaceHolder(); | |
|
79 | impl->preparePlaceHolder(); | |
|
80 | layout->insertWidget(index, impl->m_placeHolder.get()); | |
|
81 | impl->m_placeHolder->show(); | |
|
82 | } | |
|
83 | ||
|
84 | void DragDropHelper::removePlaceHolder() | |
|
85 | { | |
|
86 | auto parentWidget = impl->m_placeHolder->parentWidget(); | |
|
87 | if (parentWidget) | |
|
88 | { | |
|
89 | parentWidget->layout()->removeWidget(impl->m_placeHolder.get()); | |
|
90 | impl->m_placeHolder->setParent(nullptr); | |
|
91 | impl->m_placeHolder->hide(); | |
|
92 | } | |
|
93 | } | |
|
94 | ||
|
95 | bool DragDropHelper::isPlaceHolderSet() const | |
|
96 | { | |
|
97 | return impl->m_placeHolder->parentWidget(); | |
|
98 | } | |
|
99 | ||
|
100 | QUrl DragDropHelper::imageTemporaryUrl(const QImage& image) const | |
|
101 | { | |
|
102 | image.save(impl->m_imageTempUrl); | |
|
103 | return QUrl::fromLocalFile(impl->m_imageTempUrl); | |
|
104 | } | |
|
105 |
@@ -1,52 +1,56 | |||
|
1 | 1 | #ifndef SCIQLOP_SQPAPPLICATION_H |
|
2 | 2 | #define SCIQLOP_SQPAPPLICATION_H |
|
3 | 3 | |
|
4 | 4 | #include "SqpApplication.h" |
|
5 | 5 | |
|
6 | 6 | #include <QApplication> |
|
7 | 7 | #include <QLoggingCategory> |
|
8 | 8 | |
|
9 | 9 | #include <Common/spimpl.h> |
|
10 | 10 | |
|
11 | 11 | Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication) |
|
12 | 12 | |
|
13 | 13 | #if defined(sqpApp) |
|
14 | 14 | #undef sqpApp |
|
15 | 15 | #endif |
|
16 | 16 | #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance())) |
|
17 | 17 | |
|
18 | 18 | class DataSourceController; |
|
19 | 19 | class NetworkController; |
|
20 | 20 | class TimeController; |
|
21 | 21 | class VariableController; |
|
22 | 22 | class VisualizationController; |
|
23 | class DragDropHelper; | |
|
23 | 24 | |
|
24 | 25 | /** |
|
25 | 26 | * @brief The SqpApplication class aims to make the link between SciQlop |
|
26 | 27 | * and its plugins. This is the intermediate class that SciQlop has to use |
|
27 | 28 | * in the way to connect a data source. Please first use load method to initialize |
|
28 | 29 | * a plugin specified by its metadata name (JSON plugin source) then others specifics |
|
29 | 30 | * method will be able to access it. |
|
30 | 31 | * You can load a data source driver plugin then create a data source. |
|
31 | 32 | */ |
|
32 | 33 | |
|
33 | 34 | class SqpApplication : public QApplication { |
|
34 | 35 | Q_OBJECT |
|
35 | 36 | public: |
|
36 | 37 | explicit SqpApplication(int &argc, char **argv); |
|
37 | 38 | virtual ~SqpApplication(); |
|
38 | 39 | void initialize(); |
|
39 | 40 | |
|
40 | 41 | /// Accessors for the differents sciqlop controllers |
|
41 | 42 | DataSourceController &dataSourceController() noexcept; |
|
42 | 43 | NetworkController &networkController() noexcept; |
|
43 | 44 | TimeController &timeController() noexcept; |
|
44 | 45 | VariableController &variableController() noexcept; |
|
45 | 46 | VisualizationController &visualizationController() noexcept; |
|
46 | 47 | |
|
48 | /// Accessors for the differents sciqlop helpers | |
|
49 | DragDropHelper &dragDropHelper() noexcept; | |
|
50 | ||
|
47 | 51 | private: |
|
48 | 52 | class SqpApplicationPrivate; |
|
49 | 53 | spimpl::unique_impl_ptr<SqpApplicationPrivate> impl; |
|
50 | 54 | }; |
|
51 | 55 | |
|
52 | 56 | #endif // SCIQLOP_SQPAPPLICATION_H |
@@ -1,150 +1,159 | |||
|
1 | 1 | #include "SqpApplication.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/IDataProvider.h> |
|
4 | 4 | #include <DataSource/DataSourceController.h> |
|
5 | 5 | #include <Network/NetworkController.h> |
|
6 | 6 | #include <QThread> |
|
7 | 7 | #include <Time/TimeController.h> |
|
8 | 8 | #include <Variable/Variable.h> |
|
9 | 9 | #include <Variable/VariableController.h> |
|
10 | 10 | #include <Visualization/VisualizationController.h> |
|
11 | #include <DragDropHelper.h> | |
|
11 | 12 | |
|
12 | 13 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
13 | 14 | |
|
14 | 15 | class SqpApplication::SqpApplicationPrivate { |
|
15 | 16 | public: |
|
16 | 17 | SqpApplicationPrivate() |
|
17 | 18 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
18 | 19 | m_NetworkController{std::make_unique<NetworkController>()}, |
|
19 | 20 | m_TimeController{std::make_unique<TimeController>()}, |
|
20 | 21 | m_VariableController{std::make_unique<VariableController>()}, |
|
21 | m_VisualizationController{std::make_unique<VisualizationController>()} | |
|
22 | m_VisualizationController{std::make_unique<VisualizationController>()}, | |
|
23 | m_DragDropHelper{std::make_unique<DragDropHelper>()} | |
|
22 | 24 | { |
|
23 | 25 | // /////////////////////////////// // |
|
24 | 26 | // Connections between controllers // |
|
25 | 27 | // /////////////////////////////// // |
|
26 | 28 | |
|
27 | 29 | // VariableController <-> DataSourceController |
|
28 | 30 | connect(m_DataSourceController.get(), |
|
29 | 31 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, |
|
30 | 32 | std::shared_ptr<IDataProvider>)), |
|
31 | 33 | m_VariableController.get(), |
|
32 | 34 | SLOT(createVariable(const QString &, const QVariantHash &, |
|
33 | 35 | std::shared_ptr<IDataProvider>))); |
|
34 | 36 | |
|
35 | 37 | // VariableController <-> VisualizationController |
|
36 | 38 | connect(m_VariableController.get(), |
|
37 | 39 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
38 | 40 | m_VisualizationController.get(), |
|
39 | 41 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
40 | 42 | |
|
41 | 43 | connect(m_VariableController.get(), |
|
42 | 44 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), |
|
43 | 45 | m_VisualizationController.get(), |
|
44 | 46 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &))); |
|
45 | 47 | |
|
46 | 48 | |
|
47 | 49 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
48 | 50 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); |
|
49 | 51 | m_NetworkController->moveToThread(&m_NetworkControllerThread); |
|
50 | 52 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); |
|
51 | 53 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
52 | 54 | m_VariableControllerThread.setObjectName("VariableControllerThread"); |
|
53 | 55 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
54 | 56 | m_VisualizationControllerThread.setObjectName("VsualizationControllerThread"); |
|
55 | 57 | |
|
56 | 58 | |
|
57 | 59 | // Additionnal init |
|
58 | 60 | m_VariableController->setTimeController(m_TimeController.get()); |
|
59 | 61 | } |
|
60 | 62 | |
|
61 | 63 | virtual ~SqpApplicationPrivate() |
|
62 | 64 | { |
|
63 | 65 | m_DataSourceControllerThread.quit(); |
|
64 | 66 | m_DataSourceControllerThread.wait(); |
|
65 | 67 | |
|
66 | 68 | m_NetworkControllerThread.quit(); |
|
67 | 69 | m_NetworkControllerThread.wait(); |
|
68 | 70 | |
|
69 | 71 | m_VariableControllerThread.quit(); |
|
70 | 72 | m_VariableControllerThread.wait(); |
|
71 | 73 | |
|
72 | 74 | m_VisualizationControllerThread.quit(); |
|
73 | 75 | m_VisualizationControllerThread.wait(); |
|
74 | 76 | } |
|
75 | 77 | |
|
76 | 78 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
77 | 79 | std::unique_ptr<VariableController> m_VariableController; |
|
78 | 80 | std::unique_ptr<TimeController> m_TimeController; |
|
79 | 81 | std::unique_ptr<NetworkController> m_NetworkController; |
|
80 | 82 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
81 | 83 | QThread m_DataSourceControllerThread; |
|
82 | 84 | QThread m_NetworkControllerThread; |
|
83 | 85 | QThread m_VariableControllerThread; |
|
84 | 86 | QThread m_VisualizationControllerThread; |
|
87 | ||
|
88 | std::unique_ptr<DragDropHelper> m_DragDropHelper; | |
|
85 | 89 | }; |
|
86 | 90 | |
|
87 | 91 | |
|
88 | 92 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
89 | 93 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
90 | 94 | { |
|
91 | 95 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); |
|
92 | 96 | |
|
93 | 97 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
94 | 98 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
95 | 99 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
96 | 100 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
97 | 101 | |
|
98 | 102 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), |
|
99 | 103 | &NetworkController::initialize); |
|
100 | 104 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), |
|
101 | 105 | &NetworkController::finalize); |
|
102 | 106 | |
|
103 | 107 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
104 | 108 | &VariableController::initialize); |
|
105 | 109 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
106 | 110 | &VariableController::finalize); |
|
107 | 111 | |
|
108 | 112 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
109 | 113 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
110 | 114 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
111 | 115 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
112 | 116 | |
|
113 | 117 | impl->m_DataSourceControllerThread.start(); |
|
114 | 118 | impl->m_NetworkControllerThread.start(); |
|
115 | 119 | impl->m_VariableControllerThread.start(); |
|
116 | 120 | impl->m_VisualizationControllerThread.start(); |
|
117 | 121 | } |
|
118 | 122 | |
|
119 | 123 | SqpApplication::~SqpApplication() |
|
120 | 124 | { |
|
121 | 125 | } |
|
122 | 126 | |
|
123 | 127 | void SqpApplication::initialize() |
|
124 | 128 | { |
|
125 | 129 | } |
|
126 | 130 | |
|
127 | 131 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
128 | 132 | { |
|
129 | 133 | return *impl->m_DataSourceController; |
|
130 | 134 | } |
|
131 | 135 | |
|
132 | 136 | NetworkController &SqpApplication::networkController() noexcept |
|
133 | 137 | { |
|
134 | 138 | return *impl->m_NetworkController; |
|
135 | 139 | } |
|
136 | 140 | |
|
137 | 141 | TimeController &SqpApplication::timeController() noexcept |
|
138 | 142 | { |
|
139 | 143 | return *impl->m_TimeController; |
|
140 | 144 | } |
|
141 | 145 | |
|
142 | 146 | VariableController &SqpApplication::variableController() noexcept |
|
143 | 147 | { |
|
144 | 148 | return *impl->m_VariableController; |
|
145 | 149 | } |
|
146 | 150 | |
|
147 | 151 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
148 | 152 | { |
|
149 | 153 | return *impl->m_VisualizationController; |
|
150 | 154 | } |
|
155 | ||
|
156 | DragDropHelper &SqpApplication::dragDropHelper() noexcept | |
|
157 | { | |
|
158 | return *impl->m_DragDropHelper; | |
|
159 | } |
General Comments 6
Pull request updated. Auto status change to "Under Review"
Changed commits: * 1 added * 0 removed Changed files: * M gui/include/Visualization/VisualizationDragDropContainer.h * M gui/include/Visualization/VisualizationDragWidget.h * M gui/src/Visualization/VisualizationDragDropContainer.cpp * M gui/src/Visualization/VisualizationGraphWidget.cpp * M gui/src/Visualization/VisualizationZoneWidget.cpp
Status change > Approved
You need to be logged in to leave comments.
Login now