KTextWidgets

kpluralhandlingspinbox.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "kpluralhandlingspinbox.h"
8
9class KPluralHandlingSpinBoxPrivate
10{
11public:
12 KPluralHandlingSpinBoxPrivate(QSpinBox *qq)
13 : q(qq)
14 {
15 QObject::connect(q, qOverload<int>(&QSpinBox::valueChanged), q, [this](int value) {
16 updateSuffix(value);
17 });
18 }
19
20 void updateSuffix(int value)
21 {
22 if (!pluralSuffix.isEmpty()) {
23 KLocalizedString s = pluralSuffix;
24 q->setSuffix(s.subs(value).toString());
25 }
26 }
27
28 QSpinBox *const q;
29 KLocalizedString pluralSuffix;
30};
31
33 : QSpinBox(parent)
34 , d(new KPluralHandlingSpinBoxPrivate(this))
35{
36}
37
38KPluralHandlingSpinBox::~KPluralHandlingSpinBox() = default;
39
41{
42 d->pluralSuffix = suffix;
43 if (suffix.isEmpty()) {
45 } else {
46 d->updateSuffix(value());
47 }
48}
49#include "moc_kpluralhandlingspinbox.cpp"
QString toString() const
bool isEmpty() const
KLocalizedString subs(const KLocalizedString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
KPluralHandlingSpinBox(QWidget *parent=nullptr)
Default constructor.
void setSuffix(const KLocalizedString &suffix)
Sets the suffix to suffix.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setSuffix(const QString &suffix)
void valueChanged(int i)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:00:56 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.