dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
tilematrix.cpp
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 #include "tilematrix.h"
28 
29 
30 namespace internals {
32 {
33 }
35 {
36  mutex.lock();
37  foreach(Tile* t,matrix.values())
38  {
39  delete t;
40  t=nullptr;
41  }
42  matrix.clear();
43  mutex.unlock();
44 }
45 //void TileMatrix::RebuildToUpperZoom()
46 //{
47 // mutex.lock();
48 // QList<Tile*> newtiles;
49 // foreach(Tile* t,matrix.values())
50 // {
51 // Point point=Point(t->GetPos().X()*2,t->GetPos().Y()*2);
52 // Tile* tile1=new Tile(t->GetZoom()+1,point);
53 // Tile* tile2=new Tile(t->GetZoom()+1,Point(point.X()+1,point.Y()+0));
54 // Tile* tile3=new Tile(t->GetZoom()+1,Point(point.X()+0,point.Y()+1));
55 // Tile* tile4=new Tile(t->GetZoom()+1,Point(point.X()+1,point.Y()+1));
56 //
57 // foreach(QByteArray arr, t->Overlays)
58 // {
59 // QImage ima=QImage::fromData(arr);
60 // QImage ima1=ima.copy(0,0,ima.width()/2,ima.height()/2);
61 // QImage ima2=ima.copy(ima.width()/2,0,ima.width()/2,ima.height()/2);
62 // QImage ima3=ima.copy(0,ima.height()/2,ima.width()/2,ima.height()/2);
63 // QImage ima4=ima.copy(ima.width()/2,ima.height()/2,ima.width()/2,ima.height()/2);
64 // QByteArray ba;
65 // QBuffer buf(&ba);
66 // ima1.scaled(QSize(ima.width(),ima.height())).save(&buf,"PNG");
67 // tile1->Overlays.append(ba);
68 // QByteArray ba1;
69 // QBuffer buf1(&ba1);
70 // ima2.scaled(QSize(ima.width(),ima.height())).save(&buf1,"PNG");
71 // tile2->Overlays.append(ba1);
72 // QByteArray ba2;
73 // QBuffer buf2(&ba2);
74 // ima3.scaled(QSize(ima.width(),ima.height())).save(&buf2,"PNG");
75 // tile3->Overlays.append(ba2);
76 // QByteArray ba3;
77 // QBuffer buf3(&ba3);
78 // ima4.scaled(QSize(ima.width(),ima.height())).save(&buf3,"PNG");
79 // tile4->Overlays.append(ba3);
80 // newtiles.append(tile1);
81 // newtiles.append(tile2);
82 // newtiles.append(tile3);
83 // newtiles.append(tile4);
84 // }
85 // }
86 // foreach(Tile* t,matrix.values())
87 // {
88 // delete t;
89 // t=0;
90 // }
91 // matrix.clear();
92 // foreach(Tile* t,newtiles)
93 // {
94 // matrix.insert(t->GetPos(),t);
95 // }
96 //
97 // mutex.unlock();
98 //}
99 
101 {
102  removals.clear();
103  mutex.lock();
104  foreach(Point p, matrix.keys())
105  {
106  if(!list.contains(p))
107  {
108  removals.append(p);
109  }
110  }
111  mutex.unlock();
112  foreach(Point p,removals)
113  {
114  Tile* t=TileAt(p);
115  if(t!=nullptr)
116  {
117  mutex.lock();
118  delete t;
119  t=nullptr;
120  matrix.remove(p);
121  mutex.unlock();
122  }
123 
124  }
125  removals.clear();
126 }
127 Tile* TileMatrix::TileAt(const Point &p)
128 {
129 
130 #ifdef DEBUG_TILEMATRIX
131  qDebug()<<"TileMatrix:TileAt:"<<p.ToString();
132 #endif //DEBUG_TILEMATRIX
133  Tile* ret;
134  mutex.lock();
135  ret=matrix.value(p,0);
136  mutex.unlock();
137  return ret;
138 }
139 void TileMatrix::SetTileAt(const Point &p, Tile* tile)
140 {
141  mutex.lock();
142  Tile* t=matrix.value(p,0);
143  if(t!=nullptr)
144  delete t;
145  matrix.insert(p,tile);
146  mutex.unlock();
147 }
148 }
QHash< core::Point, Tile * > matrix
Definition: tilematrix.h:48
QList< core::Point > removals
Definition: tilematrix.h:49
const char t[]
Definition: coreconstants.h:40
void ClearPointsNotIn(QList< core::Point > list)
Definition: tilematrix.cpp:100
Tile * TileAt(const core::Point &p)
Definition: tilematrix.cpp:127
Definition: icore.h:39
void SetTileAt(const core::Point &p, Tile *tile)
Definition: tilematrix.cpp:139