Falkon Develop
Cross-platform Qt-based web browser
historyitem.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "historyitem.h"
19#include "qztools.h"
20
22 : canFetchMore(false)
23 , m_parent(parent)
24 , m_startTimestamp(0)
25 , m_endTimestamp(0)
26{
27 if (m_parent) {
28 m_parent->appendChild(this);
29 }
30}
31
33{
34 if (m_parent) {
35 m_parent->removeChild(this);
36 }
37
38 m_parent = parent;
39
40 if (m_parent) {
41 m_parent->prependChild(this);
42 }
43}
44
46{
47 return m_parent;
48}
49
51{
52 if (m_children.contains(child)) {
53 m_children.removeAll(child);
54 }
55
56 child->m_parent = this;
57 m_children.prepend(child);
58}
59
61{
62 if (m_children.contains(child)) {
63 m_children.removeAll(child);
64 }
65
66 child->m_parent = this;
67 m_children.append(child);
68}
69
71{
72 if (m_children.contains(child)) {
73 m_children.removeAll(child);
74 }
75
76 if (m_children.count() >= row) {
77 child->m_parent = this;
78 m_children.insert(row, child);
79 }
80}
81
83{
84 if (QzTools::containsIndex(m_children, row)) {
85 removeChild(m_children.at(row));
86 }
87}
88
90{
91 m_children.removeOne(child);
92}
93
95{
96 if (QzTools::containsIndex(m_children, row)) {
97 return m_children.at(row);
98 }
99
100 return nullptr;
101}
102
104{
105 return m_children.count();
106}
107
109{
110 return m_parent ? m_parent->indexOfChild(this) : 0;
111}
112
114{
115 return m_children.indexOf(child);
116}
117
119{
120 return (m_startTimestamp != 0);
121}
122
123QIcon HistoryItem::icon() const
124{
125 return m_icon;
126}
127
128void HistoryItem::setIcon(const QIcon &icon)
129{
130 m_icon = icon;
131}
132
134{
135 m_startTimestamp = start;
136}
137
139{
140 if (m_startTimestamp == -1) {
141 return QDateTime::currentDateTime().toMSecsSinceEpoch();
142 }
143
144 return m_startTimestamp;
145}
146
148{
149 m_endTimestamp = end;
150
151}
152
154{
155 return m_endTimestamp;
156}
157
159{
160 if (m_parent) {
161 m_parent->removeChild(this);
162 }
163
164 qDeleteAll(m_children);
165}
void removeChild(int row)
Definition: historyitem.cpp:82
void setIcon(const QIcon &icon)
HistoryItem * parent() const
Definition: historyitem.cpp:45
qint64 startTimestamp() const
qint64 endTimestamp() const
void setStartTimestamp(qint64 start)
HistoryItem * child(int row) const
Definition: historyitem.cpp:94
int indexOfChild(HistoryItem *child)
QIcon icon() const
void changeParent(HistoryItem *parent)
Definition: historyitem.cpp:32
void setEndTimestamp(qint64 end)
void prependChild(HistoryItem *child)
Definition: historyitem.cpp:50
void appendChild(HistoryItem *child)
Definition: historyitem.cpp:60
HistoryItem(HistoryItem *parent=nullptr)
Definition: historyitem.cpp:21
bool isTopLevel() const
void insertChild(int row, HistoryItem *child)
Definition: historyitem.cpp:70
int childCount() const
static bool containsIndex(const T &container, int index)
Definition: qztools.h:95