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