##// 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();
309 if (variable->dataSeries() != nullptr) {
310
311 // Check that the variable is not already in a graph
312
308 auto parent = dropContainer->parentWidget();
313 auto parent = dropContainer->parentWidget();
309 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
314 while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
310 parent = parent->parentWidget();
315 parent = parent->parentWidget(); // Search for the top level VisualizationWidget
311 }
316 }
312
317
313 if (parent) {
318 if (parent) {
314 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
319 auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
315
320
316 FindVariableOperation findVariableOperation{variables.first()};
321 FindVariableOperation findVariableOperation{variable};
317 visualizationWidget->accept(&findVariableOperation);
322 visualizationWidget->accept(&findVariableOperation);
318 auto variableContainers = findVariableOperation.result();
323 auto variableContainers = findVariableOperation.result();
319 if (!variableContainers.empty()) {
324 if (variableContainers.empty()) {
320 result = false;
325 result = true;
326 }
327 else {
328 // result = false: the variable already exist in the visualisation
321 }
329 }
322 }
330 }
323 else {
331 else {
324 qCWarning(LOG_DragDropHelper()) << QObject::tr(
332 qCWarning(LOG_DragDropHelper()) << QObject::tr(
325 "DragDropHelper::checkMimeDataForVisualization, the parent "
333 "DragDropHelper::checkMimeDataForVisualization, the parent "
326 "VisualizationWidget cannot be found.");
334 "VisualizationWidget cannot be found. Cannot check if the variable is "
327 result = false;
335 "already used or not.");
328 }
336 }
329 }
337 }
330 else {
338 else {
331 result = false;
339 // result = false: the variable is not fully loaded
332 }
340 }
333 }
341 }
342 else {
343 // result = false: cannot drop multiple variables in the visualisation
344 }
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