📄 place.cpp
字号:
/*
qpegps is a program for displaying a map centered at the current longitude/
latitude as read from a gps receiver.
Copyright (C) 2002 Ralf Haselmeier <Ralf.Haselmeier@gmx.de>
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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "place.h"
#include <qfile.h>
#include <qmessagebox.h>
PlaceList::PlaceList()
{
setAutoDelete(true);
}
int PlaceList::compareItems( Item s1, Item s2 )
{
Place *p1 = (Place *)s1;
Place *p2 = (Place *)s2;
if (p1->pos.lat > p2->pos.lat)
return -1;
else if (p1->pos.lat < p2->pos.lat)
return 1;
else {
if (p1->pos.lon < p2->pos.lon)
return -1;
else if (p1->pos.lon > p2->pos.lon)
return 1;
else
return 0;
}
return 0;
}
void PlaceList::readPlaces( const QString &filename )
{
// clear previous places
clear();
Place *newPlace;
QFile placesFile(filename);
if ( placesFile.open(IO_ReadOnly) ) {
QTextStream t( &placesFile );
t.setEncoding(QTextStream::UnicodeUTF8);
QString pro;
while ( !t.eof() ) {
t >> pro;
if ( pro[0]=='#')
pro= t.readLine();
else {
newPlace = new Place;
newPlace->name= pro;
t >> pro;
newPlace->pos.lat = pro.toDouble();
t >> pro;
newPlace->pos.lon = pro.toDouble();
t >> pro;
newPlace->altitude = pro.toDouble();
pro = t.readLine().stripWhiteSpace();
newPlace->comment= pro;
append(newPlace);
}
}
placesFile.close();
}
sort();
// add none place
newPlace = new Place;
newPlace->name = QObject::tr("none");
newPlace->pos.lat = 0;
newPlace->pos.lon = 0;
newPlace->altitude.val = 0;
prepend(newPlace);
}
void PlaceList::writePlaces( const QString &filename )
{
int ok=0;
bool newpl;
// make a backup copy
::remove(filename + "~");
::rename(filename, filename + "~");
QFile placesFile(filename);
if ( placesFile.exists() )
newpl = false;
else
newpl = true;
if ( ! (placesFile.open(IO_WriteOnly)) ) {
while ( !QMessageBox::warning( NULL, "Saving places...",
"Can't open/create file:\n" + filename +
"\nPlace not saved. Please check file/directory access rights.\n",
"Try again","Ignore", 0, 0, 1 ) ) {
ok = placesFile.open(IO_WriteOnly);
if (ok)
break;
}
if ( !ok ) {
::rename(filename+"~", filename);
return;
}
}
QTextStream t( &placesFile );
t.setEncoding(QTextStream::UnicodeUTF8);
if ( newpl ) {
t << "#format is: <Name> <latitude (fload decimal)> <longitude (fload decimal)> <altitude> <comment>\r\n";
}
first();
Place *pl = next();
while ( pl != NULL ) {
t << (pl->name+"\t" + QObject::tr("%1").arg(pl->pos.lat,6,'f') +
"\t" + QObject::tr("%1").arg(pl->pos.lon,6,'f') +
"\t" + QObject::tr("%1").arg(pl->altitude.val,6,'f') +
"\t" + pl->comment + "\r\n");
pl = next();
};
placesFile.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -