From 34e951298f9e088ad40a0177d922e5259cdcacf7 Mon Sep 17 00:00:00 2001 From: Zach H Date: Tue, 1 Dec 2020 11:30:22 -0500 Subject: [PATCH] Address a handful of warnings from #6095 (#4199) --- cockatrice/src/dlg_update.cpp | 16 ++++++++-------- cockatrice/src/dlg_update.h | 8 ++++---- cockatrice/src/playertarget.cpp | 13 +++++++------ cockatrice/src/remoteclient.cpp | 20 ++++++++++---------- cockatrice/src/remoteclient.h | 6 +++--- cockatrice/src/tab_deck_editor.cpp | 21 +++++++++++---------- cockatrice/src/userinfobox.cpp | 11 ++++++----- 7 files changed, 49 insertions(+), 46 deletions(-) diff --git a/cockatrice/src/dlg_update.cpp b/cockatrice/src/dlg_update.cpp index 86ba00a9..98d318ad 100644 --- a/cockatrice/src/dlg_update.cpp +++ b/cockatrice/src/dlg_update.cpp @@ -45,7 +45,7 @@ DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent) connect(stopDownload, SIGNAL(clicked()), this, SLOT(cancelDownload())); connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog())); - QVBoxLayout *parentLayout = new QVBoxLayout(this); + auto *parentLayout = new QVBoxLayout(this); parentLayout->addWidget(descriptionLabel); parentLayout->addWidget(statusLabel); parentLayout->addWidget(progress); @@ -54,8 +54,8 @@ DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent) setLayout(parentLayout); setWindowTitle(tr("Check for Client Updates")); - setFixedHeight(sizeHint().height()); - setFixedWidth(sizeHint().width()); + setFixedHeight(this->sizeHint().height()); + setFixedWidth(this->sizeHint().width()); // Check for SSL (this probably isn't necessary) if (!QSslSocket::supportsSsl()) { @@ -144,7 +144,7 @@ void DlgUpdate::finishedUpdateCheck(bool needToUpdate, bool isCompatible, Releas return; } - publishDate = release->getPublishDate().toString(Qt::DefaultLocaleLongDate); + publishDate = release->getPublishDate().toString(QLocale().dateFormat(QLocale::LongFormat)); if (isCompatible) { int reply; reply = QMessageBox::question( @@ -194,19 +194,19 @@ void DlgUpdate::enableOkButton(bool enable) ok->setEnabled(enable); } -void DlgUpdate::setLabel(QString newText) +void DlgUpdate::setLabel(const QString &newText) { statusLabel->setText(newText); } -void DlgUpdate::updateCheckError(QString errorString) +void DlgUpdate::updateCheckError(const QString &errorString) { setLabel(tr("Error")); QMessageBox::critical(this, tr("Update Error"), tr("An error occurred while checking for updates:") + QString(" ") + errorString); } -void DlgUpdate::downloadError(QString errorString) +void DlgUpdate::downloadError(const QString &errorString) { setLabel(tr("Error")); enableUpdateButton(true); @@ -214,7 +214,7 @@ void DlgUpdate::downloadError(QString errorString) tr("An error occurred while downloading an update:") + QString(" ") + errorString); } -void DlgUpdate::downloadSuccessful(QUrl filepath) +void DlgUpdate::downloadSuccessful(const QUrl &filepath) { setLabel(tr("Installing...")); // Try to open the installer. If it opens, quit Cockatrice diff --git a/cockatrice/src/dlg_update.h b/cockatrice/src/dlg_update.h index 2c8f2bbb..42cfc5f5 100644 --- a/cockatrice/src/dlg_update.h +++ b/cockatrice/src/dlg_update.h @@ -19,10 +19,10 @@ private slots: void gotoDownloadPage(); void downloadUpdate(); void cancelDownload(); - void updateCheckError(QString errorString); - void downloadSuccessful(QUrl filepath); + void updateCheckError(const QString &errorString); + void downloadSuccessful(const QUrl &filepath); void downloadProgressMade(qint64 bytesRead, qint64 totalBytes); - void downloadError(QString errorString); + void downloadError(const QString &errorString); void closeDialog(); private: @@ -31,7 +31,7 @@ private: void enableOkButton(bool enable); void addStopDownloadAndRemoveOthers(bool enable); void beginUpdateCheck(); - void setLabel(QString text); + void setLabel(const QString &text); QLabel *statusLabel, *descriptionLabel; QProgressBar *progress; QPushButton *manualDownload, *gotoDownload, *ok, *stopDownload; diff --git a/cockatrice/src/playertarget.cpp b/cockatrice/src/playertarget.cpp index fb4c9f3d..194bfcda 100644 --- a/cockatrice/src/playertarget.cpp +++ b/cockatrice/src/playertarget.cpp @@ -24,7 +24,7 @@ PlayerCounter::PlayerCounter(Player *_player, QRectF PlayerCounter::boundingRect() const { - return QRectF(0, 0, 50, 30); + return {0, 0, 50, 30}; } void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) @@ -56,13 +56,14 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /* } PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem, QWidget *_game) - : ArrowTarget(_owner, parentItem), playerCounter(0), game(_game) + : ArrowTarget(_owner, parentItem), playerCounter(nullptr), game(_game) { setCacheMode(DeviceCoordinateCache); const std::string &bmp = _owner->getUserInfo()->avatar_bmp(); - if (!fullPixmap.loadFromData((const uchar *)bmp.data(), bmp.size())) + if (!fullPixmap.loadFromData((const uchar *)bmp.data(), static_cast(bmp.size()))) { fullPixmap = QPixmap(); + } } PlayerTarget::~PlayerTarget() @@ -74,7 +75,7 @@ PlayerTarget::~PlayerTarget() QRectF PlayerTarget::boundingRect() const { - return QRectF(0, 0, 160, 64); + return {0, 0, 160, 64}; } void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) @@ -153,7 +154,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, int _value) { if (playerCounter) { - disconnect(playerCounter, 0, this, 0); + disconnect(playerCounter, nullptr, this, nullptr); playerCounter->delCounter(); } @@ -167,5 +168,5 @@ AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, void PlayerTarget::counterDeleted() { - playerCounter = 0; + playerCounter = nullptr; } diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index d6fb7bd8..47f22744 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -337,9 +337,9 @@ void RemoteClient::websocketMessageReceived(const QByteArray &message) void RemoteClient::sendCommandContainer(const CommandContainer &cont) { #if GOOGLE_PROTOBUF_VERSION > 3001000 - unsigned int size = cont.ByteSizeLong(); + auto size = static_cast(cont.ByteSizeLong()); #else - unsigned int size = cont.ByteSize(); + auto size = static_cast(cont.ByteSize()); #endif #ifdef QT_DEBUG qDebug() << "OUT" << size << QString::fromStdString(cont.ShortDebugString()); @@ -419,7 +419,7 @@ void RemoteClient::doActivateToServer(const QString &_token) token = _token.trimmed(); - connectToHost(lastHostname, static_cast(lastPort)); + connectToHost(lastHostname, lastPort); setStatus(StatusActivating); } @@ -502,7 +502,7 @@ void RemoteClient::disconnectFromServer() emit sigDisconnectFromServer(); } -QString RemoteClient::getSrvClientID(const QString _hostname) +QString RemoteClient::getSrvClientID(const QString &_hostname) { QString srvClientID = SettingsCache::instance().getClientID(); QHostInfo hostInfo = QHostInfo::fromName(_hostname); @@ -518,11 +518,11 @@ QString RemoteClient::getSrvClientID(const QString _hostname) return uniqueServerClientID; } -bool RemoteClient::newMissingFeatureFound(QString _serversMissingFeatures) +bool RemoteClient::newMissingFeatureFound(const QString &_serversMissingFeatures) { bool newMissingFeature = false; QStringList serversMissingFeaturesList = _serversMissingFeatures.split(","); - foreach (const QString &feature, serversMissingFeaturesList) { + for (const QString &feature : serversMissingFeaturesList) { if (!feature.isEmpty()) { if (!SettingsCache::instance().getKnownMissingFeatures().contains(feature)) return true; @@ -535,7 +535,7 @@ void RemoteClient::clearNewClientFeatures() { QString newKnownMissingFeatures; QStringList existingKnownMissingFeatures = SettingsCache::instance().getKnownMissingFeatures().split(","); - foreach (const QString &existingKnownFeature, existingKnownMissingFeatures) { + for (const QString &existingKnownFeature : existingKnownMissingFeatures) { if (!existingKnownFeature.isEmpty()) { if (!clientFeatures.contains(existingKnownFeature)) newKnownMissingFeatures.append("," + existingKnownFeature); @@ -566,7 +566,7 @@ void RemoteClient::doRequestForgotPasswordToServer(const QString &hostname, unsi lastHostname = hostname; lastPort = port; - connectToHost(lastHostname, static_cast(lastPort)); + connectToHost(lastHostname, lastPort); setStatus(StatusRequestingForgotPassword); } @@ -598,7 +598,7 @@ void RemoteClient::doSubmitForgotPasswordResetToServer(const QString &hostname, token = _token.trimmed(); password = _newpassword; - connectToHost(lastHostname, static_cast(lastPort)); + connectToHost(lastHostname, lastPort); setStatus(StatusSubmitForgotPasswordReset); } @@ -632,7 +632,7 @@ void RemoteClient::doSubmitForgotPasswordChallengeToServer(const QString &hostna lastPort = port; email = _email; - connectToHost(lastHostname, static_cast(lastPort)); + connectToHost(lastHostname, lastPort); setStatus(StatusSubmitForgotPasswordChallenge); } diff --git a/cockatrice/src/remoteclient.h b/cockatrice/src/remoteclient.h index 3639a0ab..9ae7e628 100644 --- a/cockatrice/src/remoteclient.h +++ b/cockatrice/src/remoteclient.h @@ -97,10 +97,10 @@ private: QTcpSocket *socket; QWebSocket *websocket; QString lastHostname; - int lastPort; + unsigned int lastPort; - QString getSrvClientID(QString _hostname); - bool newMissingFeatureFound(QString _serversMissingFeatures); + QString getSrvClientID(const QString &_hostname); + bool newMissingFeatureFound(const QString &_serversMissingFeatures); void clearNewClientFeatures(); void connectToHost(const QString &hostname, unsigned int port); diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index bcb46501..061412c0 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -138,9 +138,9 @@ void TabDeckEditor::createDeckDock() lowerLayout->addWidget(deckView, 1, 0, 1, 5); // Create widgets for both layouts to make splitter work correctly - QWidget *topWidget = new QWidget; + auto *topWidget = new QWidget; topWidget->setLayout(upperLayout); - QWidget *bottomWidget = new QWidget; + auto *bottomWidget = new QWidget; bottomWidget->setLayout(lowerLayout); auto *split = new QSplitter; @@ -163,7 +163,7 @@ void TabDeckEditor::createDeckDock() deckDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); deckDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); - QWidget *deckDockContents = new QWidget(); + auto *deckDockContents = new QWidget(); deckDockContents->setObjectName("deckDockContents"); deckDockContents->setLayout(rightFrame); deckDock->setWidget(deckDockContents); @@ -187,7 +187,7 @@ void TabDeckEditor::createCardInfoDock() cardInfoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); cardInfoDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); - QWidget *cardInfoDockContents = new QWidget(); + auto *cardInfoDockContents = new QWidget(); cardInfoDockContents->setObjectName("cardInfoDockContents"); cardInfoDockContents->setLayout(cardInfoFrame); cardInfoDock->setWidget(cardInfoDockContents); @@ -249,7 +249,7 @@ void TabDeckEditor::createFiltersDock() filterDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); - QWidget *filterDockContents = new QWidget(this); + auto *filterDockContents = new QWidget(this); filterDockContents->setObjectName("filterDockContents"); filterDockContents->setLayout(filterFrame); filterDock->setWidget(filterDockContents); @@ -475,7 +475,7 @@ void TabDeckEditor::databaseCustomMenu(QPoint point) relatedMenu->setDisabled(true); } else { for (const CardRelation *rel : relatedCards) { - QString relatedCardName = rel->getName(); + const QString &relatedCardName = rel->getName(); QAction *relatedCard = relatedMenu->addAction(relatedCardName); connect(relatedCard, &QAction::triggered, cardInfo, [this, relatedCardName] { cardInfo->setCard(relatedCardName); }); @@ -874,7 +874,7 @@ void TabDeckEditor::actSaveDeckToClipboardRaw() void TabDeckEditor::actPrintDeck() { - QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this); + auto *dlg = new QPrintPreviewDialog(this); connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *))); dlg->exec(); } @@ -932,8 +932,9 @@ void TabDeckEditor::actClearFilterAll() void TabDeckEditor::actClearFilterOne() { QModelIndexList selIndexes = filterView->selectionModel()->selectedIndexes(); - foreach (QModelIndex idx, selIndexes) + for (QModelIndex idx : selIndexes) { filterModel->removeRow(idx.row(), idx.parent()); + } } void TabDeckEditor::recursiveExpand(const QModelIndex &index) @@ -1248,7 +1249,7 @@ void TabDeckEditor::showSearchSyntaxHelp() .replace(QRegularExpression("^(##)(.*)", opts), "

