LeechCraft 0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
ijobholder.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <concepts>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <vector>
16#include <QModelIndex>
17#include <QtPlugin>
19
20class QAbstractItemModel;
21class QMenu;
22class QToolBar;
23
24template<typename>
25class QList;
26
27namespace LC
28{
29 enum class ProcessKind : std::uint8_t
30 {
34 };
35
46 {
47 TaskParameters Parameters_ {};
48
50
51 bool operator== (const ProcessInfo& other) const = default;
52 };
53
54 struct NewsInfo
55 {
56 qlonglong Count_ = 0;
57 QDateTime LastUpdate_;
58
59 bool operator== (const NewsInfo& other) const = default;
60 };
61
62 using SpecificInfo = std::variant<
65 >;
66
67 struct RowInfo
68 {
69 QString Name_;
71
72 bool operator== (const RowInfo& other) const = default;
73 };
74
75 enum class ProcessState : std::uint8_t
76 {
82 };
83
94
95 constexpr int operator+ (JobHolderRole role) noexcept
96 {
97 return static_cast<int> (role);
98 }
99
100 template<>
102
104 {
106 Total, // qint64
108 State, // ProcessState
109 StateCustomText, // QString
110 };
111
112 constexpr int operator+ (JobHolderProcessRole role) noexcept
113 {
114 return static_cast<int> (role);
115 }
116
117 template<>
119}
120
122{
123public:
125
159 virtual QAbstractItemModel& GetRepresentation () = 0;
160
164 {
166 QModelIndex Current_;
167
168 static RowSelection FromMaybe (const std::optional<QModelIndex>& row)
169 {
170 if (!row)
171 return {};
172 return FromSingle (*row);
173 }
174
175 static RowSelection FromSingle (const QModelIndex& row)
176 {
177 return { .Rows_ { row }, .Current_ { row } };
178 }
179 };
180
193 virtual void HandleSelectedRowsChanging ([[maybe_unused]] const RowSelection& selection) {}
194
205 virtual void HandleSelectedRowsSettled ([[maybe_unused]] const RowSelection& selection) {}
206
207 // Invoked synchronously from the corresponding QAbstractItemView signals.
208 virtual void HandleActivated (const QModelIndex&) {}
209 virtual void HandleClicked (const QModelIndex&) {}
210 virtual void HandleDoubleClicked (const QModelIndex&) {}
211 virtual void HandlePressed (const QModelIndex&) {}
212
213 virtual QWidget* GetInfoWidget () { return nullptr; }
214 virtual QToolBar* GetControls () { return nullptr; }
215 virtual QMenu* GetContextMenu () { return nullptr; }
216};
217
218using IJobHolderRepresentationHandler_ptr = std::unique_ptr<IJobHolderRepresentationHandler>;
219
245class Q_DECL_EXPORT IJobHolder
246{
247protected:
248 virtual ~IJobHolder () = default;
249public:
267
291 virtual std::vector<IJobHolderRepresentationHandler_ptr> CreateRepresentationHandlers (const ViewCallbacks& callbacks) = 0;
292protected:
299 template<std::derived_from<IJobHolderRepresentationHandler>... Handlers>
300 static std::vector<IJobHolderRepresentationHandler_ptr> MakeHandlers (std::unique_ptr<Handlers>... handlers)
301 {
302 std::vector<IJobHolderRepresentationHandler_ptr> result;
303 result.reserve (sizeof... (Handlers));
304 (result.push_back (std::move (handlers)), ...);
305 return result;
306 }
307};
308
311
312Q_DECLARE_INTERFACE (IJobHolder, "org.Deviant.LeechCraft.IJobHolder/1.0")
Interface for plugins holding jobs or persistent notifications.
Definition ijobholder.h:246
virtual std::vector< IJobHolderRepresentationHandler_ptr > CreateRepresentationHandlers(const ViewCallbacks &callbacks)=0
Creates the handlers representing the jobs of this plugin.
virtual ~IJobHolder()=default
static std::vector< IJobHolderRepresentationHandler_ptr > MakeHandlers(std::unique_ptr< Handlers >... handlers)
Wraps the given handlers into the list to be returned from CreateRepresentationHandlers().
Definition ijobholder.h:300
virtual void HandleActivated(const QModelIndex &)
Definition ijobholder.h:208
virtual ~IJobHolderRepresentationHandler()=default
virtual void HandleSelectedRowsChanging(const RowSelection &selection)
Called from a clean stack whenever the selection or the current row changes.
Definition ijobholder.h:193
virtual void HandleSelectedRowsSettled(const RowSelection &selection)
Called from a clean stack once the selection has settled.
Definition ijobholder.h:205
virtual QMenu * GetContextMenu()
Definition ijobholder.h:215
virtual QAbstractItemModel & GetRepresentation()=0
Returns the item representation model.
virtual QToolBar * GetControls()
Definition ijobholder.h:214
virtual void HandleClicked(const QModelIndex &)
Definition ijobholder.h:209
virtual QWidget * GetInfoWidget()
Definition ijobholder.h:213
virtual void HandleDoubleClicked(const QModelIndex &)
Definition ijobholder.h:210
virtual void HandlePressed(const QModelIndex &)
Definition ijobholder.h:211
std::unique_ptr< IJobHolderRepresentationHandler > IJobHolderRepresentationHandler_ptr
Definition ijobholder.h:218
Definition constants.h:15
constexpr int operator+(JobHolderRole role) noexcept
Definition ijobholder.h:95
constexpr int MaxValue
Definition maxvalue.h:14
ProcessState
Definition ijobholder.h:76
JobHolderProcessRole
Definition ijobholder.h:104
JobHolderRole
This enum contains roles that are used to query job states.
Definition ijobholder.h:87
std::variant< ProcessInfo, NewsInfo > SpecificInfo
Definition ijobholder.h:62
ProcessKind
Definition ijobholder.h:30
The callbacks into the view showing the handlers' representations.
Definition ijobholder.h:253
std::function< void(IJobHolderRepresentationHandler::RowSelection)> SetSelection_
Selects the given rows of the handler's representation.
Definition ijobholder.h:265
The rows of this handler's representation selected in the view.
Definition ijobholder.h:164
static RowSelection FromSingle(const QModelIndex &row)
Definition ijobholder.h:175
QModelIndex Current_
One of Rows_ (at the 0'th column), or invalid.
Definition ijobholder.h:166
static RowSelection FromMaybe(const std::optional< QModelIndex > &row)
Definition ijobholder.h:168
QList< QModelIndex > Rows_
The selected rows, at the 0'th column, in the view's order.
Definition ijobholder.h:165
qlonglong Count_
Definition ijobholder.h:56
bool operator==(const NewsInfo &other) const =default
QDateTime LastUpdate_
Definition ijobholder.h:57
Describes a process represented by a row in an IJobHolder model.
Definition ijobholder.h:46
bool operator==(const ProcessInfo &other) const =default
TaskParameters Parameters_
Definition ijobholder.h:47
ProcessKind Kind_
Definition ijobholder.h:49
SpecificInfo Specific_
Definition ijobholder.h:70
bool operator==(const RowInfo &other) const =default
QString Name_
Definition ijobholder.h:69
Q_DECLARE_METATYPE(QVariantList *)