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

« back to all changes in this revision

Viewing changes to src/scopes/qt/internal/QDepartmentImpl.cpp

  • 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
#include <unity/scopes/qt/internal/QDepartmentImpl.h>
 
20
#include <unity/scopes/qt/internal/QCannedQueryImpl.h>
 
21
#include <unity/scopes/qt/QUtils.h>
 
22
 
 
23
#include <unity/scopes/Department.h>
 
24
#include <unity/scopes/CannedQuery.h>
 
25
 
 
26
#include <QtCore/QListIterator>
 
27
 
 
28
using namespace unity::scopes;
 
29
using namespace unity::scopes::qt;
 
30
using namespace unity::scopes::qt::internal;
 
31
 
 
32
namespace sc = unity::scopes;
 
33
 
 
34
QDepartmentImpl::QDepartmentImpl(QCannedQuery const& query, QString const& label)
 
35
    : api_department_(sc::Department::create(*query.p->api_query_, label.toUtf8().data()))
 
36
{
 
37
}
 
38
 
 
39
QDepartmentImpl::QDepartmentImpl(QString const& department_id, QCannedQuery const& query, QString const& label)
 
40
    : api_department_(
 
41
          sc::Department::create(department_id.toUtf8().data(), *query.p->api_query_, label.toUtf8().data()))
 
42
{
 
43
}
 
44
 
 
45
QDepartmentImpl::QDepartmentImpl(Department const& api_department)
 
46
    : api_department_(new sc::Department(api_department))
 
47
{
 
48
}
 
49
 
 
50
void QDepartmentImpl::set_has_subdepartments(bool subdepartments)
 
51
{
 
52
    api_department_->set_has_subdepartments(subdepartments);
 
53
}
 
54
 
 
55
void QDepartmentImpl::set_subdepartments(QDepartmentList const& departments)
 
56
{
 
57
    DepartmentList api_list;
 
58
    QListIterator<QSharedPointer<QDepartment const>> it(departments);
 
59
    while (it.hasNext())
 
60
    {
 
61
        api_list.push_back(it.next().data()->p->api_department_);
 
62
    }
 
63
    api_department_->set_subdepartments(api_list);
 
64
}
 
65
 
 
66
void QDepartmentImpl::add_subdepartment(QDepartment::SCPtr const& department)
 
67
{
 
68
    api_department_->add_subdepartment(department->p->api_department_);
 
69
}
 
70
 
 
71
void QDepartmentImpl::set_alternate_label(QString const& label)
 
72
{
 
73
    api_department_->set_alternate_label(label.toUtf8().data());
 
74
}
 
75
 
 
76
QString QDepartmentImpl::alternate_label() const
 
77
{
 
78
    return QString::fromUtf8(api_department_->alternate_label().c_str());
 
79
}
 
80
 
 
81
QString QDepartmentImpl::id() const
 
82
{
 
83
    return QString::fromUtf8(api_department_->id().c_str());
 
84
}
 
85
 
 
86
QString QDepartmentImpl::label() const
 
87
{
 
88
    return QString::fromUtf8(api_department_->label().c_str());
 
89
}
 
90
 
 
91
QCannedQuery QDepartmentImpl::query() const
 
92
{
 
93
    return QCannedQuery(api_department_->query());
 
94
}
 
95
 
 
96
bool QDepartmentImpl::has_subdepartments() const
 
97
{
 
98
    return api_department_->has_subdepartments();
 
99
}
 
100
 
 
101
QDepartmentList QDepartmentImpl::subdepartments() const
 
102
{
 
103
    QDepartmentList ret_list;
 
104
    for (auto item : api_department_->subdepartments())
 
105
    {
 
106
        QSharedPointer<QDepartment> qdepartment(new QDepartment(new QDepartmentImpl(*item)));
 
107
        ret_list.push_back(qdepartment);
 
108
    }
 
109
    return ret_list;
 
110
}
 
111
 
 
112
QVariantMap QDepartmentImpl::serialize() const
 
113
{
 
114
    return scopeVariantMapToQVariantMap(api_department_->serialize());
 
115
}
 
116
 
 
117
// static QDepartment::UPtr QDepartmentImpl::create(QVariantMap const& var)
 
118
//{
 
119
//
 
120
//}
 
121
// static void QDepartmentImpl::validate_departments(QDepartment::SCPtr const& parent);
 
122
// static void QDepartmentImpl::validate_departments(QDepartment::SCPtr const& parent, QString const& current_id);
 
123
// static QVariantMap QDepartmentImpl::serialize_departments(QDepartment::SCPtr const& parent);
 
124
// static QDepartment::SCPtr QDepartmentImpl::find_subdepartment_by_id(QDepartment::SCPtr const& department, QString
 
125
// const& id);
 
126
//
 
127
//
 
128
// static void QDepartmentImpl::validate_departments(QDepartment::SCPtr const& department, std::unordered_set<QString>&
 
129
// lookup);