Fix some obvious warnings

Ignore some stupid warnings
This commit is contained in:
Rasmus Karlsson 2017-12-22 15:13:42 +01:00
parent 47647ee4b1
commit 2bd80763e7
7 changed files with 59 additions and 63 deletions

View file

@ -21,13 +21,20 @@ DEFINES += QT_DEPRECATED_WARNINGS
# Define warning flags for Chatterino # Define warning flags for Chatterino
win32-msvc* { win32-msvc* {
QMAKE_CXXFLAGS_WARN_ON = -W4 QMAKE_CXXFLAGS_WARN_ON = /W4
# 4714 - function marked as __forceinline not inlined # 4714 - function marked as __forceinline not inlined
# 4996 - occurs when the compiler encounters a function or variable that is marked as deprecated. # 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 # These functions may have a different preferred name, may be insecure or have
# a more secure variant, or may be obsolete. # 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 += /wd4714
QMAKE_CXXFLAGS_WARN_ON += /wd4996 QMAKE_CXXFLAGS_WARN_ON += /wd4996
QMAKE_CXXFLAGS_WARN_ON += /wd4505
QMAKE_CXXFLAGS_WARN_ON += /wd4127
QMAKE_CXXFLAGS_WARN_ON += /wd4503
} else { } else {
QMAKE_CXXFLAGS_WARN_ON = -Wall QMAKE_CXXFLAGS_WARN_ON = -Wall
QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-function QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-function

View file

@ -62,11 +62,11 @@ public:
return QVariant::fromValue(this->value); return QVariant::fromValue(this->value);
} }
virtual void setVariant(QVariant value) final virtual void setVariant(QVariant newValue) final
{ {
if (value.isValid()) { if (newValue.isValid()) {
assert(value.canConvert<T>()); assert(newValue.canConvert<T>());
set(value.value<T>()); set(newValue.value<T>());
} }
} }

View file

