2
* Copyright (C) 2015 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Xavi Garcia <xavi.garcia.mena@canonical.com>
21
#include <unity/util/DefinesPtrs.h>
23
#include <QtCore/QVariantMap>
24
#include <QtCore/QString>
25
#include <QtCore/QSharedPointer>
26
#include <QtCore/QScopedPointer>
44
class QDepartmentImpl;
45
class QSearchReplyImpl;
48
/*! \typedef QDepartmentList
49
\brief List of departments (see unity::scopes::qt::QDepartment)
51
typedef QList<QSharedPointer<QDepartment const>> QDepartmentList;
54
\brief A department with optional sub-departments.
56
class QDepartment final
60
UNITY_DEFINES_PTRS(QDepartment);
64
\brief Create a department with the given canned query and name.
66
The identifier of this department instance is that of the `query` instance (\link
67
QCannedQuery::department_id()\endlink).
68
\param query The query (and associated parameters, such as filter state) to be executed when the user
69
selects this department.
70
\param label The display name of this department.
72
static QDepartment::UPtr create(QCannedQuery const& query, QString const& label);
75
\brief Create a department with the given department identifier, canned query, and name.
77
The canned query's target department identifier is updated with department_id.
78
This constructor is convenient for creating multiple departments that use the same query and only
79
need a different department identifier.
80
\param department_id The department identifier.
81
\param query The canned query (and associated parameters, such as filter state) to be executed when the user
82
selects this department.
83
\param label The display name of this department.
85
static QDepartment::UPtr create(QString const& department_id, QCannedQuery const& query, QString const& label);
87
/**@name Copy and assignment
88
Copy and assignment operators (move and non-move versions) have the usual value semantics.
91
QDepartment(QDepartment const& other);
92
QDepartment(QDepartment&&);
93
QDepartment& operator=(QDepartment const& other);
94
QDepartment& operator=(QDepartment&&);
102
\brief Set sub-departments of this department.
103
\param departments The list of sub-departments.
105
void set_subdepartments(QDepartmentList const& departments);
108
\brief Add sub-department to this department.
109
\param department The subdepartment instance.
111
void add_subdepartment(QDepartment::SCPtr const& department);
114
\brief Set the alternate label (plural of the normal label) of this department.
116
The alternate label should express the plural "all" form of the normal label. For example,
117
if the normal label is "Books", then the alternate label should be "All Books". The alternate label
118
needs to be provided for the current department only.
119
\param label The alternate label to display when showing plural form of this department's name.
121
void set_alternate_label(QString const& label);
124
\brief Sets has_subdepartments flag of this department.
126
This flag is a display hint for the Shell that indicates if this department has sub-departments and as such should
128
in a way that suggests further navigation to the user.
129
Setting this flag is not needed when sub-departments have been added with set_subdepartments() method.
130
Setting this flag to false after adding sub-departments with set_subdepartments() throws unity::LogicException.
132
\throws unity::LogicException if called with false after adding sub-departments with
133
unity::scopes::Department::set_subdepartments()
135
void set_has_subdepartments(bool subdepartments = true);
138
\brief Get the identifier of this department.
139
\return The department identifier.
144
\brief Get the label of this department.
145
\return The department label.
147
QString label() const;
150
\brief Get the alternate label of this department.
152
Return the alternate label of this department. The alternate label expresses the plural "all" form of the normal
154
For example, if the normal label is "Books", then the alternate label is "All Books". Note that alternate label
155
and can be empty - in that case the normal label should be displayed instead.
157
\return The alternate label.
159
QString alternate_label() const;
162
\brief Get the canned query associated with this department.
163
\return The canned query for this department.
165
QCannedQuery query() const;
168
\brief Get list of sub-departments of this department.
169
\return The list of sub-departments.
171
QDepartmentList subdepartments() const;
174
\brief Check if this department has subdepartments or has_subdepartments flag is set
175
\return true if this deparment has subdepartments or has_subdepartments flag is set
177
bool has_subdepartments() const;
180
QVariantMap serialize() const;
185
QDepartment(internal::QDepartmentImpl* impl);
186
std::unique_ptr<internal::QDepartmentImpl> p;
187
friend class internal::QDepartmentImpl;
188
friend class internal::QSearchReplyImpl;
194
} // namespace scopes