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
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

View file

@ -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<T>());
set(value.value<T>());
if (newValue.isValid()) {
assert(newValue.canConvert<T>());
set(newValue.value<T>());
}
}

View file

@ -2,6 +2,7 @@
#include "accountmanager.hpp"
#include "credentials.hpp"
#include "debug/log.hpp"
#include "util/networkmanager.hpp"
#include <QEventLoop>
@ -9,13 +10,9 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QString>
#include <QTimer>
#include <QDebug>
#include <functional>
@ -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<void(QJsonObject)> successCallback)
{
auto manager = new QNetworkAccessManager();
QNetworkRequest request(url);
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; }")
.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->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();

View file

@ -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();
}

View file

@ -2,8 +2,6 @@
#include <QWidget>
//#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();

View file

@ -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<SharedMessageRef> 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<SharedMessageRef> ChannelView::getMessagesSnapsho
return this->messages.getSnapshot();
}
void ChannelView::setChannel(std::shared_ptr<Channel> channel)
void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
{
if (this->channel) {
this->detachChannel();
@ -335,7 +336,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> 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> 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> 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> 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<QPixmap> 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<messages::MessageRef> &_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);