@ -2,6 +2,7 @@
#include "accountmanager.hpp" #include "accountmanager.hpp"
#include "credentials.hpp" #include "credentials.hpp"
#include "debug/log.hpp"
#include "util/networkmanager.hpp" #include "util/networkmanager.hpp"
#include <QEventLoop> #include <QEventLoop>
@ -9,13 +10,9 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
#include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QString> #include <QString>
#include <QTimer>
#include <QDebug>
#include <functional> #include <functional>
@ -59,24 +56,24 @@ static void getUserID(QString username, const QObject *caller,
get("https://api.twitch.tv/kraken/users?login=" + username, caller, get("https://api.twitch.tv/kraken/users?login=" + username, caller,
[=](const QJsonObject &root) { [=](const QJsonObject &root) {
if (!root.value("users").isArray()) { 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; return;
} }
auto users = root.value("users").toArray(); auto users = root.value("users").toArray();
if (users.size() != 1) { 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; return;
} }
if (!users[0].isObject()) { 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; return;
} }
auto firstUser = users[0].toObject(); auto firstUser = users[0].toObject();
auto id = firstUser.value("_id"); auto id = firstUser.value("_id");
if (!id.isString()) { if (!id.isString()) {
qDebug() << "API Error: while getting user id, first user object `_id` key is not " debug::Log("API Error: while getting user id, first user object `_id` key is not a "
"a string"; "string");
return; return;
} }
successCallback(id.toString()); successCallback(id.toString());
@ -84,7 +81,6 @@ static void getUserID(QString username, const QObject *caller,
} }
static void put(QUrl url, std::function<void(QJsonObject)> successCallback) static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
{ {
auto manager = new QNetworkAccessManager();
QNetworkRequest request(url); QNetworkRequest request(url);
auto &accountManager = AccountManager::getInstance(); auto &accountManager = AccountManager::getInstance();

View file

@ -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: <font-size>px; }") this->setStyleSheet(QString("* { font-size: <font-size>px; }")
.replace("<font-size>", QString::number((int)(12 * newDpi)))); .replace("<font-size>", 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->hide();
this->ui->lblFollowers->setText("Loading..."); this->ui->lblFollowers->setText("Loading...");
@ -240,7 +240,7 @@ void AccountPopupWidget::focusOutEvent(QFocusEvent *event)
this->ui->lblAvatar->setText("Loading..."); this->ui->lblAvatar->setText("Loading...");
} }
void AccountPopupWidget::showEvent(QShowEvent *event) void AccountPopupWidget::showEvent(QShowEvent *)
{ {
AccountManager &accountManager = AccountManager::getInstance(); AccountManager &accountManager = AccountManager::getInstance();
auto currentTwitchUser = accountManager.Twitch.getCurrent(); auto currentTwitchUser = accountManager.Twitch.getCurrent();

View file

@ -11,11 +11,9 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
// BaseWidget::BaseWidget(ColorScheme &_colorScheme, WindowManager &_windowManager, QWidget *parent)
BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent) BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, colorScheme(_colorScheme) , colorScheme(_colorScheme)
// , windowManager(_windowManager)
{ {
this->init(); this->init();
} }
@ -23,7 +21,6 @@ BaseWidget::BaseWidget(ColorScheme &_colorScheme, QWidget *parent)
BaseWidget::BaseWidget(BaseWidget *parent) BaseWidget::BaseWidget(BaseWidget *parent)
: QWidget(parent) : QWidget(parent)
, colorScheme(*ColorScheme::instance) , colorScheme(*ColorScheme::instance)
// , windowManager(parent->windowManager)
{ {
this->init(); this->init();
} }

View file

@ -2,8 +2,6 @@
#include <QWidget> #include <QWidget>
//#include "windowmanager.hpp"
namespace chatterino { namespace chatterino {
class ColorScheme; class ColorScheme;
@ -15,8 +13,6 @@ class BaseWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
// explicit BaseWidget(ColorScheme &_colorScheme, WindowManager &windowManager, QWidget
// *parent);
explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent); explicit BaseWidget(ColorScheme &_colorScheme, QWidget *parent);
explicit BaseWidget(BaseWidget *parent); explicit BaseWidget(BaseWidget *parent);
@ -27,15 +23,13 @@ public:
float getDpiMultiplier(); float getDpiMultiplier();
// protected:
// WindowManager &windowManager;
protected: protected:
#ifdef USEWINSDK #ifdef USEWINSDK
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
#endif #endif
virtual void dpiMultiplierChanged(float oldDpi, float newDpi) // XXX: Should this be pure virtual?
virtual void dpiMultiplierChanged(float /*oldDpi*/, float /*newDpi*/)
{ {
} }
void initAsWindow(); void initAsWindow();

View file

@ -105,9 +105,9 @@ void ChannelView::layoutMessages()
void ChannelView::actuallyLayoutMessages() void ChannelView::actuallyLayoutMessages()
{ {
// BENCH(timer) // BENCH(timer)
auto messages = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
if (messages.getLength() == 0) { if (messagesSnapshot.getLength() == 0) {
this->scrollBar.setVisible(false); this->scrollBar.setVisible(false);
return; return;
@ -127,11 +127,12 @@ void ChannelView::actuallyLayoutMessages()
(this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4; (this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4;
// layout the visible messages in the view // layout the visible messages in the view
if (messages.getLength() > start) { if (messagesSnapshot.getLength() > start) {
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) { for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
auto message = messages[i]; auto message = messagesSnapshot[i];
redrawRequired |= message->layout(layoutWidth, this->getDpiMultiplier()); 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 // layout the messages at the bottom to determine the scrollbar thumb size
int h = height() - 8; int h = height() - 8;
for (std::size_t i = messages.getLength() - 1; i > 0; i--) { for (std::size_t i = messagesSnapshot.getLength() - 1; i > 0; i--) {
auto *message = messages[i].get(); auto *message = messagesSnapshot[i].get();
message->layout(layoutWidth, this->getDpiMultiplier()); message->layout(layoutWidth, this->getDpiMultiplier());
h -= message->getHeight(); h -= message->getHeight();
if (h < 0) { if (h < 0) {
this->scrollBar.setLargeChange((messages.getLength() - i) + this->scrollBar.setLargeChange((messagesSnapshot.getLength() - i) +
(qreal)h / message->getHeight()); (qreal)h / message->getHeight());
// this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue()); // this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue());
@ -169,7 +170,7 @@ void ChannelView::actuallyLayoutMessages()
this->scrollBar.setDesiredValue(0); this->scrollBar.setDesiredValue(0);
} }
this->scrollBar.setMaximum(messages.getLength()); this->scrollBar.setMaximum(messagesSnapshot.getLength());
if (this->showingLatestMessages && showScrollbar) { if (this->showingLatestMessages && showScrollbar) {
// If we were showing the latest messages and the scrollbar now wants to be rendered, scroll // 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() QString ChannelView::getSelectedText()
{ {
LimitedQueueSnapshot<SharedMessageRef> messages = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
QString text; QString text;
bool isSingleMessage = this->selection.isSingleMessage(); bool isSingleMessage = this->selection.isSingleMessage();
@ -236,7 +237,7 @@ QString ChannelView::getSelectedText()
}; };
// first line // first line
for (const messages::WordPart &part : messages[i]->getWordParts()) { for (const messages::WordPart &part : messagesSnapshot[i]->getWordParts()) {
int charLength = part.getCharacterLength(); int charLength = part.getCharacterLength();
if (charIndex + charLength < this->selection.min.charIndex) { if (charIndex + charLength < this->selection.min.charIndex) {
@ -273,7 +274,7 @@ QString ChannelView::getSelectedText()
// middle lines // middle lines
for (i++; i < this->selection.max.messageIndex; i++) { 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()) { if (!part.getCopyText().isEmpty()) {
text += part.getCopyText(); text += part.getCopyText();
@ -289,7 +290,7 @@ QString ChannelView::getSelectedText()
charIndex = 0; charIndex = 0;
for (const messages::WordPart &part : for (const messages::WordPart &part :
messages[this->selection.max.messageIndex]->getWordParts()) { messagesSnapshot[this->selection.max.messageIndex]->getWordParts()) {
int charLength = part.getCharacterLength(); int charLength = part.getCharacterLength();
if (charIndex + charLength >= this->selection.max.charIndex) { if (charIndex + charLength >= this->selection.max.charIndex) {
@ -326,7 +327,7 @@ messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapsho
return this->messages.getSnapshot(); return this->messages.getSnapshot();
} }
void ChannelView::setChannel(std::shared_ptr<Channel> channel) void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
{ {
if (this->channel) { if (this->channel) {
this->detachChannel(); this->detachChannel();
@ -335,7 +336,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> channel)
// on new message // on new message
this->messageAppendedConnection = this->messageAppendedConnection =
channel->messageAppended.connect([this](SharedMessage &message) { newChannel->messageAppended.connect([this](SharedMessage &message) {
SharedMessageRef deleted; SharedMessageRef deleted;
auto messageRef = new MessageRef(message); auto messageRef = new MessageRef(message);
@ -354,7 +355,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> channel)
// on message removed // on message removed
this->messageRemovedConnection = this->messageRemovedConnection =
channel->messageRemovedFromStart.connect([this](SharedMessage &) { newChannel->messageRemovedFromStart.connect([this](SharedMessage &) {
this->selection.min.messageIndex--; this->selection.min.messageIndex--;
this->selection.max.messageIndex--; this->selection.max.messageIndex--;
this->selection.start.messageIndex--; this->selection.start.messageIndex--;
@ -363,7 +364,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> channel)
this->layoutMessages(); this->layoutMessages();
}); });
auto snapshot = channel->getMessageSnapshot(); auto snapshot = newChannel->getMessageSnapshot();
for (size_t i = 0; i < snapshot.getLength(); i++) { for (size_t i = 0; i < snapshot.getLength(); i++) {
SharedMessageRef deleted; SharedMessageRef deleted;
@ -373,9 +374,9 @@ void ChannelView::setChannel(std::shared_ptr<Channel> channel)
this->messages.appendItem(SharedMessageRef(messageRef), deleted); this->messages.appendItem(SharedMessageRef(messageRef), deleted);
} }
this->channel = channel; this->channel = newChannel;
this->userPopupWidget.setChannel(channel); this->userPopupWidget.setChannel(newChannel);
} }
void ChannelView::detachChannel() void ChannelView::detachChannel()
@ -453,18 +454,19 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
void ChannelView::drawMessages(QPainter &painter) void ChannelView::drawMessages(QPainter &painter)
{ {
auto messages = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
size_t start = this->scrollBar.getCurrentValue(); size_t start = this->scrollBar.getCurrentValue();
if (start >= messages.getLength()) { if (start >= messagesSnapshot.getLength()) {
return; 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) { for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
messages::MessageRef *messageRef = messages[i].get(); messages::MessageRef *messageRef = messagesSnapshot[i].get();
std::shared_ptr<QPixmap> buffer = messageRef->buffer; std::shared_ptr<QPixmap> buffer = messageRef->buffer;
@ -806,14 +808,14 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) { if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
auto messages = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
if (messages.getLength() == 0) { if (messagesSnapshot.getLength() == 0) {
return; return;
} }
// Start selection at the last message at its last index // Start selection at the last message at its last index
auto lastMessageIndex = messages.getLength() - 1; auto lastMessageIndex = messagesSnapshot.getLength() - 1;
auto lastMessage = messages[lastMessageIndex]; auto lastMessage = messagesSnapshot[lastMessageIndex];
auto lastCharacterIndex = lastMessage->getLastCharacterIndex(); auto lastCharacterIndex = lastMessage->getLastCharacterIndex();
SelectionItem selectionItem(lastMessageIndex, lastCharacterIndex); SelectionItem selectionItem(lastMessageIndex, lastCharacterIndex);
@ -909,18 +911,18 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &_message, bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &_message,
QPoint &relativePos, int &index) QPoint &relativePos, int &index)
{ {
auto messages = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
size_t start = this->scrollBar.getCurrentValue(); size_t start = this->scrollBar.getCurrentValue();
if (start >= messages.getLength()) { if (start >= messagesSnapshot.getLength()) {
return false; 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) { for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
auto message = messages[i]; auto message = messagesSnapshot[i];
if (p.y() < y + message->getHeight()) { if (p.y() < y + message->getHeight()) {
relativePos = QPoint(p.x(), p.y() - y); relativePos = QPoint(p.x(), p.y() - y);