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>
19
#include <unity/scopes/qt/internal/QScopeVariant.h>
20
#include <unity/scopes/qt/QUtils.h>
22
#include <unity/scopes/Variant.h>
24
#include <QtCore/QMap>
29
using namespace unity::scopes::qt::internal;
32
// QScopeVariant::QScopeVariant() noexcept : QVariant(), internal_variant_(nullptr)
36
QScopeVariant::QScopeVariant(Variant* val) noexcept : QVariant(scopeVariantToQVariant(*val)), internal_variant_(val)
40
QScopeVariant::~QScopeVariant() = default;
42
QScopeVariant::QScopeVariant(QScopeVariant const& other)
43
: QVariant(scopeVariantToQVariant(*other.internal_variant_))
44
, internal_variant_(other.internal_variant_)
48
QScopeVariant::QScopeVariant(QScopeVariant&&) = default;
50
QScopeVariant& QScopeVariant::operator=(QScopeVariant const& other)
54
internal_variant_ = other.internal_variant_;
60
QScopeVariant& QScopeVariant::operator=(QScopeVariant&&) = default;
62
void QScopeVariant::setInternalVariant(Variant* val)
64
internal_variant_ = val;
67
QScopeVariant& QScopeVariant::operator=(int val) noexcept
69
assert(internal_variant_);
70
*internal_variant_ = val;
74
QScopeVariant& QScopeVariant::operator=(double val) noexcept
76
assert(internal_variant_);
77
*internal_variant_ = val;
81
QScopeVariant& QScopeVariant::operator=(bool val) noexcept
83
assert(internal_variant_);
84
*internal_variant_ = val;
88
QScopeVariant& QScopeVariant::operator=(QString const& val)
90
assert(internal_variant_);
91
*internal_variant_ = val.toUtf8().data();
95
QScopeVariant& QScopeVariant::operator=(char const* val)
97
assert(internal_variant_);
98
*internal_variant_ = val;
102
QScopeVariant& QScopeVariant::operator=(QVariantMap const& val)
104
assert(internal_variant_);
105
VariantMap internal_val;
107
QMapIterator<QString, QVariant> it(val);
110
internal_val[it.key().toUtf8().data()] = qVariantToScopeVariant(it.value());
112
*internal_variant_ = internal_val;
116
QScopeVariant& QScopeVariant::operator=(QVariant const& val)
118
Variant internal_val = qVariantToScopeVariant(val);
119
*internal_variant_ = internal_val;
123
std::string QScopeVariant::get_string() const
125
assert(internal_variant_);
126
return internal_variant_->get_string();
129
void QScopeVariant::sync()
131
*internal_variant_ = qVariantToScopeVariant(*this);