unity.scopes.qt.QSearchReply

Allows the results of a search query to be sent to the query source. More...

#include <unity/scopes/qt/QSearchReply.h>

Inheritance diagram for unity::scopes::qt::QSearchReply: src="https://assets.ubuntu.com/v1/e39a435a-classunity_1_1scopes_1_1qt_1_1_q_search_reply__inherit__graph.png" border="0" alt="Inheritance graph"/>

Public Member Functions

virtual ~QSearchReply ()
 Destroys a QSearchReply.
 
virtual void register_departments (QDepartment::SCPtr const &parent)
 Register departments for the current search reply and provide the current department. More...
 
virtual QCategory::SCPtr register_category (QString const &id, QString const &title, QString const &icon, unity::scopes::CategoryRenderer const &renderer_template=unity::scopes::CategoryRenderer())
 Register new category and send it to the source of the query. More...
 
virtual bool push (QCategorisedResult const &result)
 Sends a single result to the source of a query. More...
 
virtual void error (std::exception_ptr ex)
 Informs the source of a query that the query was terminated due to an error. More...
 

Detailed Description

Allows the results of a search query to be sent to the query source.

Member Function Documentation

void QSearchReply::error ( std::exception_ptr  ex)
virtual

Informs the source of a query that the query was terminated due to an error.

Multiple calls to error() and calls to finished() after error() was called are ignored.

Parameters
exAn exception_ptr indicating the cause of the error. If ex is a std::exception, the return value of what() is made available to the query source. Otherwise, the query source receives "unknown exception".
bool QSearchReply::push ( QCategorisedResult const &  result)
virtual

Sends a single result to the source of a query.

Any calls to push() after finished() was called are ignored.

Returns
The return value is true if the result was accepted, false otherwise. A false return value can be due to finished() having been called earlier, or the client that sent the query having cancelled that query. The return value is false also if the query has a cardinality limit and is reached or exceeded. (The return value is false for the last valid push and subsequent pushes.)
QCategory::SCPtr QSearchReply::register_category ( QString const &  id,
QString const &  title,
QString const &  icon,
unity::scopes::CategoryRenderer const &  renderer_template = unity::scopes::CategoryRenderer() 
)
virtual

Register new category and send it to the source of the query.

Parameters
idThe identifier of the category
titleThe title of the category
iconThe icon of the category
renderer_templateThe renderer template to be used for results in this category
Returns
The category instance
Exceptions
unity::scopes::InvalidArgumentExceptionif category with that id has already been registered.
void QSearchReply::register_departments ( QDepartment::SCPtr const &  parent)
virtual

Register departments for the current search reply and provide the current department.

Departments are optional. If scope supports departments, it is expected to register departments on every search as follows:

For example, assuming the user is visiting a "History" department in "Books", and "History" has sub-departments such as "World War Two" and "Ancient", the code that registers departments for current search in "History" may look like this:

unity::scopes::qt::QDepartment::SPtr books = move(<a class="code" href="unity.scopes.qt.QDepartment.md#a9bf07a3b3b3e57a391100f15abb4c651">unity::scopes::qt::QDepartment::create</a>(<span class="stringliteral">&quot;books&quot;</span>, query, <span class="stringliteral">&quot;Books&quot;</span>));
<span class="comment">// the</span>
parent of <span class="stringliteral">&quot;History&quot;</span>
unity::scopes::Department::SPtr history = move(<a class="code" href="unity.scopes.qt.QDepartment.md#a9bf07a3b3b3e57a391100f15abb4c651">unity::scopes::qt::QDepartment::create</a>(<span class="stringliteral">&quot;history&quot;</span>, query,
<span class="stringliteral">&quot;History&quot;</span>));
<a class="code" href="unity.scopes.md#ab8effc4ea05a59f2ddea896833f07231">unity::scopes::DepartmentList</a> history_depts({
move(<a class="code" href="unity.scopes.qt.QDepartment.md#a9bf07a3b3b3e57a391100f15abb4c651">unity::scopes::qt::QDepartment::create</a>(<span class="stringliteral">&quot;ww2&quot;</span>, query, <span class="stringliteral">&quot;World War</span>
<span class="stringliteral">Two&quot;</span>)),
move(<a class="code" href="unity.scopes.qt.QDepartment.md#a9bf07a3b3b3e57a391100f15abb4c651">unity::scopes::qt::QDepartment::create</a>(<span class="stringliteral">&quot;ancient&quot;</span>, query,
<span class="stringliteral">&quot;Ancient&quot;</span>))});
history-&gt;set_subdepartments(history_depts);
books-&gt;set_subdepartments({history});
reply-&gt;register_departments(books);

Current department should be the department returned by unity::scopes::CannedQuery::department_id(). Empty department id denotes the root deparment.

Parameters
parentThe parent department of current department, or current one if visiting root department.
Exceptions
unity::LogicExceptionif departments are invalid (nullptr passed, current department not present in the parent's tree, duplicated department ids present in the tree).