##// END OF EJS Templates
prevent dropping an variable without data in the visu
trabillard -
r876:da9523540c62
parent child
Show More
@@ -5,6 +5,7
5 #include "Visualization/VisualizationWidget.h"
5 #include "Visualization/VisualizationWidget.h"
6 #include "Visualization/operations/FindVariableOperation.h"
6 #include "Visualization/operations/FindVariableOperation.h"
7
7
8 #include "Variable/Variable.h"
8 #include "Variable/VariableController.h"
9 #include "Variable/VariableController.h"
9
10
10 #include "Common/MimeTypesDef.h"
11 #include "Common/MimeTypesDef.h"
@@ -160,7 +161,7 struct DragDropHelper::DragDropHelperPrivate {
160 sqpApp->installEventFilter(m_DragDropScroller.get());
161 sqpApp->installEventFilter(m_DragDropScroller.get());
161
162
162
163
163 m_ImageTempUrl = QDir::temp().absoluteFilePath("Scqlop_graph.png");
164 m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png");
164 }
165 }
165
166
166 void preparePlaceHolder() const
167 void preparePlaceHolder() const
@@ -293,44 +294,60 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
293 qCWarning(LOG_DragDropHelper()) << QObject::tr(
294 qCWarning(LOG_DragDropHelper()) << QObject::tr(
294 "DragDropHelper::checkMimeDataForVisualization, invalid input parameters.");
295 "DragDropHelper::checkMimeDataForVisualization, invalid input parameters.");
295 Q_ASSERT(false);
296 Q_ASSERT(false);
297 return false;
296 }
298 }
297
299
298 auto result = true;
300 auto result = false;
299
301
300 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) {
302 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) {
301 auto variables = sqpApp->variableController().variablesForMimeData(
303 auto variables = sqpApp->variableController().variablesForMimeData(
302 mimeData->data(MIME_TYPE_VARIABLE_LIST));
304 mimeData->data(MIME_TYPE_VARIABLE_LIST));
303
305
304 if (variables.count() == 1) {
306 if (variables.count() == 1) {
305 // Check that the viariable is not already in a graph
306
307
307 // Search for the top level VisualizationWidget
308 auto variable = variables.first();
308 auto parent = dropContainer->parentWidget();
309 if (variable->dataSeries() != nullptr) {
309 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
310
310 parent = parent->parentWidget();
311 // Check that the variable is not already in a graph
311 }
312
312
313 if (parent) {
313 auto parent = dropContainer->parentWidget();
314 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
314 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
315 parent = parent->parentWidget(); // Search for the top level VisualizationWidget
316 }
315
317
316 FindVariableOperation findVariableOperation{variables.first()};
318 if (parent) {
317 visualizationWidget->accept(&findVariableOperation);
319 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
318 auto variableContainers = findVariableOperation.result();
320
319 if (!variableContainers.empty()) {
321 FindVariableOperation findVariableOperation{variable};
320 result = false;
322 visualizationWidget->accept(&findVariableOperation);
323 auto variableContainers = findVariableOperation.result();
324 if (variableContainers.empty()) {
325 result = true;
326 }
327 else {
328 // result = false: the variable already exist in the visualisation
329 }
330 }
331 else {
332 qCWarning(LOG_DragDropHelper()) << QObject::tr(
333 "DragDropHelper::checkMimeDataForVisualization, the parent "
334 "VisualizationWidget cannot be found. Cannot check if the variable is "
335 "already used or not.");
321 }
336 }
322 }
337 }
323 else {
338 else {
324 qCWarning(LOG_DragDropHelper()) << QObject::tr(
339 // result = false: the variable is not fully loaded
325 "DragDropHelper::checkMimeDataForVisualization, the parent "
326 "VisualizationWidget cannot be found.");
327 result = false;
328 }
340 }
329 }
341 }
330 else {
342 else {
331 result = false;
343 // result = false: cannot drop multiple variables in the visualisation
332 }
344 }
333 }
345 }
346 else {
347 // Other MIME data
348 // no special rules, accepted by default
349 result = true;
350 }
334
351
335 return result;
352 return result;
336 }
353 }
General Comments 0
You need to be logged in to leave comments. Login now