]> git.lyx.org Git - features.git/blob - src/frontends/qt4/QToc.C
Rename .C ==> .cpp for files in src/frontends/qt4, part one
[features.git] / src / frontends / qt4 / QToc.C
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         return true;
114 }
115
116
117 void QToc::update()
118 {
119         updateType();
120         updateToc();
121         modelReset();
122 }
123
124
125 void QToc::updateType()
126 {
127         QStringList type_list;
128
129         vector<docstring> const & type_names = typeNames();
130         BOOST_ASSERT(!type_names.empty());
131         for (size_t i = 0; i != type_names.size(); ++i)
132                 type_list.append(toqstr(type_names[i]));
133
134         type_model_.setStringList(type_list);
135 }
136
137
138 void QToc::updateToc()
139 {
140         toc_models_.clear();
141         TocList::const_iterator it = tocs().begin();
142         TocList::const_iterator end = tocs().end();
143         for (; it != end; ++it)
144                 toc_models_.push_back(new TocModel(it->second));
145 }
146
147
148 } // namespace frontend
149 } // namespace lyx
150
151 #include "QToc_moc.cpp"