VisualizationTabWidget.cpp
102 lines
| 2.7 KiB
| text/x-c
|
CppLexer
r95 | #include "Visualization/VisualizationTabWidget.h" | |||
|
r207 | #include "Visualization/IVisualizationWidgetVisitor.h" | ||
r58 | #include "ui_VisualizationTabWidget.h" | |||
r118 | #include "Visualization/VisualizationZoneWidget.h" | |||
|
r219 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") | ||
|
r201 | 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 | ||||
|
r198 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { | ||
explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} | ||||
r118 | ||||
|
r198 | 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); | ||||
|
r267 | |||
// Widget is deleted when closed | ||||
setAttribute(Qt::WA_DeleteOnClose); | ||||
r58 | } | |||
VisualizationTabWidget::~VisualizationTabWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r118 | ||||
void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | ||||
{ | ||||
this->layout()->addWidget(zoneWidget); | ||||
} | ||||
|
r201 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | ||
r118 | { | |||
|
r201 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; | ||
r118 | this->addZone(zoneWidget); | |||
|
r201 | // Creates a new graph into the zone | ||
zoneWidget->createGraph(variable); | ||||
r118 | return zoneWidget; | |||
} | ||||
void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone) | ||||
{ | ||||
} | ||||
|
r207 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r118 | { | |||
|
r208 | if (visitor) { | ||
visitor->visitEnter(this); | ||||
// Apply visitor to zone children | ||||
for (auto i = 0; i < layout()->count(); ++i) { | ||||
if (auto item = layout()->itemAt(i)) { | ||||
|
r220 | // Widgets different from zones are not visited (no action) | ||
|
r208 | if (auto visualizationZoneWidget | ||
= dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | ||||
visualizationZoneWidget->accept(visitor); | ||||
} | ||||
} | ||||
} | ||||
visitor->visitLeave(this); | ||||
} | ||||
|
r219 | else { | ||
qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); | ||||
} | ||||
r118 | } | |||
|
r209 | bool VisualizationTabWidget::canDrop(const Variable &variable) const | ||
{ | ||||
// A tab can always accomodate a variable | ||||
Q_UNUSED(variable); | ||||
return true; | ||||
} | ||||
r119 | QString VisualizationTabWidget::name() const | |||
r118 | { | |||
|
r198 | return impl->m_Name; | ||
r118 | } | |||