KTextTemplate

abstractlocalizer.cpp
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#include "abstractlocalizer.h"
11
12#include "util.h"
13
14#include <QDateTime>
15
16using namespace KTextTemplate;
17
19
21
23{
24 if (variant.userType() == qMetaTypeId<QDate>())
25 return localizeDate(variant.value<QDate>());
26 if (variant.userType() == qMetaTypeId<QTime>())
27 return localizeTime(variant.value<QTime>());
28 if (variant.userType() == qMetaTypeId<QDateTime>())
29 return localizeDateTime(variant.value<QDateTime>());
30 if (isSafeString(variant))
31 return localizeString(getSafeString(variant).get());
32 if (variant.userType() == qMetaTypeId<double>() || variant.userType() == qMetaTypeId<float>())
33 return localizeNumber(variant.value<double>());
34 if (variant.canConvert<int>())
35 return localizeNumber(variant.value<int>());
36 return {};
37}
virtual QString localize(const QVariant &variant) const
Processes the data in variant into a localized string.
virtual QString localizeDateTime(const QDateTime &dateTime, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
Localizes dateTime with the specified formatType.
virtual ~AbstractLocalizer()
Destructor.
virtual QString localizeNumber(int number) const =0
Localizes number.
virtual QString localizeTime(const QTime &time, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
Localizes time with the specified formatType.
virtual QString localizeString(const QString &string, const QVariantList &arguments={}) const =0
Localizes string with the specified arguments for substitution.
virtual QString localizeDate(const QDate &date, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
Localizes date with the specified formatType.
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
KTextTemplate::SafeString getSafeString(const QVariant &input)
Retrieves and returns a SafeString from the input.
Definition util.cpp:91
bool isSafeString(const QVariant &input)
Returns whether input contains a SafeString.
Definition util.cpp:99
bool canConvert() const const
int userType() const const
T value() const const
Utility functions used throughout KTextTemplate.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:14:09 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.