\\2

") .replace(QRegularExpression("^(#)(.*)", opts), "

\\2

") .replace(QRegularExpression("^------*", opts), "
") - .replace(QRegularExpression("\\[([^\[]+)\\]\\(([^\\)]+)\\)", opts), "\\1"); + .replace(QRegularExpression(R"(\[([^[]+)\]\(([^\)]+)\))", opts), R"(\1)"); auto browser = new QTextBrowser; browser->setParent(this, Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | @@ -1261,6 +1262,6 @@ void TabDeckEditor::showSearchSyntaxHelp() browser->document()->setDefaultStyleSheet(sheet); browser->setHtml(text); - connect(browser, &QTextBrowser::anchorClicked, [=](QUrl link) { searchEdit->setText(link.fragment()); }); + connect(browser, &QTextBrowser::anchorClicked, [=](const QUrl &link) { searchEdit->setText(link.fragment()); }); browser->show(); } diff --git a/cockatrice/src/userinfobox.cpp b/cockatrice/src/userinfobox.cpp index 7a767475..33b0ad61 100644 --- a/cockatrice/src/userinfobox.cpp +++ b/cockatrice/src/userinfobox.cpp @@ -31,13 +31,13 @@ UserInfoBox::UserInfoBox(AbstractClient *_client, bool _editable, QWidget *paren avatarLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); avatarLabel.setAlignment(Qt::AlignCenter); - QHBoxLayout *avatarLayout = new QHBoxLayout; + auto *avatarLayout = new QHBoxLayout; avatarLayout->setContentsMargins(0, 0, 0, 0); avatarLayout->addStretch(1); avatarLayout->addWidget(&avatarLabel, 3); avatarLayout->addStretch(1); - QGridLayout *mainLayout = new QGridLayout; + auto *mainLayout = new QGridLayout; mainLayout->addLayout(avatarLayout, 0, 0, 1, 3); mainLayout->addWidget(&nameLabel, 1, 0, 1, 3); mainLayout->addWidget(&realNameLabel1, 2, 0, 1, 1); @@ -53,7 +53,7 @@ UserInfoBox::UserInfoBox(AbstractClient *_client, bool _editable, QWidget *paren mainLayout->setColumnStretch(2, 10); if (editable) { - QHBoxLayout *buttonsLayout = new QHBoxLayout; + auto *buttonsLayout = new QHBoxLayout; buttonsLayout->addWidget(&editButton); buttonsLayout->addWidget(&passwordButton); buttonsLayout->addWidget(&avatarButton); @@ -85,10 +85,11 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user) { const UserLevelFlags userLevel(user.user_level()); - const std::string bmp = user.avatar_bmp(); - if (!avatarPixmap.loadFromData((const uchar *)bmp.data(), bmp.size())) + const std::string &bmp = user.avatar_bmp(); + if (!avatarPixmap.loadFromData((const uchar *)bmp.data(), static_cast(bmp.size()))) { avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel, false, QString::fromStdString(user.privlevel())); + } avatarLabel.setPixmap(avatarPixmap.scaled(400, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation)); nameLabel.setText(QString::fromStdString(user.name()));