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