KParts

historyprovider.cpp
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 2001 Carsten Pfeiffer <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "historyprovider.h"
9 
10 #include <QSet>
11 
12 using namespace KParts;
13 
14 class KParts::HistoryProviderPrivate
15 {
16 public:
17  HistoryProviderPrivate()
18  : q(nullptr)
19  {
20  }
21 
22  ~HistoryProviderPrivate()
23  {
24  delete q;
25  }
26 
27  QSet<QString> dict;
28  HistoryProvider *q;
29 };
30 
31 Q_GLOBAL_STATIC(HistoryProviderPrivate, historyProviderPrivate)
32 
33 HistoryProvider *HistoryProvider::self()
34 {
35  if (!historyProviderPrivate()->q) {
36  new HistoryProvider;
37  }
38 
39  return historyProviderPrivate()->q;
40 }
41 
43 {
44  return historyProviderPrivate()->q;
45 }
46 
48  : QObject(parent)
49  , d(historyProviderPrivate)
50 {
51  Q_ASSERT(!historyProviderPrivate()->q);
52  historyProviderPrivate()->q = this;
53  setObjectName(QStringLiteral("history provider"));
54 }
55 
57 {
58  if (!historyProviderPrivate.isDestroyed() && historyProviderPrivate()->q == this) {
59  historyProviderPrivate()->q = nullptr;
60  }
61 }
62 
63 bool HistoryProvider::contains(const QString &item) const
64 {
65  return d->dict.contains(item);
66 }
67 
69 {
70  d->dict.insert(item);
71  Q_EMIT inserted(item);
72 }
73 
75 {
76  d->dict.remove(item);
77 }
78 
80 {
81  d->dict.clear();
82  Q_EMIT cleared();
83 }
virtual bool contains(const QString &item) const
HistoryProvider(QObject *parent=nullptr)
Creates a KHistoryProvider with an optional parent and name.
virtual void insert(const QString &item)
Inserts item into the history.
Q_EMITQ_EMIT
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
virtual void clear()
Clears the history.
Basic class to manage a history of "items". This class is only meant for fast lookup,...
void setObjectName(const QString &name)
void cleared()
Emitted after the history has been cleared.
void inserted(const QString &item)
Emitted after the item has been inserted.
~HistoryProvider() override
Destroys the provider.
The KParts namespace,.
virtual void remove(const QString &item)
Removes item from the history.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 03:51:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.