]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiToc.cpp
8715d1bcad5538c06224ea733769f035d61e3cf9
[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(LyXView & lv)
36         : GuiDialog(lv, "toc")
37 {
38         setViewTitle(_("Outline"));
39         setController(new ControlToc(*this));
40 #ifdef Q_WS_MACX
41                 // On Mac show as a drawer at the right
42         //setView(new DockView<GuiToc, TocWidget>(
43         //              *dialog, qtoc, &gui_view, _("Outline"), Qt::RightDockWidgetArea, Qt::Drawer));
44 #else
45         //setView(new DockView<GuiToc, TocWidget>(
46 //                      *dialog, qtoc, &gui_view, _("Outline")));
47 #endif
48         bc().setPolicy(ButtonPolicy::OkCancelPolicy);
49 }
50
51
52 ControlToc & GuiToc::controller() const
53 {
54         return static_cast<ControlToc &>(Dialog::controller());
55 }
56
57
58 bool GuiToc::canOutline(int type) const
59 {
60         if (type < 0)
61                 return false;
62
63         return controller().canOutline(type);
64 }
65
66
67 int GuiToc::getTocDepth(int type)
68 {
69         if (type < 0)
70                 return 0;
71         return toc_models_[type]->modelDepth();
72 }
73
74
75 QStandardItemModel * GuiToc::tocModel(int type)
76 {
77         if (type < 0)
78                 return 0;
79
80         if (toc_models_.empty()) {
81                 LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
82                 return 0;
83         }
84
85         LYXERR(Debug::GUI)
86                 << "GuiToc: type " << type
87                 << "  toc_models_.size() " << toc_models_.size()
88                 << endl;
89
90         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
91         return toc_models_[type];
92 }
93
94
95 QModelIndex const GuiToc::getCurrentIndex(int type) const
96 {
97         if (type < 0)
98                 return QModelIndex();
99
100         // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
101         // This is because a proper ParConstIterator is not constructed in
102         // InsetCaption::addToToc()
103         if(!canOutline(type))
104                 return QModelIndex();
105
106         return toc_models_[type]->modelIndex(controller().getCurrentTocItem(type));
107 }
108
109
110 void GuiToc::goTo(int type, QModelIndex const & index)
111 {
112         if (type < 0 || !index.isValid()
113                 || index.model() != toc_models_[type]) {
114                 LYXERR(Debug::GUI)
115                         << "GuiToc::goTo(): QModelIndex is invalid!"
116                         << endl;
117                 return;
118         }
119
120         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
121
122         TocIterator const it = toc_models_[type]->tocIterator(index);
123
124         LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
125
126         controller().goTo(*it);
127 }
128
129
130 bool GuiToc::initialiseParams(std::string const & data)
131 {
132         if (!controller().initialiseParams(data))
133                 return false;
134         updateView();
135         modelReset();
136         return true;
137 }
138
139
140 void GuiToc::updateView()
141 {
142         toc_models_.clear();
143         TocList::const_iterator it = controller().tocs().begin();
144         TocList::const_iterator end = controller().tocs().end();
145         for (; it != end; ++it)
146                 toc_models_.push_back(new TocModel(it->second));
147 }
148
149
150 } // namespace frontend
151 } // namespace lyx
152
153 #include "GuiToc_moc.cpp"