BibleTime
bthistory.cpp
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
13#include "bthistory.h"
14
15#include <QAction>
16#include <QVariant>
17#include "../../backend/keys/cswordkey.h"
18#include "../../util/btassert.h"
19
20
21namespace {
22char const ActionText[] = "BtHistory key";
23}
24
26 : QObject(parent)
28
30 BT_ASSERT(newKey);
31 // Add new key Action after current index if we were not using the history functions,
32 // if it's not a duplicate and if it's not empty.
33 if (!m_inHistoryFunction && ((m_index < 0) || (newKey->key() != m_historyList.at(m_index)->property(ActionText).toString()) )) {
34 if (!newKey->key().isEmpty()) {
35 auto * const a = new QAction(newKey->key(), this);
36 a->setProperty(ActionText, newKey->key());
37 m_historyList.insert(++m_index, a);
38 }
39 // \todo history limit?
41 }
43}
44
45void BTHistory::move(QAction* historyItem) {
46 //BT_ASSERT(historyItem);
47 BT_ASSERT(m_historyList.count());
48
50 //find the action in the list
51 m_index = m_historyList.indexOf(historyItem);
52 //move to the selected item in the list, it will be the current item
53 Q_EMIT historyMoved(m_historyList.at(m_index)->property(ActionText).toString()); // signal to "outsiders"; key has been changed
55
56 m_inHistoryFunction = false;
58}
59
61 if ( m_index >= 1) {
62 move(m_historyList.at(m_index - 1));
63 }
65}
66
68 if (m_index < (m_historyList.size() - 1)) {
69 move(m_historyList.at(m_index + 1));
70 }
72}
73
74QList<QAction*> BTHistory::getBackList() {
75
76 QList<QAction*> list;
77 for (int i = m_index - 1; i >= 0; --i) {
78 list.append(m_historyList.at(i));
79 }
80
82 return list;
83}
84
85QList<QAction*> BTHistory::getFwList() {
86 QList<QAction*> list;
87 for (int i = m_index + 1; i < m_historyList.size(); ++i) {
88 list.append(m_historyList.at(i));
89 }
90
92 return list;
93}
94
96 bool backEnabled = m_index > 0; //there are items in the back list
97 bool fwEnabled = m_historyList.size() > m_index + 1; //there are items in the fw list
98 Q_EMIT historyChanged(backEnabled, fwEnabled);
100}
101
103 for (int i = 0; i < m_historyList.size(); ++i) {
104 if (!m_historyList.at(i) || m_historyList.at(i)->property(ActionText).toString().isEmpty()) return false;
105 }
106 if (!(m_index >= -1 && m_index < m_historyList.size())) return false;
107 return true;
108}
#define BT_ASSERT(...)
Definition btassert.h:17
QList< QAction * > m_historyList
Definition bthistory.h:72
void move(QAction *)
Definition bthistory.cpp:45
BTHistory(QObject *parent)
Definition bthistory.cpp:25
void historyMoved(QString newKey)
void fw()
Definition bthistory.cpp:67
QList< QAction * > getFwList()
Definition bthistory.cpp:85
bool class_invariant()
void sendChangedSignal()
Definition bthistory.cpp:95
QList< QAction * > getBackList()
Definition bthistory.cpp:74
void back()
Definition bthistory.cpp:60
bool m_inHistoryFunction
Definition bthistory.h:74
void add(CSwordKey *newKey)
Definition bthistory.cpp:29
void historyChanged(bool backEnabled, bool fwEnabled)
int m_index
Definition bthistory.h:73
virtual QString key() const =0