##// END OF EJS Templates
New helper class for the drag&drop
trabillard -
r840:deba06e71141
parent child
Show More
@@ -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 #ifndef SCIQLOP_SQPAPPLICATION_H
1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5
5
6 #include <QApplication>
6 #include <QApplication>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
12
12
13 #if defined(sqpApp)
13 #if defined(sqpApp)
14 #undef sqpApp
14 #undef sqpApp
15 #endif
15 #endif
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17
17
18 class DataSourceController;
18 class DataSourceController;
19 class NetworkController;
19 class NetworkController;
20 class TimeController;
20 class TimeController;
21 class VariableController;
21 class VariableController;
22 class VisualizationController;
22 class VisualizationController;
23 class DragDropHelper;
23
24
24 /**
25 /**
25 * @brief The SqpApplication class aims to make the link between SciQlop
26 * @brief The SqpApplication class aims to make the link between SciQlop
26 * and its plugins. This is the intermediate class that SciQlop has to use
27 * and its plugins. This is the intermediate class that SciQlop has to use
27 * in the way to connect a data source. Please first use load method to initialize
28 * in the way to connect a data source. Please first use load method to initialize
28 * a plugin specified by its metadata name (JSON plugin source) then others specifics
29 * a plugin specified by its metadata name (JSON plugin source) then others specifics
29 * method will be able to access it.
30 * method will be able to access it.
30 * You can load a data source driver plugin then create a data source.
31 * You can load a data source driver plugin then create a data source.
31 */
32 */
32
33
33 class SqpApplication : public QApplication {
34 class SqpApplication : public QApplication {
34 Q_OBJECT
35 Q_OBJECT
35 public:
36 public:
36 explicit SqpApplication(int &argc, char **argv);
37 explicit SqpApplication(int &argc, char **argv);
37 virtual ~SqpApplication();
38 virtual ~SqpApplication();
38 void initialize();
39 void initialize();
39
40
40 /// Accessors for the differents sciqlop controllers
41 /// Accessors for the differents sciqlop controllers
41 DataSourceController &dataSourceController() noexcept;
42 DataSourceController &dataSourceController() noexcept;
42 NetworkController &networkController() noexcept;
43 NetworkController &networkController() noexcept;
43 TimeController &timeController() noexcept;
44 TimeController &timeController() noexcept;
44 VariableController &variableController() noexcept;
45 VariableController &variableController() noexcept;
45 VisualizationController &visualizationController() noexcept;
46 VisualizationController &visualizationController() noexcept;
46
47
48 /// Accessors for the differents sciqlop helpers
49 DragDropHelper &dragDropHelper() noexcept;
50
47 private:
51 private:
48 class SqpApplicationPrivate;
52 class SqpApplicationPrivate;
49 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
53 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
50 };
54 };
51
55
52 #endif // SCIQLOP_SQPAPPLICATION_H
56 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,150 +1,159
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <Network/NetworkController.h>
5 #include <Network/NetworkController.h>
6 #include <QThread>
6 #include <QThread>
7 #include <Time/TimeController.h>
7 #include <Time/TimeController.h>
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9 #include <Variable/VariableController.h>
9 #include <Variable/VariableController.h>
10 #include <Visualization/VisualizationController.h>
10 #include <Visualization/VisualizationController.h>
11 #include <DragDropHelper.h>
11
12
12 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
13 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
13
14
14 class SqpApplication::SqpApplicationPrivate {
15 class SqpApplication::SqpApplicationPrivate {
15 public:
16 public:
16 SqpApplicationPrivate()
17 SqpApplicationPrivate()
17 : m_DataSourceController{std::make_unique<DataSourceController>()},
18 : m_DataSourceController{std::make_unique<DataSourceController>()},
18 m_NetworkController{std::make_unique<NetworkController>()},
19 m_NetworkController{std::make_unique<NetworkController>()},
19 m_TimeController{std::make_unique<TimeController>()},
20 m_TimeController{std::make_unique<TimeController>()},
20 m_VariableController{std::make_unique<VariableController>()},
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 // Connections between controllers //
26 // Connections between controllers //
25 // /////////////////////////////// //
27 // /////////////////////////////// //
26
28
27 // VariableController <-> DataSourceController
29 // VariableController <-> DataSourceController
28 connect(m_DataSourceController.get(),
30 connect(m_DataSourceController.get(),
29 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
31 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
30 std::shared_ptr<IDataProvider>)),
32 std::shared_ptr<IDataProvider>)),
31 m_VariableController.get(),
33 m_VariableController.get(),
32 SLOT(createVariable(const QString &, const QVariantHash &,
34 SLOT(createVariable(const QString &, const QVariantHash &,
33 std::shared_ptr<IDataProvider>)));
35 std::shared_ptr<IDataProvider>)));
34
36
35 // VariableController <-> VisualizationController
37 // VariableController <-> VisualizationController
36 connect(m_VariableController.get(),
38 connect(m_VariableController.get(),
37 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
39 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
38 m_VisualizationController.get(),
40 m_VisualizationController.get(),
39 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
41 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
40
42
41 connect(m_VariableController.get(),
43 connect(m_VariableController.get(),
42 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)),
44 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)),
43 m_VisualizationController.get(),
45 m_VisualizationController.get(),
44 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
46 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
45
47
46
48
47 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
49 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
48 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
50 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
49 m_NetworkController->moveToThread(&m_NetworkControllerThread);
51 m_NetworkController->moveToThread(&m_NetworkControllerThread);
50 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
52 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
51 m_VariableController->moveToThread(&m_VariableControllerThread);
53 m_VariableController->moveToThread(&m_VariableControllerThread);
52 m_VariableControllerThread.setObjectName("VariableControllerThread");
54 m_VariableControllerThread.setObjectName("VariableControllerThread");
53 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
55 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
54 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
56 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
55
57
56
58
57 // Additionnal init
59 // Additionnal init
58 m_VariableController->setTimeController(m_TimeController.get());
60 m_VariableController->setTimeController(m_TimeController.get());
59 }
61 }
60
62
61 virtual ~SqpApplicationPrivate()
63 virtual ~SqpApplicationPrivate()
62 {
64 {
63 m_DataSourceControllerThread.quit();
65 m_DataSourceControllerThread.quit();
64 m_DataSourceControllerThread.wait();
66 m_DataSourceControllerThread.wait();
65
67
66 m_NetworkControllerThread.quit();
68 m_NetworkControllerThread.quit();
67 m_NetworkControllerThread.wait();
69 m_NetworkControllerThread.wait();
68
70
69 m_VariableControllerThread.quit();
71 m_VariableControllerThread.quit();
70 m_VariableControllerThread.wait();
72 m_VariableControllerThread.wait();
71
73
72 m_VisualizationControllerThread.quit();
74 m_VisualizationControllerThread.quit();
73 m_VisualizationControllerThread.wait();
75 m_VisualizationControllerThread.wait();
74 }
76 }
75
77
76 std::unique_ptr<DataSourceController> m_DataSourceController;
78 std::unique_ptr<DataSourceController> m_DataSourceController;
77 std::unique_ptr<VariableController> m_VariableController;
79 std::unique_ptr<VariableController> m_VariableController;
78 std::unique_ptr<TimeController> m_TimeController;
80 std::unique_ptr<TimeController> m_TimeController;
79 std::unique_ptr<NetworkController> m_NetworkController;
81 std::unique_ptr<NetworkController> m_NetworkController;
80 std::unique_ptr<VisualizationController> m_VisualizationController;
82 std::unique_ptr<VisualizationController> m_VisualizationController;
81 QThread m_DataSourceControllerThread;
83 QThread m_DataSourceControllerThread;
82 QThread m_NetworkControllerThread;
84 QThread m_NetworkControllerThread;
83 QThread m_VariableControllerThread;
85 QThread m_VariableControllerThread;
84 QThread m_VisualizationControllerThread;
86 QThread m_VisualizationControllerThread;
87
88 std::unique_ptr<DragDropHelper> m_DragDropHelper;
85 };
89 };
86
90
87
91
88 SqpApplication::SqpApplication(int &argc, char **argv)
92 SqpApplication::SqpApplication(int &argc, char **argv)
89 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
93 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
90 {
94 {
91 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
95 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
92
96
93 connect(&impl->m_DataSourceControllerThread, &QThread::started,
97 connect(&impl->m_DataSourceControllerThread, &QThread::started,
94 impl->m_DataSourceController.get(), &DataSourceController::initialize);
98 impl->m_DataSourceController.get(), &DataSourceController::initialize);
95 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
99 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
96 impl->m_DataSourceController.get(), &DataSourceController::finalize);
100 impl->m_DataSourceController.get(), &DataSourceController::finalize);
97
101
98 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
102 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
99 &NetworkController::initialize);
103 &NetworkController::initialize);
100 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
104 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
101 &NetworkController::finalize);
105 &NetworkController::finalize);
102
106
103 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
107 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
104 &VariableController::initialize);
108 &VariableController::initialize);
105 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
109 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
106 &VariableController::finalize);
110 &VariableController::finalize);
107
111
108 connect(&impl->m_VisualizationControllerThread, &QThread::started,
112 connect(&impl->m_VisualizationControllerThread, &QThread::started,
109 impl->m_VisualizationController.get(), &VisualizationController::initialize);
113 impl->m_VisualizationController.get(), &VisualizationController::initialize);
110 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
114 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
111 impl->m_VisualizationController.get(), &VisualizationController::finalize);
115 impl->m_VisualizationController.get(), &VisualizationController::finalize);
112
116
113 impl->m_DataSourceControllerThread.start();
117 impl->m_DataSourceControllerThread.start();
114 impl->m_NetworkControllerThread.start();
118 impl->m_NetworkControllerThread.start();
115 impl->m_VariableControllerThread.start();
119 impl->m_VariableControllerThread.start();
116 impl->m_VisualizationControllerThread.start();
120 impl->m_VisualizationControllerThread.start();
117 }
121 }
118
122
119 SqpApplication::~SqpApplication()
123 SqpApplication::~SqpApplication()
120 {
124 {
121 }
125 }
122
126
123 void SqpApplication::initialize()
127 void SqpApplication::initialize()
124 {
128 {
125 }
129 }
126
130
127 DataSourceController &SqpApplication::dataSourceController() noexcept
131 DataSourceController &SqpApplication::dataSourceController() noexcept
128 {
132 {
129 return *impl->m_DataSourceController;
133 return *impl->m_DataSourceController;
130 }
134 }
131
135
132 NetworkController &SqpApplication::networkController() noexcept
136 NetworkController &SqpApplication::networkController() noexcept
133 {
137 {
134 return *impl->m_NetworkController;
138 return *impl->m_NetworkController;
135 }
139 }
136
140
137 TimeController &SqpApplication::timeController() noexcept
141 TimeController &SqpApplication::timeController() noexcept
138 {
142 {
139 return *impl->m_TimeController;
143 return *impl->m_TimeController;
140 }
144 }
141
145
142 VariableController &SqpApplication::variableController() noexcept
146 VariableController &SqpApplication::variableController() noexcept
143 {
147 {
144 return *impl->m_VariableController;
148 return *impl->m_VariableController;
145 }
149 }
146
150
147 VisualizationController &SqpApplication::visualizationController() noexcept
151 VisualizationController &SqpApplication::visualizationController() noexcept
148 {
152 {
149 return *impl->m_VisualizationController;
153 return *impl->m_VisualizationController;
150 }
154 }
155
156 DragDropHelper &SqpApplication::dragDropHelper() noexcept
157 {
158 return *impl->m_DragDropHelper;
159 }
General Comments 6
Approved

Status change > Approved

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