##// END OF EJS Templates
Drag of variables
trabillard -
r849:73092e810307
parent child
Show More
@@ -68,6 +68,8 public:
68 */
68 */
69 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
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 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
74 static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange);
73 signals:
75 signals:
@@ -18,6 +18,7 enum VariableRoles { ProgressRole = Qt::UserRole };
18
18
19 class IDataSeries;
19 class IDataSeries;
20 class Variable;
20 class Variable;
21 class VariableController;
21
22
22 /**
23 /**
23 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
24 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
@@ -25,7 +26,7 class Variable;
25 class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel {
26 class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel {
26 Q_OBJECT
27 Q_OBJECT
27 public:
28 public:
28 explicit VariableModel(QObject *parent = nullptr);
29 explicit VariableModel(VariableController *parent = nullptr);
29
30
30 /**
31 /**
31 * Adds an existing variable in the model.
32 * Adds an existing variable in the model.
@@ -73,7 +74,20 public:
73 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
74 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
74 virtual QVariant headerData(int section, Qt::Orientation orientation,
75 virtual QVariant headerData(int section, Qt::Orientation orientation,
75 int role = Qt::DisplayRole) const override;
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 void abortProgress(const QModelIndex &index);
92 void abortProgress(const QModelIndex &index);
79
93
@@ -12,6 +12,7
12 #include <Data/VariableRequest.h>
12 #include <Data/VariableRequest.h>
13 #include <Time/TimeController.h>
13 #include <Time/TimeController.h>
14
14
15 #include <QDataStream>
15 #include <QMutex>
16 #include <QMutex>
16 #include <QThread>
17 #include <QThread>
17 #include <QUuid>
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 std::shared_ptr<Variable>
321 std::shared_ptr<Variable>
281 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
322 VariableController::createVariable(const QString &name, const QVariantHash &metadata,
282 std::shared_ptr<IDataProvider> provider) noexcept
323 std::shared_ptr<IDataProvider> provider) noexcept
@@ -1,11 +1,14
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
3 #include <Variable/VariableModel.h>
3
4
4 #include <Common/DateUtils.h>
5 #include <Common/DateUtils.h>
6 #include <Common/MimeTypesDef.h>
5 #include <Common/StringUtils.h>
7 #include <Common/StringUtils.h>
6
8
7 #include <Data/IDataSeries.h>
9 #include <Data/IDataSeries.h>
8
10
11 #include <QMimeData>
9 #include <QSize>
12 #include <QSize>
10 #include <unordered_map>
13 #include <unordered_map>
11
14
@@ -66,14 +69,16 struct VariableModel::VariableModelPrivate {
66 /// Variables created in SciQlop
69 /// Variables created in SciQlop
67 std::vector<std::shared_ptr<Variable> > m_Variables;
70 std::vector<std::shared_ptr<Variable> > m_Variables;
68 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
71 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
72 VariableController *m_VariableController;
69
73
70 /// Return the row index of the variable. -1 if it's not found
74 /// Return the row index of the variable. -1 if it's not found
71 int indexOfVariable(Variable *variable) const noexcept;
75 int indexOfVariable(Variable *variable) const noexcept;
72 };
76 };
73
77
74 VariableModel::VariableModel(QObject *parent)
78 VariableModel::VariableModel(VariableController *parent)
75 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
79 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
76 {
80 {
81 impl->m_VariableController = parent;
77 }
82 }
78
83
79 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept
84 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept
@@ -255,6 +260,57 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int
255 return QVariant{};
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 void VariableModel::abortProgress(const QModelIndex &index)
314 void VariableModel::abortProgress(const QModelIndex &index)
259 {
315 {
260 if (auto variable = impl->m_Variables.at(index.row())) {
316 if (auto variable = impl->m_Variables.at(index.row())) {
General Comments 0
You need to be logged in to leave comments. Login now