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());
m_buttons.push_back(btn);
mapper->setMapping(btn, idx);
connect(btn, SIGNAL(clicked()), mapper, SLOT(map()));
connect(btn, &QPushButton::clicked, mapper, qOverload<>(&QSignalMapper::map));
++col;
if (col >= kCols)
@@ -81,7 +81,7 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
++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->setCheckable(true);

View File

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

View File

@@ -36,10 +36,10 @@ HeaderBar::HeaderBar(QWidget* parent)
layout->addWidget(btn);
m_speedButtons.push_back(btn);
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());
}
@@ -70,3 +70,4 @@ void HeaderBar::onSpeedButton(int 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);
// Signals: game world → other panels
connect(m_gameWorldView, SIGNAL(selectionChanged(std::vector<EntityId>)),
m_selectedBuildingPanel, SLOT(onSelectionChanged(std::vector<EntityId>)));
connect(m_gameWorldView, &GameWorldView::selectionChanged,
m_selectedBuildingPanel, &SelectedBuildingPanel::onSelectionChanged);
connect(m_gameWorldView, SIGNAL(stateUpdated(Tick, int, double)),
m_headerBar, SLOT(onStateUpdated(Tick, int, double)));
connect(m_gameWorldView, &GameWorldView::stateUpdated,
m_headerBar, &HeaderBar::onStateUpdated);
connect(m_gameWorldView, SIGNAL(stateUpdated(Tick, int, double)),
this, SLOT(onStateUpdated(Tick, int, double))); // for affordability
connect(m_gameWorldView, &GameWorldView::stateUpdated,
this, &MainWindow::onStateUpdated); // for affordability
connect(m_gameWorldView, SIGNAL(stateUpdated(Tick, int, double)),
m_selectedBuildingPanel, SLOT(onStateUpdated(Tick, int, double)));
connect(m_gameWorldView, &GameWorldView::stateUpdated,
m_selectedBuildingPanel, &SelectedBuildingPanel::onStateUpdated);
connect(m_gameWorldView, SIGNAL(gameOver()),
this, SLOT(onGameOver()));
connect(m_gameWorldView, &GameWorldView::gameOver,
this, &MainWindow::onGameOver);
connect(m_gameWorldView, SIGNAL(escapeMenuRequested()),
this, SLOT(onEscapeMenuRequested()));
connect(m_gameWorldView, &GameWorldView::escapeMenuRequested,
this, &MainWindow::onEscapeMenuRequested);
// Signals: build grid → game world
connect(m_buildButtonGrid, SIGNAL(buildingTypeSelected(BuildingType)),
m_gameWorldView, SLOT(enterBuilderMode(BuildingType)));
connect(m_buildButtonGrid, &BuildButtonGrid::buildingTypeSelected,
m_gameWorldView, &GameWorldView::enterBuilderMode);
connect(m_buildButtonGrid, SIGNAL(builderModeExited()),
m_gameWorldView, SLOT(exitBuilderMode()));
connect(m_buildButtonGrid, &BuildButtonGrid::builderModeExited,
m_gameWorldView, &GameWorldView::exitBuilderMode);
connect(m_gameWorldView, SIGNAL(builderModeExited()),
m_buildButtonGrid, SLOT(clearActiveButton()));
connect(m_gameWorldView, &GameWorldView::builderModeExited,
m_buildButtonGrid, &BuildButtonGrid::clearActiveButton);
connect(m_buildButtonGrid, SIGNAL(demolishModeToggleRequested()),
m_gameWorldView, SLOT(toggleDemolishMode()));
connect(m_buildButtonGrid, &BuildButtonGrid::demolishModeToggleRequested,
m_gameWorldView, &GameWorldView::toggleDemolishMode);
connect(m_gameWorldView, SIGNAL(demolishModeChanged(bool)),
m_buildButtonGrid, SLOT(setDemolishModeActive(bool)));
connect(m_gameWorldView, &GameWorldView::demolishModeChanged,
m_buildButtonGrid, &BuildButtonGrid::setDemolishModeActive);
// Signals: header bar → game world
connect(m_headerBar, SIGNAL(speedChanged(double)),
m_gameWorldView, SLOT(setGameSpeed(double)));
connect(m_headerBar, &HeaderBar::speedChanged,
m_gameWorldView, &GameWorldView::setGameSpeed);
m_gameWorldView->setFocus();

View File

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