VisualizationZoneWidget.cpp
105 lines
| 3.0 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
|
r265 | #include <SqpApplication.h> | ||
Alexandre Leroux
|
r219 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | ||
Alexandre Leroux
|
r200 | namespace { | ||
Alexandre Leroux
|
r307 | /// Minimum height for graph added in zones (in pixels) | ||
const auto GRAPH_MINIMUM_HEIGHT = 300; | ||||
Alexandre Leroux
|
r200 | /// 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); | ||||
Alexandre Leroux
|
r265 | |||
// '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; | ||||
} | ||||
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}; | ||||
Alexandre Leroux
|
r307 | |||
// Set graph properties | ||||
graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | ||||
graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); | ||||
r118 | this->addGraph(graphWidget); | |||
Alexandre Leroux
|
r200 | graphWidget->addVariable(variable); | ||
r118 | return graphWidget; | |||
} | ||||
Alexandre Leroux
|
r207 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | ||
r118 | { | |||
Alexandre Leroux
|
r208 | 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
|
r220 | // Widgets different from graphs are not visited (no action) | ||
Alexandre Leroux
|
r208 | if (auto visualizationGraphWidget | ||
= dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | ||||
visualizationGraphWidget->accept(visitor); | ||||
} | ||||
} | ||||
} | ||||
visitor->visitLeave(this); | ||||
} | ||||
Alexandre Leroux
|
r219 | else { | ||
qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | ||||
} | ||||
r118 | } | |||
Alexandre Leroux
|
r209 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | ||
{ | ||||
// A tab can always accomodate a variable | ||||
Q_UNUSED(variable); | ||||
return true; | ||||
} | ||||
r119 | QString VisualizationZoneWidget::name() const | |||
r118 | { | |||
Alexandre Leroux
|
r197 | return ui->zoneNameLabel->text(); | ||
r118 | } | |||