| 60 | } |
| 61 | |
| 62 | Location Location::fromDatabaseString(QString const& databaseLocationString) { |
| 63 | QJsonParseError parseError; |
| 64 | QJsonDocument jsonDocument = QJsonDocument::fromJson(databaseLocationString.toUtf8(), &parseError); |
| 65 | if (jsonDocument.isNull()) { |
| 66 | throw openmittsu::exceptions::InternalErrorException() << "Could not parse location string \"" << databaseLocationString.toStdString() << "\" into a JSON structure. Parser error: " << parseError.errorString().toStdString(); |
| 67 | } else if (!jsonDocument.isArray()) { |
| 68 | throw openmittsu::exceptions::InternalErrorException() << "Could not parse location string \"" << databaseLocationString.toStdString() << "\" into a JSON structure. Contained object is not an array."; |
| 69 | } else { |
| 70 | QJsonArray jsonArray = jsonDocument.array(); |
| 71 | int const neededSize = 5; |
| 72 | if (jsonArray.size() != neededSize) { |
| 73 | throw openmittsu::exceptions::InternalErrorException() << "Could not parse location string \"" << databaseLocationString.toStdString() << "\" into a JSON structure. Contained array has " << jsonArray.size() << " entries instead of " << neededSize << "."; |
| 74 | } else { |
| 75 | QJsonValue valueLat = jsonArray.at(0); |
| 76 | QJsonValue valueLon = jsonArray.at(1); |
| 77 | QJsonValue valueHei = jsonArray.at(2); |
| 78 | QJsonValue valueAdr = jsonArray.at(3); |
| 79 | QJsonValue valueDes = jsonArray.at(4); |
| 80 | |
| 81 | if (!valueLat.isDouble() || !valueLon.isDouble() || !valueHei.isDouble() || !valueAdr.isString() || !valueDes.isString()) { |
| 82 | throw openmittsu::exceptions::InternalErrorException() << "Could not parse location string \"" << databaseLocationString.toStdString() << "\" into a JSON structure. Contained array has invalid types."; |
| 83 | } else { |
| 84 | return Location(valueLat.toDouble(), valueLon.toDouble(), valueHei.toDouble(), valueAdr.toString(), valueDes.toString()); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | bool Location::operator ==(Location const& other) const { |
| 91 | return (m_latitude == other.m_latitude) && (m_longitude == other.m_longitude) && (m_height == other.m_height) && (m_address == other.m_address) && (m_description == other.m_description); |
nothing calls this directly
no test coverage detected