dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mapripper.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 "mapripper.h"
28 namespace mapcontrol
29 {
30 
31 MapRipper::MapRipper(internals::Core * core, const internals::RectLatLng & rect):sleep(100),cancel(false),progressForm(nullptr),core(core),yesToAll(false)
32  {
33  if(!rect.IsEmpty())
34  {
35  type=core->GetMapType();
36  progressForm=new MapRipForm;
37  connect(progressForm,SIGNAL(cancelRequest()),this,SLOT(stopFetching()));
38  area=rect;
39  zoom=core->Zoom();
40  maxzoom=core->MaxZoom();
41  points=core->Projection()->GetAreaTileList(area,zoom,0);
42  this->start();
43  cancel=false;
44  progressForm->show();
45  connect(this,SIGNAL(percentageChanged(int)),progressForm,SLOT(SetPercentage(int)));
46  connect(this,SIGNAL(numberOfTilesChanged(int,int)),progressForm,SLOT(SetNumberOfTiles(int,int)));
47  connect(this,SIGNAL(providerChanged(QString,int)),progressForm,SLOT(SetProvider(QString,int)));
48  connect(this,SIGNAL(finished()),this,SLOT(finish()));
49  emit numberOfTilesChanged(0,0);
50  }
51  else
52 #ifdef Q_OS_DARWIN
53  QMessageBox::information(new QWidget(),"No valid selection","This pre-caches map data.\n\nPlease first select the area of the map to rip with <COMMAND>+Left mouse click");
54 #else
55  QMessageBox::information(new QWidget(),"No valid selection","This pre-caches map data.\n\nPlease first select the area of the map to rip with <CTRL>+Left mouse click");
56 #endif
57  }
59 {
60  if(zoom<maxzoom && !cancel)
61  {
62  ++zoom;
63  int ret;
64  if(!yesToAll)
65  {
66  QMessageBox msgBox;
67  msgBox.setText(QString("Continue Ripping at zoom level %1?").arg(zoom));
68  // msgBox.setInformativeText("Do you want to save your changes?");
69  msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::YesAll);
70  msgBox.setDefaultButton(QMessageBox::Yes);
71  ret = msgBox.exec();
72  }
73  else
74  ret=QMessageBox::Yes;
75  if(ret==QMessageBox::Yes)
76  {
77  points.clear();
78  points=core->Projection()->GetAreaTileList(area,zoom,0);
79  this->start();
80  }
81  else if(ret==QMessageBox::YesAll)
82  {
83  yesToAll=true;
84  points.clear();
85  points=core->Projection()->GetAreaTileList(area,zoom,0);
86  this->start();
87  }
88  else
89  {
90  progressForm->close();
91  delete progressForm;
92  this->deleteLater();
93  }
94  }
95  else
96  {
97  yesToAll=false;
98  progressForm->close();
99  delete progressForm;
100  this->deleteLater();
101  }
102 }
103 
104 
106  {
107  int countOk = 0;
108  bool goodtile=false;
109  // Stuff.Shuffle<Point>(ref list);
110  QVector<core::MapType::Types> types = TLMaps::Instance()->GetAllLayersOfType(type);
111  int all=points.count();
112  for(int i = 0; i < all; i++)
113  {
114  emit numberOfTilesChanged(all,i+1);
115  if(cancel)
116  break;
117 
118  core::Point p = points[i];
119  {
120  //qDebug()<<"offline fetching:"<<p.ToString();
121  foreach(core::MapType::Types type,types)
122  {
123  emit providerChanged(core::MapType::StrByType(type),zoom);
124  QByteArray img = TLMaps::Instance()->GetImageFromServer(type, p, zoom);
125  if(img.length()!=0)
126  {
127  goodtile=true;
128  img=NULL;
129  }
130  else
131  goodtile=false;
132  }
133  if(goodtile)
134  {
135  countOk++;
136  }
137  else
138  {
139  i--;
140  QThread::msleep(1000);
141  continue;
142  }
143  }
144  emit percentageChanged((int) ((i+1)*100/all));//, i+1);
145  // worker.ReportProgress((int) ((i+1)*100/all), i+1);
146 
147  QThread::msleep(sleep);
148  }
149  }
150 
152  {
153  QMutexLocker locker(&mutex);
154  cancel=true;
155  }
156 }
void percentageChanged(int const &perc)
MapRipper(internals::Core *, internals::RectLatLng const &)
Definition: mapripper.cpp:31
int MaxZoom() const
Definition: core.h:147
PureProjection * Projection()
Definition: core.h:133
for i
Definition: OPPlots.m:140
QList< core::Point > GetAreaTileList(const RectLatLng &rect, const int &zoom, const int &padding)
void providerChanged(QString const &prov, int const &zoom)
A class that allows ripping of a selection of the map.
MapType::Types GetMapType()
Definition: core.h:151
int Zoom() const
Definition: core.h:144
bool IsEmpty() const
Definition: rectlatlng.h:158
void numberOfTilesChanged(int const &total, int const &actual)