Merge pull request #3031 from Trial97/lambda

do not capture by default all values in lambdas
This commit is contained in:
Alexandru Ionut Tripon
2024-11-07 23:45:31 +02:00
committed by GitHub
38 changed files with 194 additions and 211 deletions

View File

@@ -112,7 +112,7 @@ static QStringList BrowseForFileInternal(QString context,
QFileDialog w(parentWidget, caption);
QSet<QString> locations;
auto f = [&](QStandardPaths::StandardLocation l) {
auto f = [&locations](QStandardPaths::StandardLocation l) {
QString location = QStandardPaths::writableLocation(l);
QFileInfo finfo(location);
if (!finfo.exists()) {

View File

@@ -154,7 +154,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
// Qt doesn't like vertical moving toolbars, so we have to force them...
// See https://github.com/PolyMC/PolyMC/issues/493
connect(ui->instanceToolBar, &QToolBar::orientationChanged,
[=](Qt::Orientation) { ui->instanceToolBar->setOrientation(Qt::Vertical); });
[this](Qt::Orientation) { ui->instanceToolBar->setOrientation(Qt::Vertical); });
// if you try to add a widget to a toolbar in a .ui file
// qt designer will delete it when you save the file >:(

View File

@@ -148,10 +148,14 @@ void ResourceDownloadDialog::confirm()
QStringList depNames;
if (auto task = getModDependenciesTask(); task) {
connect(task.get(), &Task::failed, this,
[&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
connect(task.get(), &Task::succeeded, this, [&]() {
QStringList warnings = task->warnings();
auto weak = task.toWeakRef();
connect(task.get(), &Task::succeeded, this, [this, weak]() {
QStringList warnings;
if (auto task = weak.lock()) {
warnings = task->warnings();
}
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec();
}

View File

@@ -111,9 +111,9 @@ void ResourceUpdateDialog::checkCandidates()
}
connect(&check_task, &Task::failed, this,
[&](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
connect(&check_task, &Task::succeeded, this, [&]() {
connect(&check_task, &Task::succeeded, this, [this, &check_task]() {
QStringList warnings = check_task.warnings();
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec();
@@ -197,11 +197,15 @@ void ResourceUpdateDialog::checkCandidates()
if (mod_model != nullptr) {
auto depTask = makeShared<GetModDependenciesTask>(this, m_instance, mod_model, selectedVers);
connect(depTask.get(), &Task::failed, this,
[&](const QString& reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); });
connect(depTask.get(), &Task::succeeded, this, [&]() {
QStringList warnings = depTask->warnings();
connect(depTask.get(), &Task::failed, this, [this](const QString& reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec();
});
auto weak = depTask.toWeakRef();
connect(depTask.get(), &Task::succeeded, this, [this, weak]() {
QStringList warnings;
if (auto depTask = weak.lock()) {
warnings = depTask->warnings();
}
if (warnings.count()) {
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->exec();
}
@@ -277,7 +281,7 @@ auto ResourceUpdateDialog::ensureMetadata() -> bool
bool skip_rest = false;
ModPlatform::ResourceProvider provider_rest = ModPlatform::ResourceProvider::MODRINTH;
auto addToTmp = [&](Resource* resource, ModPlatform::ResourceProvider p) {
auto addToTmp = [&modrinth_tmp, &flame_tmp](Resource* resource, ModPlatform::ResourceProvider p) {
switch (p) {
case ModPlatform::ResourceProvider::MODRINTH:
modrinth_tmp.push_back(resource);

View File

@@ -90,7 +90,7 @@ class LogFormatProxyModel : public QIdentityProxyModel {
QModelIndex find(const QModelIndex& start, const QString& value, bool reverse) const
{
QModelIndex parentIndex = parent(start);
auto compare = [&](int r) -> QModelIndex {
auto compare = [this, start, parentIndex, value](int r) -> QModelIndex {
QModelIndex idx = index(r, start.column(), parentIndex);
if (!idx.isValid() || idx == start) {
return QModelIndex();

View File

@@ -138,7 +138,7 @@ void OtherLogsPage::on_btnReload_clicked()
m_currentFile = QString();
QMessageBox::critical(this, tr("Error"), tr("Unable to open %1 for reading: %2").arg(m_currentFile, file.errorString()));
} else {
auto setPlainText = [&](const QString& text) {
auto setPlainText = [this](const QString& text) {
QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString();
bool conversionOk = false;
int fontSize = APPLICATION->settings()->get("ConsoleFontSize").toInt(&conversionOk);
@@ -149,7 +149,7 @@ void OtherLogsPage::on_btnReload_clicked()
doc->setDefaultFont(QFont(fontFamily, fontSize));
ui->text->setPlainText(text);
};
auto showTooBig = [&]() {
auto showTooBig = [setPlainText, &file]() {
setPlainText(tr("The file (%1) is too big. You may want to open it in a viewer optimized "
"for large files.")
.arg(file.fileName()));

View File

@@ -337,7 +337,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
auto icon_fetch_action = Net::ApiDownload::makeCached(url, cache_entry);
auto full_file_path = cache_entry->getFullPath();
connect(icon_fetch_action.get(), &Task::succeeded, this, [=] {
connect(icon_fetch_action.get(), &Task::succeeded, this, [this, url, full_file_path, index] {
auto icon = QIcon(full_file_path);
QPixmapCache::insert(url.toString(), icon.pixmap(icon.actualSize({ 64, 64 })));
@@ -345,7 +345,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
emit dataChanged(index, index, { Qt::DecorationRole });
});
connect(icon_fetch_action.get(), &Task::failed, this, [=] {
connect(icon_fetch_action.get(), &Task::failed, this, [this, url] {
m_currently_running_icon_actions.remove(url);
m_failed_icon_actions.insert(url);
});

View File

@@ -57,7 +57,7 @@ void SetupWizard::pageChanged(int id)
if (basePagePtr->wantsRefreshButton()) {
setButtonLayout({ QWizard::CustomButton1, QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::FinishButton });
auto customButton = button(QWizard::CustomButton1);
connect(customButton, &QAbstractButton::clicked, [&]() {
connect(customButton, &QAbstractButton::clicked, [this]() {
auto basePagePtr = getCurrentBasePage();
if (basePagePtr) {
basePagePtr->refresh();

View File

@@ -181,7 +181,7 @@ bool CustomTheme::read(const QString& path, bool& hasCustomLogColors)
m_widgets = Json::requireString(root, "widgets", "Qt widget theme");
m_qssFilePath = Json::ensureString(root, "qssFilePath", "themeStyle.css");
auto readColor = [&](const QJsonObject& colors, const QString& colorName) -> QColor {
auto readColor = [](const QJsonObject& colors, const QString& colorName) -> QColor {
auto colorValue = Json::ensureString(colors, colorName, QString());
if (!colorValue.isEmpty()) {
QColor color(colorValue);
@@ -196,7 +196,7 @@ bool CustomTheme::read(const QString& path, bool& hasCustomLogColors)
if (root.contains("colors")) {
auto colorsRoot = Json::requireObject(root, "colors");
auto readAndSetPaletteColor = [&](QPalette::ColorRole role, const QString& colorName) {
auto readAndSetPaletteColor = [this, readColor, colorsRoot](QPalette::ColorRole role, const QString& colorName) {
auto color = readColor(colorsRoot, colorName);
if (color.isValid()) {
m_palette.setColor(role, color);
@@ -229,7 +229,7 @@ bool CustomTheme::read(const QString& path, bool& hasCustomLogColors)
hasCustomLogColors = true;
auto logColorsRoot = Json::requireObject(root, "logColors");
auto readAndSetLogColor = [&](MessageLevel::Enum level, bool fg, const QString& colorName) {
auto readAndSetLogColor = [this, readColor, logColorsRoot](MessageLevel::Enum level, bool fg, const QString& colorName) {
auto color = readColor(logColorsRoot, colorName);
if (color.isValid()) {
if (fg)