-
Notifications
You must be signed in to change notification settings - Fork 6
/
history.cpp
76 lines (65 loc) · 1.32 KB
/
history.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* \file
* <!--
* Copyright 2015 Develer S.r.l. (http://www.develer.com/)
* -->
*
* \brief History class implementation
*
* \author Aurelien Rainone <aurelien@develer.com>
*/
#include "history.h"
History::History(QObject *parent)
: QObject(parent),
max_entries(10)
{
_current = -1;
}
void History::add(const QString &entry)
{
// remove eventual duplicate of new entry
int dup = history.indexOf(entry);
if (dup >= 0)
history.removeAt(dup);
history.append(entry);
// remove extra elements
if (history.size() > max_entries)
history.pop_front();
_current = -1;
}
const QString History::previous()
{
QString prev("");
if (history.size() > 0)
{
if (_current == -1)
_current = history.size() - 1;
else if (_current > 0)
--_current;
prev = history[_current];
}
return prev;
}
const QString History::next()
{
QString nex("");
if (history.size() > 0 && _current != -1)
{
if (_current < history.size() - 1)
++_current;
nex = history[_current];
}
return nex;
}
const QStringList& History::getHistory() const
{
return history;
}
void History::setCurrent(int current_index)
{
_current = current_index;
}
int History::current() const
{
return _current;
}