VisualizationZoneWidget.cpp
97 lines
| 2.8 KiB
| text/x-c
|
CppLexer
r93 | #include "Visualization/VisualizationZoneWidget.h" | |||
Alexandre Leroux
|
r192 | #include "Visualization/IVisualizationWidgetVisitor.h" | ||
r58 | #include "ui_VisualizationZoneWidget.h" | |||
r111 | #include "Visualization/VisualizationGraphWidget.h" | |||
Alexandre Leroux
|
r245 | #include <SqpApplication.h> | ||
Alexandre Leroux
|
r204 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | ||
Alexandre Leroux
|
r186 | 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
|
r183 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | ||
r89 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} | |||
r58 | { | |||
ui->setupUi(this); | ||||
Alexandre Leroux
|
r183 | |||
ui->zoneNameLabel->setText(name); | ||||
Alexandre Leroux
|
r245 | |||
// 'Close' options : widget is deleted when closed | ||||
setAttribute(Qt::WA_DeleteOnClose); | ||||
connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | ||||
ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | ||||
r58 | } | |||
VisualizationZoneWidget::~VisualizationZoneWidget() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r111 | ||||
void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | ||||
{ | ||||
ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | ||||
} | ||||
Alexandre Leroux
|
r186 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | ||
r111 | { | |||
Alexandre Leroux
|
r186 | auto graphWidget = new VisualizationGraphWidget{ | ||
defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | ||||
r111 | this->addGraph(graphWidget); | |||
Alexandre Leroux
|
r186 | graphWidget->addVariable(variable); | ||
r111 | return graphWidget; | |||
} | ||||
Alexandre Leroux
|
r192 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r111 | { | |||
Alexandre Leroux
|
r193 | 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)) { | ||||
Alexandre Leroux
|
r205 | // Widgets different from graphs are not visited (no action) | ||
Alexandre Leroux
|
r193 | if (auto visualizationGraphWidget | ||
= dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | ||||
visualizationGraphWidget->accept(visitor); | ||||
} | ||||
} | ||||
} | ||||
visitor->visitLeave(this); | ||||
} | ||||
Alexandre Leroux
|
r204 | else { | ||
qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | ||||
} | ||||
r111 | } | |||
Alexandre Leroux
|
r194 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | ||
{ | ||||
// A tab can always accomodate a variable | ||||
Q_UNUSED(variable); | ||||
return true; | ||||
} | ||||
r112 | QString VisualizationZoneWidget::name() const | |||
r111 | { | |||
Alexandre Leroux
|
r183 | return ui->zoneNameLabel->text(); | ||
r111 | } | |||