Albert
Loading...
Searching...
No Matches
standarditem.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 <albert/item.h>
6#include <memory>
7#include <vector>
8namespace albert{ class Icon; }
9
10namespace albert
11{
12
18class ALBERT_EXPORT StandardItem : public Item
19{
20public:
21
25 template<typename T_ID = QString,
26 typename T_TEXT = QString,
27 typename T_SUBTEXT = QString,
28 typename T_ICON_FACTORY = std::function<std::unique_ptr<Icon>()>,
29 typename T_ACTIONS = std::vector<Action>,
30 typename T_INPUTACTION = QString>
31 requires(std::same_as<std::remove_cvref_t<T_ID>, QString>
32 && std::same_as<std::remove_cvref_t<T_TEXT>, QString>
33 && std::same_as<std::remove_cvref_t<T_SUBTEXT>, QString>
34 && std::convertible_to<std::remove_cvref_t<T_ICON_FACTORY>, std::function<std::unique_ptr<Icon>()>>
35 && std::same_as<std::remove_cvref_t<T_ACTIONS>, std::vector<Action>>
36 && std::same_as<std::remove_cvref_t<T_INPUTACTION>, QString>)
37 StandardItem(T_ID &&id,
38 T_TEXT &&text,
39 T_SUBTEXT &&subtext,
40 T_ICON_FACTORY &&icon_factory,
41 T_ACTIONS &&actions = std::vector<Action>{},
42 T_INPUTACTION &&input_action_text = QString{}) noexcept :
43 id_(std::forward<T_ID>(id)),
44 text_(std::forward<T_TEXT>(text)),
45 subtext_(std::forward<T_SUBTEXT>(subtext)),
46 icon_factory_(std::forward<T_ICON_FACTORY>(icon_factory)),
47 actions_(std::forward<T_ACTIONS>(actions)),
48 input_action_text_(std::forward<T_INPUTACTION>(input_action_text))
49 {}
50
51
58 template<typename T_ID = QString,
59 typename T_TEXT = QString,
60 typename T_SUBTEXT = QString,
61 typename T_ICON_FACTORY = std::function<std::unique_ptr<Icon>()>,
62 typename T_ACTIONS = std::vector<Action>,
63 typename T_INPUTACTION = QString>
64 requires(std::same_as<std::decay_t<T_ID>, QString>
65 && std::same_as<std::decay_t<T_TEXT>, QString>
66 && std::same_as<std::decay_t<T_SUBTEXT>, QString>
67 && std::convertible_to<std::decay_t<T_ICON_FACTORY>, std::function<std::unique_ptr<Icon>()>>
68 && std::same_as<std::decay_t<T_ACTIONS>, std::vector<Action>>
69 && std::same_as<std::decay_t<T_INPUTACTION>, QString>)
70 static std::shared_ptr<StandardItem> make(T_ID &&id,
71 T_TEXT &&text,
72 T_SUBTEXT &&subtext,
73 T_ICON_FACTORY &&icon_factory,
74 T_ACTIONS &&actions = std::vector<Action>{},
75 T_INPUTACTION &&input_action_text = QString{}) noexcept
76 {
77 return std::make_shared<StandardItem>(std::forward<T_ID>(id),
78 std::forward<T_TEXT>(text),
79 std::forward<T_SUBTEXT>(subtext),
80 std::forward<T_ICON_FACTORY>(icon_factory),
81 std::forward<T_ACTIONS>(actions),
82 std::forward<T_INPUTACTION>(input_action_text));
83 }
84
85 StandardItem(const StandardItem &) = delete;
87
89 StandardItem(StandardItem &&other) noexcept = default;
90
92 StandardItem &operator=(StandardItem &&other) noexcept = default;
93
96
98 void setId(QString id);
99
101 void setText(QString text);
102
104 void setSubtext(QString text);
105
107 void setIconFactory(std::function<std::unique_ptr<Icon>()> icon_factory);
108
110 std::function<std::unique_ptr<Icon>()> iconFactory();
111
113 void setActions(std::vector<Action> actions);
114
116 void setInputActionText(QString text);
117
118 QString id() const override;
119 QString text() const override;
120 QString subtext() const override;
121 QString inputActionText() const override;
122 std::unique_ptr<Icon> icon() const override;
123 std::vector<Action> actions() const override;
124
125protected:
126 QString id_;
127 QString text_;
128 QString subtext_;
129 std::function<std::unique_ptr<Icon>()> icon_factory_;
130 std::vector<Action> actions_;
132};
133
134}
Result items displayed in the query results list.
Definition item.h:71
General purpose Item implementation.
Definition standarditem.h:19
void setIconFactory(std::function< std::unique_ptr< Icon >()> icon_factory)
Sets the item factory to icon_factory.
std::unique_ptr< Icon > icon() const override
Returns the item icon.
QString subtext() const override
Returns the item subtext.
QString text_
Definition standarditem.h:127
std::vector< Action > actions() const override
Returns the item actions.
void setId(QString id)
Sets the item identifier to id.
StandardItem(const StandardItem &)=delete
QString id_
Definition standarditem.h:126
std::function< std::unique_ptr< Icon >()> iconFactory()
Returns the item icon factory.
void setInputActionText(QString text)
Sets the item input action text to text.
static std::shared_ptr< StandardItem > make(T_ID &&id, T_TEXT &&text, T_SUBTEXT &&subtext, T_ICON_FACTORY &&icon_factory, T_ACTIONS &&actions=std::vector< Action >{}, T_INPUTACTION &&input_action_text=QString{}) noexcept
Constructs a shared_ptr holding a StandardItem with the contents initialized with the data passed.
Definition standarditem.h:70
std::function< std::unique_ptr< Icon >()> icon_factory_
Definition standarditem.h:129
QString subtext_
Definition standarditem.h:128
StandardItem(StandardItem &&other) noexcept=default
Constructs a StandardItem with the contents of other using move semantics.
~StandardItem()
Destructs the StandardItem.
QString inputActionText() const override
Returns the item input action text.
void setSubtext(QString text)
Sets the item subtext to text.
void setText(QString text)
Sets the item text to text.
StandardItem & operator=(StandardItem &&other) noexcept=default
Replaces the contents with those of other using move semantics.
QString id() const override
Returns the item identifier.
StandardItem(T_ID &&id, T_TEXT &&text, T_SUBTEXT &&subtext, T_ICON_FACTORY &&icon_factory, T_ACTIONS &&actions=std::vector< Action >{}, T_INPUTACTION &&input_action_text=QString{}) noexcept
Constructs a StandardItem with the contents initialized with the data passed.
Definition standarditem.h:37
StandardItem & operator=(const StandardItem &)=delete
std::vector< Action > actions_
Definition standarditem.h:130
QString input_action_text_
Definition standarditem.h:131
QString text() const override
Returns the item text.
void setActions(std::vector< Action > actions)
Sets the item actions to actions.
Definition app.h:56