StelLocation.cpp   StelLocation.cpp 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelLocation.hpp" #include "StelLocation.hpp"
#include "StelLocationMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QTimeZone>
#include <QStringList> #include <QStringList>
const int StelLocation::DEFAULT_BORTLE_SCALE_INDEX = 2; const int StelLocation::DEFAULT_BORTLE_SCALE_INDEX = 2;
int StelLocation::metaTypeId = initMetaType(); int StelLocation::metaTypeId = initMetaType();
int StelLocation::initMetaType() int StelLocation::initMetaType()
{ {
return qRegisterMetaType<StelLocation>(); return qRegisterMetaType<StelLocation>();
} }
// Output the location as a string ready to be stored in the user_location file // Output the location as a string ready to be stored in the user_location file
QString StelLocation::serializeToLine() const QString StelLocation::serializeToLine() const
{ {
QString sanitizedTZ=StelLocationMgr::sanitizeTimezoneStringForLocati onDB(ianaTimeZone);
return QString("%1\t%2\t%3\t%4\t%5\t%6\t%7\t%8\t%9\t%10\t%11\t%12") return QString("%1\t%2\t%3\t%4\t%5\t%6\t%7\t%8\t%9\t%10\t%11\t%12")
.arg(name) .arg(name)
.arg(state) .arg(state)
.arg(country) .arg(country)
.arg(role) .arg(role)
.arg(population/1000) .arg(population/1000)
.arg(latitude<0 ? QString("%1S").arg(-latitude, 0, ' f', 6) : QString("%1N").arg(latitude, 0, 'f', 6)) .arg(latitude<0 ? QString("%1S").arg(-latitude, 0, ' f', 6) : QString("%1N").arg(latitude, 0, 'f', 6))
.arg(longitude<0 ? QString("%1W").arg(-longitude, 0, 'f', 6) : QString("%1E").arg(longitude, 0, 'f', 6)) .arg(longitude<0 ? QString("%1W").arg(-longitude, 0, 'f', 6) : QString("%1E").arg(longitude, 0, 'f', 6))
.arg(altitude) .arg(altitude)
.arg(bortleScaleIndex) .arg(bortleScaleIndex)
.arg(timeZone) .arg(sanitizedTZ)
.arg(planetName) .arg(planetName)
.arg(landscapeKey); .arg(landscapeKey);
} }
QString StelLocation::getID() const QString StelLocation::getID() const
{ {
if (name.isEmpty()) if (name.isEmpty())
{ return QString("%1, %2").arg(latitude).arg(longitude);
return QString("%1,%2").arg(latitude).arg(longitude);
}
QString ret = name;
if (!country.isEmpty()) if (!country.isEmpty())
ret += ", " + country; return QString("%1, %2").arg(name).arg(country);
return ret; else
return name;
} }
// GZ TODO: These operators may require the sanitizing for timezone names!
QDataStream& operator<<(QDataStream& out, const StelLocation& loc) QDataStream& operator<<(QDataStream& out, const StelLocation& loc)
{ {
out << loc.name << loc.state << loc.country << loc.role << loc.popul ation << loc.latitude << loc.longitude << loc.altitude << loc.bortleScaleIn dex << loc.timeZone << loc.planetName << loc.landscapeKey << loc.isUserLoca tion; out << loc.name << loc.state << loc.country << loc.role << loc.popul ation << loc.latitude << loc.longitude << loc.altitude << loc.bortleScaleIn dex << loc.ianaTimeZone << loc.planetName << loc.landscapeKey << loc.isUser Location;
return out; return out;
} }
QDataStream& operator>>(QDataStream& in, StelLocation& loc) QDataStream& operator>>(QDataStream& in, StelLocation& loc)
{ {
in >> loc.name >> loc.state >> loc.country >> loc.role >> loc.popula tion >> loc.latitude >> loc.longitude >> loc.altitude >> loc.bortleScaleInd ex >> loc.timeZone >> loc.planetName >> loc.landscapeKey >> loc.isUserLocat ion; in >> loc.name >> loc.state >> loc.country >> loc.role >> loc.popula tion >> loc.latitude >> loc.longitude >> loc.altitude >> loc.bortleScaleInd ex >> loc.ianaTimeZone >> loc.planetName >> loc.landscapeKey >> loc.isUserL ocation;
return in; return in;
} }
// Parse a location from a line serialization // Parse a location from a line serialization
StelLocation StelLocation::createFromLine(const QString& rawline) StelLocation StelLocation::createFromLine(const QString& rawline)
{ {
StelLocation loc; StelLocation loc;
const QStringList& splitline = rawline.split("\t"); const QStringList& splitline = rawline.split("\t");
loc.name = splitline.at(0).trimmed(); loc.name = splitline.at(0).trimmed();
loc.state = splitline.at(1).trimmed(); loc.state = splitline.at(1).trimmed();
skipping to change at line 115 skipping to change at line 118
loc.bortleScaleIndex = splitline.at(8).toInt(&ok); loc.bortleScaleIndex = splitline.at(8).toInt(&ok);
if (ok==false) if (ok==false)
loc.bortleScaleIndex = DEFAULT_BORTLE_SCALE_INDEX; loc.bortleScaleIndex = DEFAULT_BORTLE_SCALE_INDEX;
} }
else else
loc.bortleScaleIndex = DEFAULT_BORTLE_SCALE_INDEX; loc.bortleScaleIndex = DEFAULT_BORTLE_SCALE_INDEX;
if (splitline.size()>9) if (splitline.size()>9)
{ {
// Parse time zone // Parse time zone
loc.timeZone = splitline.at(9).trimmed(); loc.ianaTimeZone = splitline.at(9).trimmed();
// GZ Check whether the timezone ID is available in the curr
ent Qt/IANA list?
if ( ! QTimeZone::isTimeZoneIdAvailable(loc.ianaTimeZone.toU
tf8()))
{
// Try to find a currently used IANA string from our
known replacements.
QString fitName=StelLocationMgr::sanitizeTimezoneStr
ingFromLocationDB(loc.ianaTimeZone);
qDebug() << "StelLocation::createFromLine(): TimeZon
e name for " << loc.name << " not found. Translating" << loc.ianaTimeZone <
< " to " << fitName;
loc.ianaTimeZone=fitName;
}
} }
if (splitline.size()>10) if (splitline.size()>10)
{ {
// Parse planet name // Parse planet name
loc.planetName = splitline.at(10).trimmed(); loc.planetName = splitline.at(10).trimmed();
} }
else else
{ {
// Earth by default // Earth by default
 End of changes. 10 change blocks. 
10 lines changed or deleted 27 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/