libosmscout 0.1
Loading...
Searching...
No Matches
osmscout::LocationListModel Class Reference

Model for searching objects in osmscout databases by pattern written by human. More...

#include <SearchLocationModel.h>

Inheritance diagram for osmscout::LocationListModel:

Public Types

enum  Roles {
  LabelRole = Qt::UserRole , TypeRole = Qt::UserRole +1 , RegionRole = Qt::UserRole +2 , LatRole = Qt::UserRole +3 ,
  LonRole = Qt::UserRole +4 , DistanceRole = Qt::UserRole +5 , BearingRole = Qt::UserRole +6 , LocationObjectRole = Qt::UserRole +7 ,
  IndexedAdminRegionRole = Qt::UserRole +8 , AltLangName = Qt::UserRole +9
}

Public Slots

void onLocationAdminRegionFinished (const osmscout::GeoCoord)
void onLocationAdminRegions (const osmscout::GeoCoord, QList< AdminRegionInfoRef >)
void onSearchFinished (const QString searchPattern, bool error)
void onSearchResult (const QString searchPattern, const QList< LocationEntry >)
void setPattern (const QString &pattern)

Signals

void countChanged (int)
void regionLookupRequested (osmscout::GeoCoord)
void SearchingChanged (bool)
void SearchRequested (const QString searchPattern, int limit, osmscout::GeoCoord searchCenter, AdminRegionInfoRef defaultRegion, osmscout::BreakerRef breaker)

Public Member Functions

Q_INVOKABLE QVariant data (const QModelIndex &index, int role) const override
Q_INVOKABLE Qt::ItemFlags flags (const QModelIndex &index) const override
Q_INVOKABLE QObject * get (int row) const
QJSValue getCompare () const
int GetDisplayLimit () const
QJSValue getEquals () const
double GetLat () const
double GetLon () const
QString getPattern () const
int GetResultLimit () const
bool isSearching () const
 LocationListModel (const LocationListModel &)=delete
 LocationListModel (LocationListModel &&)=delete
 LocationListModel (QObject *parent=nullptr)
LocationListModel & operator= (const LocationListModel &)=delete
LocationListModel & operator= (LocationListModel &&)=delete
QHash< int, QByteArray > roleNames () const override
Q_INVOKABLE int rowCount (const QModelIndex &parent=QModelIndex()) const override
void setCompare (const QJSValue &fn)
void SetDisplayLimit (int limit)
void setEquals (const QJSValue &fn)
void SetLat (double lat)
void SetLon (double lon)
void SetResultLimit (int limit)
 ~LocationListModel () override

Properties

QJSValue compare
 JavaScript function used for sorting search results.
int count
 Count of rows in model - count of search results.
int displayLimit =100
 Limit of model rows.
QJSValue equals
 JavaScript function used for check location equality.
double lat
 Lat and lon properties control where is logical search center.
double lon
QString pattern
 Searched pattern.
int resultLimit =2000
 Limit of results for each db.
bool searching =false
 True if searching is in progress.

Detailed Description

Model for searching objects in osmscout databases by pattern written by human.

Member Enumeration Documentation

◆ Roles

Enumerator
LabelRole 
TypeRole 
RegionRole 
LatRole 
LonRole 
DistanceRole 
BearingRole 
LocationObjectRole 
IndexedAdminRegionRole 
AltLangName 

Constructor & Destructor Documentation

◆ LocationListModel() [1/3]

◆ LocationListModel() [2/3]

osmscout::LocationListModel::LocationListModel ( const LocationListModel & )
delete

References LocationListModel().

◆ LocationListModel() [3/3]

osmscout::LocationListModel::LocationListModel ( LocationListModel && )
delete

References LocationListModel().

◆ ~LocationListModel()

osmscout::LocationListModel::~LocationListModel ( )
override

Member Function Documentation

◆ countChanged

void osmscout::LocationListModel::countChanged ( int )
signal

References countChanged().

Referenced by countChanged(), and setPattern().

◆ data()

◆ flags()

Qt::ItemFlags osmscout::LocationListModel::flags ( const QModelIndex & index) const
override

◆ get()

QObject * osmscout::LocationListModel::get ( int row) const

◆ getCompare()

QJSValue osmscout::LocationListModel::getCompare ( ) const
inline

◆ GetDisplayLimit()

int osmscout::LocationListModel::GetDisplayLimit ( ) const
inline

References displayLimit.

◆ getEquals()

QJSValue osmscout::LocationListModel::getEquals ( ) const
inline

◆ GetLat()

double osmscout::LocationListModel::GetLat ( ) const
inline

◆ GetLon()

double osmscout::LocationListModel::GetLon ( ) const
inline

◆ getPattern()

QString osmscout::LocationListModel::getPattern ( ) const
inline

References pattern.

◆ GetResultLimit()

int osmscout::LocationListModel::GetResultLimit ( ) const
inline

References resultLimit.

◆ isSearching()

bool osmscout::LocationListModel::isSearching ( ) const
inline

References searching.

