bool QLandmarkFileHandlerLmx::writeLandmark(const QLandmark &landmark) { m_writer->writeStartElement(m_ns, "landmark"); if (!landmark.name().isEmpty()) m_writer->writeTextElement(m_ns, "name", landmark.name()); if (!landmark.description().isEmpty()) m_writer->writeTextElement(m_ns, "description", landmark.description()); if (landmark.coordinate().isValid()) if (!writeCoordinates(landmark)) return false; if (landmark.radius() > 0) m_writer->writeTextElement(m_ns, "coverageRadius", QString::number(landmark.radius())); if (!writeAddressInfo(landmark)) return false; if (!landmark.url().isEmpty()) if (!writeMediaLink(landmark)) return false; if (m_option != QLandmarkManager::ExcludeCategoryData) { for (int i = 0; i < landmark.categoryIds().size(); ++i) { if (!writeCategory(landmark.categoryIds().at(i))) return false; } } m_writer->writeEndElement(); return true; }
bool QLandmarkFileHandlerGpx::writeWaypoint(const QLandmark &landmark, const QString &elementName) { double lat = landmark.coordinate().latitude(); double lon = landmark.coordinate().longitude(); QString latString; QString lonString; bool isInvalid = false; if (!qIsNaN(lat)) { if ((lat > 90.0 )| (lat < -90.0)) isInvalid = true; latString = QString::number(lat); } else { latString = "NaN"; isInvalid = true; } if (!qIsNaN(lon)) { if ((lon > 180.0) | (lon < -180.0)) isInvalid = true; lonString = QString::number(lon); } else { lonString = "NaN"; isInvalid = true; } if (isInvalid) { if(m_behavior == QLandmarkFileHandlerGpx::ExportAll){ m_errorString = QString("Landmarks cannot be exported with invalid coordinates (latitude is %1, longitude is %2)").arg(latString).arg(lonString); m_errorCode = QLandmarkManager::BadArgumentError; //TODO: should be invalid error code? return false; } else { //m_behavior == QLandmarkFileHandlerGpx::ExportSome return true;//ignore landmarks with invalid coordinates. } } m_writer->writeStartElement(m_ns, elementName); m_writer->writeAttribute("lat", latString); m_writer->writeAttribute("lon", lonString); if (!qIsNaN(landmark.coordinate().altitude())) m_writer->writeTextElement(m_ns, "ele", QString::number(landmark.coordinate().altitude())); if (!landmark.name().isEmpty()) m_writer->writeTextElement(m_ns, "name", landmark.name()); if (!landmark.description().isEmpty()) m_writer->writeTextElement(m_ns, "desc", landmark.description()); m_writer->writeEndElement(); return true; }
// Initializes this landmark from the given landmark void QDeclarativeLandmark::setLandmark(const QLandmark& landmark) { // Elaborate but makes sure appropriate signals are sent // (this function is called when landmark updates). setPlace(landmark); // viewport, address, coordinate etc. setName(landmark.name()); setPhoneNumber(landmark.phoneNumber()); setDescription(landmark.description()); setRadius(landmark.radius()); setIconSource(landmark.iconUrl()); setUrl(landmark.url()); m_landmark = landmark; }
LandmarkAddDialog::LandmarkAddDialog(QWidget *parent, Qt::WindowFlags flags, const QLandmark &landmark) : QDialog(parent, flags) { setupUi(this); if (landmark != QLandmark()) { setWindowTitle("Edit Landmark"); lm = landmark; nameLineEdit->setText(landmark.name()); latitudeLineEdit->setText(QString::number(landmark.coordinate().latitude())); longitudeLineEdit->setText(QString::number(landmark.coordinate().longitude())); streetLineEdit->setText(landmark.address().street()); districtLineEdit->setText(landmark.address().district()); cityLineEdit->setText(landmark.address().city()); countyLineEdit->setText(landmark.address().county()); stateLineEdit->setText(landmark.address().state()); countryLineEdit->setText(landmark.address().country()); descriptionLineEdit->setText(landmark.description()); iconUrlLineEdit->setText(landmark.iconUrl().toString()); urlLineEdit->setText(landmark.url().toString()); phoneLineEdit->setText(landmark.phoneNumber()); radiusLineEdit->setText(QString::number(landmark.radius())); } else { setWindowTitle("Add Landmark"); } QLandmarkManager manager; QList<QLandmarkCategory> categories = manager.categories(); foreach( QLandmarkCategory category, categories) { QListWidgetItem *categoryItem = new QListWidgetItem(categoryList,QListWidgetItem::UserType + 1); categoryItem->setData(Qt::DisplayRole,category.name()); QVariant var; var.setValue(category.categoryId()); categoryItem->setData(Qt::UserRole, var); categoryItem->setFlags(Qt::ItemIsEnabled); if (landmark.categoryIds().contains(category.categoryId())) categoryItem->setCheckState(Qt::Checked); else categoryItem->setCheckState(Qt::Unchecked); }