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
9#if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(6, 6)
10
11class KPluralHandlingSpinBoxPrivate
12{
13public:
14 KPluralHandlingSpinBoxPrivate(QSpinBox *qq)
15 : q(qq)
16 {
17 QObject::connect(q, qOverload<int>(&QSpinBox::valueChanged), q, [this](int value) {
18 updateSuffix(value);
19 });
20 }
21
22 void updateSuffix(int value)
23 {
24 if (!pluralSuffix.isEmpty()) {
25 KLocalizedString s = pluralSuffix;
26 q->setSuffix(s.subs(value).toString());
27 }
28 }
29
30 QSpinBox *const q;
31 KLocalizedString pluralSuffix;
32};
33
35 : QSpinBox(parent)
36 , d(new KPluralHandlingSpinBoxPrivate(this))
37{
38}
39
40KPluralHandlingSpinBox::~KPluralHandlingSpinBox() = default;
41
43{
44 d->pluralSuffix = suffix;
45 if (suffix.isEmpty()) {
47 } else {
48 d->updateSuffix(value());
49 }
50}
51#include "moc_kpluralhandlingspinbox.cpp"
52
53#endif
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 Dec 20 2024 11:49:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.