From 2bd80763e7513896772e9ba62cb469e0906bc3d7 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Fri, 22 Dec 2017 15:13:42 +0100 Subject: [PATCH] Fix some obvious warnings Ignore some stupid warnings --- chatterino.pro | 9 +++- src/setting.hpp | 8 ++-- src/util/urlfetch.hpp | 16 +++---- src/widgets/accountpopup.cpp | 6 +-- src/widgets/basewidget.cpp | 3 -- src/widgets/basewidget.hpp | 10 +---- src/widgets/helper/channelview.cpp | 70 +++++++++++++++--------------- 7 files changed, 59 insertions(+), 63 deletions(-) diff --git a/chatterino.pro b/chatterino.pro index 9e64e994f..1c71d8e4a 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -21,13 +21,20 @@ DEFINES += QT_DEPRECATED_WARNINGS # Define warning flags for Chatterino win32-msvc* { - QMAKE_CXXFLAGS_WARN_ON = -W4 + QMAKE_CXXFLAGS_WARN_ON = /W4 # 4714 - function marked as __forceinline not inlined # 4996 - occurs when the compiler encounters a function or variable that is marked as deprecated. # These functions may have a different preferred name, may be insecure or have # a more secure variant, or may be obsolete. + # 4505 - unreferenced local version has been removed + # 4127 - conditional expression is constant + # 4503 - decorated name length exceeded, name was truncated QMAKE_CXXFLAGS_WARN_ON += /wd4714 QMAKE_CXXFLAGS_WARN_ON += /wd4996 + QMAKE_CXXFLAGS_WARN_ON += /wd4505 + QMAKE_CXXFLAGS_WARN_ON += /wd4127 + QMAKE_CXXFLAGS_WARN_ON += /wd4503 + } else { QMAKE_CXXFLAGS_WARN_ON = -Wall QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-function diff --git a/src/setting.hpp b/src/setting.hpp index b22463809..781367a19 100644 --- a/src/setting.hpp +++ b/src/setting.hpp @@ -62,11 +62,11 @@ public: return QVariant::fromValue(this->value); } - virtual void setVariant(QVariant value) final + virtual void setVariant(QVariant newValue) final { - if (value.isValid()) { - assert(value.canConvert()); - set(value.value()); + if (newValue.isValid()) { + assert(newValue.canConvert()); + set(newValue.value()); } } diff --git a/src/util/urlfetch.hpp b/src/util/urlfetch.hpp index f322a2382..70be90fd7 100644 --- a/src/util/urlfetch.hpp +++ b/src/util/urlfetch.hpp @@ -2,6 +2,7 @@ #include "accountmanager.hpp" #include "credentials.hpp" +#include "debug/log.hpp" #include "util/networkmanager.hpp" #include @@ -9,13 +10,9 @@ #include #include #include -#include #include #include #include -#include - -#include #include @@ -59,24 +56,24 @@ static void getUserID(QString username, const QObject *caller, get("https://api.twitch.tv/kraken/users?login=" + username, caller, [=](const QJsonObject &root) { if (!root.value("users").isArray()) { - qDebug() << "API Error while getting user id, users is not an array"; + debug::Log("API Error while getting user id, users is not an array"); return; } auto users = root.value("users").toArray(); if (users.size() != 1) { - qDebug() << "API Error while getting user id, users array size is not 1"; + debug::Log("API Error while getting user id, users array size is not 1"); return; } if (!users[0].isObject()) { - qDebug() << "API Error while getting user id, first user is not an object"; + debug::Log("API Error while getting user id, first user is not an object"); return; } auto firstUser = users[0].toObject(); auto id = firstUser.value("_id"); if (!id.isString()) { - qDebug() << "API Error: while getting user id, first user object `_id` key is not " - "a string"; + debug::Log("API Error: while getting user id, first user object `_id` key is not a " + "string"); return; } successCallback(id.toString()); @@ -84,7 +81,6 @@ static void getUserID(QString username, const QObject *caller, } static void put(QUrl url, std::function successCallback) { - auto manager = new QNetworkAccessManager(); QNetworkRequest request(url); auto &accountManager = AccountManager::getInstance(); diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index 0c97dffb0..a770f8fe0 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -200,7 +200,7 @@ void AccountPopupWidget::updatePermissions() } } -void AccountPopupWidget::dpiMultiplierChanged(float oldDpi, float newDpi) +void AccountPopupWidget::dpiMultiplierChanged(float /*oldDpi*/, float newDpi) { this->setStyleSheet(QString("* { font-size: px; }") .replace("", QString::number((int)(12 * newDpi)))); @@ -230,7 +230,7 @@ void AccountPopupWidget::sendCommand(QPushButton *button, QString command) }); } -void AccountPopupWidget::focusOutEvent(QFocusEvent *event) +void AccountPopupWidget::focusOutEvent(QFocusEvent *) { this->hide(); this->ui->lblFollowers->setText("Loading..."); @@ -240,7 +240,7 @@ void AccountPopupWidget::focusOutEvent(QFocusEvent *event) this->ui->lblAvatar->setText("Loading..."); } -void AccountPopupWidget::showEvent(QShowEvent *event) +void AccountPopupWidget::showEvent(QShowEvent *) { AccountManager &accountManager = AccountManager::getInstance(); auto currentTwitchUser = accountManager.Twitch.getCurrent(); diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index c043db4d5..a3f475a8d 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -11,11 +11,9 @@ namespace chatterino { namespace widgets { -// BaseWidget::BaseWidget(ColorScheme &_colorScheme, WindowManager &_windowManager, QWidget *parent) BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent) : QWidget(parent) , colorScheme(_colorScheme) -// , windowManager(_windowManager) { this->init(); } @@ -23,7 +21,6 @@ BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent) BaseWidget::BaseWidget(BaseWidget *parent) : QWidget(parent) , colorScheme(*ColorScheme::instance) -// , windowManager(parent->windowManager) { this->init(); } diff --git a/src/widgets/basewidget.hpp b/src/widgets/basewidget.hpp index e542d9a46..47db2b4a6 100644 --- a/src/widgets/basewidget.hpp +++ b/src/widgets/basewidget.hpp @@ -2,8 +2,6 @@ #include -//#include "windowmanager.hpp" - namespace chatterino { class ColorScheme; @@ -15,8 +13,6 @@ class BaseWidget : public QWidget Q_OBJECT public: - // explicit BaseWidget(ColorScheme &_colorScheme, WindowManager &windowManager, QWidget - // *parent); explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent); explicit BaseWidget(BaseWidget *parent); @@ -27,15 +23,13 @@ public: float getDpiMultiplier(); - // protected: - // WindowManager &windowManager; - protected: #ifdef USEWINSDK virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; #endif - virtual void dpiMultiplierChanged(float oldDpi, float newDpi) + // XXX: Should this be pure virtual? + virtual void dpiMultiplierChanged(float /*oldDpi*/, float /*newDpi*/) { } void initAsWindow(); diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index b4b366734..aafbefad7 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -105,9 +105,9 @@ void ChannelView::layoutMessages() void ChannelView::actuallyLayoutMessages() { // BENCH(timer) - auto messages = this->getMessagesSnapshot(); + auto messagesSnapshot = this->getMessagesSnapshot(); - if (messages.getLength() == 0) { + if (messagesSnapshot.getLength() == 0) { this->scrollBar.setVisible(false); return; @@ -127,11 +127,12 @@ void ChannelView::actuallyLayoutMessages() (this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4; // layout the visible messages in the view - if (messages.getLength() > start) { - int y = -(messages[start]->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1))); + if (messagesSnapshot.getLength() > start) { + int y = + -(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1))); - for (size_t i = start; i < messages.getLength(); ++i) { - auto message = messages[i]; + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + auto message = messagesSnapshot[i]; redrawRequired |= message->layout(layoutWidth, this->getDpiMultiplier()); @@ -146,15 +147,15 @@ void ChannelView::actuallyLayoutMessages() // layout the messages at the bottom to determine the scrollbar thumb size int h = height() - 8; - for (std::size_t i = messages.getLength() - 1; i > 0; i--) { - auto *message = messages[i].get(); + for (std::size_t i = messagesSnapshot.getLength() - 1; i > 0; i--) { + auto *message = messagesSnapshot[i].get(); message->layout(layoutWidth, this->getDpiMultiplier()); h -= message->getHeight(); if (h < 0) { - this->scrollBar.setLargeChange((messages.getLength() - i) + + this->scrollBar.setLargeChange((messagesSnapshot.getLength() - i) + (qreal)h / message->getHeight()); // this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue()); @@ -169,7 +170,7 @@ void ChannelView::actuallyLayoutMessages() this->scrollBar.setDesiredValue(0); } - this->scrollBar.setMaximum(messages.getLength()); + this->scrollBar.setMaximum(messagesSnapshot.getLength()); if (this->showingLatestMessages && showScrollbar) { // If we were showing the latest messages and the scrollbar now wants to be rendered, scroll @@ -212,7 +213,7 @@ ScrollBar &ChannelView::getScrollBar() QString ChannelView::getSelectedText() { - LimitedQueueSnapshot messages = this->getMessagesSnapshot(); + auto messagesSnapshot = this->getMessagesSnapshot(); QString text; bool isSingleMessage = this->selection.isSingleMessage(); @@ -236,7 +237,7 @@ QString ChannelView::getSelectedText() }; // first line - for (const messages::WordPart &part : messages[i]->getWordParts()) { + for (const messages::WordPart &part : messagesSnapshot[i]->getWordParts()) { int charLength = part.getCharacterLength(); if (charIndex + charLength < this->selection.min.charIndex) { @@ -273,7 +274,7 @@ QString ChannelView::getSelectedText() // middle lines for (i++; i < this->selection.max.messageIndex; i++) { - for (const messages::WordPart &part : messages[i]->getWordParts()) { + for (const messages::WordPart &part : messagesSnapshot[i]->getWordParts()) { if (!part.getCopyText().isEmpty()) { text += part.getCopyText(); @@ -289,7 +290,7 @@ QString ChannelView::getSelectedText() charIndex = 0; for (const messages::WordPart &part : - messages[this->selection.max.messageIndex]->getWordParts()) { + messagesSnapshot[this->selection.max.messageIndex]->getWordParts()) { int charLength = part.getCharacterLength(); if (charIndex + charLength >= this->selection.max.charIndex) { @@ -326,7 +327,7 @@ messages::LimitedQueueSnapshot ChannelView::getMessagesSnapsho return this->messages.getSnapshot(); } -void ChannelView::setChannel(std::shared_ptr channel) +void ChannelView::setChannel(std::shared_ptr newChannel) { if (this->channel) { this->detachChannel(); @@ -335,7 +336,7 @@ void ChannelView::setChannel(std::shared_ptr channel) // on new message this->messageAppendedConnection = - channel->messageAppended.connect([this](SharedMessage &message) { + newChannel->messageAppended.connect([this](SharedMessage &message) { SharedMessageRef deleted; auto messageRef = new MessageRef(message); @@ -354,7 +355,7 @@ void ChannelView::setChannel(std::shared_ptr channel) // on message removed this->messageRemovedConnection = - channel->messageRemovedFromStart.connect([this](SharedMessage &) { + newChannel->messageRemovedFromStart.connect([this](SharedMessage &) { this->selection.min.messageIndex--; this->selection.max.messageIndex--; this->selection.start.messageIndex--; @@ -363,7 +364,7 @@ void ChannelView::setChannel(std::shared_ptr channel) this->layoutMessages(); }); - auto snapshot = channel->getMessageSnapshot(); + auto snapshot = newChannel->getMessageSnapshot(); for (size_t i = 0; i < snapshot.getLength(); i++) { SharedMessageRef deleted; @@ -373,9 +374,9 @@ void ChannelView::setChannel(std::shared_ptr channel) this->messages.appendItem(SharedMessageRef(messageRef), deleted); } - this->channel = channel; + this->channel = newChannel; - this->userPopupWidget.setChannel(channel); + this->userPopupWidget.setChannel(newChannel); } void ChannelView::detachChannel() @@ -453,18 +454,19 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/) void ChannelView::drawMessages(QPainter &painter) { - auto messages = this->getMessagesSnapshot(); + auto messagesSnapshot = this->getMessagesSnapshot(); size_t start = this->scrollBar.getCurrentValue(); - if (start >= messages.getLength()) { + if (start >= messagesSnapshot.getLength()) { return; } - int y = -(messages[start].get()->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1))); + int y = -(messagesSnapshot[start].get()->getHeight() * + (fmod(this->scrollBar.getCurrentValue(), 1))); - for (size_t i = start; i < messages.getLength(); ++i) { - messages::MessageRef *messageRef = messages[i].get(); + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + messages::MessageRef *messageRef = messagesSnapshot[i].get(); std::shared_ptr buffer = messageRef->buffer; @@ -806,14 +808,14 @@ void ChannelView::mousePressEvent(QMouseEvent *event) if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) { setCursor(Qt::ArrowCursor); - auto messages = this->getMessagesSnapshot(); - if (messages.getLength() == 0) { + auto messagesSnapshot = this->getMessagesSnapshot(); + if (messagesSnapshot.getLength() == 0) { return; } // Start selection at the last message at its last index - auto lastMessageIndex = messages.getLength() - 1; - auto lastMessage = messages[lastMessageIndex]; + auto lastMessageIndex = messagesSnapshot.getLength() - 1; + auto lastMessage = messagesSnapshot[lastMessageIndex]; auto lastCharacterIndex = lastMessage->getLastCharacterIndex(); SelectionItem selectionItem(lastMessageIndex, lastCharacterIndex); @@ -909,18 +911,18 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr &_message, QPoint &relativePos, int &index) { - auto messages = this->getMessagesSnapshot(); + auto messagesSnapshot = this->getMessagesSnapshot(); size_t start = this->scrollBar.getCurrentValue(); - if (start >= messages.getLength()) { + if (start >= messagesSnapshot.getLength()) { return false; } - int y = -(messages[start]->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1))); + int y = -(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1))); - for (size_t i = start; i < messages.getLength(); ++i) { - auto message = messages[i]; + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + auto message = messagesSnapshot[i]; if (p.y() < y + message->getHeight()) { relativePos = QPoint(p.x(), p.y() - y);