File indexing completed on 2024-04-28 04:58:10

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2001 Carsten Pfeiffer <pfeiffer@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "historyprovider.h"
0009 
0010 #include <QSet>
0011 
0012 class HistoryProviderPrivate
0013 {
0014 public:
0015     HistoryProviderPrivate()
0016         : q(nullptr)
0017     {
0018     }
0019 
0020     ~HistoryProviderPrivate()
0021     {
0022         delete q;
0023     }
0024 
0025     QSet<QString> dict;
0026     HistoryProvider *q;
0027 };
0028 
0029 Q_GLOBAL_STATIC(HistoryProviderPrivate, historyProviderPrivate)
0030 
0031 HistoryProvider *HistoryProvider::self()
0032 {
0033     if (!historyProviderPrivate()->q) {
0034         new HistoryProvider;
0035     }
0036 
0037     return historyProviderPrivate()->q;
0038 }
0039 
0040 bool HistoryProvider::exists()
0041 {
0042     return historyProviderPrivate()->q;
0043 }
0044 
0045 HistoryProvider::HistoryProvider(QObject *parent)
0046     : QObject(parent)
0047     , d(historyProviderPrivate)
0048 {
0049     Q_ASSERT(!historyProviderPrivate()->q);
0050     historyProviderPrivate()->q = this;
0051     setObjectName(QStringLiteral("history provider"));
0052 }
0053 
0054 HistoryProvider::~HistoryProvider()
0055 {
0056     if (!historyProviderPrivate.isDestroyed() && historyProviderPrivate()->q == this) {
0057         historyProviderPrivate()->q = nullptr;
0058     }
0059 }
0060 
0061 bool HistoryProvider::contains(const QString &item) const
0062 {
0063     return d->dict.contains(item);
0064 }
0065 
0066 void HistoryProvider::insert(const QString &item)
0067 {
0068     d->dict.insert(item);
0069     Q_EMIT inserted(item);
0070 }
0071 
0072 void HistoryProvider::remove(const QString &item)
0073 {
0074     d->dict.remove(item);
0075 }
0076 
0077 void HistoryProvider::clear()
0078 {
0079     d->dict.clear();
0080     Q_EMIT cleared();
0081 }
0082 
0083 #include "moc_historyprovider.cpp"