Messagelib

model.h
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 *
7 *******************************************************************************/
8
9#pragma once
10
11#include <QAbstractItemModel>
12#include <QHash>
13#include <QList>
14#include <QMultiHash>
15
16#include "core/enums.h"
17
18#include <ctime> // time_t
19#include <memory>
20
21namespace MessageList
22{
23namespace Core
24{
25using MessageItemSetReference = long;
26
27class Filter;
28class GroupHeaderItem;
29class Item;
30class MessageItem;
31class Theme;
32class StorageModel;
33class View;
34class ModelPrivate;
35class SortOrder;
36class Aggregation;
37
38/**
39 * This class manages the huge tree of displayable objects: GroupHeaderItems and MessageItems.
40 * The tree is exposed via a 'hacked' QAbstractItemModel interface to a QTreeView
41 * subclass (which is MessageList::View).
42 *
43 * The keypoint in this class is that it has to be non-blocking in manipulating the tree:
44 * fill, cleanup and update operations are performed in timed chunks. Perfect non-blocking
45 * behaviour is not possible since there are some small operations that basically can't be
46 * split in chunks. However, these exceptions apply to a minority of tasks and in the
47 * average case the user will not notice.
48 *
49 * The data for building the tree is obtained from a subclass of StorageModel. The
50 * StorageModel must offer a consistent rappresentation of a "flat" folder containing
51 * messages.
52 */
54{
55 friend class Item;
56 friend class ItemPrivate;
57
59public:
60 /**
61 * Creates the mighty Model attached to the specified View.
62 */
63 explicit Model(View *pParent);
64
65 /**
66 * Destroys the mighty model along with the tree of items it manages.
67 */
68 ~Model() override;
69
70 /**
71 * Returns the StorageModel currently set.
72 */
74
75 /**
76 * Sets the storage model from that the messages to be displayed should be fetched.
77 * The model is then reset and a new fill operation is started. The fill operation may
78 * or may not complete before setStorageModel() returns. This depends on the fill
79 * strategy and the size of the folder. You can check if the fill operation has
80 * completed by looking at the return value of isLoading().
81 *
82 * Pre-selection is the action of automatically selecting a message just after the folder
83 * has finished loading. We may want to select the message that was selected the last
84 * time this folder has been open, or we may want to select the first unread message.
85 * We also may want to do no pre-selection at all (for example, when the user
86 * starts navigating the view before the pre-selection could actually be made
87 * and pre-selecting would confuse him). The pre-selection is applied once
88 * loading is complete.
89 */
91
92 /**
93 * Sets the pre-selection mode.
94 *
95 * Called with PreSelectNone to abort any pending message pre-selection. This may be done if the user
96 * starts navigating the view and selecting items before we actually could
97 * apply the pre-selection.
98 */
100
101 /**
102 * Returns the hidden root item that all the messages are (or will be) attached to.
103 * The returned value is never 0.
104 */
105 Item *rootItem() const;
106
107 /**
108 * Returns true if the view is currently loading, that is
109 * it's in the first (possibly lengthy) job batch after attaching to a StorageModel.
110 */
111 [[nodiscard]] bool isLoading() const;
112
113 /**
114 * Returns the message item that is at the _current_ storage row index
115 * or zero if no such storage item is found. Please note that this may return 0
116 * also if the specified storage row hasn't been actually read yet. This may happen
117 * if isLoading() returns true. In this case the only thing you can do is to retry in a while.
118 */
119 MessageItem *messageItemByStorageRow(int row) const;
120
121 /**
122 * Sets the Aggregation mode.
123 * Does not reload the model in any way: you need to call setStorageModel( storageModel() ) for this to happen.
124 * The pointer ownership remains of the caller which must ensure its validity until the next
125 * call to setAggretation() or until this Model dies. The caller, in fact, is Widget which
126 * takes care of meeting the above conditions. The aggregation pointer must not be null.
127 */
128 void setAggregation(const Aggregation *aggregation);
129
130 /**
131 * Sets the Theme.
132 * Does not reload the model in any way: you need to call setStorageModel( storageModel() ) for this to happen.
133 * The pointer ownership remains of the caller which must ensure its validity until the next
134 * call to setTheme() or until this Model dies. The caller, in fact, is Widget which
135 * takes care of meeting the above conditions. The theme pointer must not be null.
136 */
137 void setTheme(const Theme *theme);
138
139 /**
140 * Sets the sort order. As with setTheme() and setAggregation(), this does not reload the
141 * model in any way.
142 */
143 void setSortOrder(const SortOrder *sortOrder);
144
145 /**
146 * Returns the sort order
147 */
148 const SortOrder *sortOrder() const;
149
150 /**
151 * Sets the Filter to be applied on messages. filter may be null (no filter is applied).
152 * The pointer ownership remains of the caller which must ensure its validity until the next
153 * call to setFilter() or until this Model dies. The caller, in fact, is Widget which
154 * takes care of meeting the above conditions. The Filter pointer may be null.
155 */
156 void setFilter(const Filter *filter);
157
158 /**
159 * Creates a persistent set for the specified MessageItems and
160 * returns its reference. Later you can use this reference
161 * to retrieve the list of MessageItems that are still valid.
162 * See persistentSetActualMessageList() for that.
163 *
164 * Persistent sets consume resources (both memory and CPU time
165 * while manipulating the view) so be sure to call deletePersistentSet()
166 * when you no longer need it.
167 */
168 [[nodiscard]] MessageItemSetReference createPersistentSet(const QList<MessageItem *> &items);
169
170 /**
171 * Returns the list of MessageItems that are still existing in the
172 * set pointed by the specified reference. This list will contain
173 * at most the messages that you have passed to createPersistentSet()
174 * but may contain less (even 0) if these MessageItem object were removed
175 * from the view for some reason.
176 */
178
179 /**
180 * Deletes the persistent set pointed by the specified reference.
181 * If the set does not exist anymore, nothing happens.
182 */
183 void deletePersistentSet(MessageItemSetReference ref);
184
185 // Mandatory QAbstractItemModel interface.
186
187 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
188 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
189 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
190 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
191 QModelIndex index(Item *item, int column) const;
192 QModelIndex parent(const QModelIndex &index) const override;
193 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
194 Qt::ItemFlags flags(const QModelIndex &index) const override;
195
196 /// Called when user initiates a drag from the messagelist
197 QMimeData *mimeData(const QModelIndexList &indexes) const override;
198
200 /**
201 * Notify the outside when updating the status bar with a message
202 * could be useful
203 */
204 void statusMessage(const QString &message);
205
206private:
207 friend class ModelPrivate;
208 std::unique_ptr<ModelPrivate> const d;
209};
210} // namespace Core
211} // namespace MessageList
A set of aggregation options that can be applied to the MessageList::Model in a single shot.
Definition aggregation.h:29
This class is responsible of matching messages that should be displayed in the View.
Definition filter.h:33
A single item of the MessageList tree managed by MessageList::Model.
Definition item.h:36
The MessageItem class.
Definition messageitem.h:35
This class manages the huge tree of displayable objects: GroupHeaderItems and MessageItems.
Definition model.h:54
void statusMessage(const QString &message)
Notify the outside when updating the status bar with a message could be useful.
void setTheme(const Theme *theme)
Sets the Theme.
Definition model.cpp:374
QMimeData * mimeData(const QModelIndexList &indexes) const override
Called when user initiates a drag from the messagelist.
Definition model.cpp:4507
void setStorageModel(StorageModel *storageModel, PreSelectionMode preSelectionMode=PreSelectLastSelected)
Sets the storage model from that the messages to be displayed should be fetched.
Definition model.cpp:740
MessageItem * messageItemByStorageRow(int row) const
Returns the message item that is at the current storage row index or zero if no such storage item is ...
Definition model.cpp:4531
QList< MessageItem * > persistentSetCurrentMessageItemList(MessageItemSetReference ref)
Returns the list of MessageItems that are still existing in the set pointed by the specified referenc...
Definition model.cpp:4558
StorageModel * storageModel() const
Returns the StorageModel currently set.
Definition model.cpp:690
MessageItemSetReference createPersistentSet(const QList< MessageItem * > &items)
Creates a persistent set for the specified MessageItems and returns its reference.
Definition model.cpp:4544
Item * rootItem() const
Returns the hidden root item that all the messages are (or will be) attached to.
Definition model.cpp:4521
void setAggregation(const Aggregation *aggregation)
Sets the Aggregation mode.
Definition model.cpp:368
void setPreSelectionMode(PreSelectionMode preSelect)
Sets the pre-selection mode.
Definition model.cpp:1001
~Model() override
Destroys the mighty model along with the tree of items it manages.
Definition model.cpp:350
void setSortOrder(const SortOrder *sortOrder)
Sets the sort order.
Definition model.cpp:379
Model(View *pParent)
Creates the mighty Model attached to the specified View.
Definition model.cpp:304
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition model.cpp:485
const SortOrder * sortOrder() const
Returns the sort order.
Definition model.cpp:384
bool isLoading() const
Returns true if the view is currently loading, that is it's in the first (possibly lengthy) job batch...
Definition model.cpp:4526
void setFilter(const Filter *filter)
Sets the Filter to be applied on messages.
Definition model.cpp:389
void deletePersistentSet(MessageItemSetReference ref)
Deletes the persistent set pointed by the specified reference.
Definition model.cpp:4566
A class which holds information about sorting, e.g.
Definition sortorder.h:23
The QAbstractItemModel based interface that you need to provide for your storage to work with Message...
The Theme class defines the visual appearance of the MessageList.
Definition theme.h:48
The MessageList::View is the real display of the message list.
Definition view.h:47
PreSelectionMode
Pre-selection is the action of automatically selecting a message just after the folder has finished l...
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
T qobject_cast(QObject *object)
DisplayRole
typedef ItemFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.