Class which implements live queries with Tracker. More...
Classes | |
struct | CollationColumn |
Public Slots | |
bool | start () |
Must be called after giving data (setIdentityColumns(), setCollationColumns(), addUpdater()) is done and the model can start its operation. | |
void | setUpdatesEnabled (bool enable) |
Pauses or resumes the live updates. | |
Signals | |
void | initialQueryFinished () |
Emitted when the model is filled with the initial query data (the result of original query passed to the TrackerLiveQuery()). | |
Public Member Functions | |
TrackerLiveQuery (const QString &originalQuery, int columnCount, const QList< int > &identityColumns, QSparqlConnection &connection) | |
Constructs a TrackerLiveQuery. | |
TrackerLiveQuery (const QSparqlQuery &originalQuery, int columnCount, const QList< int > &identityColumns, QSparqlConnection &connection) | |
Constructs a TrackerLiveQuery. | |
TrackerLiveQuery (const QString &originalQuery, int columnCount, QSparqlConnection &connection) | |
Constructs a TrackerLiveQuery. | |
TrackerLiveQuery (const QSparqlQuery &originalQuery, int columnCount, QSparqlConnection &connection) | |
Constructs a TrackerLiveQuery. | |
~TrackerLiveQuery () | |
Destroys the TrackerLiveQuery. | |
void | setIdentityColumns (const QList< int > &columns) |
Sets columns to be used as identity columns when merging new data into the model. | |
void | setCollationColumns (const QList< CollationColumn > &columns) |
Sets columns to define the sorting of the rows in the model. | |
void | addUpdater (const TrackerPartialUpdater &updater) |
Adds a TrackerPartialUpdater to keep the data model up to date. | |
void | addUpdater (const TrackerFullUpdater &updater) |
Adds a TrackerFullUpdater to keep the data model up to date. | |
QAbstractItemModel * | model () const |
Returns a model that can be used e.g., in UIs. | |
Properties | |
QAbstractItemModel | model |
Class which implements live queries with Tracker.
TrackerLiveQuery is an interface to a QAbstractItemModel which contains the result of a query and which is kept up to date when the result changes.
TrackerLiveQuery first runs the initial query, given by the user. Then it connects to the GraphChanged signal which Tracker sends when data in its database has changed. When the signal arrives, TrackerLiveQuery runs an update query to find out how the changes affect the current data, and merges the changes back into the data.
The user specifies how the TrackerLiveQuery should reach to changes by associating updaters with it. Each updater knows which changes it should react to (ontology class name and property name) and what kind of an update query to run.
Two kinds of updaters can be used for keeping the TrackerLiveQuery up to date:
TrackerLiveQuery::TrackerLiveQuery | ( | const QString & | originalQuery, | |
int | columnCount, | |||
const QList< int > & | identityColumns, | |||
QSparqlConnection & | connection | |||
) |
Constructs a TrackerLiveQuery.
First the model is filled with the results of originalQuery, and the data is kept up to date with updaters (TrackerPartialUpdater and TrackerFullUpdater) which are added to this TrackerLiveQuery with addUpdater(). columnCount is the number of columns in the original query, and identityColumns are the identity columns of the model. connection is the QSparqlConnection for executing the queries (the original query and the queries generated by the updaters).
TrackerLiveQuery::TrackerLiveQuery | ( | const QSparqlQuery & | originalQuery, | |
int | columnCount, | |||
const QList< int > & | identityColumns, | |||
QSparqlConnection & | connection | |||
) |
Constructs a TrackerLiveQuery.
First the model is filled with the results of originalQuery, and the data is kept up to date with updaters (TrackerPartialUpdater and TrackerFullUpdater) which are added to this TrackerLiveQuery with addUpdater(). columnCount is the number of columns in the original query, and connection is the QSparqlConnection for executing the queries (the original query and the queries generated by the updaters).
TrackerLiveQuery::TrackerLiveQuery | ( | const QString & | originalQuery, | |
int | columnCount, | |||
QSparqlConnection & | connection | |||
) |
Constructs a TrackerLiveQuery.
First the model is filled with the results of originalQuery, and the data is kept up to date with updaters (TrackerPartialUpdater and TrackerFullUpdater) which are added to this TrackerLiveQuery with addUpdater(). columnCount is the number of columns in the original query, and connection is the QSparqlConnection for executing the queries (the original query and the queries generated by the updaters).
TrackerLiveQuery::TrackerLiveQuery | ( | const QSparqlQuery & | originalQuery, | |
int | columnCount, | |||
QSparqlConnection & | connection | |||
) |
Constructs a TrackerLiveQuery.
First the model is filled with the results of originalQuery, and the data is kept up to date with updaters (TrackerPartialUpdater and TrackerFullUpdater) which are added to this TrackerLiveQuery with addUpdater(). columnCount is the number of columns in the original query, and connection is the QSparqlConnection for executing the queries (the original query and the queries generated by the updaters).
void TrackerLiveQuery::addUpdater | ( | const TrackerPartialUpdater & | updater | ) |
Adds a TrackerPartialUpdater to keep the data model up to date.
It will re-run a limited query to update the data in the model.
void TrackerLiveQuery::addUpdater | ( | const TrackerFullUpdater & | updater | ) |
Adds a TrackerFullUpdater to keep the data model up to date.
It will re-run the original query to update the data in the model.
void TrackerLiveQuery::initialQueryFinished | ( | ) | [signal] |
Emitted when the model is filled with the initial query data (the result of original query passed to the TrackerLiveQuery()).
QAbstractItemModel* TrackerLiveQuery::model | ( | ) | const |
Returns a model that can be used e.g., in UIs.
The model will change its data and emit the corresponding QAbstractItemModel signals when data in the database changes.
void TrackerLiveQuery::setCollationColumns | ( | const QList< CollationColumn > & | columns | ) |
Sets columns to define the sorting of the rows in the model.
The sorting is used when merging new data into the model.
void TrackerLiveQuery::setIdentityColumns | ( | const QList< int > & | columns | ) |
Sets columns to be used as identity columns when merging new data into the model.
The values in the identity columns determine if two rows are the same. The model cannot have two rows with the same identity. A limitation: the contents of the identity columns must be integers.
void TrackerLiveQuery::setUpdatesEnabled | ( | bool | enable | ) | [slot] |
Pauses or resumes the live updates.
When the updates are disabled, the TrackerLiveQuery gathers data about update queries to be run, but doesn't run them. The queries are eventually ran when updates are enabled the next time. By default, the updates are enabled.
bool TrackerLiveQuery::start | ( | ) | [slot] |
Must be called after giving data (setIdentityColumns(), setCollationColumns(), addUpdater()) is done and the model can start its operation.
After calling start(), the user must spin the event loop regularly for the TrackerLiveQuery to operate correctly.