Commit 812ee272 authored by Don Gagne's avatar Don Gagne
Browse files

Cut over 100% to new Map/Mission code

- Delete all old map code
parent 782af62d
/**
******************************************************************************
*
* @file kibertilecache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef KIBERTILECACHE_H
#define KIBERTILECACHE_H
#include "rawtile.h"
#include <QMutex>
#include <QReadWriteLock>
#include <QQueue>
#include <QDebug>
#include "debugheader.h"
namespace core {
class KiberTileCache
{
public:
KiberTileCache();
void setMemoryCacheCapacity(const int &value);
int MemoryCacheCapacity();
double MemoryCacheSize(){return memoryCacheSize/1048576.0;}
void RemoveMemoryOverload();
QReadWriteLock kiberCacheLock;
QHash <RawTile,QByteArray> cachequeue;
QQueue <RawTile> list;
long memoryCacheSize;
private:
int _MemoryCacheCapacity;
};
}
#endif // KIBERTILECACHE_H
/**
******************************************************************************
*
* @file languagetype.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "languagetype.h"
namespace core {
LanguageType::LanguageType()
{
list
<<"ar"
<<"bg"
<<"bn"
<<"ca"
<<"cs"
<<"da"
<<"de"
<<"el"
<<"en"
<<"en-AU"
<<"en-GB"
<<"es"
<<"eu"
<<"fi"
<<"fil"
<<"fr"
<<"gl"
<<"gu"
<<"hi"
<<"hr"
<<"hu"
<<"id"
<<"it"
<<"iw"
<<"ja"
<<"kn"
<<"ko"
<<"lt"
<<"lv"
<<"ml"
<<"mr"
<<"nl"
<<"nn"
<<"no"
<<"or"
<<"pl"
<<"pt"
<<"pt-BR"
<<"pt-PT"
<<"rm"
<<"ro"
<<"ru"
<<"sk"
<<"sl"
<<"sr"
<<"sv"
<<"ta"
<<"te"
<<"th"
<<"tr"
<<"uk"
<<"vi"
<<"zh-CN"
<<"zh-TW";
}
QString LanguageType::toShortString(Types type)
{
return list[type];
}
LanguageType::~LanguageType()
{
list.clear();
}
}
/**
******************************************************************************
*
* @file languagetype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LANGUAGETYPE_H
#define LANGUAGETYPE_H
#include <QString>
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace core {
class LanguageType:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
Arabic,
Bulgarian,
Bengali,
Catalan,
Czech,
Danish,
German,
Greek,
English,
EnglishAustralian,
EnglishGreatBritain,
Spanish,
Basque,
Finnish,
Filipino,
French,
Galician,
Gujarati,
Hindi,
Croatian,
Hungarian,
Indonesian,
Italian,
Hebrew,
Japanese,
Kannada,
Korean,
Lithuanian,
Latvian,
Malayalam,
Marathi,
Dutch,
NorwegianNynorsk,
Norwegian,
Oriya,
Polish,
Portuguese,
PortugueseBrazil,
PortuguesePortugal,
Romansch,
Romanian,
Russian,
Slovak,
Slovenian,
Serbian,
Swedish,
Tamil,
Telugu,
Thai,
Turkish,
Ukrainian,
Vietnamese,
ChineseSimplified,
ChineseTraditional
};
static QString StrByType(Types const& value)
{
QMetaObject metaObject = LanguageType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
QString s=metaEnum.valueToKey(value);
return s;
}
static Types TypeByStr(QString const& value)
{
QMetaObject metaObject = LanguageType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
Types s=(Types)metaEnum.keyToValue(value.toLatin1());
return s;
}
static QStringList TypesList()
{
QStringList ret;
QMetaObject metaObject = LanguageType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
for(int x=0;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
QString toShortString(Types type);
LanguageType();
~LanguageType();
private:
QStringList list;
};
}
#endif // LANGUAGETYPE_H
/**
******************************************************************************
*
* @file maptype.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MAPTYPE_H
#define MAPTYPE_H
#include <QMetaObject>
#include <QMetaEnum>
#include <QStringList>
namespace core {
class MapType:public QObject
{
Q_OBJECT
Q_ENUMS(Types)
public:
enum Types
{
GoogleMap=1,
GoogleSatellite=4,
GoogleLabels=8,
GoogleTerrain=16,
GoogleHybrid=20,
GoogleMapChina=22,
GoogleSatelliteChina=24,
GoogleLabelsChina=26,
GoogleTerrainChina=28,
GoogleHybridChina=29,
OpenStreetMap=32,
OpenStreetOsm=33,
OpenStreetMapSurfer=34,
OpenStreetMapSurferTerrain=35,
YahooMap=64,
YahooSatellite=128,
YahooLabels=256,
YahooHybrid=333,
BingMap=444,
BingSatellite=555,
BingHybrid=666,
ArcGIS_Map=777,
ArcGIS_Satellite=788,
ArcGIS_ShadedRelief=799,
ArcGIS_Terrain=811,
// use these numbers to clean up old stuff
//ArcGIS_MapsLT_Map_Old= 877,
//ArcGIS_MapsLT_OrtoFoto_Old = 888,
//ArcGIS_MapsLT_Map_Labels_Old = 890,
//ArcGIS_MapsLT_Map_Hybrid_Old = 899,
//ArcGIS_MapsLT_Map=977,
//ArcGIS_MapsLT_OrtoFoto=988,
//ArcGIS_MapsLT_Map_Labels=990,
//ArcGIS_MapsLT_Map_Hybrid=999,
//ArcGIS_MapsLT_Map=978,
//ArcGIS_MapsLT_OrtoFoto=989,
//ArcGIS_MapsLT_Map_Labels=991,
//ArcGIS_MapsLT_Map_Hybrid=998,
ArcGIS_MapsLT_Map=1000,
ArcGIS_MapsLT_OrtoFoto=1001,
ArcGIS_MapsLT_Map_Labels=1002,
ArcGIS_MapsLT_Map_Hybrid=1003,
PergoTurkeyMap = 2001,
SigPacSpainMap = 3001,
GoogleMapKorea=4001,
GoogleSatelliteKorea=4002,
GoogleLabelsKorea=4003,
GoogleHybridKorea=4005,
YandexMapRu = 5000
};
static QString StrByType(Types const& value)
{
QMetaObject metaObject = MapType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
QString s=metaEnum.valueToKey(value);
return s;
}
static Types TypeByStr(QString const& value)
{
QMetaObject metaObject = MapType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
Types s=(Types)metaEnum.keyToValue(value.toLatin1());
return s;
}
static QStringList TypesList()
{
QStringList ret;
QMetaObject metaObject = MapType().staticMetaObject;
QMetaEnum metaEnum= metaObject.enumerator( metaObject.indexOfEnumerator("Types"));
for(int x=0;x<metaEnum.keyCount();++x)
{
ret.append(metaEnum.key(x));
}
return ret;
}
};
}
#endif // MAPTYPE_H
/**
******************************************************************************
*
* @file memorycache.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "memorycache.h"
//TODO add readwrite lock
namespace core {
MemoryCache::MemoryCache()
{
}
QByteArray MemoryCache::GetTileFromMemoryCache(const RawTile &tile)
{
kiberCacheLock.lockForRead();
QByteArray pic;
pic=TilesInMemory.cachequeue.value(tile);
// TilesInMemory.find(key,&pic);
kiberCacheLock.unlock();
return pic;
}
void MemoryCache::AddTileToMemoryCache(const RawTile &tile, const QByteArray &pic)
{
kiberCacheLock.lockForWrite();
// QPixmapCache::Key key=TilesInMemory.insert(pic);
TilesInMemory.memoryCacheSize +=pic.size();
#ifdef DEBUG_MEMORY_CACHE
qDebug()<<"Current memory="<<TilesInMemory.memoryCacheSize<<" in "<<TilesInMemory.cachequeue.count()<<" tiles";
#endif
TilesInMemory.cachequeue.insert(tile,pic);
TilesInMemory.list.enqueue(tile);
kiberCacheLock.unlock();
}
}
/**
******************************************************************************
*
* @file memorycache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MEMORYCACHE_H
#define MEMORYCACHE_H
#include "rawtile.h"
#include <QMutex>
#include <QReadWriteLock>
#include <QQueue>
#include "kibertilecache.h"
#include <QDebug>
#include "debugheader.h"
namespace core {
class MemoryCache
{
public:
MemoryCache();
KiberTileCache TilesInMemory;
QByteArray GetTileFromMemoryCache(const RawTile &tile);
void AddTileToMemoryCache(const RawTile &tile, const QByteArray &pic);
QReadWriteLock kiberCacheLock;
};
}
#endif // MEMORYCACHE_H
/**
******************************************************************************
*
* @file OPMaps.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "opmaps.h"
namespace core {
OPMaps* OPMaps::m_pInstance=0;
OPMaps* OPMaps::Instance()
{
if(!m_pInstance)
m_pInstance=new OPMaps;
return m_pInstance;
}
OPMaps::OPMaps():RetryLoadTile(2),useMemoryCache(true)
{
accessmode=AccessMode::ServerAndCache;
Language=LanguageType::PortuguesePortugal;
LanguageStr=LanguageType().toShortString(Language);
Cache::Instance();
}
OPMaps::~OPMaps()
{
TileDBcacheQueue.wait();
}
QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom)
{
#ifdef DEBUG_TIMINGS
QTime time;
time.restart();
#endif
#ifdef DEBUG_GMAPS
qDebug()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
QByteArray ret;
if(useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from memory:Size="<<TilesInMemory.MemoryCacheSize();
#endif //DEBUG_GMAPS
ret=GetTileFromMemoryCache(RawTile(type,pos,zoom));
if(!ret.isEmpty())
{
errorvars.lock();
++diag.tilesFromMem;
errorvars.unlock();
}
}
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Tile not in memory";
#endif //DEBUG_GMAPS
if(accessmode != (AccessMode::ServerOnly))
{
#ifdef DEBUG_GMAPS
qDebug()<<"Try tile from DataBase";
#endif //DEBUG_GMAPS
ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom);
if(!ret.isEmpty())
{
errorvars.lock();
++diag.tilesFromDB;
errorvars.unlock();
#ifdef DEBUG_GMAPS
qDebug()<<"Tile found in Database";
#endif //DEBUG_GMAPS
if(useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add Tile to memory";
#endif //DEBUG_GMAPS
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
}
return ret;
}
}
if(accessmode!=AccessMode::CacheOnly)
{
QEventLoop q;
QNetworkReply *reply;
QNetworkRequest qheader;
QNetworkAccessManager network;
QTimer tT;
tT.setSingleShot(true);
connect(&network, SIGNAL(finished(QNetworkReply*)),
&q, SLOT(quit()));
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
network.setProxy(Proxy);
#ifdef DEBUG_GMAPS
qDebug()<<"Try Tile from the Internet";
#endif //DEBUG_GMAPS
#ifdef DEBUG_TIMINGS
qDebug()<<"opmaps before make image url"<<time.elapsed();
#endif
QString url=MakeImageUrl(type,pos,zoom,LanguageStr);
#ifdef DEBUG_TIMINGS
qDebug()<<"opmaps after make image url"<<time.elapsed();
#endif //url "http://vec02.maps.yandex.ru/tiles?l=map&v=2.10.2&x=7&y=5&z=3" string
//"http://map3.pergo.com.tr/tile/02/000/000/007/000/000/002.png"
qheader.setUrl(QUrl(url));
qheader.setRawHeader("User-Agent",UserAgent);
qheader.setRawHeader("Accept","*/*");
switch(type)
{
case MapType::GoogleMap:
case MapType::GoogleSatellite:
case MapType::GoogleLabels:
case MapType::GoogleTerrain:
case MapType::GoogleHybrid:
{
qheader.setRawHeader("Referrer", "http://maps.google.com/");
}
break;
case MapType::GoogleMapChina:
case MapType::GoogleSatelliteChina:
case MapType::GoogleLabelsChina:
case MapType::GoogleTerrainChina:
case MapType::GoogleHybridChina:
{
qheader.setRawHeader("Referrer", "http://ditu.google.cn/");
}
break;
case MapType::BingHybrid:
case MapType::BingMap:
case MapType::BingSatellite:
{
qheader.setRawHeader("Referrer", "http://www.bing.com/maps/");
}
break;
case MapType::YahooHybrid:
case MapType::YahooLabels:
case MapType::YahooMap:
case MapType::YahooSatellite:
{
qheader.setRawHeader("Referrer", "http://maps.yahoo.com/");
}
break;
case MapType::ArcGIS_MapsLT_Map_Labels:
case MapType::ArcGIS_MapsLT_Map:
case MapType::ArcGIS_MapsLT_OrtoFoto:
case MapType::ArcGIS_MapsLT_Map_Hybrid:
{
qheader.setRawHeader("Referrer", "http://www.maps.lt/map_beta/");
}
break;
case MapType::OpenStreetMapSurfer:
case MapType::OpenStreetMapSurferTerrain:
{
qheader.setRawHeader("Referrer", "http://www.mapsurfer.net/");
}
break;
case MapType::OpenStreetMap:
case MapType::OpenStreetOsm:
{
qheader.setRawHeader("Referrer", "http://www.openstreetmap.org/");
}
break;
case MapType::YandexMapRu:
{
qheader.setRawHeader("Referrer", "http://maps.yandex.ru/");
}
break;
default:
break;
}
reply=network.get(qheader);
tT.start(Timeout);
q.exec();
if(!tT.isActive()){
errorvars.lock();
++diag.timeouts;
errorvars.unlock();
return ret;
}
tT.stop();
if( (reply->error()!=QNetworkReply::NoError))
{
errorvars.lock();
++diag.networkerrors;
errorvars.unlock();
reply->deleteLater();
return ret;
}
ret=reply->readAll();
reply->deleteLater();//TODO can't this be global??
if(ret.isEmpty())
{
#ifdef DEBUG_GMAPS
qDebug()<<"Invalid Tile";
#endif //DEBUG_GMAPS
errorvars.lock();
++diag.emptytiles;
errorvars.unlock();
return ret;
}
#ifdef DEBUG_GMAPS
qDebug()<<"Received Tile from the Internet";
#endif //DEBUG_GMAPS
errorvars.lock();
++diag.tilesFromNet;
errorvars.unlock();
if (useMemoryCache)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add Tile to memory cache";
#endif //DEBUG_GMAPS
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
}
if(accessmode!=AccessMode::ServerOnly)
{
#ifdef DEBUG_GMAPS
qDebug()<<"Add tile to DataBase";
#endif //DEBUG_GMAPS
CacheItemQueue * item=new CacheItemQueue(type,pos,ret,zoom);
TileDBcacheQueue.EnqueueCacheTask(item);
}
}
}
#ifdef DEBUG_GMAPS
qDebug()<<"Entered GetImageFrom";
#endif //DEBUG_GMAPS
return ret;
}
bool OPMaps::ExportToGMDB(const QString &file)
{
return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file);
}
bool OPMaps::ImportFromGMDB(const QString &file)
{
return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb");
}
diagnostics OPMaps::GetDiagnostics()
{
diagnostics i;
errorvars.lock();
i=diag;
errorvars.unlock();
return i;
}
}
/**
******************************************************************************
*
* @file OPMaps.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef OPMaps_H
#define OPMaps_H
#include "debugheader.h"
#include "memorycache.h"
#include "rawtile.h"
#include "cache.h"
#include "accessmode.h"
#include "languagetype.h"
#include "cacheitemqueue.h"
#include "tilecachequeue.h"
#include "pureimagecache.h"
#include "alllayersoftype.h"
#include "urlfactory.h"
#include "diagnostics.h"
//#include "point.h"
namespace core {
class OPMaps: public MemoryCache,public AllLayersOfType,public UrlFactory
{
public:
~OPMaps();
static OPMaps* Instance();
bool ImportFromGMDB(const QString &file);
bool ExportToGMDB(const QString &file);
/// <summary>
/// timeout for map connections
/// </summary>
QByteArray GetImageFrom(const MapType::Types &type,const core::Point &pos,const int &zoom);
bool UseMemoryCache(){return useMemoryCache;}//TODO
void setUseMemoryCache(const bool& value){useMemoryCache=value;}
void setLanguage(const LanguageType::Types& language){Language=language;}//TODO
LanguageType::Types GetLanguage(){return Language;}//TODO
AccessMode::Types GetAccessMode()const{return accessmode;}
void setAccessMode(const AccessMode::Types& mode){accessmode=mode;}
int RetryLoadTile;
diagnostics GetDiagnostics();
private:
bool useMemoryCache;
LanguageType::Types Language;
AccessMode::Types accessmode;
// PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set
TileCacheQueue TileDBcacheQueue;
OPMaps();
//OPMaps(OPMaps const&){}
OPMaps& operator=(OPMaps const&){ return *this; }
static OPMaps* m_pInstance;
diagnostics diag;
QMutex errorvars;
protected:
// MemoryCache TilesInMemory;
};
}
#endif // OPMaps_H
/**
******************************************************************************
*
* @file placemark.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "placemark.h"
/**
******************************************************************************
*
* @file placemark.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PLACEMARK_H
#define PLACEMARK_H
#include <QString>
namespace core {
class Placemark
{
public:
Placemark(const QString &address)
{
this->address = address;
}
QString Address(){return address;}
int Accuracy(){return accuracy;}
void SetAddress(const QString &adr){address=adr;}
void SetAccuracy(const int &value){accuracy=value;}
private:
QString address;
int accuracy;
protected:
};
}
#endif // PLACEMARK_H
/**
******************************************************************************
*
* @file point.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "point.h"
#include "size.h"
namespace core {
Point::Point(int dw)
{
this->x=(short)Point::loWord(dw);
this->y=(short)Point::hiWord(dw);
empty=false;
}
Point::Point(Size sz)
{
this->x=sz.Width();
this->y=sz.Height();
empty=false;
}
Point::Point(int x, int y)
{
this->x=x;
this->y=y;
empty=false;
}
Point::Point():x(0),y(0),empty(true)
{}
uint qHash(Point const& point)
{
return point.x^point.y;
}
bool operator==(Point const &lhs,Point const &rhs)
{
return (lhs.x==rhs.x && lhs.y==rhs.y);
}
bool operator!=(Point const &lhs,Point const &rhs)
{
return !(lhs==rhs);
}
Point Point::Empty=Point();
}
/**
******************************************************************************
*
* @file point.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef OPOINT_H
#define OPOINT_H
#include <QString>
namespace core {
struct Size;
struct Point
{
friend uint qHash(Point const& point);
friend bool operator==(Point const& lhs,Point const& rhs);
friend bool operator!=(Point const& lhs,Point const& rhs);
public:
Point();
Point(int x,int y);
Point(Size sz);
Point(int dw);
bool IsEmpty(){return empty;}
int X()const{return this->x;}
int Y()const{return this->y;}
void SetX(const int &value){x=value;empty=false;}
void SetY(const int &value){y=value;empty=false;}
QString ToString()const{return "{"+QString::number(x)+","+QString::number(y)+"}";}
static Point Empty;
void Offset(const int &dx,const int &dy)
{
x += dx;
y += dy;
}
void Offset(Point p)
{
Offset(p.x, p.y);
}
static int hiWord(int n)
{
return (n >> 16) & 0xffff;
}
static int loWord(int n)
{
return n & 0xffff;
}
private:
int x;
int y;
bool empty;
};
}
#endif // POINT_H
/**
******************************************************************************
*
* @file providerstrings.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "providerstrings.h"
namespace core {
const QString ProviderStrings::levelsForSigPacSpainMap[] = {"0", "1", "2", "3", "4",
"MTNSIGPAC",
"MTN2000", "MTN2000", "MTN2000", "MTN2000", "MTN2000",
"MTN200", "MTN200", "MTN200",
"MTN25", "MTN25",
"ORTOFOTOS","ORTOFOTOS","ORTOFOTOS","ORTOFOTOS"};
ProviderStrings::ProviderStrings()
{
// VersionGoogleMap = "m@132";
// VersionGoogleSatellite = "71";
// VersionGoogleLabels = "h@132";
// VersionGoogleTerrain = "t@125,r@132";
// Google version strings
VersionGoogleMap = "m@132";
VersionGoogleSatellite = "71";
VersionGoogleLabels = "h@132";
VersionGoogleTerrain = "t@125,r@132";
SecGoogleWord = "Galileo";
// Google (China) version strings
VersionGoogleMapChina = "m@132";
VersionGoogleSatelliteChina = "s@71";
VersionGoogleLabelsChina = "h@132";
VersionGoogleTerrainChina = "t@125,r@132";
// Google (Korea) version strings
VersionGoogleMapKorea = "kr1.12";
VersionGoogleSatelliteKorea = "66";
VersionGoogleLabelsKorea = "kr1t.12";
/// <summary>
/// Google Maps API generated using http://greatmaps.codeplex.com/
/// from http://code.google.com/intl/en-us/apis/maps/signup.html
/// </summary>
GoogleMapsAPIKey = "ABQIAAAA5Q6wxQ6lxKS8haLVdUJaqhSjosg_0jiTTs2iXtkDVG0n0If1mBRHzhWw5VqBZX-j4NuzoVpU-UaHVg";
// Yahoo version strings
VersionYahooMap = "4.3";
VersionYahooSatellite = "1.9";
VersionYahooLabels = "4.3";
// BingMaps
VersionBingMaps = "563";
// YandexMap
VersionYandexMap = "2.16.0";
//VersionYandexSatellite = "1.19.0";
////////////////////
/// <summary>
/// Bing Maps Customer Identification, more info here
/// http://msdn.microsoft.com/en-us/library/bb924353.aspx
/// </summary>
BingMapsClientToken = "";
}
}
/**
******************************************************************************
*
* @file providerstrings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PROVIDERSTRINGS_H
#define PROVIDERSTRINGS_H
#include <QString>
namespace core {
class ProviderStrings
{
public:
ProviderStrings();
static const QString levelsForSigPacSpainMap[];
QString GoogleMapsAPIKey;
// Google version strings
QString VersionGoogleMap;
QString VersionGoogleSatellite;
QString VersionGoogleLabels;
QString VersionGoogleTerrain;
QString SecGoogleWord;
// Google (China) version strings
QString VersionGoogleMapChina;
QString VersionGoogleSatelliteChina;
QString VersionGoogleLabelsChina;
QString VersionGoogleTerrainChina;
// Google (Korea) version strings
QString VersionGoogleMapKorea;
QString VersionGoogleSatelliteKorea;
QString VersionGoogleLabelsKorea;
/// <summary>
/// Google Maps API generated using http://greatmaps.codeplex.com/
/// from http://code.google.com/intl/en-us/apis/maps/signup.html
/// </summary>
// Yahoo version strings
QString VersionYahooMap;
QString VersionYahooSatellite;
QString VersionYahooLabels;
// BingMaps
QString VersionBingMaps;
// YandexMap
QString VersionYandexMap;
/// <summary>
/// Bing Maps Customer Identification, more info here
/// http://msdn.microsoft.com/en-us/library/bb924353.aspx
/// </summary>
QString BingMapsClientToken;
};
}
#endif // PROVIDERSTRINGS_H
/**
******************************************************************************
*
* @file pureimage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pureimage.h"
namespace core {
PureImageProxy::PureImageProxy()
{
}
QPixmap PureImageProxy::FromStream(const QByteArray &array)
{
return QPixmap::fromImage(QImage::fromData(array));
}
bool PureImageProxy::Save(const QByteArray &array, QPixmap &pic)
{
pic=QPixmap::fromImage(QImage::fromData(array));
return true;
}
}
/**
******************************************************************************
*
* @file pureimage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PUREIMAGE_H
#define PUREIMAGE_H
#include <QPixmap>
#include <QByteArray>
namespace core {
class PureImageProxy
{
public:
PureImageProxy();
static QPixmap FromStream(const QByteArray &array);
static bool Save(const QByteArray &array,QPixmap &pic);
};
}
#endif // PUREIMAGE_H
/**
******************************************************************************
*
* @file pureimagecache.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pureimagecache.h"
#include <QDateTime>
#include <QSettings>
//#define DEBUG_PUREIMAGECACHE
namespace core {
static QMutex addDatabaseMutex; // QSqlDatabase::addDatabase is not thread safe when loadingn plugins
qlonglong PureImageCache::ConnCounter=0;
PureImageCache::PureImageCache()
{
}
void PureImageCache::setGtileCache(const QString &value)
{
lock.lockForWrite();
gtilecache=value;
QDir d;
if(!d.exists(gtilecache))
{
d.mkdir(gtilecache);
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create Cache directory";
#endif //DEBUG_PUREIMAGECACHE
}
{
QString db=gtilecache+"Data.qmdb";
if(!QFileInfo(db).exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Try to create EmptyDB";
#endif //DEBUG_PUREIMAGECACHE
CreateEmptyDB(db);
}
}
lock.unlock();
}
QString PureImageCache::GtileCache()
{
return gtilecache;
}
bool PureImageCache::CreateEmptyDB(const QString &file)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Create database at!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:"<<file;
#endif //DEBUG_PUREIMAGECACHE
QFileInfo File(file);
QDir dir=File.absoluteDir();
QString path=dir.absolutePath();
QString filename=File.fileName();
if(File.exists())
QFile(filename).remove();
if(!dir.exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: Cache path doesn't exist, try to create";
#endif //DEBUG_PUREIMAGECACHE
if(!dir.mkpath(path))
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: Could not create path";
#endif //DEBUG_PUREIMAGECACHE
return false;
}
}
addDatabaseMutex.lock();
QSqlDatabase db(QSqlDatabase::addDatabase("QSQLITE",QLatin1String("CreateConn")));
addDatabaseMutex.unlock();
db.setDatabaseName(file);
if (!db.open())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: Unable to create database";
#endif //DEBUG_PUREIMAGECACHE
return false;
}
QSqlQuery query(db);
query.exec("CREATE TABLE IF NOT EXISTS Tiles (id INTEGER NOT NULL PRIMARY KEY, X INTEGER NOT NULL, Y INTEGER NOT NULL, Zoom INTEGER NOT NULL, Type INTEGER NOT NULL,Date TEXT)");
if(query.numRowsAffected()==-1)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: "<<query.lastError().driverText();
#endif //DEBUG_PUREIMAGECACHE
db.close();
return false;
}
query.exec("CREATE TABLE IF NOT EXISTS TilesData (id INTEGER NOT NULL PRIMARY KEY CONSTRAINT fk_Tiles_id REFERENCES Tiles(id) ON DELETE CASCADE, Tile BLOB NULL)");
if(query.numRowsAffected()==-1)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: "<<query.lastError().driverText();
#endif //DEBUG_PUREIMAGECACHE
db.close();
return false;
}
query.exec(
"CREATE TRIGGER fki_TilesData_id_Tiles_id "
"BEFORE INSERT ON [TilesData] "
"FOR EACH ROW BEGIN "
"SELECT RAISE(ROLLBACK, 'insert on table TilesData violates foreign key constraint fki_TilesData_id_Tiles_id') "
"WHERE (SELECT id FROM Tiles WHERE id = NEW.id) IS NULL; "
"END");
if(query.numRowsAffected()==-1)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: "<<query.lastError().driverText();
#endif //DEBUG_PUREIMAGECACHE
db.close();
return false;
}
query.exec(
"CREATE TRIGGER fku_TilesData_id_Tiles_id "
"BEFORE UPDATE ON [TilesData] "
"FOR EACH ROW BEGIN "
"SELECT RAISE(ROLLBACK, 'update on table TilesData violates foreign key constraint fku_TilesData_id_Tiles_id') "
"WHERE (SELECT id FROM Tiles WHERE id = NEW.id) IS NULL; "
"END");
if(query.numRowsAffected()==-1)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: "<<query.lastError().driverText();
#endif //DEBUG_PUREIMAGECACHE
db.close();
return false;
}
query.exec(
"CREATE TRIGGER fkdc_TilesData_id_Tiles_id "
"BEFORE DELETE ON Tiles "
"FOR EACH ROW BEGIN "
"DELETE FROM TilesData WHERE TilesData.id = OLD.id; "
"END");
if(query.numRowsAffected()==-1)
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"CreateEmptyDB: "<<query.lastError().driverText();
#endif //DEBUG_PUREIMAGECACHE
db.close();
return false;
}
db.close();
QSqlDatabase::removeDatabase(QLatin1String("CreateConn"));
return true;
}
bool PureImageCache::PutImageToCache(const QByteArray &tile, const MapType::Types &type,const Point &pos,const int &zoom)
{
if(gtilecache.isEmpty()|gtilecache.isNull())
return false;
lock.lockForRead();
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"PutImageToCache Start:";//<<pos;
#endif //DEBUG_PUREIMAGECACHE
Mcounter.lock();
qlonglong id=++ConnCounter;
Mcounter.unlock();
{
addDatabaseMutex.lock();
QSqlDatabase cn(QSqlDatabase::addDatabase("QSQLITE",QString::number(id)));
addDatabaseMutex.unlock();
QString db=gtilecache+"Data.qmdb";
cn.setDatabaseName(db);
cn.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE");
if(cn.open())
{
{
QSqlQuery query(cn);
query.prepare("INSERT INTO Tiles(X, Y, Zoom, Type,Date) VALUES(?, ?, ?, ?,?)");
query.addBindValue(pos.X());
query.addBindValue(pos.Y());
query.addBindValue(zoom);
query.addBindValue((int)type);
query.addBindValue(QDateTime::currentDateTime().toString());
query.exec();
}
{
QSqlQuery query(cn);
query.prepare("INSERT INTO TilesData(id, Tile) VALUES((SELECT last_insert_rowid()), ?)");
query.addBindValue(tile);
query.exec();
}
cn.close();
}
}
QSqlDatabase::removeDatabase(QString::number(id));
lock.unlock();
return true;
}
QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int zoom)
{
lock.lockForRead();
QByteArray ar;
if(gtilecache.isEmpty()|gtilecache.isNull())
return ar;
QString dir=gtilecache;
Mcounter.lock();
qlonglong id=++ConnCounter;
Mcounter.unlock();
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Cache dir="<<dir<<" Try to GET:"<<pos.X()<<","<<pos.Y();
#endif //DEBUG_PUREIMAGECACHE
QString db=dir+"Data.qmdb";
{
addDatabaseMutex.lock();
QSqlDatabase cn(QSqlDatabase::addDatabase("QSQLITE",QString::number(id)));
addDatabaseMutex.unlock();
cn.setDatabaseName(db);
cn.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE");
if(cn.open())
{
QSqlQuery query(cn);
query.exec(QString("SELECT Tile FROM TilesData WHERE id = (SELECT id FROM Tiles WHERE X=%1 AND Y=%2 AND Zoom=%3 AND Type=%4)").arg(pos.X()).arg(pos.Y()).arg(zoom).arg((int) type));
query.next();
if(query.isValid())
{
ar=query.value(0).toByteArray();
}
cn.close();
}
}
QSqlDatabase::removeDatabase(QString::number(id));
lock.unlock();
return ar;
}
void PureImageCache::deleteOlderTiles(int const& days)
{
if(gtilecache.isEmpty()|gtilecache.isNull())
return;
QList<long> add;
bool ret=true;
QString dir=gtilecache;
{
QString db=dir+"Data.qmdb";
ret=QFileInfo(db).exists();
if(ret)
{
Mcounter.lock();
qlonglong id=++ConnCounter;
Mcounter.unlock();
addDatabaseMutex.lock();
QSqlDatabase cn(QSqlDatabase::addDatabase("QSQLITE",QString::number(id)));
addDatabaseMutex.unlock();
cn.setDatabaseName(db);
cn.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE");
if(cn.open())
{
{
QSqlQuery query(cn);
query.exec(QString("SELECT id, X, Y, Zoom, Type, Date FROM Tiles"));
while(query.next())
{
if(QDateTime::fromString(query.value(5).toString()).daysTo(QDateTime::currentDateTime())>days)
add.append(query.value(0).toLongLong());
}
foreach(long i,add)
{
query.exec(QString("DELETE FROM Tiles WHERE id = %1;").arg(i));
}
}
cn.close();
}
QSqlDatabase::removeDatabase(QString::number(id));
}
}
}
// PureImageCache::ExportMapDataToDB("C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data.qmdb","C:/Users/Xapo/Documents/mapcontrol/debug/mapscache/data2.qmdb");
bool PureImageCache::ExportMapDataToDB(QString sourceFile, QString destFile)
{
bool ret=true;
QList<long> add;
if(!QFileInfo(destFile).exists())
{
#ifdef DEBUG_PUREIMAGECACHE
qDebug()<<"Try to create EmptyDB";
#endif //DEBUG_PUREIMAGECACHE
ret=CreateEmptyDB(destFile);
}
if(!ret) return false;
addDatabaseMutex.lock();
QSqlDatabase ca(QSqlDatabase::addDatabase("QSQLITE","ca"));
addDatabaseMutex.unlock();
ca.setDatabaseName(sourceFile);
if(ca.open())
{
addDatabaseMutex.lock();
QSqlDatabase cb(QSqlDatabase::addDatabase("QSQLITE","cb"));
addDatabaseMutex.unlock();
cb.setDatabaseName(destFile);
if(cb.open())
{
QSqlQuery queryb(cb);
queryb.exec(QString("ATTACH DATABASE \"%1\" AS Source").arg(sourceFile));
QSqlQuery querya(ca);
querya.exec("SELECT id, X, Y, Zoom, Type, Date FROM Tiles");
while(querya.next())
{
long id=querya.value(0).toLongLong();
queryb.exec(QString("SELECT id FROM Tiles WHERE X=%1 AND Y=%2 AND Zoom=%3 AND Type=%4;").arg(querya.value(1).toLongLong()).arg(querya.value(2).toLongLong()).arg(querya.value(3).toLongLong()).arg(querya.value(4).toLongLong()));
if(!queryb.next())
{
add.append(id);
}
}
long f;
foreach(f,add)
{
queryb.exec(QString("INSERT INTO Tiles(X, Y, Zoom, Type, Date) SELECT X, Y, Zoom, Type, Date FROM Source.Tiles WHERE id=%1").arg(f));
queryb.exec(QString("INSERT INTO TilesData(id, Tile) Values((SELECT last_insert_rowid()), (SELECT Tile FROM Source.TilesData WHERE id=%1))").arg(f));
}
add.clear();
ca.close();
cb.close();
}
else return false;
}
else return false;
QSqlDatabase::removeDatabase("ca");
QSqlDatabase::removeDatabase("cb");
return true;
}
}
/**
******************************************************************************
*
* @file pureimagecache.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PUREIMAGECACHE_H
#define PUREIMAGECACHE_H
#include <QtSql/QSqlDatabase>
#include <QString>
#include <QDir>
#include <QDebug>
#include <QFileInfo>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlError>
#include <QBuffer>
#include "maptype.h"
#include "point.h"
#include <QVariant>
#include "pureimage.h"
#include <QList>
#include <QMutex>
#include <QReadWriteLock>
namespace core {
class PureImageCache
{
public:
PureImageCache();
static bool CreateEmptyDB(const QString &file);
bool PutImageToCache(const QByteArray &tile,const MapType::Types &type,const core::Point &pos, const int &zoom);
QByteArray GetImageFromCache(MapType::Types type, core::Point pos, int zoom);
QString GtileCache();
void setGtileCache(const QString &value);
static bool ExportMapDataToDB(QString sourceFile, QString destFile);
void deleteOlderTiles(int const& days);
private:
QString gtilecache;
QMutex Mcounter;
QReadWriteLock lock;
static qlonglong ConnCounter;
};
}
#endif // PUREIMAGECACHE_H
/**
******************************************************************************
*
* @file rawtile.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rawtile.h"
namespace core {
RawTile::RawTile(const MapType::Types &Type, const Point &Pos, const int &Zoom)
{
zoom=Zoom;
type=Type;
pos=Pos;
}
QString RawTile::ToString()
{
return QString("%1 at zoom %2, pos:%3,%4").arg(type).arg(zoom).arg(pos.X()).arg(pos.Y());
}
Point RawTile::Pos()
{
return pos;
}
MapType::Types RawTile::Type()
{
return type;
}
int RawTile::Zoom()
{
return zoom;
}
void RawTile::setType(const MapType::Types &value)
{
type=value;
}
void RawTile::setPos(const Point &value)
{
pos=value;
}
void RawTile::setZoom(const int &value)
{
zoom=value;
}
uint qHash(RawTile const& tile)
{
// RawTile tile=tilee;
quint64 tmp=(((quint64)(tile.zoom))<<54)+(((quint64)(tile.type))<<36)+(((quint64)(tile.pos.X()))<<18)+(((quint64)(tile.pos.Y())));
// quint64 tmp5=tmp+tmp2+tmp3+tmp4;
return ::qHash(tmp);
}
bool operator==(RawTile const &lhs,RawTile const &rhs)
{
return (lhs.pos==rhs.pos && lhs.zoom==rhs.zoom && lhs.type==rhs.type);
}
}
/**
******************************************************************************
*
* @file rawtile.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef RAWTILE_H
#define RAWTILE_H
#include "maptype.h"
#include "point.h"
#include <QString>
#include <QHash>
namespace core {
class RawTile
{
friend uint qHash(RawTile const& tile);
friend bool operator==(RawTile const& lhs,RawTile const& rhs);
public:
RawTile(const MapType::Types &Type,const core::Point &Pos,const int &Zoom);
QString ToString(void);
MapType::Types Type();
core::Point Pos();
int Zoom();
void setType(const MapType::Types &value);
void setPos(const core::Point &value);
void setZoom(const int &value);
private:
MapType::Types type;
core::Point pos;
int zoom;
};
}
#endif // RAWTILE_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment