]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToc.cpp
remove recursive call
[lyx.git] / src / frontends / qt4 / GuiToc.cpp
1 /**
2  * \file GuiToc.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiToc.h"
15
16 #include "TocModel.h"
17 #include "qt_helpers.h"
18
19 #include "debug.h"
20
21 #include <algorithm>
22
23 using std::endl;
24
25 namespace lyx {
26 namespace frontend {
27
28
29 GuiToc::GuiToc(Dialog & dialog)
30         : ControlToc(dialog)
31 {
32 }
33
34
35 bool GuiToc::canOutline(int type) const
36 {
37         if (type < 0)
38                 return false;
39         return ControlToc::canOutline(type);
40 }
41
42
43 int GuiToc::getTocDepth(int type)
44 {
45         if (type < 0)
46                 return 0;
47         return toc_models_[type]->modelDepth();
48 }
49
50
51 QStandardItemModel * GuiToc::tocModel(int type)
52 {
53         if (type < 0)
54                 return 0;
55
56         if (toc_models_.empty()) {
57                 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
58                 return 0;
59         }
60
61         LYXERR(Debug::GUI)
62                 << "GuiToc: type " << type
63                 << "  toc_models_.size() " << toc_models_.size()
64                 << endl;
65
66         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
67         return toc_models_[type];
68 }
69
70
71 QModelIndex const GuiToc::getCurrentIndex(int type) const
72 {
73         if (type < 0)
74                 return QModelIndex();
75
76         // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
77         // This is because a proper ParConstIterator is not constructed in
78         // InsetCaption::addToToc()
79         if(!canOutline(type))
80                 return QModelIndex();
81
82         return toc_models_[type]->modelIndex(getCurrentTocItem(type));
83 }
84
85
86 void GuiToc::goTo(int type, QModelIndex const & index)
87 {
88         if (type < 0 || !index.isValid()
89                 || index.model() != toc_models_[type]) {
90                 LYXERR(Debug::GUI)
91                         << "GuiToc::goTo(): QModelIndex is invalid!"
92                         << endl;
93                 return;
94         }
95
96         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
97
98         TocIterator const it = toc_models_[type]->tocIterator(index);
99
100         LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
101
102         ControlToc::goTo(*it);
103 }
104
105
106 bool GuiToc::initialiseParams(std::string const & data)
107 {
108         if (!ControlToc::initialiseParams(data))
109                 return false;
110         updateView();
111         modelReset();
112         return true;
113 }
114
115
116 void GuiToc::updateView()
117 {
118         toc_models_.clear();
119         TocList::const_iterator it = tocs().begin();
120         TocList::const_iterator end = tocs().end();
121         for (; it != end; ++it)
122                 toc_models_.push_back(new TocModel(it->second));
123 }
124
125
126 } // namespace frontend
127 } // namespace lyx
128
129 #include "GuiToc_moc.cpp"