VisualizationZoneWidget.cpp
72 lines
| 1.7 KiB
| text/x-c
|
CppLexer
r95 | #include "Visualization/VisualizationZoneWidget.h" | |||
Alexandre Leroux
|
r207 | #include "Visualization/IVisualizationWidgetVisitor.h" | ||
r58 | #include "ui_VisualizationZoneWidget.h" | |||
r118 | #include "Visualization/VisualizationGraphWidget.h" | |||
Alexandre Leroux
|
r200 | 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 | ||||
Alexandre Leroux
|
r197 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | ||
r91 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} | |||
r58 | { | |||
ui->setupUi(this); | ||||
Alexandre Leroux
|
r197 | |||
ui->zoneNameLabel->setText(name); | ||||
r58 | } | |||
VisualizationZoneWidget::~VisualizationZoneWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r118 | ||||
void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | ||||
{ | ||||
ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | ||||
} | ||||
Alexandre Leroux
|
r200 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | ||
r118 | { | |||
Alexandre Leroux
|
r200 | auto graphWidget = new VisualizationGraphWidget{ | ||
defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | ||||
r118 | this->addGraph(graphWidget); | |||
Alexandre Leroux
|
r200 | graphWidget->addVariable(variable); | ||
r118 | return graphWidget; | |||
} | ||||
void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) | ||||
{ | ||||
} | ||||
Alexandre Leroux
|
r207 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r118 | { | |||
// TODO: manage the visitor | ||||
} | ||||
void VisualizationZoneWidget::close() | ||||
{ | ||||
// The main view cannot be directly closed. | ||||
return; | ||||
} | ||||
r119 | QString VisualizationZoneWidget::name() const | |||
r118 | { | |||
Alexandre Leroux
|
r197 | return ui->zoneNameLabel->text(); | ||
r118 | } | |||