]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QToc.cpp
InsetListings: touch up the include dialog
[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         return toc_models_[type]->modelIndex(getCurrentTocItem(type));
85 }
86
87
88 void QToc::goTo(int type, QModelIndex const & index)
89 {
90         if (type < 0 || !index.isValid() 
91                 || index.model() != toc_models_[type]) {
92                 LYXERR(Debug::GUI)
93                         << "QToc::goTo(): QModelIndex is invalid!"
94                         << endl;
95                 return;
96         }
97
98         BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
99
100         TocIterator const it = toc_models_[type]->tocIterator(index);
101         
102         LYXERR(Debug::GUI) << "QToc::goTo " << to_utf8(it->str()) << endl;
103
104         ControlToc::goTo(*it);
105 }
106
107
108 bool QToc::initialiseParams(std::string const & data)
109 {
110         if (!ControlToc::initialiseParams(data))
111                 return false;
112         update();
113         modelReset();
114         return true;
115 }
116
117
118 void QToc::update()
119 {
120         toc_models_.clear();
121         TocList::const_iterator it = tocs().begin();
122         TocList::const_iterator end = tocs().end();
123         for (; it != end; ++it)
124                 toc_models_.push_back(new TocModel(it->second));
125 }
126
127
128 } // namespace frontend
129 } // namespace lyx
130
131 #include "QToc_moc.cpp"