VisualizationWidget.cpp
136 lines
| 4.3 KiB
| text/x-c
|
CppLexer
r93 | #include "Visualization/VisualizationWidget.h" | |||
Alexandre Leroux
|
r192 | #include "Visualization/IVisualizationWidgetVisitor.h" | ||
Alexandre Leroux
|
r163 | #include "Visualization/VisualizationGraphWidget.h" | ||
r93 | #include "Visualization/VisualizationTabWidget.h" | |||
Alexandre Leroux
|
r163 | #include "Visualization/VisualizationZoneWidget.h" | ||
r111 | #include "Visualization/qcustomplot.h" | |||
r58 | #include "ui_VisualizationWidget.h" | |||
r87 | ||||
#include <QToolButton> | ||||
Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") | ||||
r58 | ||||
VisualizationWidget::VisualizationWidget(QWidget *parent) | ||||
r89 | : QWidget{parent}, ui{new Ui::VisualizationWidget} | |||
r58 | { | |||
ui->setupUi(this); | ||||
r87 | ||||
r89 | auto addTabViewButton = new QToolButton{ui->tabWidget}; | |||
addTabViewButton->setText(tr("Add View")); | ||||
r87 | addTabViewButton->setCursor(Qt::ArrowCursor); | |||
ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); | ||||
r173 | ||||
Alexandre Leroux
|
r175 | auto enableMinimumCornerWidgetSize = [this](bool enable) { | ||
r173 | ||||
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); | ||||
}; | ||||
Alexandre Leroux
|
r175 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { | ||
Alexandre Leroux
|
r184 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), | ||
ui->tabWidget}; | ||||
auto index = ui->tabWidget->addTab(widget, widget->name()); | ||||
r173 | if (ui->tabWidget->count() > 0) { | |||
Alexandre Leroux
|
r175 | enableMinimumCornerWidgetSize(false); | ||
r173 | } | |||
r87 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); | |||
}; | ||||
Alexandre Leroux
|
r175 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { | ||
r173 | if (ui->tabWidget->count() == 1) { | |||
Alexandre Leroux
|
r175 | enableMinimumCornerWidgetSize(true); | ||
r173 | } | |||
r87 | ui->tabWidget->removeTab(index); | |||
qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); | ||||
r173 | ||||
r87 | }; | |||
ui->tabWidget->setTabsClosable(true); | ||||
connect(addTabViewButton, &QToolButton::clicked, addTabView); | ||||
connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); | ||||
Alexandre Leroux
|
r185 | |||
// Adds default tab | ||||
addTabView(); | ||||
r58 | } | |||
VisualizationWidget::~VisualizationWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r111 | ||||
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) | ||||
} | ||||
Alexandre Leroux
|
r192 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r111 | { | |||
Alexandre Leroux
|
r193 | if (visitor) { | ||
visitor->visitEnter(this); | ||||
// Apply visitor for tab children | ||||
for (auto i = 0; i < ui->tabWidget->count(); ++i) { | ||||
Alexandre Leroux
|
r205 | // Widgets different from tabs are not visited (no action) | ||
Alexandre Leroux
|
r193 | if (auto visualizationTabWidget | ||
= dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | ||||
visualizationTabWidget->accept(visitor); | ||||
} | ||||
} | ||||
visitor->visitLeave(this); | ||||
} | ||||
Alexandre Leroux
|
r204 | else { | ||
qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); | ||||
} | ||||
r111 | } | |||
Alexandre Leroux
|
r194 | bool VisualizationWidget::canDrop(const Variable &variable) const | ||
{ | ||||
// The main widget can never accomodate a variable | ||||
Q_UNUSED(variable); | ||||
return false; | ||||
} | ||||
r111 | void VisualizationWidget::close() | |||
{ | ||||
// The main view cannot be directly closed. | ||||
return; | ||||
} | ||||
r112 | QString VisualizationWidget::name() const | |||
r111 | { | |||
return QStringLiteral("MainView"); | ||||
} | ||||
Alexandre Leroux
|
r162 | |||
void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept | ||||
{ | ||||
Alexandre Leroux
|
r163 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { | ||
Alexandre Leroux
|
r188 | if (!currentTab->createZone(variable)) { | ||
Alexandre Leroux
|
r175 | qCCritical(LOG_VisualizationWidget()) | ||
Alexandre Leroux
|
r163 | << tr("Can't display the variable : can't create a new zone in the current tab"); | ||
} | ||||
} | ||||
else { | ||||
Alexandre Leroux
|
r175 | qCCritical(LOG_VisualizationWidget()) | ||
Alexandre Leroux
|
r163 | << tr("Can't display the variable : there is no current tab"); | ||
} | ||||
Alexandre Leroux
|
r162 | } | ||