From 9fe356527297ce79a9d539167ca5f4c62f93e7ad Mon Sep 17 00:00:00 2001 From: legend-df <78252402+legend-df@users.noreply.github.com> Date: Tue, 14 Oct 2025 11:23:17 +0800 Subject: [PATCH] Add orientation controls to calculator flowcharts --- examples/calculator/FlowchartManager.cpp | 64 +++++++++++++++++++++++- examples/calculator/FlowchartManager.hpp | 13 +++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/examples/calculator/FlowchartManager.cpp b/examples/calculator/FlowchartManager.cpp index 0a58acd2..f7fec9d0 100644 --- a/examples/calculator/FlowchartManager.cpp +++ b/examples/calculator/FlowchartManager.cpp @@ -6,8 +6,10 @@ #include #include +#include #include #include +#include #include @@ -20,6 +22,7 @@ QString createDefaultName(int index) FlowchartPage::FlowchartPage(std::shared_ptr registry, QString displayName, + Qt::Orientation orientation, QWidget *parent) : QWidget(parent) , _model(std::move(registry)) @@ -43,6 +46,7 @@ FlowchartPage::FlowchartPage(std::shared_ptr layout->addWidget(controlsWidget); _scene = new QtNodes::DataFlowGraphicsScene(_model, this); + _scene->setOrientation(orientation); _view = new QtNodes::GraphicsView(_scene); layout->addWidget(_view); @@ -60,6 +64,15 @@ FlowchartPage::FlowchartPage(std::shared_ptr connect(_runButton, &QPushButton::clicked, this, &FlowchartPage::runFlowchart); } +void FlowchartPage::setOrientation(Qt::Orientation orientation) +{ + if (_scene) + _scene->setOrientation(orientation); + + if (_view) + _view->centerScene(); +} + bool FlowchartPage::save() { if (_scene->save()) { @@ -137,6 +150,14 @@ FlowchartManager::FlowchartManager(std::shared_ptraddWidget(_runAllButton); controlsLayout->addStretch(); + auto *orientationLabel = new QLabel(tr("Orientation:"), controlsWidget); + _horizontalOrientationButton = new QRadioButton(tr("Horizontal"), controlsWidget); + _verticalOrientationButton = new QRadioButton(tr("Vertical"), controlsWidget); + + controlsLayout->addWidget(orientationLabel); + controlsLayout->addWidget(_horizontalOrientationButton); + controlsLayout->addWidget(_verticalOrientationButton); + layout->addWidget(controlsWidget); _tabWidget = new QTabWidget(this); @@ -151,6 +172,14 @@ FlowchartManager::FlowchartManager(std::shared_ptrload()) + if (page->load()) { updateTabText(page); + page->setOrientation(_orientation); + } } } @@ -247,7 +279,7 @@ FlowchartPage *FlowchartManager::createFlowchart(QString const &displayName) ++_flowchartCount; auto title = displayName.isEmpty() ? createDefaultName(_flowchartCount) : displayName; - auto *page = new FlowchartPage(_registry, title, _tabWidget); + auto *page = new FlowchartPage(_registry, title, _orientation, _tabWidget); auto index = _tabWidget->addTab(page, title); _tabWidget->setCurrentIndex(index); @@ -260,10 +292,38 @@ FlowchartPage *FlowchartManager::createFlowchart(QString const &displayName) updateTabText(page); updateWindowModifiedFlag(); updateActionsState(); + page->setOrientation(_orientation); return page; } +void FlowchartManager::setOrientation(Qt::Orientation orientation) +{ + if (_orientation == orientation) + return; + + _orientation = orientation; + updateOrientationButtons(); + applyOrientationToAllPages(); +} + +void FlowchartManager::applyOrientationToAllPages() +{ + for (int i = 0; i < _tabWidget->count(); ++i) { + if (auto *page = pageAt(i)) + page->setOrientation(_orientation); + } +} + +void FlowchartManager::updateOrientationButtons() +{ + if (_horizontalOrientationButton) + _horizontalOrientationButton->setChecked(_orientation == Qt::Horizontal); + + if (_verticalOrientationButton) + _verticalOrientationButton->setChecked(_orientation == Qt::Vertical); +} + void FlowchartManager::updateTabText(FlowchartPage *page) { if (!page) diff --git a/examples/calculator/FlowchartManager.hpp b/examples/calculator/FlowchartManager.hpp index fdf8a3bb..ad2341a8 100644 --- a/examples/calculator/FlowchartManager.hpp +++ b/examples/calculator/FlowchartManager.hpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include #include @@ -13,6 +15,7 @@ class QAction; class QPushButton; +class QRadioButton; class FlowchartPage : public QWidget { @@ -21,6 +24,7 @@ class FlowchartPage : public QWidget public: FlowchartPage(std::shared_ptr registry, QString displayName, + Qt::Orientation orientation, QWidget *parent = nullptr); bool save(); @@ -32,6 +36,8 @@ class FlowchartPage : public QWidget void setDisplayName(QString name); + void setOrientation(Qt::Orientation orientation); + public Q_SLOTS: void runFlowchart(); @@ -73,6 +79,10 @@ private Q_SLOTS: FlowchartPage *createFlowchart(QString const &displayName = QString()); + void setOrientation(Qt::Orientation orientation); + void applyOrientationToAllPages(); + void updateOrientationButtons(); + void updateTabText(FlowchartPage *page); void updateWindowModifiedFlag(); void updateActionsState(); @@ -87,5 +97,8 @@ private Q_SLOTS: QAction *_closeAction = nullptr; QPushButton *_runCurrentButton = nullptr; QPushButton *_runAllButton = nullptr; + QRadioButton *_horizontalOrientationButton = nullptr; + QRadioButton *_verticalOrientationButton = nullptr; + Qt::Orientation _orientation = Qt::Horizontal; int _flowchartCount = 0; };