history_location_manager: fix all warnings by Qt's Clang Code Model

The Code Model options were:
Clang: -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-unused-macros
-Wno-newline-eof -Wno-exit-time-destructors -Wno-global-constructors
-Wno-gnu-zero-variadic-macro-arguments -Wno-documentation -Wno-shadow
-Wno-switch-enum -Wno-missing-prototypes -Wno-used-but-marked-unused;

Clang-tidy: bugprone, clang-analyzer, clang-diagnostics, misc, modernize,
performance, readability;

Clazy: level 0.
This commit is contained in:
leha-bot 2019-01-29 01:21:30 +03:00 committed by Alex
parent b2e70e63a2
commit 6bb875727c
1 changed files with 43 additions and 25 deletions

View File

@ -33,7 +33,6 @@
namespace { namespace {
constexpr auto kCoordPrecision = 8;
constexpr auto kMaxHttpRedirects = 5; constexpr auto kMaxHttpRedirects = 5;
} // namespace } // namespace
@ -147,7 +146,7 @@ QString LocationClickHandler::copyToClipboardContextItemText() const {
return lang(lng_context_copy_link); return lang(lng_context_copy_link);
} }
void LocationClickHandler::onClick(Qt::MouseButton button) const { void LocationClickHandler::onClick([[maybe_unused]] Qt::MouseButton button) const {
if (!psLaunchMaps(_coords)) { if (!psLaunchMaps(_coords)) {
QDesktopServices::openUrl(_text); QDesktopServices::openUrl(_text);
} }
@ -158,23 +157,23 @@ void LocationClickHandler::setup() {
} }
void initLocationManager() { void initLocationManager() {
if (!locationManager) { if (locationManager == nullptr) {
locationManager = new LocationManager(); locationManager = new LocationManager();
locationManager->init(); locationManager->init();
} }
if (!locationMapTileHelper) { if (locationMapTileHelper == nullptr) {
locationMapTileHelper = new LocationMapTileHelper(); locationMapTileHelper = new LocationMapTileHelper();
} }
} }
void reinitLocationManager() { void reinitLocationManager() {
if (locationManager) { if (locationManager != nullptr) {
locationManager->reinit(); locationManager->reinit();
} }
} }
void deinitLocationManager() { void deinitLocationManager() {
if (locationManager) { if (locationManager != nullptr) {
locationManager->deinit(); locationManager->deinit();
delete locationManager; delete locationManager;
locationManager = nullptr; locationManager = nullptr;
@ -185,7 +184,7 @@ void deinitLocationManager() {
} }
void LocationManager::init() { void LocationManager::init() {
if (manager) delete manager; delete manager;
manager = new QNetworkAccessManager(); manager = new QNetworkAccessManager();
App::setProxySettings(*manager); App::setProxySettings(*manager);
@ -197,7 +196,7 @@ void LocationManager::init() {
#endif // OS_MAC_OLD #endif // OS_MAC_OLD
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(onFinished(QNetworkReply *))); connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(onFinished(QNetworkReply *)));
if (notLoadedPlaceholder) { if (notLoadedPlaceholder != nullptr) {
delete notLoadedPlaceholder->v(); delete notLoadedPlaceholder->v();
delete notLoadedPlaceholder; delete notLoadedPlaceholder;
} }
@ -208,15 +207,17 @@ void LocationManager::init() {
} }
void LocationManager::reinit() { void LocationManager::reinit() {
if (manager) App::setProxySettings(*manager); if (manager != nullptr) {
App::setProxySettings(*manager);
}
} }
void LocationManager::deinit() { void LocationManager::deinit() {
if (manager) { if (manager != nullptr) {
delete manager; delete manager;
manager = nullptr; manager = nullptr;
} }
if (notLoadedPlaceholder) { if (notLoadedPlaceholder != nullptr) {
delete notLoadedPlaceholder->v(); delete notLoadedPlaceholder->v();
delete notLoadedPlaceholder; delete notLoadedPlaceholder;
notLoadedPlaceholder = nullptr; notLoadedPlaceholder = nullptr;
@ -226,7 +227,7 @@ void LocationManager::deinit() {
} }
void LocationManager::getData(LocationData *data) { void LocationManager::getData(LocationData *data) {
if (!manager) { if (manager == nullptr) {
DEBUG_LOG(("App Error: getting image link data without manager init!")); DEBUG_LOG(("App Error: getting image link data without manager init!"));
return failed(data); return failed(data);
} }
@ -246,8 +247,12 @@ void LocationManager::getData(LocationData *data) {
} }
void LocationManager::onFinished(QNetworkReply *reply) { void LocationManager::onFinished(QNetworkReply *reply) {
if (!manager) return; if (manager == nullptr) {
if (reply->error() != QNetworkReply::NoError) return onFailed(reply); return;
}
if (reply->error() != QNetworkReply::NoError) {
return onFailed(reply);
}
QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (statusCode.isValid()) { if (statusCode.isValid()) {
@ -268,7 +273,8 @@ void LocationManager::onFinished(QNetworkReply *reply) {
dataLoadings.erase(i); dataLoadings.erase(i);
dataLoadings.insert(manager->get(QNetworkRequest(loc)), d); dataLoadings.insert(manager->get(QNetworkRequest(loc)), d);
return; return;
} else if ((i = imageLoadings.find(reply)) != imageLoadings.cend()) { }
if ((i = imageLoadings.find(reply)) != imageLoadings.cend()) {
LocationData *d = i.value(); LocationData *d = i.value();
if (serverRedirects.constFind(d) == serverRedirects.cend()) { if (serverRedirects.constFind(d) == serverRedirects.cend()) {
serverRedirects.insert(d, 1); serverRedirects.insert(d, 1);
@ -289,7 +295,7 @@ void LocationManager::onFinished(QNetworkReply *reply) {
} }
} }
LocationData *d = 0; LocationData *d = nullptr;
QMap<QNetworkReply *, LocationData *>::iterator i = dataLoadings.find(reply); QMap<QNetworkReply *, LocationData *>::iterator i = dataLoadings.find(reply);
if (i != dataLoadings.cend()) { if (i != dataLoadings.cend()) {
d = i.value(); d = i.value();
@ -303,7 +309,9 @@ void LocationManager::onFinished(QNetworkReply *reply) {
} }
failed(d); failed(d);
if (App::main()) App::main()->update(); if (App::main() != nullptr) {
App::main()->update();
}
} else { } else {
i = imageLoadings.find(reply); i = imageLoadings.find(reply);
if (i != imageLoadings.cend()) { if (i != imageLoadings.cend()) {
@ -322,20 +330,26 @@ void LocationManager::onFinished(QNetworkReply *reply) {
thumb = QPixmap::fromImageReader(&reader, Qt::ColorOnly); thumb = QPixmap::fromImageReader(&reader, Qt::ColorOnly);
format = reader.format(); format = reader.format();
thumb.setDevicePixelRatio(cRetinaFactor()); thumb.setDevicePixelRatio(cRetinaFactor());
if (format.isEmpty()) format = QByteArray("JPG"); if (format.isEmpty()) {
format = QByteArray("JPG");
}
} }
d->loading = false; d->loading = false;
d->thumb = thumb.isNull() ? (*notLoadedPlaceholder) : ImagePtr(thumb, format); d->thumb = thumb.isNull() ? (*notLoadedPlaceholder) : ImagePtr(thumb, format);
serverRedirects.remove(d); serverRedirects.remove(d);
if (App::main()) App::main()->update(); if (App::main() != nullptr) {
App::main()->update();
}
} }
} }
} }
void LocationManager::onFailed(QNetworkReply *reply) { void LocationManager::onFailed(QNetworkReply *reply) {
if (!manager) return; if (manager == nullptr) {
return;
}
LocationData *d = 0; LocationData *d = nullptr;
QMap<QNetworkReply *, LocationData *>::iterator i = dataLoadings.find(reply); QMap<QNetworkReply *, LocationData *>::iterator i = dataLoadings.find(reply);
if (i != dataLoadings.cend()) { if (i != dataLoadings.cend()) {
d = i.value(); d = i.value();
@ -351,7 +365,7 @@ void LocationManager::onFailed(QNetworkReply *reply) {
.arg(d ? d->coords.latAsString() : QString()) .arg(d ? d->coords.latAsString() : QString())
.arg(d ? d->coords.lonAsString() : QString()) .arg(d ? d->coords.lonAsString() : QString())
.arg(reply->errorString())); .arg(reply->errorString()));
if (d) { if (d != nullptr) {
failed(d); failed(d);
} }
} }
@ -363,11 +377,15 @@ void LocationManager::failed(LocationData *data) {
} }
void LocationData::load() { void LocationData::load() {
if (!thumb->isNull()) return thumb->load(false, false); if (!thumb->isNull()) {
if (loading) return; return thumb->load(false, false);
}
if (loading) {
return;
}
loading = true; loading = true;
if (locationManager) { if (locationManager != nullptr) {
locationManager->getData(this); locationManager->getData(this);
} }
} }