]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToc.cpp
remove dead code.
[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
40         return canOutline(type);
41 }
42
43
44 int GuiToc::getTocDepth(int type)
45 {
46         if (type < 0)
47                 return 0;
48         return toc_models_[type]->modelDepth();
49 }
50
51
52 QStandardItemModel * GuiToc::tocModel(int type)
53 {
54         if (type < 0)
55                 return 0;
56
57         if (toc_models_.empty()) {
58                 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
59                 return 0;
60         }
61
62         LYXERR(Debug::GUI)
63                 << "GuiToc: type " << type
64                 << "  toc_models_.size() " << toc_models_.size()
65                 << endl;
66
67         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
68         return toc_models_[type];
69 }
70
71
72 QModelIndex const GuiToc::getCurrentIndex(int type) const
73 {
74         if (type < 0)
75                 return QModelIndex();
76
77         // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
78         // This is because a proper ParConstIterator is not constructed in
79         // InsetCaption::addToToc()
80         if(!canOutline(type))
81                 return QModelIndex();
82
83         return toc_models_[type]->modelIndex(getCurrentTocItem(type));
84 }
85
86
87 void GuiToc::goTo(int type, QModelIndex const & index)
88 {
89         if (type < 0 || !index.isValid()
90                 || index.model() != toc_models_[type]) {
91                 LYXERR(Debug::GUI)
92                         << "GuiToc::goTo(): QModelIndex is invalid!"
93                         << endl;
94                 return;
95         }
96
97         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
98
99         TocIterator const it = toc_models_[type]->tocIterator(index);
100
101         LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
102
103         ControlToc::goTo(*it);
104 }
105
106
107 bool GuiToc::initialiseParams(std::string const & data)
108 {
109         if (!ControlToc::initialiseParams(data))
110                 return false;
111         updateView();
112         modelReset();
113         return true;
114 }
115
116
117 void GuiToc::updateView()
118 {
119         toc_models_.clear();
120         TocList::const_iterator it = tocs().begin();
121         TocList::const_iterator end = tocs().end();
122         for (; it != end; ++it)
123                 toc_models_.push_back(new TocModel(it->second));
124 }
125
126
127 } // namespace frontend
128 } // namespace lyx
129
130 #include "GuiToc_moc.cpp"