VisualizationWidget.cpp
131 lines
| 4.3 KiB
| text/x-c
|
CppLexer
r95 | #include "Visualization/VisualizationWidget.h" | |||
|
r207 | #include "Visualization/IVisualizationWidgetVisitor.h" | ||
|
r176 | #include "Visualization/VisualizationGraphWidget.h" | ||
r95 | #include "Visualization/VisualizationTabWidget.h" | |||
|
r176 | #include "Visualization/VisualizationZoneWidget.h" | ||
|
r248 | #include "Visualization/operations/GenerateVariableMenuOperation.h" | ||
r118 | #include "Visualization/qcustomplot.h" | |||
r58 | #include "ui_VisualizationWidget.h" | |||
r88 | ||||
#include <QToolButton> | ||||
Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") | ||||
r58 | ||||
VisualizationWidget::VisualizationWidget(QWidget *parent) | ||||
r91 | : QWidget{parent}, ui{new Ui::VisualizationWidget} | |||
r58 | { | |||
ui->setupUi(this); | ||||
r88 | ||||
r91 | auto addTabViewButton = new QToolButton{ui->tabWidget}; | |||
addTabViewButton->setText(tr("Add View")); | ||||
r88 | addTabViewButton->setCursor(Qt::ArrowCursor); | |||
ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); | ||||
r186 | ||||
|
r188 | auto enableMinimumCornerWidgetSize = [this](bool enable) { | ||
r186 | ||||
auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); | ||||
auto width = enable ? tabViewCornerWidget->width() : 0; | ||||
auto height = enable ? tabViewCornerWidget->height() : 0; | ||||
tabViewCornerWidget->setMinimumHeight(height); | ||||
tabViewCornerWidget->setMinimumWidth(width); | ||||
ui->tabWidget->setMinimumHeight(height); | ||||
ui->tabWidget->setMinimumWidth(width); | ||||
}; | ||||
|
r188 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { | ||
|
r198 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), | ||
ui->tabWidget}; | ||||
auto index = ui->tabWidget->addTab(widget, widget->name()); | ||||
r186 | if (ui->tabWidget->count() > 0) { | |||
|
r188 | enableMinimumCornerWidgetSize(false); | ||
r186 | } | |||
r88 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); | |||
}; | ||||
|
r188 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { | ||
r186 | if (ui->tabWidget->count() == 1) { | |||
|
r188 | enableMinimumCornerWidgetSize(true); | ||
r186 | } | |||
|
r267 | // Removes widget from tab and closes it | ||
auto widget = ui->tabWidget->widget(index); | ||||
r88 | ui->tabWidget->removeTab(index); | |||
|
r267 | if (widget) { | ||
widget->close(); | ||||
} | ||||
r88 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); | |||
r186 | ||||
r88 | }; | |||
ui->tabWidget->setTabsClosable(true); | ||||
connect(addTabViewButton, &QToolButton::clicked, addTabView); | ||||
connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); | ||||
|
r199 | |||
// Adds default tab | ||||
addTabView(); | ||||
r58 | } | |||
VisualizationWidget::~VisualizationWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r118 | ||||
void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) | ||||
{ | ||||
// NOTE: check is this method has to be deleted because of its dupplicated version visible as | ||||
// lambda function (in the constructor) | ||||
} | ||||
VisualizationTabWidget *VisualizationWidget::createTab() | ||||
{ | ||||
} | ||||
void VisualizationWidget::removeTab(VisualizationTabWidget *tab) | ||||
{ | ||||
// NOTE: check is this method has to be deleted because of its dupplicated version visible as | ||||
// lambda function (in the constructor) | ||||
} | ||||
|
r207 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r118 | { | |||
|
r208 | if (visitor) { | ||
visitor->visitEnter(this); | ||||
// Apply visitor for tab children | ||||
for (auto i = 0; i < ui->tabWidget->count(); ++i) { | ||||
|
r220 | // Widgets different from tabs are not visited (no action) | ||
|
r208 | if (auto visualizationTabWidget | ||
= dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | ||||
visualizationTabWidget->accept(visitor); | ||||
} | ||||
} | ||||
visitor->visitLeave(this); | ||||
} | ||||
|
r219 | else { | ||
qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); | ||||
} | ||||
r118 | } | |||
|
r209 | bool VisualizationWidget::canDrop(const Variable &variable) const | ||
{ | ||||
// The main widget can never accomodate a variable | ||||
Q_UNUSED(variable); | ||||
return false; | ||||
} | ||||
r119 | QString VisualizationWidget::name() const | |||
r118 | { | |||
return QStringLiteral("MainView"); | ||||
} | ||||
|
r175 | |||
|
r248 | void VisualizationWidget::attachVariableMenu(QMenu *menu, | ||
std::shared_ptr<Variable> variable) noexcept | ||||
|
r175 | { | ||
|
r248 | // Generates the actions that make it possible to visualize the variable | ||
auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | ||||
accept(&generateVariableMenuOperation); | ||||
|
r175 | } | ||