##// END OF EJS Templates
Revert "Remove worse commit"...
Revert "Remove worse commit" This reverts commit a6522680236132283b040266dfb186fb73be0d8f.

File last commit:

r220:d787e1653d55
r255:120010a3d4ff
Show More
VisualizationZoneWidget.cpp
100 lines | 2.7 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationZoneWidget.cpp
#include "Visualization/VisualizationZoneWidget.h"
#include "Visualization/IVisualizationWidgetVisitor.h"
#include "ui_VisualizationZoneWidget.h"
#include "Visualization/VisualizationGraphWidget.h"
Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
namespace {
/// Generates a default name for a new graph, according to the number of graphs already displayed in
/// the zone
QString defaultGraphName(const QLayout &layout)
{
auto count = 0;
for (auto i = 0; i < layout.count(); ++i) {
if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
count++;
}
}
return QObject::tr("Graph %1").arg(count + 1);
}
} // namespace
VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
: QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
{
ui->setupUi(this);
ui->zoneNameLabel->setText(name);
}
VisualizationZoneWidget::~VisualizationZoneWidget()
{
delete ui;
}
void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
{
ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
}
VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
{
auto graphWidget = new VisualizationGraphWidget{
defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
this->addGraph(graphWidget);
graphWidget->addVariable(variable);
return graphWidget;
}
void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
{
}
void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
{
if (visitor) {
visitor->visitEnter(this);
// Apply visitor to graph children
auto layout = ui->visualizationZoneFrame->layout();
for (auto i = 0; i < layout->count(); ++i) {
if (auto item = layout->itemAt(i)) {
// Widgets different from graphs are not visited (no action)
if (auto visualizationGraphWidget
= dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
visualizationGraphWidget->accept(visitor);
}
}
}
visitor->visitLeave(this);
}
else {
qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
}
}
bool VisualizationZoneWidget::canDrop(const Variable &variable) const
{
// A tab can always accomodate a variable
Q_UNUSED(variable);
return true;
}
void VisualizationZoneWidget::close()
{
// The main view cannot be directly closed.
return;
}
QString VisualizationZoneWidget::name() const
{
return ui->zoneNameLabel->text();
}