##// END OF EJS Templates
Comments variable cancellation after a drop as it is not sure if it is really needed.
Comments variable cancellation after a drop as it is not sure if it is really needed.

File last commit:

r842:52187f027c9a
r842:52187f027c9a
Show More
VisualizationTabWidget.cpp
219 lines | 6.6 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationTabWidget.cpp
mv visualization -> Visualization...
r95 #include "Visualization/VisualizationTabWidget.h"
Alexandre Leroux
Updates visitor interface...
r207 #include "Visualization/IVisualizationWidgetVisitor.h"
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 #include "ui_VisualizationTabWidget.h"
Add the visualization gui classes
r118 #include "Visualization/VisualizationZoneWidget.h"
Integrates the drag&drop classes into the existing visualization classes.
r839 #include "Visualization/VisualizationGraphWidget.h"
Manage drag&drop of empty graphs
r841 #include "Variable/VariableController.h"
Integrates the drag&drop classes into the existing visualization classes.
r839 #include "SqpApplication.h"
#include "DragDropHelper.h"
Add the visualization gui classes
r118
Alexandre Leroux
Adds logs for null visitors
r219 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
Alexandre Leroux
Completes the method of creating a zone from a variable
r201 namespace {
/// Generates a default name for a new zone, according to the number of zones already displayed in
/// the tab
QString defaultZoneName(const QLayout &layout)
{
auto count = 0;
for (auto i = 0; i < layout.count(); ++i) {
if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
count++;
}
}
return QObject::tr("Zone %1").arg(count + 1);
}
Alexandre Leroux
Handles desynchronisation when removing variable from a graph (2)...
r738 /**
* Applies a function to all zones of the tab represented by its layout
* @param layout the layout that contains zones
* @param fun the function to apply to each zone
*/
template <typename Fun>
void processZones(QLayout &layout, Fun fun)
{
for (auto i = 0; i < layout.count(); ++i) {
if (auto item = layout.itemAt(i)) {
if (auto visualizationZoneWidget
= dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
fun(*visualizationZoneWidget);
}
}
}
}
Alexandre Leroux
Completes the method of creating a zone from a variable
r201 } // namespace
Alexandre Leroux
Adds a name for a tab...
r198 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
Add the visualization gui classes
r118
Alexandre Leroux
Adds a name for a tab...
r198 QString m_Name;
};
VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
: QWidget{parent},
ui{new Ui::VisualizationTabWidget},
impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 {
ui->setupUi(this);
Alexandre Leroux
Updates tab widget so it can be deleted when closed
r267
Integrates the drag&drop classes into the existing visualization classes.
r839 ui->dragDropContainer->setAcceptedMimeTypes({DragDropHelper::MIME_TYPE_GRAPH, DragDropHelper::MIME_TYPE_ZONE});
connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccured, this, &VisualizationTabWidget::dropMimeData);
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 sqpApp->dragDropHelper().addDragDropScrollArea(ui->scrollArea);
Integrates the drag&drop classes into the existing visualization classes.
r839
Alexandre Leroux
Updates tab widget so it can be deleted when closed
r267 // Widget is deleted when closed
setAttribute(Qt::WA_DeleteOnClose);
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 }
VisualizationTabWidget::~VisualizationTabWidget()
{
Manage the scroll of the tab QScrollArea during a drag&drop operation
r840 sqpApp->dragDropHelper().removeDragDropScrollArea(ui->scrollArea);
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 delete ui;
}
Add the visualization gui classes
r118
void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
{
Integrates the drag&drop classes into the existing visualization classes.
r839 ui->dragDropContainer->addDragWidget(zoneWidget);
}
void VisualizationTabWidget::insertZone(int index, VisualizationZoneWidget *zoneWidget)
{
ui->dragDropContainer->insertDragWidget(index, zoneWidget);
Add the visualization gui classes
r118 }
Alexandre Leroux
Completes the method of creating a zone from a variable
r201 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
Add the visualization gui classes
r118 {
Integrates the drag&drop classes into the existing visualization classes.
r839 return createZone({variable}, -1);
}
VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index)
{
Manage drag&drop of empty graphs
r841 auto zoneWidget = createEmptyZone(index);
Add the visualization gui classes
r118
Alexandre Leroux
Completes the method of creating a zone from a variable
r201 // Creates a new graph into the zone
Integrates the drag&drop classes into the existing visualization classes.
r839 zoneWidget->createGraph(variables, index);
Alexandre Leroux
Completes the method of creating a zone from a variable
r201
Add the visualization gui classes
r118 return zoneWidget;
}
Manage drag&drop of empty graphs
r841 VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index)
{
auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this};
this->insertZone(index, zoneWidget);
return zoneWidget;
}
Alexandre Leroux
Updates visitor interface...
r207 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
Add the visualization gui classes
r118 {
Alexandre Leroux
Implements accept() method of visualization widgets
r208 if (visitor) {
visitor->visitEnter(this);
Alexandre Leroux
Handles desynchronisation when removing variable from a graph (2)...
r738 // Apply visitor to zone children: widgets different from zones are not visited (no action)
processZones(tabLayout(), [visitor](VisualizationZoneWidget &zoneWidget) {
zoneWidget.accept(visitor);
});
Alexandre Leroux
Implements accept() method of visualization widgets
r208
visitor->visitLeave(this);
}
Alexandre Leroux
Adds logs for null visitors
r219 else {
qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
}
Add the visualization gui classes
r118 }
Alexandre Leroux
Creates a interface that defines a variable container...
r209 bool VisualizationTabWidget::canDrop(const Variable &variable) const
{
// A tab can always accomodate a variable
Q_UNUSED(variable);
return true;
}
Alexandre Leroux
Unplot menu (5): adds contains() method to an IVariableContainer...
r327 bool VisualizationTabWidget::contains(const Variable &variable) const
{
Q_UNUSED(variable);
return false;
}
Add const and override
r119 QString VisualizationTabWidget::name() const
Add the visualization gui classes
r118 {
Alexandre Leroux
Adds a name for a tab...
r198 return impl->m_Name;
Add the visualization gui classes
r118 }
Alexandre Leroux
Adds scrollbar to tabs
r307
Alexandre Leroux
Handles desynchronisation when removing variable from a graph (2)...
r738 void VisualizationTabWidget::closeEvent(QCloseEvent *event)
{
// Closes zones in the tab
processZones(tabLayout(), [](VisualizationZoneWidget &zoneWidget) { zoneWidget.close(); });
QWidget::closeEvent(event);
}
Alexandre Leroux
Adds scrollbar to tabs
r307 QLayout &VisualizationTabWidget::tabLayout() const noexcept
{
Integrates the drag&drop classes into the existing visualization classes.
r839 return *ui->dragDropContainer->layout();
}
void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
{
auto& helper = sqpApp->dragDropHelper();
if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_GRAPH))
{
auto graphWidget = static_cast<VisualizationGraphWidget*>(helper.getCurrentDragWidget());
auto parentDragDropContainer = qobject_cast<VisualizationDragDropContainer*>(graphWidget->parentWidget());
Q_ASSERT(parentDragDropContainer);
auto nbGraph = parentDragDropContainer->countDragWidget();
Manage drag&drop of empty graphs
r841
const auto& variables = graphWidget->variables();
if (!variables.isEmpty())
Integrates the drag&drop classes into the existing visualization classes.
r839 {
Comments variable cancellation after a drop as it is not sure if it is really needed.
r842 //Abort the requests for the variables (if any)
//Commented, because it's not sure if it's needed or not
//for (const auto& var : variables)
//{
// sqpApp->variableController().onAbortProgressRequested(var);
//}
Manage drag&drop of empty graphs
r841 if (nbGraph == 1)
{
//This is the only graph in the previous zone, close the zone
graphWidget->parentZoneWidget()->close();
}
else
{
//Close the graph
graphWidget->close();
}
createZone(variables, index);
Integrates the drag&drop classes into the existing visualization classes.
r839 }
else
{
Manage drag&drop of empty graphs
r841 //The graph is empty, create an empty zone and move the graph inside
Integrates the drag&drop classes into the existing visualization classes.
r839
Manage drag&drop of empty graphs
r841 auto parentZoneWidget = graphWidget->parentZoneWidget();
parentDragDropContainer->layout()->removeWidget(graphWidget);
auto zoneWidget = createEmptyZone(index);
zoneWidget->addGraph(graphWidget);
//Close the old zone if it was the only graph inside
if (nbGraph == 1)
parentZoneWidget->close();
}
Integrates the drag&drop classes into the existing visualization classes.
r839 }
else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE))
{
//Simple move of the zone, no variable operation associated
auto zoneWidget = static_cast<VisualizationZoneWidget*>(helper.getCurrentDragWidget());
auto parentDragDropContainer = zoneWidget->parentWidget();
parentDragDropContainer->layout()->removeWidget(zoneWidget);
ui->dragDropContainer->insertDragWidget(index, zoneWidget);
}
Alexandre Leroux
Adds scrollbar to tabs
r307 }