Marble

TileCoordsPyramid.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2
3#include "TileCoordsPyramid.h"
4
5#include <QRect>
6#include <QVector>
7#include <MarbleDebug.h>
8
9#include <algorithm>
10
11namespace Marble
12{
13
14class Q_DECL_HIDDEN TileCoordsPyramid::Private
15{
16public:
17 Private( int const topLevel, int const bottomLevel );
18
19 int m_topLevel;
20 int m_bottomLevel;
21 QRect m_bottomLevelCoords;
22 QVector<int> m_validLevels;
23};
24
25TileCoordsPyramid::Private::Private( int const topLevel, int const bottomLevel )
26 : m_topLevel( topLevel ),
27 m_bottomLevel( bottomLevel )
28{
29 Q_ASSERT( m_topLevel <= m_bottomLevel );
30}
31
32
33TileCoordsPyramid::TileCoordsPyramid( int const topLevel, int const bottomLevel )
34 : d( new Private( topLevel, bottomLevel ))
35{
36}
37
38TileCoordsPyramid::TileCoordsPyramid( TileCoordsPyramid const & other )
39 : d( new Private( *other.d ))
40{
41}
42
43TileCoordsPyramid::TileCoordsPyramid()
44 :d( new Private( 0, 0 ) )
45{
46
47}
48
49TileCoordsPyramid & TileCoordsPyramid::operator=( TileCoordsPyramid const & rhs )
50{
51 TileCoordsPyramid temp( rhs );
52 swap( temp );
53 return *this;
54}
55
56TileCoordsPyramid::~TileCoordsPyramid()
57{
58 delete d;
59}
60
61int TileCoordsPyramid::topLevel() const
62{
63 return d->m_topLevel;
64}
65
66int TileCoordsPyramid::bottomLevel() const
67{
68 return d->m_bottomLevel;
69}
70
71void TileCoordsPyramid::setBottomLevelCoords( QRect const & coords )
72{
73 d->m_bottomLevelCoords = coords;
74}
75
76QRect TileCoordsPyramid::coords( int const level ) const
77{
78 Q_ASSERT( d->m_topLevel <= level && level <= d->m_bottomLevel );
79 int bottomX1, bottomY1, bottomX2, bottomY2;
80 d->m_bottomLevelCoords.getCoords( &bottomX1, &bottomY1, &bottomX2, &bottomY2 );
81 int const deltaLevel = d->m_bottomLevel - level;
82 int const x1 = bottomX1 >> deltaLevel;
83 int const y1 = bottomY1 >> deltaLevel;
84 int const x2 = bottomX2 >> deltaLevel;
85 int const y2 = bottomY2 >> deltaLevel;
86 QRect result;
87 result.setCoords( x1, y1, x2, y2 );
88 return result;
89}
90
91void TileCoordsPyramid::setValidTileLevels(const QVector<int> validLevels)
92{
93 d->m_validLevels = validLevels;
94}
95
96QVector<int> TileCoordsPyramid::validTileLevels()
97{
98 return d->m_validLevels;
99}
100
101qint64 TileCoordsPyramid::tilesCount() const
102{
103 qint64 result = 0;
104 for ( int level = d->m_topLevel; level <= d->m_bottomLevel; ++level ) {
105 if (!d->m_validLevels.isEmpty() && !d->m_validLevels.contains(level)) continue;
106
107 QRect const levelCoords = coords( level );
108 // w*h can exceed 32 bit range, so force 64 bit calculation; see bug 342397
109 result += qint64( levelCoords.width() ) * levelCoords.height();
110 }
111 return result;
112}
113
114void TileCoordsPyramid::swap( TileCoordsPyramid & other )
115{
116 std::swap( d, other.d );
117}
118
119}
QStringView level(QStringView ifopt)
Binds a QML item to a specific geodetic location in screen coordinates.
int height() const const
void setCoords(int x1, int y1, int x2, int y2)
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.