LeechCraft 0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
progressmanager.cpp
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#include "progressmanager.h"
10
11namespace LC::Util
12{
13 ProgressModelRow::ProgressModelRow (ProgressManager& model, const QModelIndex& index)
14 : Manager_ { model }
15 , Index_ { index }
16 {
17 }
18
20 {
21 if (Index_.isValid ())
22 Manager_.Model_.RemoveItem (Index_.row ());
23 }
24
26 {
27 Index_ = QPersistentModelIndex {};
28 }
29
30 void ProgressModelRow::SetDone (qint64 done)
31 {
32 if (Index_.isValid ())
33 Manager_.Model_.SetField<&ProgressManager::Item::Done_> (Index_.row (), done);
34 }
35
36 void ProgressModelRow::SetTotal (qint64 total)
37 {
38 if (Index_.isValid ())
39 Manager_.Model_.SetField<&ProgressManager::Item::Total_> (Index_.row (), total);
40 }
41
43 {
44 if (Index_.isValid ())
45 {
46 const auto total = Manager_.Model_.GetItems () [Index_.row ()].Total_;
47 Manager_.Model_.SetField<&ProgressManager::Item::Total_> (Index_.row (), total + delta);
48 }
49 }
50
51 void ProgressModelRow::SetState (ProcessState state, QString customText)
52 {
53 if (Index_.isValid ())
54 Manager_.Model_.SetFields<
55 &ProgressManager::Item::State_,
56 &ProgressManager::Item::CustomStateText_
57 > (Index_.row (), state, std::move (customText));
58 }
59
60 void ProgressModelRow::SetCustomData (const QVariant& data)
61 {
62 if (Index_.isValid ())
63 Manager_.Model_.GetMutItems () [Index_.row ()].CustomData_ = data;
64 }
65
67 {
68 if (!Index_.isValid ())
69 return;
70
71 const auto done = Manager_.Model_.GetItems () [Index_.row ()].Done_;
72 Manager_.Model_.SetField<&ProgressManager::Item::Done_> (Index_.row (), done + 1);
73 }
74
76 : QObject { parent }
77 {
78 }
79
80 void ProgressManager::SetGlobalData (const QVariant& data, int role)
81 {
82 Model_.SetGlobalData (data, role);
83 }
84
85 QAbstractItemModel& ProgressManager::GetModel ()
86 {
87 return Model_;
88 }
89
91 {
92 struct Handler : IJobHolderRepresentationHandler
93 {
94 QAbstractItemModel& Model_;
95
96 explicit Handler (QAbstractItemModel& model)
97 : Model_ { model }
98 {
99 }
100
101 QAbstractItemModel& GetRepresentation () override
102 {
103 return Model_;
104 }
105 };
106
107 return std::make_unique<Handler> (Model_);
108 }
109
110 std::unique_ptr<ProgressModelRow> ProgressManager::AddRow (RowInfo info)
111 {
112 return AddRow (std::move (info), {});
113 }
114
115 std::unique_ptr<ProgressModelRow> ProgressManager::AddRow (RowInfo info, Initializers inits)
116 {
117 auto name = info.Name_;
118 const auto pos = Model_.AddItem ({
119 .RowInfo_ = std::move (info),
120 .Total_ = inits.Total_,
121 .State_ = inits.State_,
122 .CustomStateText_ = std::move (inits.CustomStateText_),
123 .Icon_ = std::move (inits.Icon_),
124
125 .CachedName_ = std::move (name),
126
127 .CustomData_ = std::move (inits.CustomData_),
128 });
129 return std::make_unique<ProgressModelRow> (*this, Model_.index (pos, 0));
130 }
131
132 QVariant ProgressManager::GetCustomData (const QModelIndex& index) const
133 {
134 return Model_.GetItems () [index.row ()].CustomData_;
135 }
136}
std::unique_ptr< ProgressModelRow > AddRow(RowInfo)
ProgressManager(QObject *parent=nullptr)
QVariant GetCustomData(const QModelIndex &) const
void SetGlobalData(const QVariant &data, int role)
IJobHolderRepresentationHandler_ptr CreateDefaultHandler()
QAbstractItemModel & GetModel()
void ChangeTotalBy(qint64 delta)
void SetCustomData(const QVariant &)
ProgressModelRow(ProgressManager &, const QModelIndex &)
void SetState(ProcessState state, QString customText={})
std::unique_ptr< IJobHolderRepresentationHandler > IJobHolderRepresentationHandler_ptr
Definition ijobholder.h:172
ProcessState
Definition ijobholder.h:72
QString Name_
Definition ijobholder.h:65