QtSparql  0.2.6
Signals | Public Member Functions | Protected Member Functions | List of all members
QSparqlQueryModel Class Reference

The QSparqlQueryModel class provides a read-only data model for SPARQL result sets. More...

Inherits QAbstractTableModel.

Inherited by SparqlListModel.

Signals

void finished ()
 
void started ()
 

Public Member Functions

 QSparqlQueryModel (QObject *parent=0)
 
virtual ~QSparqlQueryModel ()
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const
 
QSparqlResultRow resultRow (int row) const
 
QSparqlResultRow resultRow () const
 
QVariant data (const QModelIndex &item, int role=Qt::DisplayRole) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 
void setQuery (const QSparqlQuery &query, QSparqlConnection &conn)
 
QSparqlQuery query () const
 
virtual void clear ()
 
QSparqlError lastError () const
 
virtual QHash< int, QByteArray > roleNames () const
 

Protected Member Functions

virtual void queryChange ()
 
QModelIndex indexInQuery (const QModelIndex &item) const
 
void setLastError (const QSparqlError &error)
 

Detailed Description

The QSparqlQueryModel class provides a read-only data model for SPARQL result sets.

QSparqlQueryModel is a high-level interface for executing SPARQL statements and traversing the result set. It is built on top of the lower-level QSparqlQuery and can be used to provide data to view classes such as QTableView.

QSparqlQueryModel can also be used to access a connection programmatically, without binding it to a view.

See also
QSparqlQuery

Constructor & Destructor Documentation

◆ QSparqlQueryModel()

QSparqlQueryModel::QSparqlQueryModel ( QObject *  parent = 0)
explicit

Creates an empty QSparqlQueryModel with the given parent.

◆ ~QSparqlQueryModel()

QSparqlQueryModel::~QSparqlQueryModel ( )
virtual

Destroys the object and frees any allocated resources.

See also
clear()

Member Function Documentation

◆ clear()

void QSparqlQueryModel::clear ( )
virtual

Clears the model and releases any acquired resources. After this function, the model is not usable until setQuery() has been called.

See also
setQuery()

◆ columnCount()

int QSparqlQueryModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Returns the number of columns, which is the number of variables in the select part of the query

◆ data()

QVariant QSparqlQueryModel::data ( const QModelIndex &  item,
int  role = Qt::DisplayRole 
) const

Returns the value for the specified item and role.

If item is out of bounds or if an error occurred, an invalid QVariant is returned.

See also
lastError()

◆ finished

void QSparqlQueryModel::finished ( )
signal

This signal is emitted when the QSparqlResult, used by the model, has finished retrieving its data or when there was an error.

◆ headerData()

QVariant QSparqlQueryModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const

Returns the header data for the given role in the section of the header with the specified orientation.

◆ indexInQuery()

QModelIndex QSparqlQueryModel::indexInQuery ( const QModelIndex &  item) const
protected

Returns the index of the value in the connection result set for the given item in the model.

The return value is identical to item if no columns or rows have been inserted, removed, or moved around.

Returns an invalid model index if item is out of bounds or if item does not point to a value in the result set.

See also
QSparqlTableModel::indexInQuery(), insertColumns(), removeColumns()

◆ insertColumns()

bool QSparqlQueryModel::insertColumns ( int  column,
int  count,
const QModelIndex &  parent = QModelIndex() 
)

Inserts count columns into the model at position column. The parent parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.

Returns true if column is within bounds; otherwise returns false.

By default, inserted columns are empty. To fill them with data, reimplement data() and handle any inserted column separately.

See also
removeColumns()

◆ lastError()

QSparqlError QSparqlQueryModel::lastError ( ) const

Returns information about the last error that occurred on the connection.

See also
query()

◆ query()

QSparqlQuery QSparqlQueryModel::query ( ) const

Returns the QSparqlQuery associated with this model.

See also
setQuery()

◆ queryChange()

void QSparqlQueryModel::queryChange ( )
protectedvirtual

This virtual function is called whenever the query changes. The default implementation does nothing.

query() returns the new query.

See also
query(), setQuery()

◆ removeColumns()

bool QSparqlQueryModel::removeColumns ( int  column,
int  count,
const QModelIndex &  parent = QModelIndex() 
)

Removes count columns from the model starting from position column. The parent parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.

Removing columns effectively hides them. It does not affect the underlying QSparqlQuery.

Returns true if the columns were removed; otherwise returns false.

◆ resultRow() [1/2]

QSparqlResultRow QSparqlQueryModel::resultRow ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns an empty record containing information about the fields of the current query.

If the model is not initialized, an empty record will be returned.

See also
QSparqlResultRow::isEmpty()

◆ resultRow() [2/2]

QSparqlResultRow QSparqlQueryModel::resultRow ( int  row) const

Returns the record containing information about the fields of the current query. If row is the index of a valid row, the record will be populated with values from that row.

If the model is not initialized, an empty record will be returned.

See also
QSparqlResultRow::isEmpty()

◆ rowCount()

int QSparqlQueryModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

If the connection supports returning the size of a query (see QSparqlConnection::hasFeature()), the number of rows of the current query is returned. Otherwise, returns the number of rows currently cached on the client.

parent should always be an invalid QModelIndex.

See also
canFetchMore(), QSparqlConnection::hasFeature()

◆ setHeaderData()

bool QSparqlQueryModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant &  value,
int  role = Qt::EditRole 
)

Sets the caption for a horizontal header for the specified role to value. This is useful if the model is used to display data in a view (e.g., QTableView).

Returns true if orientation is Qt::Horizontal and the section refers to a valid section; otherwise returns false.

Note that this function cannot be used to modify values in the connection since the model is read-only.

See also
data()

◆ setLastError()

void QSparqlQueryModel::setLastError ( const QSparqlError error)
protected

Protected function which allows derived classes to set the value of the last error that occurred on the connection to error.

See also
lastError()

◆ setQuery()

void QSparqlQueryModel::setQuery ( const QSparqlQuery query,
QSparqlConnection connection 
)

Executes the query query for the given connection connection connection. If no connection is specified, the default connection is used.

lastError() can be used to retrieve verbose information if there was an error setting the query.

See also
query(), queryChange(), lastError()

◆ started

void QSparqlQueryModel::started ( )
signal

This signal is emitted when the QSparqlResult, used by the model, has started to execute.


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