VisualizationTabWidget.cpp
77 lines
| 1.8 KiB
| text/x-c
|
CppLexer
r93 | #include "Visualization/VisualizationTabWidget.h" | |||
r58 | #include "ui_VisualizationTabWidget.h" | |||
r111 | #include "Visualization/VisualizationZoneWidget.h" | |||
|
r187 | 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); | ||||
} | ||||
} // namespace | ||||
|
r184 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { | ||
explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} | ||||
r111 | ||||
|
r184 | QString m_Name; | ||
}; | ||||
VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) | ||||
: QWidget{parent}, | ||||
ui{new Ui::VisualizationTabWidget}, | ||||
impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} | ||||
r58 | { | |||
ui->setupUi(this); | ||||
} | ||||
VisualizationTabWidget::~VisualizationTabWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r111 | ||||
void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | ||||
{ | ||||
this->layout()->addWidget(zoneWidget); | ||||
} | ||||
|
r187 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | ||
r111 | { | |||
|
r187 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; | ||
r111 | this->addZone(zoneWidget); | |||
|
r187 | // Creates a new graph into the zone | ||
zoneWidget->createGraph(variable); | ||||
r111 | return zoneWidget; | |||
} | ||||
void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone) | ||||
{ | ||||
} | ||||
void VisualizationTabWidget::accept(IVisualizationWidget *visitor) | ||||
{ | ||||
// TODO: manage the visitor | ||||
} | ||||
void VisualizationTabWidget::close() | ||||
{ | ||||
// The main view cannot be directly closed. | ||||
return; | ||||
} | ||||
r112 | QString VisualizationTabWidget::name() const | |||
r111 | { | |||
|
r184 | return impl->m_Name; | ||
r111 | } | |||