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 e6234b3 commit ad66d1c
Show file tree
Hide file tree
Showing 18 changed files with 599 additions and 98 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
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
2 changes: 1 addition & 1 deletion lib/src/QGVLayerTilesOnline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
****************************************************************************/

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

QGVLayerTilesOnline::~QGVLayerTilesOnline()
{
Expand Down
113 changes: 113 additions & 0 deletions lib/src/Raster/QGVIcon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/***************************************************************************
* 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.
****************************************************************************/

#include "Raster/QGVIcon.h"
#include "QGVMap.h"

#include <QPainter>

QGVIcon::QGVIcon()
{
setFlag(QGV::ItemFlag::IgnoreScale);
setFlag(QGV::ItemFlag::IgnoreAzimuth);
}

void QGVIcon::setGeometry(const QGV::GeoPos& geoPos, const QSizeF& imageSize)
{
mGeoPos = geoPos;
mProjPos = {};
mImageSize = imageSize;
mProjRect = {};
calculateGeometry();
}

void QGVIcon::setGeometry(const QPointF& projPos, const QSizeF& imageSize)
{
mGeoPos = {};
mProjPos = projPos;
mImageSize = imageSize;
mProjRect = {};
calculateGeometry();
}

QImage QGVIcon::getImage() const
{
return mImage;
}

bool QGVIcon::isImage() const
{
return !mImage.isNull();
}

void QGVIcon::loadImage(const QByteArray& rawData)
{
QImage image;
image.loadFromData(rawData);
loadImage(image);
}

void QGVIcon::loadImage(const QImage& image)
{
mImage = image;
calculateGeometry();
}

void QGVIcon::onProjection(QGVMap* geoMap)
{
QGVDrawItem::onProjection(geoMap);
calculateGeometry();
}

QPainterPath QGVIcon::projShape() const
{
QPainterPath path;
path.addRect(mProjRect);
return path;
}

void QGVIcon::projPaint(QPainter* painter)
{
if (mImage.isNull() || mProjRect.isEmpty()) {
return;
}

QRectF paintRect = mProjRect;

painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter->drawImage(paintRect, getImage());
}

void QGVIcon::calculateGeometry()
{
if (getMap() == nullptr) {
return;
}

if (!mGeoPos.isEmpty()) {
mProjPos = getMap()->getProjection()->geoToProj(mGeoPos);
}

const QSizeF baseSize = !mImageSize.isEmpty() ? mImageSize : mImage.size();
const QPointF baseAnchor = QPointF(baseSize.width() / 2, baseSize.height() / 2);

mProjRect = QRectF(mProjPos - baseAnchor, baseSize);

resetBoundary();
refresh();
}
Loading

0 comments on commit ad66d1c

Please sign in to comment.