]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QToc.C
Remove unused symbol encoding
[lyx.git] / src / frontends / qt4 / QToc.C
1 /**
2  * \file QToc.C
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 #include "TocModel.h"
16 #include "Qt2BC.h"
17 #include "qt_helpers.h"
18
19 #include "debug.h"
20
21 #include "controllers/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 QToc::QToc(Dialog & parent)
36         : ControlToc(parent)
37 {
38         update();
39 }
40
41
42 bool QToc::canOutline()
43 {
44         vector<string> const & types = getTypes();
45
46         if (types.empty())
47                 return false;
48
49         BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
50         return ControlToc::canOutline(types[type_]);
51 }
52
53
54 QStandardItemModel * QToc::tocModel()
55 {
56         lyxerr[Debug::GUI]
57                 << "QToc: type_ " << type_
58                 << "  toc_models_.size() " << toc_models_.size()
59                 << endl;
60
61         if (toc_models_.empty())
62                 return 0;
63
64         BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
65         return toc_models_[type_];
66 }
67
68
69 QStandardItemModel * QToc::setTocModel(int type)
70 {
71         type_ = type;
72
73         lyxerr[Debug::GUI]
74                 << "QToc: type_ " << type_
75                 << "  toc_models_.size() " << toc_models_.size()
76                 << endl;
77
78         BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
79         return toc_models_[type_];
80 }
81
82
83 QModelIndex const QToc::getCurrentIndex()
84 {
85         vector<string> const & types = getTypes();
86         TocIterator const it = getCurrentTocItem(types[type_]);
87         if (!it->isValid()) {
88                 lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
89                 return QModelIndex();
90         }
91
92         return toc_models_[type_]->modelIndex(it);
93 }
94
95
96 void QToc::goTo(QModelIndex const & index)
97 {
98         if (!index.isValid()) {
99                 lyxerr[Debug::GUI]
100                         << "QToc::goTo(): QModelIndex is invalid!"
101                         << endl;
102                 return;
103         }
104
105         TocIterator const it = toc_models_[type_]->tocIterator(index);
106         
107         lyxerr[Debug::GUI]
108                 << "QToc::goTo " << lyx::to_utf8(it->str())
109                 << endl;
110
111         it->goTo(kernel().lyxview());
112 }
113
114
115 void QToc::update()
116 {
117         toc_models_.clear();
118
119         QStringList type_list;
120
121         type_ = 0;
122
123         vector<string> const & types = getTypes();
124         if (types.empty()) {
125                 type_model_.setStringList(type_list);
126                 toc_models_.clear();
127                 return;
128         }
129
130         string const & selected_type = toc::getType(params().getCmdName());
131         lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
132
133         QString gui_names_;
134         for (size_t i = 0; i != types.size(); ++i) {
135                 string const & type_str = types[i];
136                 type_list.append(toqstr(getGuiName(type_str)));
137                 if (type_str == selected_type)
138                         type_ = i;
139                 
140                 lyxerr[Debug::GUI]
141                         << "QToc: new type " << type_str
142                         << "\ttoc_models_.size() " << toc_models_.size()
143                         << endl;
144
145                 toc_models_.push_back(new TocModel(getContents(types[i])));
146         }
147         type_model_.setStringList(type_list);
148 }
149
150
151 void QToc::updateToc(int type)
152 {
153         toc_models_[type] = new TocModel(getContents(getTypes()[type]));
154 }
155
156
157 } // namespace frontend
158 } // namespace lyx