~ci-train-bot/history-service/history-service-ubuntu-yakkety-landing-052

62.2.1 by Gustavo Pichorim Boiko
Add a COPYING file and copyright headers to all source files.
1
/*
2
 * Copyright (C) 2013 Canonical, Ltd.
3
 *
4
 * Authors:
5
 *  Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
6
 *
7
 * This file is part of history-service.
8
 *
9
 * history-service is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; version 3.
12
 *
13
 * history-service is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
22
#include "sort.h"
23
#include "sort_p.h"
24
25
namespace History
26
{
27
28
// ------------- SortPrivate ------------------------------------------------
29
30
SortPrivate::SortPrivate(const QString &theSortField,
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
31
                                       Qt::SortOrder theSortOrder,
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
32
                                       Qt::CaseSensitivity theCaseSensitivity)
33
    : sortField(theSortField), sortOrder(theSortOrder), caseSensitivity(theCaseSensitivity)
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
34
{
35
}
36
37
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
38
SortPrivate::~SortPrivate()
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
39
{
40
}
41
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
42
// ------------- Sort -------------------------------------------------------
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
43
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
44
Sort::Sort(const QString &sortField,
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
45
                         Qt::SortOrder sortOrder,
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
46
                         Qt::CaseSensitivity caseSensitivity)
47
    : d_ptr(new SortPrivate(sortField, sortOrder, caseSensitivity))
48 by Gustavo Pichorim Boiko
Make HistorySort use shared data.
48
{
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
49
}
50
88.3.3 by Gustavo Pichorim Boiko
Do not use pointers for the sort either.
51
Sort::Sort(const Sort &other)
52
    : d_ptr(new SortPrivate(*other.d_ptr))
53
{
54
}
55
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
56
Sort::~Sort()
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
57
{
58
}
59
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
60
QString Sort::sortField() const
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
61
{
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
62
    Q_D(const Sort);
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
63
    return d->sortField;
64
}
65
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
66
void Sort::setSortField(const QString &value)
67
{
68
    Q_D(Sort);
69
    d->sortField = value;
70
}
71
72
Qt::SortOrder Sort::sortOrder() const
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
73
{
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
74
    Q_D(const Sort);
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
75
    return d->sortOrder;
76
}
77
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
78
void Sort::setSortOrder(Qt::SortOrder value)
79
{
80
    Q_D(Sort);
81
    d->sortOrder = value;
82
}
83
84
Qt::CaseSensitivity Sort::caseSensitivity() const
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
85
{
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
86
    Q_D(const Sort);
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
87
    return d->caseSensitivity;
26 by Gustavo Pichorim Boiko
Add the implementation for HistorySort.
88
}
48 by Gustavo Pichorim Boiko
Make HistorySort use shared data.
89
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
90
void Sort::setCaseSensitivity(Qt::CaseSensitivity value)
48 by Gustavo Pichorim Boiko
Make HistorySort use shared data.
91
{
69.1.1 by Gustavo Pichorim Boiko
Implement very basic sorting capabilities.
92
    Q_D(Sort);
93
    d->caseSensitivity = value;
48 by Gustavo Pichorim Boiko
Make HistorySort use shared data.
94
}
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
95
88.2.3 by Gustavo Pichorim Boiko
Implement the client side of history-service to go via dbus.
96
QVariantMap Sort::properties() const
97
{
98
    Q_D(const Sort);
99
    QVariantMap map;
100
112.1.3 by Gustavo Pichorim Boiko
Update the sort tests and rename the sort field enums to be consistent with the
101
    map[FieldSortField] = d->sortField;
102
    map[FieldSortOrder] = (int)d->sortOrder;
103
    map[FieldCaseSensitivity] = (int)d->caseSensitivity;
88.2.3 by Gustavo Pichorim Boiko
Implement the client side of history-service to go via dbus.
104
105
    return map;
106
}
107
88.3.3 by Gustavo Pichorim Boiko
Do not use pointers for the sort either.
108
Sort Sort::fromProperties(const QVariantMap &properties)
88.2.7 by Gustavo Pichorim Boiko
Implement the thread view via dbus.
109
{
88.3.3 by Gustavo Pichorim Boiko
Do not use pointers for the sort either.
110
    Sort sort;
88.2.7 by Gustavo Pichorim Boiko
Implement the thread view via dbus.
111
    if (properties.isEmpty()) {
112
        return sort;
113
    }
114
112.1.3 by Gustavo Pichorim Boiko
Update the sort tests and rename the sort field enums to be consistent with the
115
    sort = Sort(properties[FieldSortField].toString(),
116
                (Qt::SortOrder) properties[FieldSortOrder].toInt(),
117
                (Qt::CaseSensitivity) properties[FieldCaseSensitivity].toInt());
88.2.7 by Gustavo Pichorim Boiko
Implement the thread view via dbus.
118
    return sort;
119
}
120
56 by Gustavo Pichorim Boiko
Wrap all classes in a namespace, and rename some classes to better represent
121
}