##// END OF EJS Templates
Parser refactoring (1)...
Parser refactoring (1) Creates a helper that will be used to read the properties and values of an AMDA file, to generate the dataset. The helper is intended to replace the current implementation of the parser, to be more generic and thus manage the spectrograms more easily

File last commit:

r912:fedc6e2cf64d
r944:e1494a5194f1
Show More
DragDropHelper.cpp
294 lines | 9.8 KiB | text/x-c | CppLexer
Moves the DragDropHelper file
r884 #include "DragAndDrop/DragDropHelper.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
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 Q_LOGGING_CATEGORY(LOG_DragDropHelper, "DragDropHelper")
drop of variables in the visualization
r850
New helper class for the drag&drop
r837
struct DragDropHelper::DragDropHelperPrivate {
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;
New helper class for the drag&drop
r837 explicit DragDropHelperPrivate()
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 }
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 void preparePlaceHolder(DragDropHelper::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) {
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
r837 }
};
Fix format for linux
r912 DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()}
{
}
New helper class for the drag&drop
r837
DragDropHelper::~DragDropHelper()
{
Format changes
r844 QFile::remove(impl->m_ImageTempUrl);
New helper class for the drag&drop
r837 }
drop of variables in the visualization
r850 void DragDropHelper::resetDragAndDrop()
{
setCurrentDragWidget(nullptr);
Improves visual effect of dropping a variable in a graph
r873 impl->m_HighlightedDragWidget = nullptr;
drop of variables in the visualization
r850 }
New helper class for the drag&drop
r837 void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget)
{
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 }
VisualizationDragWidget *DragDropHelper::getCurrentDragWidget() const
{
Format changes
r844 return impl->m_CurrentDragWidget;
New helper class for the drag&drop
r837 }
Format changes
r844 QWidget &DragDropHelper::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 }
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 void DragDropHelper::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 }
void DragDropHelper::removePlaceHolder()
{
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 }
}
bool DragDropHelper::isPlaceHolderSet() const
{
Format changes
r844 return impl->m_PlaceHolder->parentWidget();
New helper class for the drag&drop
r837 }
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 void DragDropHelper::addDragDropScrollArea(QScrollArea *scrollArea)
{
Format changes
r844 impl->m_DragDropScroller->addScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 }
void DragDropHelper::removeDragDropScrollArea(QScrollArea *scrollArea)
{
Format changes
r844 impl->m_DragDropScroller->removeScrollArea(scrollArea);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 }
New event filter class to manage the tab switching of a tabBar during a drag&drop
r886 void DragDropHelper::addDragDropTabBar(QTabBar *tabBar)
{
impl->m_DragDropTabSwitcher->addTabBar(tabBar);
}
void DragDropHelper::removeDragDropTabBar(QTabBar *tabBar)
{
impl->m_DragDropTabSwitcher->removeTabBar(tabBar);
}
Format changes
r844 QUrl DragDropHelper::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
Improves visual effect of dropping a variable in a graph
r873 void DragDropHelper::setHightlightedDragWidget(VisualizationDragWidget *dragWidget)
{
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 }
drop of variable inside an existing graph
r875 VisualizationDragWidget *DragDropHelper::getHightlightedDragWidget() const
{
return impl->m_HighlightedDragWidget;
}
Thibaud Rabillard
Fix for D&D bug on mac
r911 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
r850 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
VisualizationDragDropContainer *dropContainer)
{
Drag of product
r868 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
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 {
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
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;
}