##// END OF EJS Templates
Fix move of an event in another catalogue
Fix move of an event in another catalogue

File last commit:

r1341:36d2186e2f24
r1379:99a785298325
Show More
DragDropGuiController.cpp
308 lines | 10.5 KiB | text/x-c | CppLexer
/ gui / src / DragAndDrop / DragDropGuiController.cpp
Rename "DragDropHelper" in "DragDropGuiController"
r1110 #include "DragAndDrop/DragDropGuiController.h"
Moves the class DragDropScroller in its own file
r891 #include "DragAndDrop/DragDropScroller.h"
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 #include "DragAndDrop/DragDropTabSwitcher.h"
New helper class for the drag&drop
r840 #include "SqpApplication.h"
drop of variables in the visualization
r852 #include "Visualization/VisualizationDragDropContainer.h"
Format changes
r847 #include "Visualization/VisualizationDragWidget.h"
drop of variables in the visualization
r852 #include "Visualization/VisualizationWidget.h"
#include "Visualization/operations/FindVariableOperation.h"
drop of products in visu
r1341 #include "DataSource/DataSourceController.h"
prevent dropping an variable without data in the visu
r882 #include "Variable/Variable.h"
drop of variables in the visualization
r852 #include "Variable/VariableController.h"
#include "Common/MimeTypesDef.h"
#include "Common/VisualizationDef.h"
New helper class for the drag&drop
r840
Format changes
r847 #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.
r887 #include <QLabel>
Moves the class DragDropScroller in its own file
r891 #include <QUrl>
Format changes
r847 #include <QVBoxLayout>
New helper class for the drag&drop
r840
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843
Rename "DragDropHelper" in "DragDropGuiController"
r1110 Q_LOGGING_CATEGORY(LOG_DragDropGuiController, "DragDropGuiController")
drop of variables in the visualization
r852
New helper class for the drag&drop
r840
Rename "DragDropHelper" in "DragDropGuiController"
r1110 struct DragDropGuiController::DragDropGuiControllerPrivate {
New helper class for the drag&drop
r840
Format changes
r847 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.
r887 QLabel *m_PlaceHolderLabel;
QWidget *m_PlaceBackground;
Format changes
r847 std::unique_ptr<DragDropScroller> m_DragDropScroller = nullptr;
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 std::unique_ptr<DragDropTabSwitcher> m_DragDropTabSwitcher = nullptr;
Format changes
r847 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
r840
Improves visual effect of dropping a variable in a graph
r879 VisualizationDragWidget *m_HighlightedDragWidget = nullptr;
Improves reliability
r880 QMetaObject::Connection m_DragWidgetDestroyedConnection;
QMetaObject::Connection m_HighlightedWidgetDestroyedConnection;
Thibaud Rabillard
Fix for D&D bug on mac
r912 QList<QWidget *> m_WidgetToClose;
Rename "DragDropHelper" in "DragDropGuiController"
r1110 explicit DragDropGuiControllerPrivate()
Format changes
r847 : m_PlaceHolder{std::make_unique<QWidget>()},
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 m_DragDropScroller{std::make_unique<DragDropScroller>()},
m_DragDropTabSwitcher{std::make_unique<DragDropTabSwitcher>()}
New helper class for the drag&drop
r840 {
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.
r887 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
r892 sqpApp->installEventFilter(m_DragDropTabSwitcher.get());
New helper class for the drag&drop
r840
prevent dropping an variable without data in the visu
r882 m_ImageTempUrl = QDir::temp().absoluteFilePath("Sciqlop_graph.png");
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void preparePlaceHolder(DragDropGuiController::PlaceHolderType type,
const QString &topLabelText) const
New helper class for the drag&drop
r840 {
Format changes
r847 if (m_CurrentDragWidget) {
m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy());
New helper class for the drag&drop
r840 }
Format changes
r847 else {
drop of variables in the visualization
r852 // 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
r853 m_PlaceHolder->setMinimumSize(0, GRAPH_MINIMUM_HEIGHT);
drop of variables in the visualization
r852 m_PlaceHolder->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
New helper class for the drag&drop
r840 }
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.
r887
switch (type) {
Rename "DragDropHelper" in "DragDropGuiController"
r1110 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.
r887 m_PlaceBackground->setStyleSheet(
"background-color: #BBD5EE; border: 1px solid #2A7FD4");
break;
Rename "DragDropHelper" in "DragDropGuiController"
r1110 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.
r887 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
r840 }
};
Rename "DragDropHelper" in "DragDropGuiController"
r1110 DragDropGuiController::DragDropGuiController()
: impl{spimpl::make_unique_impl<DragDropGuiControllerPrivate>()}
Fix format for linux
r913 {
}
New helper class for the drag&drop
r840
Rename "DragDropHelper" in "DragDropGuiController"
r1110 DragDropGuiController::~DragDropGuiController()
New helper class for the drag&drop
r840 {
Format changes
r847 QFile::remove(impl->m_ImageTempUrl);
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::resetDragAndDrop()
drop of variables in the visualization
r852 {
setCurrentDragWidget(nullptr);
Improves visual effect of dropping a variable in a graph
r879 impl->m_HighlightedDragWidget = nullptr;
drop of variables in the visualization
r852 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::setCurrentDragWidget(VisualizationDragWidget *dragWidget)
New helper class for the drag&drop
r840 {
Improves reliability
r880 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
r847 impl->m_CurrentDragWidget = dragWidget;
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 VisualizationDragWidget *DragDropGuiController::getCurrentDragWidget() const
New helper class for the drag&drop
r840 {
Format changes
r847 return impl->m_CurrentDragWidget;
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 QWidget &DragDropGuiController::placeHolder() const
New helper class for the drag&drop
r840 {
Format changes
r847 return *impl->m_PlaceHolder;
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::insertPlaceHolder(QVBoxLayout *layout, int index, PlaceHolderType type,
const QString &topLabelText)
New helper class for the drag&drop
r840 {
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.
r887 impl->preparePlaceHolder(type, topLabelText);
Format changes
r847 layout->insertWidget(index, impl->m_PlaceHolder.get());
impl->m_PlaceHolder->show();
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::removePlaceHolder()
New helper class for the drag&drop
r840 {
Format changes
r847 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
r840 }
}
Rename "DragDropHelper" in "DragDropGuiController"
r1110 bool DragDropGuiController::isPlaceHolderSet() const
New helper class for the drag&drop
r840 {
Format changes
r847 return impl->m_PlaceHolder->parentWidget();
New helper class for the drag&drop
r840 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::addDragDropScrollArea(QScrollArea *scrollArea)
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 {
Format changes
r847 impl->m_DragDropScroller->addScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::removeDragDropScrollArea(QScrollArea *scrollArea)
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 {
Format changes
r847 impl->m_DragDropScroller->removeScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::addDragDropTabBar(QTabBar *tabBar)
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 {
impl->m_DragDropTabSwitcher->addTabBar(tabBar);
}
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::removeDragDropTabBar(QTabBar *tabBar)
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 {
impl->m_DragDropTabSwitcher->removeTabBar(tabBar);
}
Rename "DragDropHelper" in "DragDropGuiController"
r1110 QUrl DragDropGuiController::imageTemporaryUrl(const QImage &image) const
New helper class for the drag&drop
r840 {
Format changes
r847 image.save(impl->m_ImageTempUrl);
return QUrl::fromLocalFile(impl->m_ImageTempUrl);
New helper class for the drag&drop
r840 }
drop of variables in the visualization
r852
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::setHightlightedDragWidget(VisualizationDragWidget *dragWidget)
Improves visual effect of dropping a variable in a graph
r879 {
if (impl->m_HighlightedDragWidget) {
impl->m_HighlightedDragWidget->highlightForMerge(false);
Improves reliability
r880 QObject::disconnect(impl->m_HighlightedWidgetDestroyedConnection);
Improves visual effect of dropping a variable in a graph
r879 }
if (dragWidget) {
Improves reliability
r880 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
r879 }
Improves reliability
r880
impl->m_HighlightedDragWidget = dragWidget;
Improves visual effect of dropping a variable in a graph
r879 }
Rename "DragDropHelper" in "DragDropGuiController"
r1110 VisualizationDragWidget *DragDropGuiController::getHightlightedDragWidget() const
drop of variable inside an existing graph
r881 {
return impl->m_HighlightedDragWidget;
}
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::delayedCloseWidget(QWidget *widget)
Thibaud Rabillard
Fix for D&D bug on mac
r912 {
widget->hide();
impl->m_WidgetToClose << widget;
}
Rename "DragDropHelper" in "DragDropGuiController"
r1110 void DragDropGuiController::doCloseWidgets()
Thibaud Rabillard
Fix for D&D bug on mac
r912 {
for (auto widget : impl->m_WidgetToClose) {
widget->close();
}
impl->m_WidgetToClose.clear();
}
Rename "DragDropHelper" in "DragDropGuiController"
r1110 bool DragDropGuiController::checkMimeDataForVisualization(
const QMimeData *mimeData, VisualizationDragDropContainer *dropContainer)
drop of variables in the visualization
r852 {
Drag of product
r876 if (!mimeData || !dropContainer) {
Rename "DragDropHelper" in "DragDropGuiController"
r1110 qCWarning(LOG_DragDropGuiController()) << QObject::tr(
"DragDropGuiController::checkMimeDataForVisualization, invalid input parameters.");
Drag of product
r876 Q_ASSERT(false);
prevent dropping an variable without data in the visu
r882 return false;
Drag of product
r876 }
prevent dropping an variable without data in the visu
r882 auto result = false;
drop of variables in the visualization
r852
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
r882 auto variable = variables.first();
if (variable->dataSeries() != nullptr) {
// Check that the variable is not already in a graph
drop of variables in the visualization
r852
prevent dropping an variable without data in the visu
r882 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
r852
prevent dropping an variable without data in the visu
r882 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"
r1110 qCWarning(LOG_DragDropGuiController()) << QObject::tr(
"DragDropGuiController::checkMimeDataForVisualization, the parent "
prevent dropping an variable without data in the visu
r882 "VisualizationWidget cannot be found. Cannot check if the variable is "
"already used or not.");
drop of variables in the visualization
r852 }
}
else {
prevent dropping an variable without data in the visu
r882 // result = false: the variable is not fully loaded
drop of variables in the visualization
r852 }
}
else {
prevent dropping an variable without data in the visu
r882 // result = false: cannot drop multiple variables in the visualisation
drop of variables in the visualization
r852 }
}
drop of products in visu
r1341 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
auto productDataList = sqpApp->dataSourceController().productsDataForMimeData(
mimeData->data(MIME_TYPE_PRODUCT_LIST));
if (productDataList.count() == 1) {
result = true;
}
else {
// result = false: cannot drop multiple products in the visualisation
}
}
prevent dropping an variable without data in the visu
r882 else {
// Other MIME data
// no special rules, accepted by default
result = true;
}
drop of variables in the visualization
r852
drop of products in visu
r1341
drop of variables in the visualization
r852 return result;
}