@@ -68,6 +68,8 public: | |||
|
68 | 68 | */ |
|
69 | 69 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; |
|
70 | 70 | |
|
71 | QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const; | |
|
72 | QList<std::shared_ptr<Variable> > variablesForMimeData(const QByteArray &mimeData) const; | |
|
71 | 73 | |
|
72 | 74 | static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange); |
|
73 | 75 | signals: |
@@ -18,6 +18,7 enum VariableRoles { ProgressRole = Qt::UserRole }; | |||
|
18 | 18 | |
|
19 | 19 | class IDataSeries; |
|
20 | 20 | class Variable; |
|
21 | class VariableController; | |
|
21 | 22 | |
|
22 | 23 | /** |
|
23 | 24 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
@@ -25,7 +26,7 class Variable; | |||
|
25 | 26 | class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel { |
|
26 | 27 | Q_OBJECT |
|
27 | 28 | public: |
|
28 |
explicit VariableModel( |
|
|
29 | explicit VariableModel(VariableController *parent = nullptr); | |
|
29 | 30 | |
|
30 | 31 | /** |
|
31 | 32 | * Adds an existing variable in the model. |
@@ -73,7 +74,20 public: | |||
|
73 | 74 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
74 | 75 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
75 | 76 | int role = Qt::DisplayRole) const override; |
|
76 | ||
|
77 | virtual Qt::ItemFlags flags(const QModelIndex &index) const override; | |
|
78 | ||
|
79 | // ///////////////// // | |
|
80 | // Drag&Drop methods // | |
|
81 | // ///////////////// // | |
|
82 | ||
|
83 | virtual Qt::DropActions supportedDropActions() const override; | |
|
84 | virtual Qt::DropActions supportedDragActions() const override; | |
|
85 | virtual QStringList mimeTypes() const override; | |
|
86 | virtual QMimeData *mimeData(const QModelIndexList &indexes) const override; | |
|
87 | virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | |
|
88 | const QModelIndex &parent) const override; | |
|
89 | virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | |
|
90 | const QModelIndex &parent) override; | |
|
77 | 91 | |
|
78 | 92 | void abortProgress(const QModelIndex &index); |
|
79 | 93 |
@@ -12,6 +12,7 | |||
|
12 | 12 | #include <Data/VariableRequest.h> |
|
13 | 13 | #include <Time/TimeController.h> |
|
14 | 14 | |
|
15 | #include <QDataStream> | |
|
15 | 16 | #include <QMutex> |
|
16 | 17 | #include <QThread> |
|
17 | 18 | #include <QUuid> |
@@ -277,6 +278,46 void VariableController::deleteVariables( | |||
|
277 | 278 | } |
|
278 | 279 | } |
|
279 | 280 | |
|
281 | QByteArray | |
|
282 | VariableController::mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const | |
|
283 | { | |
|
284 | auto encodedData = QByteArray{}; | |
|
285 | ||
|
286 | QVariantList ids; | |
|
287 | for (auto &var : variables) { | |
|
288 | auto itVar = impl->m_VariableToIdentifierMap.find(var); | |
|
289 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { | |
|
290 | qCCritical(LOG_VariableController()) | |
|
291 | << tr("Impossible to find the data for an unknown variable."); | |
|
292 | } | |
|
293 | ||
|
294 | ids << itVar->second.toByteArray(); | |
|
295 | } | |
|
296 | ||
|
297 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
|
298 | stream << ids; | |
|
299 | ||
|
300 | return encodedData; | |
|
301 | } | |
|
302 | ||
|
303 | QList<std::shared_ptr<Variable> > | |
|
304 | VariableController::variablesForMimeData(const QByteArray &mimeData) const | |
|
305 | { | |
|
306 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
|
307 | QDataStream stream{mimeData}; | |
|
308 | ||
|
309 | QVariantList ids; | |
|
310 | stream >> ids; | |
|
311 | ||
|
312 | for (auto id : ids) { | |
|
313 | auto uuid = QUuid(id.toByteArray()); | |
|
314 | auto var = impl->findVariable(uuid); | |
|
315 | variables << var; | |
|
316 | } | |
|
317 | ||
|
318 | return variables; | |
|
319 | } | |
|
320 | ||
|
280 | 321 | std::shared_ptr<Variable> |
|
281 | 322 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
282 | 323 | std::shared_ptr<IDataProvider> provider) noexcept |
@@ -1,11 +1,14 | |||
|
1 | 1 | #include <Variable/Variable.h> |
|
2 | #include <Variable/VariableController.h> | |
|
2 | 3 | #include <Variable/VariableModel.h> |
|
3 | 4 | |
|
4 | 5 | #include <Common/DateUtils.h> |
|
6 | #include <Common/MimeTypesDef.h> | |
|
5 | 7 | #include <Common/StringUtils.h> |
|
6 | 8 | |
|
7 | 9 | #include <Data/IDataSeries.h> |
|
8 | 10 | |
|
11 | #include <QMimeData> | |
|
9 | 12 | #include <QSize> |
|
10 | 13 | #include <unordered_map> |
|
11 | 14 | |
@@ -66,14 +69,16 struct VariableModel::VariableModelPrivate { | |||
|
66 | 69 | /// Variables created in SciQlop |
|
67 | 70 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
68 | 71 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; |
|
72 | VariableController *m_VariableController; | |
|
69 | 73 | |
|
70 | 74 | /// Return the row index of the variable. -1 if it's not found |
|
71 | 75 | int indexOfVariable(Variable *variable) const noexcept; |
|
72 | 76 | }; |
|
73 | 77 | |
|
74 |
VariableModel::VariableModel( |
|
|
78 | VariableModel::VariableModel(VariableController *parent) | |
|
75 | 79 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
76 | 80 | { |
|
81 | impl->m_VariableController = parent; | |
|
77 | 82 | } |
|
78 | 83 | |
|
79 | 84 | void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept |
@@ -255,6 +260,57 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int | |||
|
255 | 260 | return QVariant{}; |
|
256 | 261 | } |
|
257 | 262 | |
|
263 | Qt::ItemFlags VariableModel::flags(const QModelIndex &index) const | |
|
264 | { | |
|
265 | return QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; | |
|
266 | } | |
|
267 | ||
|
268 | Qt::DropActions VariableModel::supportedDropActions() const | |
|
269 | { | |
|
270 | return Qt::MoveAction; | |
|
271 | } | |
|
272 | ||
|
273 | Qt::DropActions VariableModel::supportedDragActions() const | |
|
274 | { | |
|
275 | return Qt::CopyAction | Qt::MoveAction; | |
|
276 | } | |
|
277 | ||
|
278 | QStringList VariableModel::mimeTypes() const | |
|
279 | { | |
|
280 | return {MIME_TYPE_VARIABLE_LIST}; | |
|
281 | } | |
|
282 | ||
|
283 | QMimeData *VariableModel::mimeData(const QModelIndexList &indexes) const | |
|
284 | { | |
|
285 | auto mimeData = new QMimeData; | |
|
286 | ||
|
287 | QList<std::shared_ptr<Variable> > variableList; | |
|
288 | ||
|
289 | for (const auto &index : indexes) { | |
|
290 | auto variable = impl->m_Variables.at(index.row()); | |
|
291 | if (variable.get() && index.isValid()) { | |
|
292 | variableList << variable; | |
|
293 | } | |
|
294 | } | |
|
295 | ||
|
296 | auto encodedData = impl->m_VariableController->mimeDataForVariables(variableList); | |
|
297 | mimeData->setData(MIME_TYPE_VARIABLE_LIST, encodedData); | |
|
298 | ||
|
299 | return mimeData; | |
|
300 | } | |
|
301 | ||
|
302 | bool VariableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, | |
|
303 | int column, const QModelIndex &parent) const | |
|
304 | { | |
|
305 | return false; | |
|
306 | } | |
|
307 | ||
|
308 | bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | |
|
309 | const QModelIndex &parent) | |
|
310 | { | |
|
311 | return false; | |
|
312 | } | |
|
313 | ||
|
258 | 314 | void VariableModel::abortProgress(const QModelIndex &index) |
|
259 | 315 | { |
|
260 | 316 | if (auto variable = impl->m_Variables.at(index.row())) { |
General Comments 0
You need to be logged in to leave comments.
Login now