Merge remote-tracking branch 'origin/Applications/16.08'
[kdepim.git] / akregator / src / treenode.cpp
blobc4ee9bea5d69eb4acf46e89e9409999e43ee13d0
1 /*
2 This file is part of Akregator.
4 Copyright (C) 2004 Frank Osterfeld <osterfeld@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
25 #include "treenode.h"
26 #include "folder.h"
27 #include "articlejobs.h"
28 #include "article.h"
30 #include <QPoint>
31 #include <QString>
32 #include <QList>
34 #include "akregator_debug.h"
36 #include <cassert>
38 namespace Akregator
41 class TreeNode::TreeNodePrivate
43 public:
44 TreeNodePrivate();
45 bool doNotify;
46 bool nodeChangeOccurred;
47 bool articleChangeOccurred;
48 QString title;
49 Folder *parent;
50 uint id;
51 bool signalDestroyedEmitted;
52 QPoint scrollBarPositions;
55 TreeNode::TreeNodePrivate::TreeNodePrivate() : doNotify(true),
56 nodeChangeOccurred(false),
57 articleChangeOccurred(false),
58 title(),
59 parent(0),
60 id(0),
61 signalDestroyedEmitted(false)
65 TreeNode::TreeNode()
66 : QObject(0), d(new TreeNodePrivate)
70 void TreeNode::emitSignalDestroyed()
72 if (!d->signalDestroyedEmitted) {
73 if (parent()) {
74 parent()->removeChild(this);
76 Q_EMIT signalDestroyed(this);
77 d->signalDestroyedEmitted = true;
81 TreeNode::~TreeNode()
83 Q_ASSERT(d->signalDestroyedEmitted || !"TreeNode subclasses must call emitSignalDestroyed in their destructor");
84 delete d;
85 d = 0;
88 QString TreeNode::title() const
90 return d->title;
93 void TreeNode::setTitle(const QString &title)
96 if (d->title != title) {
97 d->title = title;
98 nodeModified();
102 TreeNode *TreeNode::nextSibling()
104 if (!d->parent) {
105 return 0;
107 const QList<TreeNode *> children = parent()->children();
108 const int idx = children.indexOf(this);
110 return (idx + 1 < children.size()) ? children.at(idx + 1) : Q_NULLPTR;
113 const TreeNode *TreeNode::nextSibling() const
115 if (!d->parent) {
116 return 0;
118 const QList<const TreeNode *> children = parent()->children();
119 const int idx = children.indexOf(this);
121 return (idx + 1 < children.size()) ? children.at(idx + 1) : Q_NULLPTR;
124 TreeNode *TreeNode::prevSibling()
126 if (!d->parent) {
127 return 0;
129 const QList<TreeNode *> children = parent()->children();
131 const int idx = children.indexOf(this);
132 return (idx > 0) ? children.at(idx - 1) : Q_NULLPTR;
135 const TreeNode *TreeNode::prevSibling() const
137 if (!d->parent) {
138 return 0;
140 const QList<const TreeNode *> children = parent()->children();
141 const int idx = children.indexOf(this);
142 return (idx > 0) ? children.at(idx - 1) : Q_NULLPTR;
145 const Folder *TreeNode::parent() const
147 return d->parent;
150 Folder *TreeNode::parent()
152 return d->parent;
155 QList<const TreeNode *> TreeNode::children() const
157 return QList<const TreeNode *>();
160 QList<TreeNode *> TreeNode::children()
162 return QList<TreeNode *>();
165 const TreeNode *TreeNode::childAt(int pos) const
167 Q_UNUSED(pos)
168 return 0;
171 TreeNode *TreeNode::childAt(int pos)
173 Q_UNUSED(pos)
174 return 0;
177 void TreeNode::setParent(Folder *parent)
179 d->parent = parent;
182 void TreeNode::setNotificationMode(bool doNotify)
184 if (doNotify && !d->doNotify) { // turned on
185 d->doNotify = true;
186 if (d->nodeChangeOccurred) {
187 Q_EMIT signalChanged(this);
189 if (d->articleChangeOccurred) {
190 doArticleNotification();
192 d->nodeChangeOccurred = false;
193 d->articleChangeOccurred = false;
194 } else if (!doNotify && d->doNotify) { //turned off
195 d->nodeChangeOccurred = false;
196 d->articleChangeOccurred = false;
197 d->doNotify = false;
201 uint TreeNode::id() const
203 return d->id;
206 void TreeNode::setId(uint id)
208 d->id = id;
211 void TreeNode::nodeModified()
213 if (d->doNotify) {
214 Q_EMIT signalChanged(this);
215 } else {
216 d->nodeChangeOccurred = true;
220 void TreeNode::articlesModified()
222 if (d->doNotify) {
223 doArticleNotification();
224 } else {
225 d->articleChangeOccurred = true;
229 void TreeNode::doArticleNotification()
233 QPoint TreeNode::listViewScrollBarPositions() const
235 return d->scrollBarPositions;
238 void TreeNode::setListViewScrollBarPositions(const QPoint &pos)
240 d->scrollBarPositions = pos;
243 ArticleListJob *TreeNode::createListJob()
245 return new ArticleListJob(this);
248 } // namespace Akregator