Пример #1
0
    void fileImport() {
        QFETCH(QString, fileIn);
        QFETCH(QString, fileOut);
        QFETCH(QString, exportPrefix);
        QFETCH(QList<QLandmark>, landmarks);
        QFETCH(QList<QLandmarkCategory>, categories);

        QHash<QString,QString> categoryNameIdHash; //name to local id
        for (int i = 0; i < categories.size(); ++i) {
            categoryNameIdHash.insert(categories[i].name(),categories[i].categoryId().localId());
        }

        QFile file(fileIn);
        file.open(QIODevice::ReadOnly);

         //set the category ids for the landmarks from the handler
        QVERIFY(m_handler->importData(&file));
        QList<QLandmark> handlerLandmarks = m_handler->landmarks();
        QList<QStringList> handlerLandmarkCategoryNames = m_handler->landmarkCategoryNames();
        for (int i=0; i < handlerLandmarks.count(); ++i) {
            for(int j=0; j < handlerLandmarkCategoryNames.at(i).count(); ++j) {
                QLandmarkCategoryId catId;
                catId.setManagerUri(m_manager->managerUri());
                catId.setLocalId(categoryNameIdHash.value(handlerLandmarkCategoryNames.at(i).at(j)));
                handlerLandmarks[i].addCategoryId(catId);
            }

        }

        file.close();
        QCOMPARE(handlerLandmarks, landmarks);
    }
    void testUnionFilter()
    {
        QLandmarkCategoryId catId;
        catId.setLocalId("1");
        catId.setManagerUri("qtlandmarks:mock:");

        QLandmarkCategoryId catId2;
        catId2.setLocalId("2");
        catId2.setManagerUri("qtlandmarks:mock:");

        //test a match with the union filter
        QLandmarkUnionFilter unionFilter;
        QLandmarkNameFilter nameFilter("beach");
        QLandmarkProximityFilter proximityFilter(QGeoCoordinate(30,30));
        proximityFilter.setRadius(QGeoCoordinate(30,30).distanceTo(QGeoCoordinate(30,32)));
        QLandmarkCategoryFilter categoryFilter;
        categoryFilter.setCategoryId(catId);

        QLandmark lm;
        lm.setName("statue");
        lm.setCoordinate(QGeoCoordinate(-30,-29));
        lm.addCategoryId(catId);

        unionFilter << nameFilter << categoryFilter << proximityFilter;
        QVERIFY(MockEngine::testFilter(unionFilter,lm));

        //test no match with union filter
        lm.removeCategoryId(catId);
        lm.addCategoryId(catId2);
        QVERIFY(!MockEngine::testFilter(unionFilter,lm));

        //test empty union filter
        unionFilter.clear();
        QVERIFY(!MockEngine::testFilter(unionFilter,lm));
    }
Пример #3
0
bool QLandmarkFileHandlerLmx::writeCategory(const QLandmarkCategoryId &id)
{
    if (!id.isValid()) {
        m_errorCode = QLandmarkManager::BadArgumentError;
        m_error = QString("The category with id \"%1\" from manager \"%2\" is invalid.").arg(id.localId()).arg(id.managerUri());
        return false;
    }

    if (!m_categoryIdNameHash.contains(id.localId())) {
        m_errorCode = QLandmarkManager::UnknownError;
        m_error = "Category for landmark could not be identified";
        return false;
    }

    m_writer->writeStartElement(m_ns, "category");
    m_writer->writeTextElement(m_ns, "name", m_categoryIdNameHash.value(id.localId()));
    m_writer->writeEndElement();

    return true;
}
Пример #4
0
void LandmarkBrowser::on_deleteCategoriesButton_clicked()
{
    QItemSelectionModel *selection  = categoryTable->selectionModel();
    QModelIndexList selectedIndexes = selection->selectedRows();

    QList<QLandmarkCategoryId> deleteIds;

    QLandmarkCategoryId id;
    QModelIndex index;
    bool alreadyWarned = false;
    while(selectedIndexes.count() > 0) {
        index = selectedIndexes.takeLast();
        id.setManagerUri(manager->managerUri());
        id.setLocalId(categoryTable->item(index.row(),1)->text());
        if (manager->isReadOnly(id)) {
            if (!alreadyWarned) {
                QMessageBox::warning(this,"Warning", "Cannot delete a global category", QMessageBox::Ok, QMessageBox::NoButton);
                alreadyWarned = true;
            }

            selection->setCurrentIndex(index, QItemSelectionModel::Deselect);
            categoryTable->setSelectionModel(selection);

        } else {
            deleteIds.append(id);
            categoryTable->removeRow(index.row());
        }

        selectedIndexes = categoryTable->selectionModel()->selectedRows();
    }

    if (deleteIds.count() == 0)
        return;

    categoryRemove->setCategoryIds(deleteIds);
    categoryRemove->start();
#ifdef Q_OS_SYMBIAN
    categoryRemove->waitForFinished(30);
#endif
}
    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);
    }
