Skip to content

Commit

Permalink
Added missing setup for QNetworkAccessManager and QNetworkDiskCache
Browse files Browse the repository at this point in the history
  • Loading branch information
AmonRaNet committed Jan 3, 2024
1 parent 359b49a commit 3402554
Show file tree
Hide file tree
Showing 26 changed files with 36 additions and 61 deletions.
2 changes: 1 addition & 1 deletion samples/10000/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MainWindow::MainWindow()
mMap = new QGVMap(this);
setCentralWidget(mMap);

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

// Background layer
auto osmLayer = new QGVLayerOSM();
Expand Down
4 changes: 0 additions & 4 deletions samples/10000/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#pragma once

#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -37,7 +35,5 @@ class MainWindow : public QMainWindow
QGVLayer* create10000Layer() const;

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
};
6 changes: 4 additions & 2 deletions samples/background/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

#include "mainwindow.h"

#include <QButtonGroup>
#include <QGeoView/QGVLayerBing.h>
#include <QGeoView/QGVLayerGoogle.h>
#include <QGeoView/QGVLayerOSM.h>
#include <helpers.h>

#include <QButtonGroup>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QRadioButton>
Expand All @@ -34,7 +36,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/background/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVMap.h>

Expand All @@ -36,7 +34,5 @@ class MainWindow : public QMainWindow
QGroupBox* createOptionsList();

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
};
3 changes: 2 additions & 1 deletion samples/basic/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QTimer>

#include <QGeoView/QGVLayerOSM.h>
#include <helpers.h>

MainWindow::MainWindow()
{
Expand All @@ -29,7 +30,7 @@ MainWindow::MainWindow()
mMap = new QGVMap(this);
setCentralWidget(mMap);

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

// Background layer
auto osmLayer = new QGVLayerOSM();
Expand Down
4 changes: 0 additions & 4 deletions samples/basic/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#pragma once

#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVMap.h>

Expand All @@ -33,7 +31,5 @@ class MainWindow : public QMainWindow
~MainWindow();

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
};
2 changes: 1 addition & 1 deletion samples/camera-actions/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/camera-actions/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -47,8 +45,6 @@ class MainWindow : public QMainWindow
Rectangle* getRandomItem();

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
QGVLayer* mItemsLayer;
bool mFlyMode;
Expand Down
3 changes: 2 additions & 1 deletion samples/custom-tiles/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QGeoView/QGVLayerOSM.h>
#include <QTimer>

#include <helpers.h>
#include <mytiles.h>

MainWindow::MainWindow()
Expand All @@ -30,7 +31,7 @@ MainWindow::MainWindow()
mMap = new QGVMap(this);
setCentralWidget(mMap);

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

// Background layer
auto osmLayer = new QGVLayerOSM();
Expand Down
4 changes: 0 additions & 4 deletions samples/custom-tiles/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#pragma once

#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVMap.h>

Expand All @@ -35,7 +33,5 @@ class MainWindow : public QMainWindow
QGV::GeoRect targetArea() const;

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
};
2 changes: 1 addition & 1 deletion samples/debug/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/debug/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -39,8 +37,6 @@ class MainWindow : public QMainWindow
QGroupBox* createOptionsList();

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
QGVLayer* mItemsLayer;
};
2 changes: 1 addition & 1 deletion samples/flags/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/flags/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -42,8 +40,6 @@ class MainWindow : public QMainWindow
void applySelectable(bool enabled);

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
QGVLayer* mItemsLayer;
};
3 changes: 2 additions & 1 deletion samples/fun/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <functional>

#include <helpers.h>
#include <placemark.h>
#include <waveanimation.h>

Expand All @@ -40,7 +41,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/fun/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -42,8 +40,6 @@ class MainWindow : public QMainWindow
QGroupBox* createOptionsList();

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
QGVLayer* mQGVLayer;
QAbstractAnimation* mQGVAnimation;
Expand Down
2 changes: 1 addition & 1 deletion samples/layers/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/layers/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -39,7 +37,5 @@ class MainWindow : public QMainWindow
QGroupBox* createLayersList();

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
};
2 changes: 1 addition & 1 deletion samples/mouse-actions/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
4 changes: 0 additions & 4 deletions samples/mouse-actions/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <QGroupBox>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVLayer.h>
#include <QGeoView/QGVMap.h>
Expand All @@ -44,8 +42,6 @@ class MainWindow : public QMainWindow
void enableAction(bool enable, QGV::MouseAction action);

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
QGVLayer* mItemsLayer;
};
3 changes: 2 additions & 1 deletion samples/moving-objects/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QRandomGenerator>
#include <QTimer>

#include <helpers.h>
#include <placemarkcircle.h>

#include <QGeoView/QGVLayerOSM.h>
Expand All @@ -32,7 +33,7 @@ MainWindow::MainWindow()
mMap = new QGVMap(this);
setCentralWidget(mMap);

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

// Background layer
auto osmLayer = new QGVLayerOSM();
Expand Down
4 changes: 0 additions & 4 deletions samples/moving-objects/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#pragma once

#include <QMainWindow>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

#include <QGeoView/QGVMap.h>
#include <placemarkcircle.h>
Expand All @@ -36,8 +34,6 @@ class MainWindow : public QMainWindow
void moveObject(PlacemarkCircle* item);

private:
QNetworkAccessManager* mManager;
QNetworkDiskCache* mCache;
QGVMap* mMap;
QTimer* mTimer;
};
14 changes: 14 additions & 0 deletions samples/shared/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <random>
#endif

#include <QDir>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>

static auto initRand = []() {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
std::srand(std::time(nullptr));
Expand Down Expand Up @@ -67,3 +71,13 @@ QSizeF Helpers::randSize(int baseSize)
return QSize(baseSize + (qrand() % range), baseSize + (qrand() % range));
#endif
}

void Helpers::setupCachedNetworkAccessManager(QObject* parent)
{
QDir("cacheDir").removeRecursively();
auto cache = new QNetworkDiskCache(parent);
cache->setCacheDirectory("cacheDir");
auto manager = new QNetworkAccessManager(parent);
manager->setCache(cache);
QGV::setNetworkManager(manager);
}
2 changes: 2 additions & 0 deletions samples/shared/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <QGeoView/QGVMap.h>

namespace Helpers {
void setupCachedNetworkAccessManager(QObject* parent);

QGV::GeoRect randRect(QGVMap* geoMap, const QGV::GeoRect& targetArea, const QSizeF& size);
QGV::GeoRect randRect(QGVMap* geoMap, const QGV::GeoRect& targetArea, int baseSize);
QGV::GeoPos randPos(const QGV::GeoRect& targetArea);
Expand Down
3 changes: 2 additions & 1 deletion samples/widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QGeoView/QGVWidgetCompass.h>
#include <QGeoView/QGVWidgetScale.h>
#include <QGeoView/QGVWidgetZoom.h>
#include <helpers.h>

MainWindow::MainWindow()
{
Expand All @@ -34,7 +35,7 @@ MainWindow::MainWindow()
setCentralWidget(new QWidget());
centralWidget()->setLayout(new QVBoxLayout());

QGV::setNetworkManager(new QNetworkAccessManager());
Helpers::setupCachedNetworkAccessManager(this);

mMap = new QGVMap(this);
centralWidget()->layout()->addWidget(mMap);
Expand Down
Loading

0 comments on commit 3402554

Please sign in to comment.