VisualizationTabWidget.cpp
110 lines
| 2.9 KiB
| text/x-c
|
CppLexer
r93 | #include "Visualization/VisualizationTabWidget.h" | |||
Alexandre Leroux
|
r192 | #include "Visualization/IVisualizationWidgetVisitor.h" | ||
r58 | #include "ui_VisualizationTabWidget.h" | |||
r111 | #include "Visualization/VisualizationZoneWidget.h" | |||
Alexandre Leroux
|
r204 | Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget") | ||
Alexandre Leroux
|
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 | ||||
Alexandre Leroux
|
r184 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { | ||
explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} | ||||
r111 | ||||
Alexandre Leroux
|
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); | ||||
Alexandre Leroux
|
r247 | |||
// Widget is deleted when closed | ||||
setAttribute(Qt::WA_DeleteOnClose); | ||||
r58 | } | |||
VisualizationTabWidget::~VisualizationTabWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r111 | ||||
void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | ||||
{ | ||||
Alexandre Leroux
|
r284 | tabLayout().addWidget(zoneWidget); | ||
r111 | } | |||
Alexandre Leroux
|
r187 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | ||
r111 | { | |||
Alexandre Leroux
|
r284 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(tabLayout()), this}; | ||
r111 | this->addZone(zoneWidget); | |||
Alexandre Leroux
|
r187 | // Creates a new graph into the zone | ||
zoneWidget->createGraph(variable); | ||||
r111 | return zoneWidget; | |||
} | ||||
Alexandre Leroux
|
r192 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r111 | { | |||
Alexandre Leroux
|
r193 | if (visitor) { | ||
visitor->visitEnter(this); | ||||
// Apply visitor to zone children | ||||
Alexandre Leroux
|
r284 | auto &layout = tabLayout(); | ||
for (auto i = 0; i < layout.count(); ++i) { | ||||
if (auto item = layout.itemAt(i)) { | ||||
Alexandre Leroux
|
r205 | // Widgets different from zones are not visited (no action) | ||
Alexandre Leroux
|
r193 | if (auto visualizationZoneWidget | ||
= dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | ||||
visualizationZoneWidget->accept(visitor); | ||||
} | ||||
} | ||||
} | ||||
visitor->visitLeave(this); | ||||
} | ||||
Alexandre Leroux
|
r204 | else { | ||
qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); | ||||
} | ||||
r111 | } | |||
Alexandre Leroux
|
r194 | bool VisualizationTabWidget::canDrop(const Variable &variable) const | ||
{ | ||||
// A tab can always accomodate a variable | ||||
Q_UNUSED(variable); | ||||
return true; | ||||
} | ||||
Alexandre Leroux
|
r301 | bool VisualizationTabWidget::contains(const Variable &variable) const | ||
{ | ||||
Q_UNUSED(variable); | ||||
return false; | ||||
} | ||||
r112 | QString VisualizationTabWidget::name() const | |||
r111 | { | |||
Alexandre Leroux
|
r184 | return impl->m_Name; | ||
r111 | } | |||
Alexandre Leroux
|
r284 | |||
QLayout &VisualizationTabWidget::tabLayout() const noexcept | ||||
{ | ||||
return *ui->scrollAreaWidgetContents->layout(); | ||||
} | ||||