~xavi-garcia-mena/unity-scopes-api/utils-qt

« back to all changes in this revision

Viewing changes to include/unity/scopes/qt/QDepartment.h

  • Committer: Xavi Garcia
  • Date: 2015-01-20 13:59:36 UTC
  • Revision ID: xavi.garcia.mena@canonical.com-20150120135936-cogxk8ok7g0gvo8g
Added Qt-bindings classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical Ltd
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Xavi Garcia <xavi.garcia.mena@canonical.com>
 
17
 */
 
18
 
 
19
#pragma once
 
20
 
 
21
#include <unity/util/DefinesPtrs.h>
 
22
 
 
23
#include <QtCore/QVariantMap>
 
24
#include <QtCore/QString>
 
25
#include <QtCore/QSharedPointer>
 
26
#include <QtCore/QScopedPointer>
 
27
 
 
28
#include <memory>
 
29
 
 
30
namespace unity
 
31
{
 
32
 
 
33
namespace scopes
 
34
{
 
35
 
 
36
namespace qt
 
37
{
 
38
 
 
39
class QDepartment;
 
40
class QCannedQuery;
 
41
 
 
42
namespace internal
 
43
{
 
44
class QDepartmentImpl;
 
45
class QSearchReplyImpl;
 
46
}
 
47
 
 
48
/*! \typedef QDepartmentList
 
49
\brief List of departments (see unity::scopes::qt::QDepartment)
 
50
*/
 
51
typedef QList<QSharedPointer<QDepartment const>> QDepartmentList;
 
52
 
 
53
/**
 
54
\brief A department with optional sub-departments.
 
55
*/
 
56
class QDepartment final
 
57
{
 
58
public:
 
59
    /// @cond
 
60
    UNITY_DEFINES_PTRS(QDepartment);
 
61
    /// @endcond
 
62
 
 
63
    /**
 
64
    \brief Create a department with the given canned query and name.
 
65
 
 
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.
 
71
    */
 
72
    static QDepartment::UPtr create(QCannedQuery const& query, QString const& label);
 
73
 
 
74
    /**
 
75
    \brief Create a department with the given department identifier, canned query, and name.
 
76
 
 
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.
 
84
    */
 
85
    static QDepartment::UPtr create(QString const& department_id, QCannedQuery const& query, QString const& label);
 
86
 
 
87
    /**@name Copy and assignment
 
88
    Copy and assignment operators (move and non-move versions) have the usual value semantics.
 
89
    */
 
90
    //{@
 
91
    QDepartment(QDepartment const& other);
 
92
    QDepartment(QDepartment&&);
 
93
    QDepartment& operator=(QDepartment const& other);
 
94
    QDepartment& operator=(QDepartment&&);
 
95
    //@}
 
96
 
 
97
    /// @cond
 
98
    ~QDepartment();
 
99
    /// @endcond
 
100
 
 
101
    /**
 
102
    \brief Set sub-departments of this department.
 
103
    \param departments The list of sub-departments.
 
104
    */
 
105
    void set_subdepartments(QDepartmentList const& departments);
 
106
 
 
107
    /**
 
108
    \brief Add sub-department to this department.
 
109
    \param department The subdepartment instance.
 
110
    */
 
111
    void add_subdepartment(QDepartment::SCPtr const& department);
 
112
 
 
113
    /**
 
114
     \brief Set the alternate label (plural of the normal label) of this department.
 
115
 
 
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.
 
120
    */
 
121
    void set_alternate_label(QString const& label);
 
122
 
 
123
    /**
 
124
     \brief Sets has_subdepartments flag of this department.
 
125
 
 
126
     This flag is a display hint for the Shell that indicates if this department has sub-departments and as such should
 
127
     be displayed
 
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.
 
131
 
 
132
     \throws unity::LogicException if called with false after adding sub-departments with
 
133
     unity::scopes::Department::set_subdepartments()
 
134
     */
 
135
    void set_has_subdepartments(bool subdepartments = true);
 
136
 
 
137
    /**
 
138
    \brief Get the identifier of this department.
 
139
    \return The department identifier.
 
140
    */
 
141
    QString id() const;
 
142
 
 
143
    /**
 
144
    \brief Get the label of this department.
 
145
    \return The department label.
 
146
    */
 
147
    QString label() const;
 
148
 
 
149
    /**
 
150
    \brief Get the alternate label of this department.
 
151
 
 
152
    Return the alternate label of this department. The alternate label expresses the plural "all" form of the normal
 
153
    label.
 
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.
 
156
 
 
157
    \return The alternate label.
 
158
     */
 
159
    QString alternate_label() const;
 
160
 
 
161
    /**
 
162
    \brief Get the canned query associated with this department.
 
163
    \return The canned query for this department.
 
164
    */
 
165
    QCannedQuery query() const;
 
166
 
 
167
    /**
 
168
    \brief Get list of sub-departments of this department.
 
169
    \return The list of sub-departments.
 
170
    */
 
171
    QDepartmentList subdepartments() const;
 
172
 
 
173
    /**
 
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
 
176
     */
 
177
    bool has_subdepartments() const;
 
178
 
 
179
    /// @cond
 
180
    QVariantMap serialize() const;
 
181
    /// @endcond
 
182
 
 
183
private:
 
184
    /// @cond
 
185
    QDepartment(internal::QDepartmentImpl* impl);
 
186
    std::unique_ptr<internal::QDepartmentImpl> p;
 
187
    friend class internal::QDepartmentImpl;
 
188
    friend class internal::QSearchReplyImpl;
 
189
    /// @endcond
 
190
};
 
191
 
 
192
}  // namespace qt
 
193
 
 
194
}  // namespace scopes
 
195
 
 
196
}  // namespace unity