Skip to content

Commit

Permalink
Added basic raster objects
Browse files Browse the repository at this point in the history
  • Loading branch information
AmonRaNet committed Mar 26, 2024
1 parent eb02e42 commit a9caa55
Show file tree
Hide file tree
Showing 21 changed files with 620 additions and 182 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (${BUILD_EXAMPLES})
add_subdirectory(samples/widgets)
add_subdirectory(samples/flags)
add_subdirectory(samples/layers)
add_subdirectory(samples/raster)
add_subdirectory(samples/fun)
add_subdirectory(samples/10000)
add_subdirectory(samples/debug)
Expand Down
1 change: 1 addition & 0 deletions QGeoView.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SUBDIRS = \
samples/widgets \
samples/flags \
samples/layers \
samples/raster \
samples/fun \
samples/10000 \
samples/debug \
Expand Down
6 changes: 4 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ add_library(qgeoview SHARED
include/QGeoView/QGVItem.h
include/QGeoView/QGVDrawItem.h
include/QGeoView/QGVLayer.h
include/QGeoView/QGVImage.h
include/QGeoView/QGVLayerTiles.h
include/QGeoView/QGVLayerTilesOnline.h
include/QGeoView/QGVLayerGoogle.h
Expand All @@ -48,6 +47,8 @@ add_library(qgeoview SHARED
include/QGeoView/QGVWidgetScale.h
include/QGeoView/QGVWidgetZoom.h
include/QGeoView/QGVWidgetText.h
include/QGeoView/Raster/QGVImage.h
include/QGeoView/Raster/QGVIcon.h
src/QGVUtils.cpp
src/QGVGlobal.cpp
src/QGVProjection.cpp
Expand All @@ -60,7 +61,6 @@ add_library(qgeoview SHARED
src/QGVItem.cpp
src/QGVDrawItem.cpp
src/QGVLayer.cpp
src/QGVImage.cpp
src/QGVLayerTiles.cpp
src/QGVLayerTilesOnline.cpp
src/QGVLayerGoogle.cpp
Expand All @@ -72,6 +72,8 @@ add_library(qgeoview SHARED
src/QGVWidgetScale.cpp
src/QGVWidgetZoom.cpp
src/QGVWidgetText.cpp
src/Raster/QGVImage.cpp
src/Raster/QGVIcon.cpp
)

target_include_directories(qgeoview
Expand Down
13 changes: 5 additions & 8 deletions lib/include/QGeoView/QGVGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ class QGV_LIB_DECL GeoPos
public:
GeoPos();
GeoPos(double lat, double lon);
GeoPos(const GeoPos& other);
GeoPos(const GeoPos&& other);
GeoPos& operator=(const GeoPos& other);
GeoPos& operator=(const GeoPos&& other);

bool isEmpty() const;

double latitude() const;
double longitude() const;
Expand All @@ -124,6 +122,7 @@ class QGV_LIB_DECL GeoPos
static QString latToString(double lat, const QString& format = "[+-]d");

private:
bool mEmpty;
double mLat;
double mLon;
};
Expand All @@ -134,10 +133,8 @@ class QGV_LIB_DECL GeoRect
GeoRect();
GeoRect(double lat1, double lon1, double lat2, double lon2);
GeoRect(GeoPos const& pos1, GeoPos const& pos2);
GeoRect(const GeoRect& other);
GeoRect(const GeoRect&& other);
GeoRect& operator=(const GeoRect& other);
GeoRect& operator=(const GeoRect&& other);

bool isEmpty() const;

GeoPos topLeft() const;
GeoPos topRight() const;
Expand Down
4 changes: 1 addition & 3 deletions lib/include/QGeoView/QGVLayerTilesOnline.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ class QGV_LIB_DECL QGVLayerTilesOnline : public QGVLayerTiles
virtual QString tilePosToUrl(const QGV::GeoTilePos& tilePos) const = 0;

private:
void onProjection(QGVMap* geoMap) override;
void onClean() override;
void request(const QGV::GeoTilePos& tilePos) override;
void cancel(const QGV::GeoTilePos& tilePos) override;
void onReplyFinished(QNetworkReply* reply);
void onReplyFinished(QNetworkReply* reply, const QGV::GeoTilePos& tilePos);
void removeReply(const QGV::GeoTilePos& tilePos);

private:
Expand Down
55 changes: 55 additions & 0 deletions lib/include/QGeoView/Raster/QGVIcon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/***************************************************************************
* QGeoView is a Qt / C ++ widget for visualizing geographic data.
* Copyright (C) 2018-2023 Andrey Yaroshenko.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see https://www.gnu.org/licenses.
****************************************************************************/

#pragma once

#include <QGeoView/QGVDrawItem.h>

class QGV_LIB_DECL QGVIcon : public QGVDrawItem
{
Q_OBJECT

public:
QGVIcon();

void setGeometry(const QGV::GeoPos& geoPos, const QSizeF& imageSize = QSizeF());
void setGeometry(const QPointF& projPos, const QSizeF& imageSize = QSizeF());

QImage getImage() const;
bool isImage() const;

void loadImage(const QByteArray& rawData);
void loadImage(const QImage& image);

protected:
void onProjection(QGVMap* geoMap) override;
QPainterPath projShape() const override;
void projPaint(QPainter* painter) override;

private:
void calculateGeometry();

private:
QGV::GeoPos mGeoPos;
QPointF mProjPos;
QSizeF mImageSize;
QRectF mProjRect;

QString mUrl;
QImage mImage;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

#pragma once

#include "QGVDrawItem.h"
#include <QNetworkReply>
#include <QGeoView/QGVDrawItem.h>

class QGV_LIB_DECL QGVImage : public QGVDrawItem
{
Expand All @@ -29,39 +28,29 @@ class QGV_LIB_DECL QGVImage : public QGVDrawItem
QGVImage();

void setGeometry(const QGV::GeoRect& geoRect);
void setGeometry(const QGV::GeoPos& geoPos, const QSize& imageSize = QSize(), const QPoint& imageAnchor = QPoint());
void setGeometry(const QRectF& projRect);

QImage getImage() const;
bool isImage() const;

void load(const QString& url);
void loadImage(const QByteArray& rawData);
void loadImage(const QImage& image);

void setCeilingOnScale(bool enabled);

protected:
void onProjection(QGVMap* geoMap) override;
QPainterPath projShape() const override;
QPointF projAnchor() const override;
void projPaint(QPainter* painter) override;

private:
void onReplyFinished();
void calculateGeometry();

private:
enum class GeometryType
{
None,
ByRect,
ByPos,
} mGeometryType;
QGV::GeoRect mGeoRect;
QGV::GeoPos mGeoPos;
QSize mImageSize;
QPoint mImageAnchor;
QRectF mProjRect;
QPointF mProjAnchor;

QString mUrl;
QImage mImage;
QScopedPointer<QNetworkReply> mReply;
bool mCeilingOnScale;
};
10 changes: 6 additions & 4 deletions lib/lib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ HEADERS += \
$$PWD/include/QGeoView/QGVDrawItem.h \
$$PWD/include/QGeoView/QGVGlobal.h \
$$PWD/include/QGeoView/QGVUtils.h \
$$PWD/include/QGeoView/QGVImage.h \
$$PWD/include/QGeoView/QGVItem.h \
$$PWD/include/QGeoView/QGVLayer.h \
$$PWD/include/QGeoView/QGVLayerBing.h \
Expand All @@ -29,14 +28,15 @@ HEADERS += \
$$PWD/include/QGeoView/QGVWidgetCompass.h \
$$PWD/include/QGeoView/QGVWidgetScale.h \
$$PWD/include/QGeoView/QGVWidgetText.h \
$$PWD/include/QGeoView/QGVWidgetZoom.h
$$PWD/include/QGeoView/QGVWidgetZoom.h \
$$PWD/include/QGeoView/Raster/QGVImage.h \
$$PWD/include/QGeoView/Raster/QGVIcon.h \

SOURCES += \
$$PWD/src/QGVCamera.cpp \
$$PWD/src/QGVDrawItem.cpp \
$$PWD/src/QGVGlobal.cpp \
$$PWD/src/QGVUtils.cpp \
$$PWD/src/QGVImage.cpp \
$$PWD/src/QGVItem.cpp \
$$PWD/src/QGVLayer.cpp \
$$PWD/src/QGVLayerBing.cpp \
Expand All @@ -55,7 +55,9 @@ SOURCES += \
$$PWD/src/QGVWidgetCompass.cpp \
$$PWD/src/QGVWidgetScale.cpp \
$$PWD/src/QGVWidgetText.cpp \
$$PWD/src/QGVWidgetZoom.cpp
$$PWD/src/QGVWidgetZoom.cpp \
$$PWD/src/Raster/QGVImage.cpp \
$$PWD/src/Raster/QGVIcon.cpp

INCLUDEPATH += \
$$PWD/include/ \
Expand Down
54 changes: 7 additions & 47 deletions lib/src/QGVGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,22 @@ QNetworkAccessManager* networkManager = nullptr;
namespace QGV {

GeoPos::GeoPos()
: mLat(0)
: mEmpty(true)
, mLat(0)
, mLon(0)
{
}

GeoPos::GeoPos(double lat, double lon)
: mEmpty(false)
{
setLat(lat);
setLon(lon);
}

GeoPos::GeoPos(const GeoPos& other)
: mLat(other.latitude())
, mLon(other.longitude())
bool GeoPos::isEmpty() const
{
}

GeoPos::GeoPos(const GeoPos&& other)
: mLat(std::move(other.latitude()))
, mLon(std::move(other.longitude()))
{
}

GeoPos& GeoPos::operator=(const GeoPos& other)
{
mLat = other.latitude();
mLon = other.longitude();
return *this;
}

GeoPos& GeoPos::operator=(const GeoPos&& other)
{
mLat = std::move(other.latitude());
mLon = std::move(other.longitude());
return *this;
return mEmpty;
}

double GeoPos::latitude() const
Expand Down Expand Up @@ -191,30 +172,9 @@ GeoRect::GeoRect(GeoPos const& pos1, GeoPos const& pos2)
mBottomRight = GeoPos(qMin(pos1.latitude(), pos2.latitude()), qMax(pos1.longitude(), pos2.longitude()));
}

GeoRect::GeoRect(const GeoRect& other)
: mTopLeft(other.mTopLeft)
, mBottomRight(other.mBottomRight)
bool GeoRect::isEmpty() const
{
}

GeoRect::GeoRect(const GeoRect&& other)
: mTopLeft(std::move(other.mTopLeft))
, mBottomRight(std::move(other.mBottomRight))
{
}

GeoRect& GeoRect::operator=(const GeoRect& other)
{
mTopLeft = other.mTopLeft;
mBottomRight = other.mBottomRight;
return *this;
}

GeoRect& GeoRect::operator=(const GeoRect&& other)
{
mTopLeft = std::move(other.mTopLeft);
mBottomRight = std::move(other.mBottomRight);
return *this;
return mTopLeft.isEmpty() || mBottomRight.isEmpty();
}

GeoPos GeoRect::topLeft() const
Expand Down
36 changes: 9 additions & 27 deletions lib/src/QGVLayerTilesOnline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,36 @@
****************************************************************************/

#include "QGVLayerTilesOnline.h"
#include "QGVImage.h"
#include "Raster/QGVImage.h"

QGVLayerTilesOnline::~QGVLayerTilesOnline()
{
qDeleteAll(mRequest);
}

void QGVLayerTilesOnline::onProjection(QGVMap* geoMap)
void QGVLayerTilesOnline::request(const QGV::GeoTilePos& tilePos)
{
Q_ASSERT(QGV::getNetworkManager());
QGVLayerTiles::onProjection(geoMap);
connect(QGV::getNetworkManager(), &QNetworkAccessManager::finished, this, &QGVLayerTilesOnline::onReplyFinished);
}

void QGVLayerTilesOnline::onClean()
{
Q_ASSERT(QGV::getNetworkManager());
disconnect(QGV::getNetworkManager(), 0, this, 0);
}

void QGVLayerTilesOnline::request(const QGV::GeoTilePos& tilePos)
{
const QUrl url(tilePosToUrl(tilePos));

QNetworkRequest request(url);
QSslConfiguration conf = request.sslConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);

request.setSslConfiguration(conf);
request.setRawHeader("User-Agent",
"Mozilla/5.0 (Windows; U; MSIE "
"6.0; Windows NT 5.1; SV1; .NET "
"CLR 2.0.50727)");
request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);

QNetworkReply* reply = QGV::getNetworkManager()->get(request);
reply->setProperty("TILE_OWNER", QVariant::fromValue(this));
reply->setProperty("TILE_REQUEST", true);
reply->setProperty("TILE_POS", QVariant::fromValue(tilePos));

mRequest[tilePos] = reply;
connect(reply, &QNetworkReply::finished, reply, [this, reply, tilePos]() { onReplyFinished(reply, tilePos); });

qgvDebug() << "request" << url;
}

Expand All @@ -63,18 +55,8 @@ void QGVLayerTilesOnline::cancel(const QGV::GeoTilePos& tilePos)
removeReply(tilePos);
}

void QGVLayerTilesOnline::onReplyFinished(QNetworkReply* reply)
void QGVLayerTilesOnline::onReplyFinished(QNetworkReply* reply, const QGV::GeoTilePos& tilePos)
{
const auto tileRequest = reply->property("TILE_REQUEST").toBool();
if (!tileRequest) {
return;
}
const auto tileOwner = reply->property("TILE_OWNER").value<QGVLayerTilesOnline*>();
if (tileOwner != this) {
return;
}
const auto tilePos = reply->property("TILE_POS").value<QGV::GeoTilePos>();

if (reply->error() != QNetworkReply::NoError) {
if (reply->error() != QNetworkReply::OperationCanceledError) {
qgvCritical() << "ERROR" << reply->errorString();
Expand Down
Loading

0 comments on commit a9caa55

Please sign in to comment.