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