use new signals slots syntax

This commit is contained in:
2026-04-24 22:29:13 +02:00
parent 409ec93d7d
commit b21fc352b4
5 changed files with 35 additions and 34 deletions

View File

@@ -72,7 +72,7 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
const int idx = static_cast<int>(m_buttons.size()); const int idx = static_cast<int>(m_buttons.size());
m_buttons.push_back(btn); m_buttons.push_back(btn);
mapper->setMapping(btn, idx); mapper->setMapping(btn, idx);
connect(btn, SIGNAL(clicked()), mapper, SLOT(map())); connect(btn, &QPushButton::clicked, mapper, qOverload<>(&QSignalMapper::map));
++col; ++col;
if (col >= kCols) if (col >= kCols)
@@ -81,7 +81,7 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
++row; ++row;
} }
} }
connect(mapper, SIGNAL(mapped(int)), this, SLOT(onBuildButton(int))); connect(mapper, qOverload<int>(&QSignalMapper::mapped), this, &BuildButtonGrid::onBuildButton);
m_demolishButton = new QPushButton("Demolish", this); m_demolishButton = new QPushButton("Demolish", this);
m_demolishButton->setCheckable(true); m_demolishButton->setCheckable(true);

View File

@@ -126,7 +126,7 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
m_renderTimer = new QTimer(this); m_renderTimer = new QTimer(this);
m_renderTimer->setInterval(16); m_renderTimer->setInterval(16);
connect(m_renderTimer, SIGNAL(timeout()), this, SLOT(onFrame())); connect(m_renderTimer, &QTimer::timeout, this, &GameWorldView::onFrame);
m_renderTimer->start(); m_renderTimer->start();
m_frameTimer.start(); m_frameTimer.start();
} }

View File

@@ -36,9 +36,9 @@ HeaderBar::HeaderBar(QWidget* parent)
layout->addWidget(btn); layout->addWidget(btn);
m_speedButtons.push_back(btn); m_speedButtons.push_back(btn);
mapper->setMapping(btn, i); mapper->setMapping(btn, i);
connect(btn, SIGNAL(clicked()), mapper, SLOT(map())); connect(btn, &QPushButton::clicked, mapper, qOverload<>(&QSignalMapper::map));
} }
connect(mapper, SIGNAL(mapped(int)), this, SLOT(onSpeedButton(int))); connect(mapper, qOverload<int>(&QSignalMapper::mapped), this, &HeaderBar::onSpeedButton);
setFixedHeight(sizeHint().height()); setFixedHeight(sizeHint().height());
} }
@@ -70,3 +70,4 @@ void HeaderBar::onSpeedButton(int index)
emit speedChanged(kSpeeds[index]); emit speedChanged(kSpeeds[index]);
} }
} }

View File

@@ -41,43 +41,43 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir, QWidget* p
bottomLayout->addWidget(m_buildButtonGrid, 1); bottomLayout->addWidget(m_buildButtonGrid, 1);
// Signals: game world → other panels // Signals: game world → other panels
connect(m_gameWorldView, SIGNAL(selectionChanged(std::vector<EntityId>)), connect(m_gameWorldView, &GameWorldView::selectionChanged,
m_selectedBuildingPanel, SLOT(onSelectionChanged(std::vector<EntityId>))); m_selectedBuildingPanel, &SelectedBuildingPanel::onSelectionChanged);
connect(m_gameWorldView, SIGNAL(stateUpdated(Tick, int, double)), connect(m_gameWorldView, &GameWorldView::stateUpdated,
m_headerBar, SLOT(onStateUpdated(Tick, int, double))); m_headerBar, &HeaderBar::onStateUpdated);
connect(m_gameWorldView, SIGNAL(stateUpdated(Tick, int, double)), connect(m_gameWorldView, &GameWorldView::stateUpdated,
this, SLOT(onStateUpdated(Tick, int, double))); // for affordability this, &MainWindow::onStateUpdated); // for affordability
connect(m_gameWorldView, SIGNAL(stateUpdated(Tick, int, double)), connect(m_gameWorldView, &GameWorldView::stateUpdated,
m_selectedBuildingPanel, SLOT(onStateUpdated(Tick, int, double))); m_selectedBuildingPanel, &SelectedBuildingPanel::onStateUpdated);
connect(m_gameWorldView, SIGNAL(gameOver()), connect(m_gameWorldView, &GameWorldView::gameOver,
this, SLOT(onGameOver())); this, &MainWindow::onGameOver);
connect(m_gameWorldView, SIGNAL(escapeMenuRequested()), connect(m_gameWorldView, &GameWorldView::escapeMenuRequested,
this, SLOT(onEscapeMenuRequested())); this, &MainWindow::onEscapeMenuRequested);
// Signals: build grid → game world // Signals: build grid → game world
connect(m_buildButtonGrid, SIGNAL(buildingTypeSelected(BuildingType)), connect(m_buildButtonGrid, &BuildButtonGrid::buildingTypeSelected,
m_gameWorldView, SLOT(enterBuilderMode(BuildingType))); m_gameWorldView, &GameWorldView::enterBuilderMode);
connect(m_buildButtonGrid, SIGNAL(builderModeExited()), connect(m_buildButtonGrid, &BuildButtonGrid::builderModeExited,
m_gameWorldView, SLOT(exitBuilderMode())); m_gameWorldView, &GameWorldView::exitBuilderMode);
connect(m_gameWorldView, SIGNAL(builderModeExited()), connect(m_gameWorldView, &GameWorldView::builderModeExited,
m_buildButtonGrid, SLOT(clearActiveButton())); m_buildButtonGrid, &BuildButtonGrid::clearActiveButton);
connect(m_buildButtonGrid, SIGNAL(demolishModeToggleRequested()), connect(m_buildButtonGrid, &BuildButtonGrid::demolishModeToggleRequested,
m_gameWorldView, SLOT(toggleDemolishMode())); m_gameWorldView, &GameWorldView::toggleDemolishMode);
connect(m_gameWorldView, SIGNAL(demolishModeChanged(bool)), connect(m_gameWorldView, &GameWorldView::demolishModeChanged,
m_buildButtonGrid, SLOT(setDemolishModeActive(bool))); m_buildButtonGrid, &BuildButtonGrid::setDemolishModeActive);
// Signals: header bar → game world // Signals: header bar → game world
connect(m_headerBar, SIGNAL(speedChanged(double)), connect(m_headerBar, &HeaderBar::speedChanged,
m_gameWorldView, SLOT(setGameSpeed(double))); m_gameWorldView, &GameWorldView::setGameSpeed);
m_gameWorldView->setFocus(); m_gameWorldView->setFocus();

View File

@@ -84,10 +84,10 @@ SelectedBuildingPanel::SelectedBuildingPanel(Simulation* sim,
m_layout->addWidget(m_clearBeltBtn); m_layout->addWidget(m_clearBeltBtn);
m_layout->addWidget(m_buffersLabel); m_layout->addWidget(m_buffersLabel);
connect(m_recipeCombo, SIGNAL(currentIndexChanged(int)), connect(m_recipeCombo, qOverload<int>(&QComboBox::currentIndexChanged),
this, SLOT(onRecipeChanged(int))); this, &SelectedBuildingPanel::onRecipeChanged);
connect(m_clearBeltBtn, SIGNAL(clicked()), connect(m_clearBeltBtn, &QPushButton::clicked,
this, SLOT(onClearBelt())); this, &SelectedBuildingPanel::onClearBelt);
buildEmpty(); buildEmpty();
} }