##// END OF EJS Templates
Again a dmg fix :)...
Again a dmg fix :) Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1422:a323cf6b7201
r1470:04e52d50cd7a
Show More
DragDropGuiController.cpp
331 lines | 10.6 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"
drop of products in visu
r1287 #include "DataSource/DataSourceController.h"
All the codebase is modified to build with new Variable Controller...
r1348 #include "Variable/VariableController2.h"
drop of variables in the visualization
r850
#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
Switched to new TS impl but quite broken!...
r1420 struct DragDropGuiController::DragDropGuiControllerPrivate
{
New helper class for the drag&drop
r837
Switched to new TS impl but quite broken!...
r1420 VisualizationDragWidget* m_CurrentDragWidget = nullptr;
Format changes
r844 std::unique_ptr<QWidget> m_PlaceHolder = nullptr;
Switched to new TS impl but quite broken!...
r1420 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
Switched to new TS impl but quite broken!...
r1420 VisualizationDragWidget* m_HighlightedDragWidget = nullptr;
Improves visual effect of dropping a variable in a graph
r873
Improves reliability
r874 QMetaObject::Connection m_DragWidgetDestroyedConnection;
QMetaObject::Connection m_HighlightedWidgetDestroyedConnection;
Switched to new TS impl but quite broken!...
r1420 QList<QWidget*> m_WidgetToClose;
Thibaud Rabillard
Fix for D&D bug on mac
r911
Rename "DragDropHelper" in "DragDropGuiController"
r1075 explicit DragDropGuiControllerPrivate()
Switched to new TS impl but quite broken!...
r1420 : m_PlaceHolder { std::make_unique<QWidget>() }
, m_DragDropScroller { std::make_unique<DragDropScroller>() }
, m_DragDropTabSwitcher { std::make_unique<DragDropTabSwitcher>() }
New helper class for the drag&drop
r837 {
Switched to new TS impl but quite broken!...
r1420 auto layout = new QVBoxLayout { m_PlaceHolder.get() };
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 layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
Switched to new TS impl but quite broken!...
r1420 m_PlaceHolderLabel = new QLabel { "", m_PlaceHolder.get() };
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_PlaceHolderLabel->setMinimumHeight(25);
layout->addWidget(m_PlaceHolderLabel);
Switched to new TS impl but quite broken!...
r1420 m_PlaceBackground = new QWidget { m_PlaceHolder.get() };
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->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 }
Switched to new TS impl but quite broken!...
r1420 void preparePlaceHolder(
DragDropGuiController::PlaceHolderType type, const QString& topLabelText) const
New helper class for the drag&drop
r837 {
Switched to new TS impl but quite broken!...
r1420 if (m_CurrentDragWidget)
{
Format changes
r844 m_PlaceHolder->setMinimumSize(m_CurrentDragWidget->size());
m_PlaceHolder->setSizePolicy(m_CurrentDragWidget->sizePolicy());
New helper class for the drag&drop
r837 }
Switched to new TS impl but quite broken!...
r1420 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
Switched to new TS impl but quite broken!...
r1420 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()
Switched to new TS impl but quite broken!...
r1420 : 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 }
Switched to new TS impl but quite broken!...
r1420 void DragDropGuiController::setCurrentDragWidget(VisualizationDragWidget* dragWidget)
New helper class for the drag&drop
r837 {
Switched to new TS impl but quite broken!...
r1420 if (impl->m_CurrentDragWidget)
{
Improves reliability
r874
QObject::disconnect(impl->m_DragWidgetDestroyedConnection);
}
Switched to new TS impl but quite broken!...
r1420 if (dragWidget)
{
Improves reliability
r874 // ensures the impl->m_CurrentDragWidget is reset when the widget is destroyed
Switched to new TS impl but quite broken!...
r1420 impl->m_DragWidgetDestroyedConnection = QObject::connect(dragWidget,
&VisualizationDragWidget::destroyed, [this]() { impl->m_CurrentDragWidget = nullptr; });
Improves reliability
r874 }
Format changes
r844 impl->m_CurrentDragWidget = dragWidget;
New helper class for the drag&drop
r837 }
Switched to new TS impl but quite broken!...
r1420 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 }
Switched to new TS impl but quite broken!...
r1420 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 }
Switched to new TS impl but quite broken!...
r1420 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();
Switched to new TS impl but quite broken!...
r1420 if (parentWidget)
{
Format changes
r844 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 }
Switched to new TS impl but quite broken!...
r1420 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 }
Switched to new TS impl but quite broken!...
r1420 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 }
Switched to new TS impl but quite broken!...
r1420 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);
}
Switched to new TS impl but quite broken!...
r1420 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);
}
Switched to new TS impl but quite broken!...
r1420 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
Switched to new TS impl but quite broken!...
r1420 void DragDropGuiController::setHightlightedDragWidget(VisualizationDragWidget* dragWidget)
Improves visual effect of dropping a variable in a graph
r873 {
Switched to new TS impl but quite broken!...
r1420 if (impl->m_HighlightedDragWidget)
{
Improves visual effect of dropping a variable in a graph
r873 impl->m_HighlightedDragWidget->highlightForMerge(false);
Improves reliability
r874 QObject::disconnect(impl->m_HighlightedWidgetDestroyedConnection);
Improves visual effect of dropping a variable in a graph
r873 }
Switched to new TS impl but quite broken!...
r1420 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,
Switched to new TS impl but quite broken!...
r1420 [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 }
Switched to new TS impl but quite broken!...
r1420 VisualizationDragWidget* DragDropGuiController::getHightlightedDragWidget() const
drop of variable inside an existing graph
r875 {
return impl->m_HighlightedDragWidget;
}
Switched to new TS impl but quite broken!...
r1420 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 {
Switched to new TS impl but quite broken!...
r1420 for (auto widget : impl->m_WidgetToClose)
{
Thibaud Rabillard
Fix for D&D bug on mac
r911 widget->close();
}
impl->m_WidgetToClose.clear();
}
Rename "DragDropHelper" in "DragDropGuiController"
r1075 bool DragDropGuiController::checkMimeDataForVisualization(
Switched to new TS impl but quite broken!...
r1420 const QMimeData* mimeData, VisualizationDragDropContainer* dropContainer)
drop of variables in the visualization
r850 {
Switched to new TS impl but quite broken!...
r1420 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
Switched to new TS impl but quite broken!...
r1420 if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST))
{
All the codebase is modified to build with new Variable Controller...
r1348 auto variables = sqpApp->variableController().variables(
Removed old Variable impl...
r1422 Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST)));
drop of variables in the visualization
r850
Switched to new TS impl but quite broken!...
r1420 if (variables.size() == 1)
{
drop of variables in the visualization
r850
All the codebase is modified to build with new Variable Controller...
r1348 auto variable = variables[0];
Switched to new TS impl but quite broken!...
r1420 if (variable->data() != nullptr)
{
prevent dropping an variable without data in the visu
r876
// 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();
Switched to new TS impl but quite broken!...
r1420 while (parent && qobject_cast<VisualizationWidget*>(parent) == nullptr)
{
prevent dropping an variable without data in the visu
r876 parent = parent->parentWidget(); // Search for the top level VisualizationWidget
}
drop of variables in the visualization
r850
Switched to new TS impl but quite broken!...
r1420 if (parent)
{
auto visualizationWidget = static_cast<VisualizationWidget*>(parent);
prevent dropping an variable without data in the visu
r876
Switched to new TS impl but quite broken!...
r1420 FindVariableOperation findVariableOperation { variable };
prevent dropping an variable without data in the visu
r876 visualizationWidget->accept(&findVariableOperation);
auto variableContainers = findVariableOperation.result();
Switched to new TS impl but quite broken!...
r1420 if (variableContainers.empty())
{
prevent dropping an variable without data in the visu
r876 result = true;
}
Switched to new TS impl but quite broken!...
r1420 else
{
prevent dropping an variable without data in the visu
r876 // result = false: the variable already exist in the visualisation
}
}
Switched to new TS impl but quite broken!...
r1420 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 }
}
Switched to new TS impl but quite broken!...
r1420 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 }
}
Switched to new TS impl but quite broken!...
r1420 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 }
}
Switched to new TS impl but quite broken!...
r1420 else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST))
{
drop of products in visu
r1287 auto productDataList = sqpApp->dataSourceController().productsDataForMimeData(
mimeData->data(MIME_TYPE_PRODUCT_LIST));
Switched to new TS impl but quite broken!...
r1420 if (productDataList.count() == 1)
{
drop of products in visu
r1287 result = true;
}
Switched to new TS impl but quite broken!...
r1420 else
{
drop of products in visu
r1287 // result = false: cannot drop multiple products in the visualisation
}
}
Switched to new TS impl but quite broken!...
r1420 else
{
prevent dropping an variable without data in the visu
r876 // Other MIME data
// no special rules, accepted by default
result = true;
}
drop of variables in the visualization
r850
drop of products in visu
r1287
drop of variables in the visualization
r850 return result;
}