Albert
Loading...
Searching...
No Matches
item.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Manuel Schneider
2// SPDX-License-Identifier: MIT
3
4#pragma once
5#include <QStringList>
6#include <albert/export.h>
7#include <functional>
8#include <vector>
9
10namespace albert
11{
12class Icon;
13
19class ALBERT_EXPORT Action final
20{
21public:
22
23 // ///
24 // /// Constructs an \ref Action with the contents initialized with the data passed.
25 // /// \param id_ \copybrief id
26 // /// \param text_ \copybrief text
27 // /// \param function_ \copybrief function
28 // /// \param hide_on_activation_ \copybrief hide_on_activation
29 // ///
30 // template<typename T1 = QString,
31 // typename T2 = QString,
32 // typename T3 = std::function<void()>>
33 // Action(T1 &&id_,
34 // T2 &&text_,
35 // T3 &&function_,
36 // bool hide_on_activation_ = true) noexcept :
37 // id(std::forward<T1>(id_)),
38 // text(std::forward<T2>(text_)),
39 // function(std::forward<T3>(function_)),
40 // hide_on_activation(hide_on_activation_)
41 // {}
42
46 QString id;
47
51 QString text;
52
56 std::function<void()> function;
57
61 bool hide_on_activation = true;
62};
63
64
70class ALBERT_EXPORT Item
71{
72public:
73
77 virtual ~Item();
78
86 virtual QString id() const = 0;
87
95 virtual QString text() const = 0;
96
102 virtual QString subtext() const = 0;
103
111 virtual QString inputActionText() const;
112
122 virtual std::unique_ptr<Icon> icon() const = 0;
123
129 virtual std::vector<Action> actions() const;
130
135 {
136 public:
137
141 virtual void notify(const albert::Item *item) = 0;
142
143 protected:
144
148 virtual ~Observer();
149 };
150
154 virtual void addObserver(Observer *observer);
155
159 virtual void removeObserver(Observer *observer);
160
161};
162
163namespace detail
164{
165class ALBERT_EXPORT DynamicItem : public Item
166{
167public:
168
169 DynamicItem();
170 ~DynamicItem() override;
171
172 void dataChanged() const;
173
174 void addObserver(Observer *) override;
175 void removeObserver(Observer *) override;
176
177private:
178
179 class Private;
180 std::unique_ptr<Private> d;
181
182};
183}
184
186template<typename T>
187concept ItemPtr
188 = std::is_base_of_v<Item, typename std::decay_t<T>::element_type>
189 && std::same_as<std::shared_ptr<typename std::decay_t<T>::element_type>, std::decay_t<T>>;
190
192template<typename R>
193concept ItemRange = std::ranges::range<R> && ItemPtr<std::ranges::range_value_t<R>>;
194
195} // namespace albert
196
Action used by result items (Item).
Definition item.h:20
QString text
The description.
Definition item.h:51
std::function< void()> function
The function executed on activation.
Definition item.h:56
QString id
The identifier.
Definition item.h:46
Interface class for item observers.
Definition item.h:135
virtual void notify(const albert::Item *item)=0
Notifies the observer about any changes in item.
virtual ~Observer()
Destructs the observer.
Result items displayed in the query results list.
Definition item.h:71
virtual ~Item()
Destructs the item.
virtual std::unique_ptr< Icon > icon() const =0
Returns the item icon.
virtual void removeObserver(Observer *observer)
Stops notifying observer about any changes.
virtual QString subtext() const =0
Returns the item subtext.
virtual QString id() const =0
Returns the item identifier.
virtual QString inputActionText() const
Returns the item input action text.
virtual QString text() const =0
Returns the item text.
virtual std::vector< Action > actions() const
Returns the item actions.
virtual void addObserver(Observer *observer)
Starts notifying observer about any changes.
A shared pointer to an Item or subclass thereof.
Definition item.h:188
A range of ItemPtr.
Definition item.h:193
Definition app.h:56