File indexing completed on 2024-04-28 15:29:20

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 using namespace KParts;
0013 
0014 class KParts::HistoryProviderPrivate
0015 {
0016 public:
0017     HistoryProviderPrivate()
0018         : q(nullptr)
0019     {
0020     }
0021 
0022     ~HistoryProviderPrivate()
0023     {
0024         delete q;
0025     }
0026 
0027     QSet<QString> dict;
0028     HistoryProvider *q;
0029 };
0030 
0031 Q_GLOBAL_STATIC(HistoryProviderPrivate, historyProviderPrivate)
0032 
0033 HistoryProvider *HistoryProvider::self()
0034 {
0035     if (!historyProviderPrivate()->q) {
0036         new HistoryProvider;
0037     }
0038 
0039     return historyProviderPrivate()->q;
0040 }
0041 
0042 bool HistoryProvider::exists()
0043 {
0044     return historyProviderPrivate()->q;
0045 }
0046 
0047 HistoryProvider::HistoryProvider(QObject *parent)
0048     : QObject(parent)
0049     , d(historyProviderPrivate)
0050 {
0051     Q_ASSERT(!historyProviderPrivate()->q);
0052     historyProviderPrivate()->q = this;
0053     setObjectName(QStringLiteral("history provider"));
0054 }
0055 
0056 HistoryProvider::~HistoryProvider()
0057 {
0058     if (!historyProviderPrivate.isDestroyed() && historyProviderPrivate()->q == this) {
0059         historyProviderPrivate()->q = nullptr;
0060     }
0061 }
0062 
0063 bool HistoryProvider::contains(const QString &item) const
0064 {
0065     return d->dict.contains(item);
0066 }
0067 
0068 void HistoryProvider::insert(const QString &item)
0069 {
0070     d->dict.insert(item);
0071     Q_EMIT inserted(item);
0072 }
0073 
0074 void HistoryProvider::remove(const QString &item)
0075 {
0076     d->dict.remove(item);
0077 }
0078 
0079 void HistoryProvider::clear()
0080 {
0081     d->dict.clear();
0082     Q_EMIT cleared();
0083 }
0084 
0085 #include "moc_historyprovider.cpp"