Referenced by onSearchFinished(), and setPattern().

◆ onLocationAdminRegionFinished

void osmscout::LocationListModel::onLocationAdminRegionFinished ( const osmscout::GeoCoord location)
slot

◆ onLocationAdminRegions

void osmscout::LocationListModel::onLocationAdminRegions ( const osmscout::GeoCoord location,
QList< AdminRegionInfoRef > adminRegionList )
slot

◆ onSearchFinished

void osmscout::LocationListModel::onSearchFinished ( const QString searchPattern,
bool error )
slot

◆ onSearchResult

void osmscout::LocationListModel::onSearchResult ( const QString searchPattern,
const QList< LocationEntry > foundLocationsConst )
slot

Adding huge batch of entries to model (more that 100) may take longer than ~16 ms and UI may become choppy. So, we enqueue all found entries to postponedEntries and start postponeTimer that adds entries by small chunks. Whole operation is splitted to multiple animation frames.

References pattern.

Referenced by LocationListModel(), and regionLookupRequested().

◆ operator=() [1/2]

LocationListModel & osmscout::LocationListModel::operator= ( const LocationListModel & )
delete

References LocationListModel().

◆ operator=() [2/2]

LocationListModel & osmscout::LocationListModel::operator= ( LocationListModel && )
delete

References LocationListModel().

◆ regionLookupRequested

◆ roleNames()

QHash< int, QByteArray > osmscout::LocationListModel::roleNames ( ) const
override

◆ rowCount()

int osmscout::LocationListModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

◆ SearchingChanged

void osmscout::LocationListModel::SearchingChanged ( bool )
signal

◆ SearchRequested

void osmscout::LocationListModel::SearchRequested ( const QString searchPattern,
int limit,
osmscout::GeoCoord searchCenter,
AdminRegionInfoRef defaultRegion,
osmscout::BreakerRef breaker )
signal

◆ setCompare()

void osmscout::LocationListModel::setCompare ( const QJSValue & fn)
inline

◆ SetDisplayLimit()

void osmscout::LocationListModel::SetDisplayLimit ( int limit)
inline

References displayLimit.

◆ setEquals()

void osmscout::LocationListModel::setEquals ( const QJSValue & fn)
inline

◆ SetLat()

void osmscout::LocationListModel::SetLat ( double lat)
inline

References lat.

◆ SetLon()

void osmscout::LocationListModel::SetLon ( double lon)
inline

References lon.

◆ setPattern

◆ SetResultLimit()

void osmscout::LocationListModel::SetResultLimit ( int limit)
inline

References resultLimit.

Property Documentation

◆ compare

QJSValue osmscout::LocationListModel::compare
readwrite

JavaScript function used for sorting search results.

Compare function will receive two locations arguments, A and B, where A < B (A should be shown before B), compare function should return number < 0.

For sorting results alphabetically:

compare: function(a, b){
if (a.label < b.label){
return -1;
}
return +1;
}
}
QJSValue compare
JavaScript function used for sorting search results.
Definition SearchLocationModel.h:105
LocationListModel(QObject *parent=nullptr)
Definition SearchLocationModel.cpp:35

◆ count

int osmscout::LocationListModel::count
read

Count of rows in model - count of search results.

◆ displayLimit

int osmscout::LocationListModel::displayLimit =100
readwrite

Limit of model rows.

Referenced by GetDisplayLimit(), regionLookupRequested(), and SetDisplayLimit().

◆ equals

QJSValue osmscout::LocationListModel::equals
readwrite

JavaScript function used for check location equality.

It is possible that model will returns one physical location multiple times, for example one from location index and second from fulltext search, or two db segments for one real street...

Such results may be merged in model. Function will receive two locations (only locations with same label will be checked) and should return boolean result.

For example, merge near objects with same label and type:

equals: function(a, b){
if (a.objectType == b.objectType &&
a.distanceTo(b.lat, b.lon) < 300 &&
a.distanceTo(searchCenterLat, searchCenterLon) > 3000 ){
return true;
}
return false;
}
}
QJSValue equals
JavaScript function used for check location equality.
Definition SearchLocationModel.h:131

◆ lat

double osmscout::LocationListModel::lat
readwrite

Lat and lon properties control where is logical search center.

Local admin region is used as default region, databases used for search are sorted by distance from this point (local results should be available faster).

Referenced by SetLat().

◆ lon

double osmscout::LocationListModel::lon
readwrite
See also
lat property

Referenced by SetLon().

◆ pattern

QString osmscout::LocationListModel::pattern
readwrite

◆ resultLimit

int osmscout::LocationListModel::resultLimit =2000
readwrite

Limit of results for each db.

Referenced by GetResultLimit(), onSearchFinished(), regionLookupRequested(), setPattern(), and SetResultLimit().

◆ searching

bool osmscout::LocationListModel::searching =false
read

True if searching is in progress.

Referenced by isSearching(), onSearchFinished(), regionLookupRequested(), and setPattern().


The documentation for this class was generated from the following files: