Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

PlaceSearchModel

The PlaceSearchModel element provides access to place search results. More...

Inherits QtObject

This type was introduced in Qt Location 5.0.

Properties

Methods

Detailed Description

PlaceSearchModel provides a model of place search results within the searchArea. The searchTerm and categories properties can be set to restrict the search results to places matching those criteria.

The PlaceSearchModel returns both sponsored and organic search results. Sponsored search results will have the sponsored role set to true.

The model returns data for the following roles:

RoleTypeDescription
typeenumThe type of search result.
distancerealValid only when the type role is PlaceResult, the distance to the place from the center of the searchArea. If no searchArea has been specified, the distance is NaN.
placePlaceValid only when the type role is PlaceResult, an object representing the place.
sponsoredboolValid only when the type role is PlaceResult, true if the search result is a sponsored result.
correctionstringValid only when the type role is CorrectionResult, a suggested correction to the search term.

Search Result Types

The type role can take on the following values:

PlaceSearchModel.PlaceResultThe search result contains a place.
PlaceSearchModel.CorrectionResultThe search result contains a search term correction.
PlaceSearchModel.UnknownSearchResultThe contents of the search result are unknown.

Detection of Updated and Removed Places

The PlaceSearchModel listens for places that have been updated or removed from its plugin's backend. If it detects that a place has been updated and that place is currently present in the model, then it will call Place::getDetails to refresh the details. If it detects that a place has been removed, then correspondingly the place will be removed from the model if it is currently present.

Example

The following example shows how to use the PlaceSearchModel to search for Pizza restaurants in close proximity of a given position. A searchTerm and searchArea are provided to the model and execute() is used to perform a lookup query. Note that the model does not incrementally fetch search results, but rather performs a single fetch when execute() is run. The count is set to the number of search results returned during the fetch.

 import QtQuick 2.0
 import QtLocation 5.0

 PlaceSearchModel {
     id: searchModel

     plugin: myPlugin

     searchTerm: "Pizza"
     searchArea: BoundingCircle {
         center: Coordinate {
             // Brisbane
             longitude: 153.02778
             latitude: -27.46778
         }
     }

     Component.onCompleted: update()
 }

 ListView {
     model: searchModel
     delegate: Text { text: 'Name: ' + place.name }
 }

Paging

The PlaceSearchModel API has some limited support for paging. The offset and limit properties can be used to access paged search results. When the offset and limit properties are set the search results between offset and (offset + limit - 1) will be returned. For example, if the backend has 5 search results in total [a,b,c,d,e], an offset of 0 specifies that the first item returned in the model will be 'a'. An offset of 1 secifies that the first item in the model will be 'b' and so on. The limit specifies the maximum number of items to be returned. For example, assuming an offset of 0 and limit of 3 then a,b,c is returned. If the offset exceeds (or equals) the total number of items, then 0 results are returned in the model. Note that the API currently does not support a means to retrieve the total number of items available from the backed. Also note that support for offset and limit can vary according to the plugin.

Corrections

The PlaceSearchModel can return correction results if supported by the plugin. Correction results consist of a string which can be used as a search term for another query and are often used in the context of "Did you mean" corrections. The maximumCorrections property can be used to limit the maximum number of search term correction results that may be returned. Setting maximumCorrections to 0 will prevent any search term correction results from being returned.

See also PlaceRecommendationModel, CategoryModel, and QPlaceManager.

Property Documentation

read-onlycategories : list<Category>

This property holds a list of categories to be used when searching. Returned search results will be for places that match at least one of the categories.


read-onlycount : int

This property holds the number of results the model has.

Note that it does not refer to the total number of search results available in the backend. The total number of search results is not currently supported by the API.


errorString : string

This read-only property holds the textual presentation of latest place search model error. If no error has occurred or if the model was cleared an empty string is returned.

An empty string may also be returned if an error occurred which has no associated textual representation.


favoritesMatchParameters : VariantMap

This property holds a set of parameters used to specify how search result places are matched to favorites in the favoritesPlugin.

By default the parameter map is empty and implies that the favorites plugin matches by alternative identifiers. Generally, an application developer will not need to set this property.

In cases where the favorites plugin does not support matching by alternative identifiers, then the backend plugin documentation should be consulted to see precisely what key-value parameters to set.


favoritesPlugin : Plugin

This property holds the Plugin which will be used to search for favorites. Any places from the search which can be cross-referenced or matched in the favoritesPlugin will have their favorite property set to the corresponding Place from the favoritesPlugin.

If the favoritesPlugin is not set, the favorite property of the places in the results will always be null.

See also Favorites.


limit : int

This property holds the limit of the number of items that will be returned.

See also offset.


maximumCorrections : int

This property holds the maximum number of search term corrections that may be returned.


offset : int

This property holds the index of the first search result in the model.

See also limit.


plugin : Plugin

This property holds the Plugin which will be used to perform the search.


relevanceHint : enumeration

This property holds a relevance hint used in the search query. The hint is given to the provider to help but not dictate the ranking of results. For example, the distance hint may give closer places a higher ranking but it does not necessarily mean the results will be strictly ordered according to distance. A provider may ignore the hint altogether.

SearchResultModel.UnspecifiedHintNo relevance hint is given to the provider.
SearchResultModel.DistanceHintThe distance of the place from the user's current location is important to the user. This hint is only meaningful when a circular search area is used.
SearchResultModel.LexicalPlaceNameHintThe lexical ordering of place names (in ascending alphabetical order) is relevant to the user. This hint is useful for providers based on a local data store.

searchArea : BoundingArea

This property holds the search area. The search result returned by the model will be within the search area.

If this property is set to a BoundingCircle its radius property may be left unset, in which case the Plugin will choose an appropriate radius for the search.

Support for specifying a search area can vary according to the plugin backend implementation. For example, some may support a search center only while others may only support bounding boxes.


searchTerm : string

This property holds search term used in query. The search term is a free-form text string.


read-onlystatus : enum

This property holds the status of the model. It can be one of:

PlaceSearchModel.NullNo search query has been executed. The model is empty.
PlaceSearchModel.ReadyThe search query has completed, and the results are available.
PlaceSearchModel.LoadingA search query is currently being executed.
PlaceSearchModel.ErrorAn error occurred when executing the previous search query.

visibilityScope : enum

This property holds the visibility scope of the places to search. Only places with the specified visibility will be returned in the search results.

The visibility scope can be one of:

Place.UnspecifiedVisibilityNo explicit visibility scope specified, places with any visibility may be part of search results.
Place.DeviceVisibilityOnly places stored on the local device will be part of the search results.
Place.PrivateVisibilityOnly places that are private to the current user will be part of the search results.
Place.PublicVisibilityOnly places that are public will be part of the search results.

Method Documentation

PlaceSearchModel::cancel()

Cancels an ongoing search query.

See also execute() and status.


PlaceSearchModel::data(int index, string role)

Returns the data for a given role at the specified row index.


PlaceSearchModel::reset()

Resets the model. All search results are cleared, any outstanding requests are aborted and possible errors are cleared. Model status will be set to PlaceSearchModel.Null.


PlaceSearchModel::update()

Updates the model based on the provided query parameters. The model will be populated with a list of places matching the search parameters specified by the element's properties. Search criteria is specified by setting properties such as the searchTerm, categories, limit and offset. Support for these properties may vary according to plugin. update() then submits the set of criteria to the plugin to process.

While the model is updating the status of the model is set to PlaceSearchModel.Loading. If the model is successfully updated the status is set to PlaceSearchModel.Ready, while if it unsuccessfully completes, the status is set to PlaceSearchModel.Error and the model cleared.

 BoundingCircle {
     id: searchLocation
     center: Coordinate {
         latitude: 10
         longitude: 10
     }
 }

 PlaceSearchModel {
     id: model
     plugin: backendPlugin
     searchArea : searchLocation
     ...
 }

 MouseArea {
     ...
     onClicked: {
         model.searchTerm = "pizza";
         model.categories = null;  //not searching by any category
         searchLocation.center.latitude = -27.5
         searchLocation.center.longitude = 153
         model.update();
     }
 }

See also cancel() and status.


Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web