Albert
Loading...
Searching...
No Matches
standarditem.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024-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::util
11{
12
14
15class ALBERT_EXPORT StandardItem : public Item
16{
17public:
18
20 template<typename T_ID = QString,
21 typename T_TEXT = QString,
22 typename T_SUBTEXT = QString,
23 typename T_ICON_FACTORY = std::function<std::unique_ptr<Icon>()>,
24 typename T_ACTIONS = std::vector<Action>,
25 typename T_INPUTACTION = QString>
26 requires(std::same_as<std::remove_cvref_t<T_ID>, QString>
27 && std::same_as<std::remove_cvref_t<T_TEXT>, QString>
28 && std::same_as<std::remove_cvref_t<T_SUBTEXT>, QString>
29 && std::convertible_to<std::remove_cvref_t<T_ICON_FACTORY>, std::function<std::unique_ptr<Icon>()>>
30 && std::same_as<std::remove_cvref_t<T_ACTIONS>, std::vector<Action>>
31 && std::same_as<std::remove_cvref_t<T_INPUTACTION>, QString>)
32 StandardItem(T_ID &&id,
33 T_TEXT &&text,
34 T_SUBTEXT &&subtext,
35 T_ICON_FACTORY &&icon_factory,
36 T_ACTIONS &&actions = std::vector<Action>{},
37 T_INPUTACTION &&input_action_text = QString{}) noexcept :
38 id_(std::forward<T_ID>(id)),
39 text_(std::forward<T_TEXT>(text)),
40 subtext_(std::forward<T_SUBTEXT>(subtext)),
41 icon_factory_(std::forward<T_ICON_FACTORY>(icon_factory)),
42 actions_(std::forward<T_ACTIONS>(actions)),
43 input_action_text_(std::forward<T_INPUTACTION>(input_action_text))
44 {}
45
46
51
52 template<typename T_ID = QString,
53 typename T_TEXT = QString,
54 typename T_SUBTEXT = QString,
55 typename T_ICON_FACTORY = std::function<std::unique_ptr<Icon>()>,
56 typename T_ACTIONS = std::vector<Action>,
57 typename T_INPUTACTION = QString>
58 requires(std::same_as<std::decay_t<T_ID>, QString>
59 && std::same_as<std::decay_t<T_TEXT>, QString>
60 && std::same_as<std::decay_t<T_SUBTEXT>, QString>
61 && std::convertible_to<std::decay_t<T_ICON_FACTORY>, std::function<std::unique_ptr<Icon>()>>
62 && std::same_as<std::decay_t<T_ACTIONS>, std::vector<Action>>
63 && std::same_as<std::decay_t<T_INPUTACTION>, QString>)
64 static std::shared_ptr<StandardItem> make(T_ID &&id,
65 T_TEXT &&text,
66 T_SUBTEXT &&subtext,
67 T_ICON_FACTORY &&icon_factory,
68 T_ACTIONS &&actions = std::vector<Action>{},
69 T_INPUTACTION &&input_action_text = QString{}) noexcept
70 {
71 return std::make_shared<StandardItem>(std::forward<T_ID>(id),
72 std::forward<T_TEXT>(text),
73 std::forward<T_SUBTEXT>(subtext),
74 std::forward<T_ICON_FACTORY>(icon_factory),
75 std::forward<T_ACTIONS>(actions),
76 std::forward<T_INPUTACTION>(input_action_text));
77 }
78
79 StandardItem(const StandardItem &) = delete;
81
83 StandardItem(StandardItem &&other) noexcept = default;
84
86 StandardItem &operator=(StandardItem &&other) noexcept = default;
87
90
92 void setId(QString id);
93
95 void setText(QString text);
96
98 void setSubtext(QString text);
99
101 void setIconFactory(std::function<std::unique_ptr<Icon>()> icon_factory);
102
104 std::function<std::unique_ptr<Icon>()> iconFactory();
105
107 void setActions(std::vector<Action> actions);
108
110 void setInputActionText(QString text);
111
112 QString id() const override;
113 QString text() const override;
114 QString subtext() const override;
115 QString inputActionText() const override;
116 std::unique_ptr<Icon> icon() const override;
117 std::vector<Action> actions() const override;
118
119protected:
120 QString id_;
121 QString text_;
122 QString subtext_;
123 std::function<std::unique_ptr<Icon>()> icon_factory_;
124 std::vector<Action> actions_;
126};
127
128}
Result items displayed in the query results list.
Definition item.h:55
General purpose Item implementation.
Definition standarditem.h:16
void setActions(std::vector< Action > actions)
Sets the item actions to actions.
void setIconFactory(std::function< std::unique_ptr< Icon >()> icon_factory)
Sets the item factory to icon_factory.
QString subtext() const override
Returns the item subtext.
QString id() const override
Returns the item identifier.
void setId(QString id)
Sets the item identifier to id.
QString text() const override
Returns the item text.
std::function< std::unique_ptr< Icon >()> iconFactory()
Returns the item icon factory.
std::vector< Action > actions_
Definition standarditem.h:124
StandardItem & operator=(const StandardItem &)=delete
QString subtext_
Definition standarditem.h:122
std::function< std::unique_ptr< Icon >()> icon_factory_
Definition standarditem.h:123
StandardItem(StandardItem &&other) noexcept=default
Constructs a StandardItem with the contents of other using move semantics.
QString text_
Definition standarditem.h:121
std::vector< Action > actions() const override
Returns item actions.
QString id_
Definition standarditem.h:120
~StandardItem()
Destructs the StandardItem.
QString inputActionText() const override
Returns the input action text.
void setText(QString text)
Sets the item text to text.
void setInputActionText(QString text)
Sets the item input action text to text.
void setSubtext(QString text)
Sets the item subtext to text.
StandardItem & operator=(StandardItem &&other) noexcept=default
Replaces the contents with those of other using move semantics.
StandardItem(const StandardItem &)=delete
QString input_action_text_
Definition standarditem.h:125
std::unique_ptr< Icon > icon() const override
Returns the item icon.
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:64
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:32
Albert utility namespace.
Definition albert.h:14
Albert core interface namespace.
Definition albert.h:14