##// END OF EJS Templates
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
Updates PlottablesRenderingUtils to use variable's type instead of dataseries

File last commit:

r1075:029fbf916457
r1253:a119058eb032
Show More
DragDropGuiController.cpp
296 lines | 10.0 KiB | text/x-c | CppLexer
/ gui / src / DragAndDrop / DragDropGuiController.cpp
Rename "DragDropHelper" in "DragDropGuiController"
r1075 #include "DragAndDrop/DragDropGuiController.h"
Moves the class DragDropScroller in its own file
r885 #include "DragAndDrop/DragDropScroller.h"
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 #include "DragAndDrop/DragDropTabSwitcher.h"
New helper class for the drag&drop
r837 #include "SqpApplication.h"
drop of variables in the visualization
r850 #include "Visualization/VisualizationDragDropContainer.h"
Format changes
r844 #include "Visualization/VisualizationDragWidget.h"
drop of variables in the visualization
r850 #include "Visualization/VisualizationWidget.h"
#include "Visualization/operations/FindVariableOperation.h"
prevent dropping an variable without data in the visu
r876 #include "Variable/Variable.h"
drop of variables in the visualization
r850 #include "Variable/VariableController.h"
#include "Common/MimeTypesDef.h"
#include "Common/VisualizationDef.h"
New helper class for the drag&drop
r837
Format changes
r844 #include <QDir>
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881 #include <QLabel>
Moves the class DragDropScroller in its own file
r885 #include <QUrl>
Format changes
r844 #include <QVBoxLayout>
New helper class for the drag&drop
r837
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840
Rename "DragDropHelper" in "DragDropGuiController"
r1075 Q_LOGGING_CATEGORY(LOG_DragDropGuiController, "DragDropGuiController")
drop of variables in the visualization
r850
New helper class for the drag&drop
r837
Rename "DragDropHelper" in "DragDropGuiController"
r1075 struct DragDropGuiController::DragDropGuiControllerPrivate {
New helper class for the drag&drop
r837
Format changes
r844 VisualizationDragWidget *m_CurrentDragWidget = nullptr;
std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881 QLabel *m_PlaceHolderLabel;
QWidget *m_PlaceBackground;
Format changes
r844 std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr;
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 std::unique_ptr<DragDropTabSwitcher> m_DragDropTabSwitcher = nullptr;
Format changes
r844 QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using
// QTemporaryFile to have a name which is not generated.
New helper class for the drag&drop
r837
Improves visual effect of dropping a variable in a graph
r873 VisualizationDragWidget *m_HighlightedDragWidget = nullptr;
Improves reliability
r874 QMetaObject::Connection m_DragWidgetDestroyedConnection;
QMetaObject::Connection m_HighlightedWidgetDestroyedConnection;
Thibaud Rabillard
Fix for D&D bug on mac
r911 QList<QWidget *> m_WidgetToClose;
Rename "DragDropHelper" in "DragDropGuiController"
r1075 explicit DragDropGuiControllerPrivate()
Format changes
r844 : m_PlaceHolder{std::make_unique<QWidget>()},
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 m_DragDropScroller{std::make_unique<DragDropScroller>()},
m_DragDropTabSwitcher{std::make_unique<DragDropTabSwitcher>()}
New helper class for the drag&drop
r837 {
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881 auto layout = new QVBoxLayout{m_PlaceHolder.get()};
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
m_PlaceHolderLabel = new QLabel{"", m_PlaceHolder.get()};
m_PlaceHolderLabel->setMinimumHeight(25);
layout->addWidget(m_PlaceHolderLabel);
m_PlaceBackground = new QWidget{m_PlaceHolder.get()};
m_PlaceBackground->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(m_PlaceBackground);
sqpApp->installEventFilter(m_DragDropScroller.get());
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 sqpApp->installEventFilter(m_DragDropTabSwitcher.get());
New helper class for the drag&drop
r837
prevent dropping an variable without data in the visu
r876 m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png");
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void preparePlaceHolder(DragDropGuiController::PlaceHolderType type,
const QString &topLabelText) const
New helper class for the drag&drop
r837 {
Format changes
r844 if (m_CurrentDragWidget) {
m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy());
New helper class for the drag&drop
r837 }
Format changes
r844 else {
drop of variables in the visualization
r850 // Configuration of the placeHolder when there is no dragWidget
// (for instance with a drag from a variable)
Move the GRAPH_MINIMUM_HEIGHT constant in a place accessible everywhere and use it in the drag&drop
r851 m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT);
drop of variables in the visualization
r850 m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
New helper class for the drag&drop
r837 }
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881
switch (type) {
Rename "DragDropHelper" in "DragDropGuiController"
r1075 case DragDropGuiController::PlaceHolderType::Graph:
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881 m_PlaceBackground->setStyleSheet(
"background-color: #BBD5EE; border: 1px solid #2A7FD4");
break;
Rename "DragDropHelper" in "DragDropGuiController"
r1075 case DragDropGuiController::PlaceHolderType::Zone:
case DragDropGuiController::PlaceHolderType::Default:
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881 m_PlaceBackground->setStyleSheet(
"background-color: #BBD5EE; border: 2px solid #2A7FD4");
m_PlaceHolderLabel->setStyleSheet("color: #2A7FD4");
break;
}
m_PlaceHolderLabel->setText(topLabelText);
m_PlaceHolderLabel->setVisible(!topLabelText.isEmpty());
New helper class for the drag&drop
r837 }
};
Rename "DragDropHelper" in "DragDropGuiController"
r1075 DragDropGuiController::DragDropGuiController()
: impl{spimpl::make_unique_impl<DragDropGuiControllerPrivate>()}
Fix format for linux
r912 {
}
New helper class for the drag&drop
r837
Rename "DragDropHelper" in "DragDropGuiController"
r1075 DragDropGuiController::~DragDropGuiController()
New helper class for the drag&drop
r837 {
Format changes
r844 QFile::remove(impl->m_ImageTempUrl);
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::resetDragAndDrop()
drop of variables in the visualization
r850 {
setCurrentDragWidget(nullptr);
Improves visual effect of dropping a variable in a graph
r873 impl->m_HighlightedDragWidget = nullptr;
drop of variables in the visualization
r850 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::setCurrentDragWidget(VisualizationDragWidget *dragWidget)
New helper class for the drag&drop
r837 {
Improves reliability
r874 if (impl->m_CurrentDragWidget) {
QObject::disconnect(impl->m_DragWidgetDestroyedConnection);
}
if (dragWidget) {
// ensures the impl->m_CurrentDragWidget is reset when the widget is destroyed
impl->m_DragWidgetDestroyedConnection
= QObject::connect(dragWidget, &VisualizationDragWidget::destroyed,
[this]() { impl->m_CurrentDragWidget = nullptr; });
}
Format changes
r844 impl->m_CurrentDragWidget = dragWidget;
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 VisualizationDragWidget *DragDropGuiController::getCurrentDragWidget() const
New helper class for the drag&drop
r837 {
Format changes
r844 return impl->m_CurrentDragWidget;
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 QWidget &DragDropGuiController::placeHolder() const
New helper class for the drag&drop
r837 {
Format changes
r844 return *impl->m_PlaceHolder;
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type,
const QString &topLabelText)
New helper class for the drag&drop
r837 {
removePlaceHolder();
Add an empty area at the bottom of the tab where a new zone can be created from a drop. Differentiate graph and zone placeHolders.
r881 impl->preparePlaceHolder(type, topLabelText);
Format changes
r844 layout->insertWidget(index, impl->m_PlaceHolder.get());
impl->m_PlaceHolder->show();
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::removePlaceHolder()
New helper class for the drag&drop
r837 {
Format changes
r844 auto parentWidget = impl->m_PlaceHolder->parentWidget();
if (parentWidget) {
parentWidget->layout()->removeWidget(impl->m_PlaceHolder.get());
impl->m_PlaceHolder->setParent(nullptr);
impl->m_PlaceHolder->hide();
New helper class for the drag&drop
r837 }
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 bool DragDropGuiController::isPlaceHolderSet() const
New helper class for the drag&drop
r837 {
Format changes
r844 return impl->m_PlaceHolder->parentWidget();
New helper class for the drag&drop
r837 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::addDragDropScrollArea(QScrollArea *scrollArea)
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 {
Format changes
r844 impl->m_DragDropScroller->addScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::removeDragDropScrollArea(QScrollArea *scrollArea)
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 {
Format changes
r844 impl->m_DragDropScroller->removeScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::addDragDropTabBar(QTabBar *tabBar)
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 {
impl->m_DragDropTabSwitcher->addTabBar(tabBar);
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::removeDragDropTabBar(QTabBar *tabBar)
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 {
impl->m_DragDropTabSwitcher->removeTabBar(tabBar);
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 QUrl DragDropGuiController::imageTemporaryUrl(const QImage &image) const
New helper class for the drag&drop
r837 {
Format changes
r844 image.save(impl->m_ImageTempUrl);
return QUrl::fromLocalFile(impl->m_ImageTempUrl);
New helper class for the drag&drop
r837 }
drop of variables in the visualization
r850
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::setHightlightedDragWidget(VisualizationDragWidget *dragWidget)
Improves visual effect of dropping a variable in a graph
r873 {
if (impl->m_HighlightedDragWidget) {
impl->m_HighlightedDragWidget->highlightForMerge(false);
Improves reliability
r874 QObject::disconnect(impl->m_HighlightedWidgetDestroyedConnection);
Improves visual effect of dropping a variable in a graph
r873 }
if (dragWidget) {
Improves reliability
r874 dragWidget->highlightForMerge(true);
// ensures the impl->m_HighlightedDragWidget is reset when the widget is destroyed
impl->m_DragWidgetDestroyedConnection
= QObject::connect(dragWidget, &VisualizationDragWidget::destroyed,
[this]() { impl->m_HighlightedDragWidget = nullptr; });
Improves visual effect of dropping a variable in a graph
r873 }
Improves reliability
r874
impl->m_HighlightedDragWidget = dragWidget;
Improves visual effect of dropping a variable in a graph
r873 }
Rename "DragDropHelper" in "DragDropGuiController"
r1075 VisualizationDragWidget *DragDropGuiController::getHightlightedDragWidget() const
drop of variable inside an existing graph
r875 {
return impl->m_HighlightedDragWidget;
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::delayedCloseWidget(QWidget *widget)
Thibaud Rabillard
Fix for D&D bug on mac
r911 {
widget->hide();
impl->m_WidgetToClose << widget;
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 void DragDropGuiController::doCloseWidgets()
Thibaud Rabillard
Fix for D&D bug on mac
r911 {
for (auto widget : impl->m_WidgetToClose) {
widget->close();
}
impl->m_WidgetToClose.clear();
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 bool DragDropGuiController::checkMimeDataForVisualization(
const QMimeData *mimeData, VisualizationDragDropContainer *dropContainer)
drop of variables in the visualization
r850 {
Drag of product
r868 if (!mimeData || !dropContainer) {
Rename "DragDropHelper" in "DragDropGuiController"
r1075 qCWarning(LOG_DragDropGuiController()) << QObject::tr(
"DragDropGuiController::checkMimeDataForVisualization, invalid input parameters.");
Drag of product
r868 Q_ASSERT(false);
prevent dropping an variable without data in the visu
r876 return false;
Drag of product
r868 }
prevent dropping an variable without data in the visu
r876 auto result = false;
drop of variables in the visualization
r850
if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) {
auto variables = sqpApp->variableController().variablesForMimeData(
mimeData->data(MIME_TYPE_VARIABLE_LIST));
if (variables.count() == 1) {
prevent dropping an variable without data in the visu
r876 auto variable = variables.first();
if (variable->dataSeries() != nullptr) {
// Check that the variable is not already in a graph
drop of variables in the visualization
r850
prevent dropping an variable without data in the visu
r876 auto parent = dropContainer->parentWidget();
while (parent && qobject_cast<VisualizationWidget *>(parent) == nullptr) {
parent = parent->parentWidget(); // Search for the top level VisualizationWidget
}
drop of variables in the visualization
r850
prevent dropping an variable without data in the visu
r876 if (parent) {
auto visualizationWidget = static_cast<VisualizationWidget *>(parent);
FindVariableOperation findVariableOperation{variable};
visualizationWidget->accept(&findVariableOperation);
auto variableContainers = findVariableOperation.result();
if (variableContainers.empty()) {
result = true;
}
else {
// result = false: the variable already exist in the visualisation
}
}
else {
Rename "DragDropHelper" in "DragDropGuiController"
r1075 qCWarning(LOG_DragDropGuiController()) << QObject::tr(
"DragDropGuiController::checkMimeDataForVisualization, the parent "
prevent dropping an variable without data in the visu
r876 "VisualizationWidget cannot be found. Cannot check if the variable is "
"already used or not.");
drop of variables in the visualization
r850 }
}
else {
prevent dropping an variable without data in the visu
r876 // result = false: the variable is not fully loaded
drop of variables in the visualization
r850 }
}
else {
prevent dropping an variable without data in the visu
r876 // result = false: cannot drop multiple variables in the visualisation
drop of variables in the visualization
r850 }
}
prevent dropping an variable without data in the visu
r876 else {
// Other MIME data
// no special rules, accepted by default
result = true;
}
drop of variables in the visualization
r850
return result;
}