##// END OF EJS Templates
Parser refactoring (3)...
Parser refactoring (3) Implements properties reading and properties checking Implementation takes some of the basic parser, which will be deleted at the end

File last commit:

r913:fedc6e2cf64d
r987:49134789d5f3
Show More
DragDropHelper.cpp
294 lines | 9.8 KiB | text/x-c | CppLexer
Moves the DragDropHelper file
r890 #include "DragAndDrop/DragDropHelper.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"
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
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 Q_LOGGING_CATEGORY(LOG_DragDropHelper, "DragDropHelper")
drop of variables in the visualization
r852
New helper class for the drag&drop
r840
struct DragDropHelper::DragDropHelperPrivate {
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;
New helper class for the drag&drop
r840 explicit DragDropHelperPrivate()
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 }
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 void preparePlaceHolder(DragDropHelper::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) {
case DragDropHelper::PlaceHolderType::Graph:
m_PlaceBackground->setStyleSheet(
"background-color: #BBD5EE; border: 1px solid #2A7FD4");
break;
case DragDropHelper::PlaceHolderType::Zone:
case DragDropHelper::PlaceHolderType::Default:
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 }
};
Fix format for linux
r913 DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()}
{
}
New helper class for the drag&drop
r840
DragDropHelper::~DragDropHelper()
{
Format changes
r847 QFile::remove(impl->m_ImageTempUrl);
New helper class for the drag&drop
r840 }
drop of variables in the visualization
r852 void DragDropHelper::resetDragAndDrop()
{
setCurrentDragWidget(nullptr);
Improves visual effect of dropping a variable in a graph
r879 impl->m_HighlightedDragWidget = nullptr;
drop of variables in the visualization
r852 }
New helper class for the drag&drop
r840 void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget)
{
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 }
VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const
{
Format changes
r847 return impl->m_CurrentDragWidget;
New helper class for the drag&drop
r840 }
Format changes
r847 QWidget &DragDropHelper::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 }
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 void DragDropHelper::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 }
void DragDropHelper::removePlaceHolder()
{
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 }
}
bool DragDropHelper::isPlaceHolderSet() const
{
Format changes
r847 return impl->m_PlaceHolder->parentWidget();
New helper class for the drag&drop
r840 }
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 void DragDropHelper::addDragDropScrollArea(QScrollArea *scrollArea)
{
Format changes
r847 impl->m_DragDropScroller->addScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 }
void DragDropHelper::removeDragDropScrollArea(QScrollArea *scrollArea)
{
Format changes
r847 impl->m_DragDropScroller->removeScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r843 }
New event filter class to manage the tab switching of a tabBar during a drag&drop
r892 void DragDropHelper::addDragDropTabBar(QTabBar *tabBar)
{
impl->m_DragDropTabSwitcher->addTabBar(tabBar);
}
void DragDropHelper::removeDragDropTabBar(QTabBar *tabBar)
{
impl->m_DragDropTabSwitcher->removeTabBar(tabBar);
}
Format changes
r847 QUrl DragDropHelper::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
Improves visual effect of dropping a variable in a graph
r879 void DragDropHelper::setHightlightedDragWidget(VisualizationDragWidget *dragWidget)
{
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 }
drop of variable inside an existing graph
r881 VisualizationDragWidget *DragDropHelper::getHightlightedDragWidget() const
{
return impl->m_HighlightedDragWidget;
}
Thibaud Rabillard
Fix for D&D bug on mac
r912 void DragDropHelper::delayedCloseWidget(QWidget *widget)
{
widget->hide();
impl->m_WidgetToClose << widget;
}
void DragDropHelper::doCloseWidgets()
{
for (auto widget : impl->m_WidgetToClose) {
widget->close();
}
impl->m_WidgetToClose.clear();
}
drop of variables in the visualization
r852 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
VisualizationDragDropContainer *dropContainer)
{
Drag of product
r876 if (!mimeData || !dropContainer) {
qCWarning(LOG_DragDropHelper()) << QObject::tr(
"DragDropHelper::checkMimeDataForVisualization, invalid input parameters.");
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 {
qCWarning(LOG_DragDropHelper()) << QObject::tr(
"DragDropHelper::checkMimeDataForVisualization, the parent "
"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 }
}
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
return result;
}