Fix possible memleak in CDatabaseWriter

* CApplication network methods cleanup
This commit is contained in:
Michał Garapich
2016-08-02 18:29:47 +02:00
parent 1032b2f506
commit 39dae7ed45
11 changed files with 69 additions and 97 deletions

View File

@@ -52,13 +52,16 @@ namespace BlackMisc
(void)QT_TRANSLATE_NOOP("Aviation", "Airport");
}
void CAirport::fromDatabaseJson(const QJsonObject &json)
void CAirport::convertFromDatabaseJson(const QJsonObject &json)
{
Q_ASSERT(json.value("icao").isString());
setIcao(json.value("icao").toString());
Q_ASSERT(json.value("country").isString());
setCountry(json.value("country").toString());
if (json.value("alpha3").isString() && json.value("country").isString())
{
CCountry country(json.value("alpha3").toString(), json.value("country").toString());
setCountry(country);
}
Q_ASSERT(json.value("name").isString());
setDescriptiveName(json.value("name").toString());

View File

@@ -19,6 +19,7 @@
#include "blackmisc/geo/longitude.h"
#include "blackmisc/metaclass.h"
#include "blackmisc/pq/length.h"
#include "blackmisc/country.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/variant.h"
@@ -80,10 +81,10 @@ namespace BlackMisc
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
//! Get the country
QString getCountry() const { return m_country; }
const CCountry& getCountry() const { return m_country; }
//! Set the country
void setCountry(const QString &country) { this->m_country = country; }
void setCountry(const CCountry &country) { this->m_country = country; }
//! Elevation
//! \sa geodeticHeight
@@ -131,13 +132,13 @@ namespace BlackMisc
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::CValueObject::convertFromJson
void fromDatabaseJson(const QJsonObject &json);
void convertFromDatabaseJson(const QJsonObject &json);
private:
CAirportIcaoCode m_icao;
QString m_descriptiveName;
BlackMisc::Geo::CCoordinateGeodetic m_position;
QString m_country;
CCountry m_country;
BLACK_METACLASS(
CAirport,

View File

@@ -44,18 +44,17 @@ namespace BlackMisc
return this->findFirstByOrDefault(&CAirport::getIcao, icao, ifNotFound);
}
CAirportList CAirportList::fromDatabaseJson(const QJsonArray &json)
void CAirportList::convertFromDatabaseJson(const QJsonArray &json)
{
CAirportList airports;
clear();
for (const QJsonValue& value: json)
{
QJsonObject object = value.toObject();
CAirport airport;
airport.fromDatabaseJson(object);
airports.push_back(airport);
airport.convertFromDatabaseJson(object);
push_back(airport);
}
return airports;
}
} // namespace

View File

@@ -50,8 +50,9 @@ namespace BlackMisc
//! Find first station by callsign, if not return given value / default
CAirport findFirstByIcao(const CAirportIcaoCode &icao, const CAirport &ifNotFound = CAirport()) const;
//! Reads the airport list from JSON
static CAirportList fromDatabaseJson(const QJsonArray& json);
//! Reads the airport list from database JSON
void convertFromDatabaseJson(const QJsonArray& json);
};
} //namespace
} // namespace