Пример #6
0
void QLandmarkManagerEngineSqlite::databaseChanged()
{
    QSqlDatabase db = QSqlDatabase::database(m_dbConnectionName);

    QSqlQuery query(db);
    if (!query.prepare("SELECT landmarkId,action, timestamp FROM landmark_notification WHERE timestamp >= ?")) {
#ifdef QT_LANDMARK_SQLITE_ENGINE_DEBUG
        qWarning() << "Could not prepare statement: " << query.lastQuery() << " \nReason:" << query.lastError().text();
#endif
        return;
    }
    query.addBindValue(m_latestLandmarkTimestamp);
    if (!query.exec()) {
#ifdef QT_LANDMARK_SQLITE_ENGINE_DEBUG
        qWarning() << "Could not execute statement:" << query.lastQuery() << " \nReason:" << query.lastError().text();
#endif
        return;
    }

    QList<QLandmarkId> addedLandmarkIds;
    QList<QLandmarkId> changedLandmarkIds;
    QList<QLandmarkId> removedLandmarkIds;

    QString action;
    QLandmarkId landmarkId;
    landmarkId.setManagerUri(managerUri());
    bool ok;
    qint64 timestamp;
    bool landmarkTimestampWasModified = true;

    while(query.next()) {
        timestamp = query.value(2).toLongLong(&ok);
        if (!ok) //this should never happen
            continue;

        if (timestamp > m_latestLandmarkTimestamp) {
            m_latestLandmarkTimestamp = timestamp;
            landmarkTimestampWasModified = true;
        }

        action = query.value(1).toString();
        landmarkId.setLocalId((query.value(0).toString()));

        if (action == "ADD") {
            if (!addedLandmarkIds.contains(landmarkId))
                addedLandmarkIds << landmarkId;
        } else if (action == "CHANGE") {
            if (!changedLandmarkIds.contains(landmarkId))
                changedLandmarkIds << landmarkId;
        } else if (action == "REMOVE") {
            if (!removedLandmarkIds.contains(landmarkId))
                removedLandmarkIds << landmarkId;
        }
    }

    //now check for added/modified/removed categories
    if (!query.prepare("SELECT categoryId,action, timestamp FROM category_notification WHERE timestamp >= ?")) {
#ifdef QT_LANDMARK_SQLITE_ENGINE_DEBUG
        qWarning() << "Could not prepare statement: " << query.lastQuery() << " \nReason:" << query.lastError().text();
#endif
        return;
    }
    query.addBindValue(m_latestCategoryTimestamp);
    if (!query.exec()) {
#ifdef QT_LANDMARK_SQLITE_ENGINE_DEBUG
        qWarning() << "Could not execute statement:" << query.lastQuery() << " \nReason:" << query.lastError().text();
#endif
        return;
    }
    QList<QLandmarkCategoryId> addedCategoryIds;
    QList<QLandmarkCategoryId> changedCategoryIds;
    QList<QLandmarkCategoryId> removedCategoryIds;

    QLandmarkCategoryId categoryId;
    categoryId.setManagerUri(managerUri());
    bool categoryTimestampWasModified = false;

    while(query.next()) {
        timestamp = query.value(2).toLongLong(&ok);
        if (!ok) //this should never happen
            continue;

        if (timestamp > m_latestCategoryTimestamp) {
            categoryTimestampWasModified = true;
            m_latestCategoryTimestamp = timestamp;
        }
        action = query.value(1).toString();
        categoryId.setLocalId(query.value(0).toString());

        if (action == "ADD") {
            if (!addedCategoryIds.contains(categoryId))
                addedCategoryIds << categoryId;
        } else if (action == "CHANGE") {
            if (!changedCategoryIds.contains(categoryId))
            changedCategoryIds << categoryId;
        } else if (action == "REMOVE") {
            if (!removedCategoryIds.contains(categoryId))
                removedCategoryIds << categoryId;
        }
    }

    if(landmarkTimestampWasModified)
        m_latestLandmarkTimestamp +=1;

    if (categoryTimestampWasModified)
        m_latestCategoryTimestamp +=1;

    int totalChangeCount = addedCategoryIds.count() + changedCategoryIds.count() + removedCategoryIds.count()
                           + addedLandmarkIds.count() + changedLandmarkIds.count() + removedLandmarkIds.count();
    if (totalChangeCount > 50 ) {
        emit dataChanged();
    } else {
        if (addedCategoryIds.count() > 0)
            emit categoriesAdded(addedCategoryIds);

        if (changedCategoryIds.count() > 0)
            emit categoriesChanged(changedCategoryIds);

        if (removedCategoryIds.count() > 0) {
            emit categoriesRemoved(removedCategoryIds);
        }

        if (addedLandmarkIds.count() > 0)
            emit landmarksAdded(addedLandmarkIds);

        if (changedLandmarkIds.count() > 0)
            emit landmarksChanged(changedLandmarkIds);

        if (removedLandmarkIds.count() > 0)
            emit landmarksRemoved(removedLandmarkIds);
    }
}