Example #1
0
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;
}
Example #2
0
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);
    }
    void testFilterCategory() {
        //test category matches
        QLandmarkCategoryFilter categoryFilter;
        QLandmarkCategoryId catFilterId;
        catFilterId.setLocalId("1");
        catFilterId.setManagerUri("qtlandmarks:mock:");
        categoryFilter.setCategoryId(catFilterId);

        QLandmark lm;
        QLandmarkCategoryId lmCatId;
        lmCatId.setLocalId("1");
        lmCatId.setManagerUri("qtlandmarks:mock:");
        lm.addCategoryId(lmCatId);

        QVERIFY(MockEngine::testFilter(categoryFilter,lm));

        //test category id doesn't match
        lm.removeCategoryId(lmCatId);
        QVERIFY(lm.categoryIds().count() == 0);
        lmCatId.setLocalId("2");
        lm.addCategoryId(lmCatId);

        QVERIFY(!MockEngine::testFilter(categoryFilter,lm));

        //test category uri that doesn't match
        QList<QLandmarkCategoryId> catIdList;
        lm.setCategoryIds(catIdList);
        QVERIFY(lm.categoryIds().count() == 0);
        lmCatId.setLocalId("1");
        lmCatId.setManagerUri("qtlandmarks:fake:");
        catIdList.append(lmCatId);
        lm.setCategoryIds(catIdList);
        QVERIFY(lm.categoryIds().count() == 1);
        QVERIFY(!MockEngine::testFilter(categoryFilter,lm));


        //try match a category when the
        //landmark has multiple categories

        QLandmarkCategoryId lmCatId2;
        QLandmarkCategoryId lmCatId3;

        lmCatId.setLocalId("1");
        lmCatId.setManagerUri("qtlandmarks:mock:");

        lmCatId2.setLocalId("2");
        lmCatId2.setManagerUri("qtlandmarks:mock:");

        lmCatId3.setLocalId("3");
        lmCatId3.setManagerUri("qtlandmarks:mock:");

        catIdList.clear();
        catIdList << lmCatId << lmCatId2 << lmCatId3;
        lm.setCategoryIds(catIdList);

        catFilterId.setLocalId("2");
        catFilterId.setManagerUri("qtlandmarks:mock:");

        categoryFilter.setCategoryId(catFilterId);
        QVERIFY(MockEngine::testFilter(categoryFilter, lm));

        //category id doesn't match when the landmark
        //has multipl catgories
        catFilterId.setLocalId("4");
        categoryFilter.setCategoryId(catFilterId);
    }