~mardy/unity-scopes-api/clientid-1554040

« back to all changes in this revision

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

  • Committer: Michi Henning
  • Date: 2015-02-25 05:20:57 UTC
  • mfrom: (163.386.1 devel)
  • mto: (163.386.2 devel)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: michi.henning@canonical.com-20150225052057-9p21sge1myzaowcb
Merged devel and resolved conflicts.

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/QScopeVariant.h>
 
20
#include <unity/scopes/qt/QUtils.h>
 
21
 
 
22
#include <unity/scopes/Variant.h>
 
23
 
 
24
#include <QtCore/QMap>
 
25
 
 
26
#include <cassert>
 
27
 
 
28
using namespace std;
 
29
using namespace unity::scopes::qt::internal;
 
30
 
 
31
/// @cond
 
32
// QScopeVariant::QScopeVariant() noexcept : QVariant(), internal_variant_(nullptr)
 
33
//{
 
34
//}
 
35
 
 
36
QScopeVariant::QScopeVariant(Variant* val) noexcept : QVariant(scopeVariantToQVariant(*val)), internal_variant_(val)
 
37
{
 
38
}
 
39
 
 
40
QScopeVariant::~QScopeVariant() = default;
 
41
 
 
42
QScopeVariant::QScopeVariant(QScopeVariant const& other)
 
43
    : QVariant(scopeVariantToQVariant(*other.internal_variant_))
 
44
    , internal_variant_(other.internal_variant_)
 
45
{
 
46
}
 
47
 
 
48
QScopeVariant::QScopeVariant(QScopeVariant&&) = default;
 
49
 
 
50
QScopeVariant& QScopeVariant::operator=(QScopeVariant const& other)
 
51
{
 
52
    if (&other != this)
 
53
    {
 
54
        internal_variant_ = other.internal_variant_;
 
55
    }
 
56
 
 
57
    return *this;
 
58
}
 
59
 
 
60
QScopeVariant& QScopeVariant::operator=(QScopeVariant&&) = default;
 
61
 
 
62
void QScopeVariant::setInternalVariant(Variant* val)
 
63
{
 
64
    internal_variant_ = val;
 
65
}
 
66
 
 
67
QScopeVariant& QScopeVariant::operator=(int val) noexcept
 
68
{
 
69
    assert(internal_variant_);
 
70
    *internal_variant_ = val;
 
71
    return *this;
 
72
}
 
73
 
 
74
QScopeVariant& QScopeVariant::operator=(double val) noexcept
 
75
{
 
76
    assert(internal_variant_);
 
77
    *internal_variant_ = val;
 
78
    return *this;
 
79
}
 
80
 
 
81
QScopeVariant& QScopeVariant::operator=(bool val) noexcept
 
82
{
 
83
    assert(internal_variant_);
 
84
    *internal_variant_ = val;
 
85
    return *this;
 
86
}
 
87
 
 
88
QScopeVariant& QScopeVariant::operator=(QString const& val)
 
89
{
 
90
    assert(internal_variant_);
 
91
    *internal_variant_ = val.toUtf8().data();
 
92
    return *this;
 
93
}
 
94
 
 
95
QScopeVariant& QScopeVariant::operator=(char const* val)
 
96
{
 
97
    assert(internal_variant_);
 
98
    *internal_variant_ = val;
 
99
    return *this;
 
100
}
 
101
 
 
102
QScopeVariant& QScopeVariant::operator=(QVariantMap const& val)
 
103
{
 
104
    assert(internal_variant_);
 
105
    VariantMap internal_val;
 
106
 
 
107
    QMapIterator<QString, QVariant> it(val);
 
108
    while (it.hasNext())
 
109
    {
 
110
        internal_val[it.key().toUtf8().data()] = qVariantToScopeVariant(it.value());
 
111
    }
 
112
    *internal_variant_ = internal_val;
 
113
    return *this;
 
114
}
 
115
 
 
116
QScopeVariant& QScopeVariant::operator=(QVariant const& val)
 
117
{
 
118
    Variant internal_val = qVariantToScopeVariant(val);
 
119
    *internal_variant_ = internal_val;
 
120
    return *this;
 
121
}
 
122
 
 
123
std::string QScopeVariant::get_string() const
 
124
{
 
125
    assert(internal_variant_);
 
126
    return internal_variant_->get_string();
 
127
}
 
128
 
 
129
void QScopeVariant::sync()
 
130
{
 
131
    *internal_variant_ = qVariantToScopeVariant(*this);
 
132
}
 
133
/// @endcond