Cutelee 6.1.0
abstractlocalizer.cpp
1/*
2 This file is part of the Cutelee template system.
3
4 Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either version
9 2.1 of the Licence, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#include "abstractlocalizer.h"
22
23#include "util.h"
24
25#include <QtCore/QDateTime>
26
27using namespace Cutelee;
28
30
32
34{
35 if (variant.userType() == qMetaTypeId<QDate>())
36 return localizeDate(variant.toDate());
37 if (variant.userType() == qMetaTypeId<QTime>())
38 return localizeTime(variant.toTime());
39 if (variant.userType() == qMetaTypeId<QDateTime>())
40 return localizeDateTime(variant.toDateTime());
41 else if (isSafeString(variant))
42 return localizeString(getSafeString(variant).get());
43 else if (variant.userType() == qMetaTypeId<double>()
44 || variant.userType() == qMetaTypeId<float>())
45 return localizeNumber(variant.value<double>());
46 else if (variant.canConvert<int>())
47 return localizeNumber(variant.value<int>());
48 return QString();
49}
virtual QString localize(const QVariant &variant) const
virtual QString localizeDate(const QDate &date, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
virtual QString localizeNumber(int number) const =0
virtual QString localizeTime(const QTime &time, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
virtual QString localizeDateTime(const QDateTime &dateTime, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
virtual QString localizeString(const QString &string, const QVariantList &arguments={}) const =0
The Cutelee namespace holds all public Cutelee API.
Definition Mainpage.dox:8
bool isSafeString(const QVariant &input)
Definition util.cpp:117
Cutelee::SafeString getSafeString(const QVariant &input)
Definition util.cpp:108
Utility functions used throughout Cutelee.