void tst_QGeoAddress::streetTest() { QGeoAddress testObj; QVERIFY2(testObj.street() == QString(), "Wrong default value"); testObj.setStreet("testText"); QVERIFY2(testObj.street() == "testText", "Wrong value returned"); }
bool QLandmarkFileHandlerLmx::writeAddressInfo(const QLandmark &landmark) { QGeoAddress address = landmark.address(); if (address.street().isEmpty() && address.city().isEmpty() && address.state().isEmpty() && address.country().isEmpty() && address.postcode().isEmpty() && landmark.phoneNumber().isEmpty()) return true; m_writer->writeStartElement(m_ns, "addressInfo"); if (!address.country().isEmpty()) m_writer->writeTextElement(m_ns, "country", address.country()); if (!address.state().isEmpty()) m_writer->writeTextElement(m_ns, "state", address.state()); if (!address.county().isEmpty()) m_writer->writeTextElement(m_ns, "county", address.county()); if (!address.city().isEmpty()) m_writer->writeTextElement(m_ns, "city", address.city()); if (!address.district().isEmpty()) m_writer->writeTextElement(m_ns, "district", address.district()); if (!address.postcode().isEmpty()) m_writer->writeTextElement(m_ns, "postalCode", address.postcode()); QString street; if (!address.street().isEmpty()) street.append(address.street()); if (!street.isEmpty()) m_writer->writeTextElement(m_ns, "street", street); if (!landmark.phoneNumber().isEmpty()) m_writer->writeTextElement(m_ns, "phoneNumber", landmark.phoneNumber()); m_writer->writeEndElement(); return true; }
static QString addressToQuery(const QGeoAddress &address) { return address.street() + QStringLiteral(", ") + address.district() + QStringLiteral(", ") + address.city() + QStringLiteral(", ") + address.state() + QStringLiteral(", ") + address.country(); }
/*! Returns true if this address is equal to \a other, otherwise returns false. \since 1.1 */ bool QGeoAddress::operator==(const QGeoAddress &other) const { #ifdef QGEOADDRESS_DEBUG qDebug() << "country" << (d->sCountry == other.country()); qDebug() << "countryCode" << (d->sCountryCode == other.countryCode()); qDebug() << "state:" << (d->sState == other.state()); qDebug() << "county:" << (d->sCounty == other.county()); qDebug() << "city:" << (d->sCity == other.city()); qDebug() << "district:" << (d->sDistrict == other.district()); qDebug() << "street:" << (d->sStreet == other.street()); qDebug() << "postcode:" << (d->sPostCode == other.postcode()); #endif return d->sCountry == other.country() && d->sCountryCode == other.countryCode() && d->sState == other.state() && d->sCounty == other.county() && d->sCity == other.city() && d->sDistrict == other.district() && d->sStreet == other.street() && d->sPostCode == other.postcode(); }
void MarkerDialog::setAddressLabel(QGeoAddress address) { QString addressFormat = tr("$street\n$city, $state $postcode\n$country"); addressFormat.replace("$street", address.street()); addressFormat.replace("$city", address.city()); addressFormat.replace("$county", address.county()); addressFormat.replace("$state", address.state()); addressFormat.replace("$postcode", address.postcode()); addressFormat.replace("$district", address.district()); addressFormat.replace("$country", address.country()); addressLabel->setText(addressFormat); }
void QDeclarativeGeoAddress::setAddress(const QGeoAddress& address) { // Elaborate but takes care of emiting needed signals setCountry(address.country()); setCountryCode(address.countryCode()); setState(address.state()); setCounty(address.county()); setCity(address.city()); setDistrict(address.district()); setStreet(address.street()); setPostcode(address.postcode()); m_address = address; }
QVariant QDeclarativeReverseGeocodeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.row() > places().count()) return QVariant(); QGeoPlace place = places().at(index.row()); if (role == Qt::DisplayRole) { QGeoAddress address = place.address(); QStringList addressStrings; if (!address.street().isEmpty()) addressStrings << address.street(); if (!address.city().isEmpty()) addressStrings << address.city(); QStringList stateLine; if (!address.state().isEmpty()) stateLine << address.state(); if (!address.postcode().isEmpty()) stateLine << address.postcode(); if (!address.country().isEmpty()) stateLine << address.country(); QString stateString = stateLine.join(" "); if (!stateString.isEmpty()) addressStrings << stateString; return addressStrings.join(", "); } return QDeclarativeGeoSearchModel::data(index, role); }
void GeoHelper::searchFinishedSlot(QGeoSearchReply *reply) { if (reply->error() == QGeoSearchReply::NoError) { QScriptEngine scriptEngine; QScriptValue replyObject = scriptEngine.newArray(); QList<QGeoPlace> places = reply->places(); for (int i = 0; i < places.count(); i++) { QScriptValue placeObject = scriptEngine.newObject(); QScriptValue coordinateObject = scriptEngine.newObject(); QGeoCoordinate coordinate = places[i].coordinate(); coordinateObject.setProperty("latitude", QScriptValue(coordinate.latitude())); coordinateObject.setProperty("longitude", QScriptValue(coordinate.longitude())); placeObject.setProperty("coordinate", coordinateObject); QScriptValue addressObject = scriptEngine.newObject(); QGeoAddress address = places[i].address(); if (!address.isEmpty()) { addressObject.setProperty("country", address.country()); addressObject.setProperty("countryCode", address.countryCode()); addressObject.setProperty("state", address.state()); addressObject.setProperty("county", address.county()); addressObject.setProperty("city", address.city()); addressObject.setProperty("district", address.district()); addressObject.setProperty("street", address.street()); addressObject.setProperty("postcode", address.postcode()); } placeObject.setProperty("address", addressObject); replyObject.setProperty(i, placeObject); } QScriptValue fun = scriptEngine.evaluate("(function(a) { return JSON.stringify(a); })"); QScriptValueList args; args << replyObject; QScriptValue result = fun.call(QScriptValue(), args); emit searchReply(result.toString()); } }
/* Returns a single formatted string representing the \a address. Lines of the address are delimited by \a newLine. By default lines are delimited by <br/>. The \l {QGeoAddress::countryCode} {countryCode} of the \a address determines the format of the resultant string. */ static QString formattedAddress(const QGeoAddress &address, const QString &newLine = QLatin1String("<br/>")) { const QString Comma(QStringLiteral(", ")); const QString Dash(QStringLiteral("-")); const QString Space(QStringLiteral(" ")); QString text; if (address.countryCode() == QLatin1String("ALB") || address.countryCode() == QLatin1String("MTQ")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("AND") || address.countryCode() == QLatin1String("AUT") || address.countryCode() == QLatin1String("FRA") || address.countryCode() == QLatin1String("GLP") || address.countryCode() == QLatin1String("GUF") || address.countryCode() == QLatin1String("ITA") || address.countryCode() == QLatin1String("LUX") || address.countryCode() == QLatin1String("MCO") || address.countryCode() == QLatin1String("REU") || address.countryCode() == QLatin1String("RUS") || address.countryCode() == QLatin1String("SMR") || address.countryCode() == QLatin1String("VAT")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("ARE") || address.countryCode() == QLatin1String("BHS")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("AUS")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << (address.district().isEmpty() ? address.city() : address.district()) << Space << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("BHR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("BRA")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << Dash << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("BRN") || address.countryCode() == QLatin1String("JOR") || address.countryCode() == QLatin1String("LBN") || address.countryCode() == QLatin1String("NZL")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CAN") || address.countryCode() == QLatin1String("USA") || address.countryCode() == QLatin1String("VIR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Comma << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CHN")) { text += addressLine(QStringList() << address.street() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CHL")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma << address.city() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("CYM")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.state() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("GBR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("GIB")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("HKG")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << newLine); text += addressLine(QStringList() << address.city() << newLine); } else if (address.countryCode() == QLatin1String("IND")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Space << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("IDN") || address.countryCode() == QLatin1String("JEY") || address.countryCode() == QLatin1String("LVA")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Comma << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("IRL")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("KWT")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Comma << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("MLT") || address.countryCode() == QLatin1String("SGP") || address.countryCode() == QLatin1String("UKR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("MEX")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("MYS")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); text += addressLine(QStringList() << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("OMN")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.postalCode() << Comma << address.city() << Comma << address.country() << newLine); } else if (address.countryCode() == QLatin1String("PRI")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Comma << address.state() << Comma << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("QAT")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Space << address.city() << Comma << address.country() << newLine); } else if (address.countryCode() == QLatin1String("SAU")) { text += addressLine(QStringList() << address.street() << Space << address.district() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("TWN")) { text += addressLine(QStringList() << address.street() << Comma << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("THA")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << Space << address.postalCode() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("TUR")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("VEN")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.city() << Space << address.postalCode() << Comma << address.state() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else if (address.countryCode() == QLatin1String("ZAF")) { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.district() << Comma << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } else { text += addressLine(QStringList() << address.street() << newLine); text += addressLine(QStringList() << address.postalCode() << Space << address.city() << newLine); text += addressLine(QStringList() << address.country() << newLine); } text.chop(newLine.length()); return text; }
GeoCodingInputDialog::GeoCodingInputDialog(QString &obloc, QGeoAddress &address, GeocodingType &type,QWidget *parent) : QDialog(parent) , m_oblocStr(obloc) , m_address(address) , m_type(type) { setWindowTitle(tr("Geocoding Parameters")); m_gbOneBox = new QGroupBox(tr("One-Box Search")); m_gbOneBox->setCheckable(true); m_gbOneBox->setChecked(true); m_obloc = new QLineEdit(m_oblocStr); m_oneBoxType = new QComboBox(this); m_oneBoxType->addItem(tr("Geocoding search"), GeocodingOneBox); m_oneBoxType->addItem(tr("Landmark search"), GeocodingLandmark); QVBoxLayout *vboxOneBox = new QVBoxLayout; vboxOneBox->addWidget(m_obloc); vboxOneBox->addWidget(m_oneBoxType); vboxOneBox->addStretch(1); m_gbOneBox->setLayout(vboxOneBox); m_gbAddress = new QGroupBox(tr("Address Search")); m_gbAddress->setCheckable(true); m_gbAddress->setChecked(false); QLabel *countrylbl = new QLabel(tr("Country:")); m_country = new QLineEdit(address.country()); m_country->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QLabel *statelbl = new QLabel(tr("State:")); m_state = new QLineEdit(address.state()); m_state->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QLabel *citylbl = new QLabel(tr("City:")); m_city = new QLineEdit(address.city()); m_city->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QLabel *ziplbl = new QLabel(tr("Zip:")); m_zip = new QLineEdit(address.postcode()); m_zip->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QLabel *streetlbl = new QLabel(tr("Street:")); m_street = new QLineEdit(address.street()); m_street->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QGridLayout *gridLayout = new QGridLayout ; gridLayout->setSizeConstraint(QLayout::SetMinimumSize); gridLayout->setSpacing(4); gridLayout->setContentsMargins(2, 1, 2, 1); #if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) gridLayout->addWidget(streetlbl, 1, 0); gridLayout->addWidget(m_street, 1, 1, 1, 3); gridLayout->addWidget(ziplbl, 2, 0); gridLayout->addWidget(citylbl, 2, 2); gridLayout->addWidget(m_zip, 2, 1); gridLayout->addWidget(m_city, 2, 3); gridLayout->addWidget(statelbl, 3, 0); gridLayout->addWidget(countrylbl, 3, 2); gridLayout->addWidget(m_state, 3, 1); gridLayout->addWidget(m_country, 3, 3); #else gridLayout->addWidget(streetlbl, 1, 0); gridLayout->addWidget(m_street, 2, 0, 1, 2); gridLayout->addWidget(ziplbl, 3, 0); gridLayout->addWidget(citylbl, 3, 1); gridLayout->addWidget(m_zip, 4, 0); gridLayout->addWidget(m_city, 4, 1); gridLayout->addWidget(statelbl, 5, 0); gridLayout->addWidget(countrylbl, 5, 1); gridLayout->addWidget(m_state, 6, 0); gridLayout->addWidget(m_country, 6, 1); #endif m_gbAddress->setLayout(gridLayout); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setSizeConstraint(QLayout::SetFixedSize); mainLayout->setSpacing(6); mainLayout->addWidget(m_gbOneBox); mainLayout->addWidget(m_gbAddress); mainLayout->addWidget(buttonBox); setLayout(mainLayout); switch (m_type) { case GeocodingOneBox: { oneBoxSearchToogled(true); break; } case GeocodingLandmark: { oneBoxSearchToogled(true); const int index = m_oneBoxType->findData(GeocodingLandmark); m_oneBoxType->setCurrentIndex(index); break; } case GeoCodingStructured: { addressSeachToogled(true); break; } } connect(m_gbOneBox, SIGNAL(toggled(bool)), this, SLOT(oneBoxSearchToogled(bool))); connect(m_gbAddress, SIGNAL(toggled(bool)), this, SLOT(addressSeachToogled(bool))); }