RasterProcessTool/RasterMainWidgetGUI/RasterMainWidget/tmsprovider.h

182 lines
3.8 KiB
C
Raw Permalink Normal View History

2025-02-07 09:16:22 +00:00
#pragma once
#include <QtMath>
#include <QSize>
#include <QString>
#include <QRunnable>
#include <QByteArray>
#include <QPointF>
#include <QImage>
#include <QObject>
#include <QSqlDatabase>
#include <layerprovider.h>
#include <pointxy.h>
2025-02-07 09:16:22 +00:00
namespace LAMPMainWidget
{
/*
* 线
*/
struct TileInfo
{
QPointF index;
QPoint position;
int zoom;
QPoint coord;
QString url;
QByteArray data;
};
// 在结构体定义后声明
Q_DECLARE_METATYPE(TileInfo);
2025-02-07 09:16:22 +00:00
/*
*
*/
class TileDownloadTask : public QObject, public QRunnable
{
Q_OBJECT
signals:
void tileReady(TileInfo tile);
public:
using tileReadyCallback = std::function<void( TileInfo )>;
explicit TileDownloadTask(TileInfo tile, tileReadyCallback=nullptr, QObject* parent = nullptr);
2025-02-07 09:16:22 +00:00
TileDownloadTask(const TileDownloadTask& other) = delete;
TileDownloadTask(TileDownloadTask&& other) = delete;
TileDownloadTask& operator=(const TileDownloadTask& other) = delete;
TileDownloadTask& operator=(TileDownloadTask&& other) = delete;
~TileDownloadTask() override = default;
2025-02-07 09:16:22 +00:00
public:
void run() override;
protected:
TileInfo mTile;
private:
tileReadyCallback mCallback;
2025-02-07 09:16:22 +00:00
};
class TmsProvider : public LayerProvider
{
Q_OBJECT
public:
explicit TmsProvider(QObject* parent = nullptr);
~TmsProvider() override;
public:
/*
*
* @return 256*256
*/
virtual const QSize tileSize() const = 0;
/*
* url
* @param pos
* @param zoom zoom
* @return url
*/
virtual QString tileUrl(const PointXY& pos, int zoom) const = 0;
/*
*
* @return
*/
const QImage preparedImage() const override { return *mImage; }
/*
*
* @return truefalse
*/
bool hasContent() const override { return static_cast<bool>(mImage); }
/*
* tms
* @return
*/
virtual const QString& id() const = 0;
public slots:
/*
*
* @param rect
* @param zoom zoom
*/
void createTask(const QRectF& rect, int zoom) override;
/*
*
* @param tile
*/
void tileReady(TileInfo tile);
protected:
/*
*
* @param rect
*/
void newImage(const QRectF& rect);
/*
*
* @param pos
* @param zoom zoom
* @return
*/
virtual QByteArray getCache(const QPoint& pos, int zoom);
/*
*
* @param pos
* @param zoom zoom
* @return
*/
virtual bool addCache(const QPoint& pos, int zoom, QByteArray data);
/*
*
* @param pos
* @param zoom zoom
* @return truefalse
*/
virtual bool cacheContains(const QPoint& pos, int zoom);
/*
*
*/
virtual bool initCache();
protected:
/*
*
*/
QImage* mImage;
/*
*
*/
const QString mDbName{"LAMPMainWidget.sqlite"};
/*
*
*/
const QString mTableName{"tiles"};
/*
*
*/
QSqlDatabase mDbConn;
};
}
inline uint qHash(const QPoint& p)
{
return qHash(qPow(p.x(), p.y()));
}