3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
18 #include "qt_helpers.h"
22 #include "controllers/ControlToc.h"
36 QToc::QToc(Dialog & parent)
42 bool QToc::canOutline()
44 vector<string> const & types = getTypes();
49 BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
50 return ControlToc::canOutline(types[type_]);
54 int QToc::getTocDepth()
56 return toc_models_[type_]->modelDepth();
60 QStandardItemModel * QToc::tocModel()
62 if (toc_models_.empty()) {
63 lyxerr[Debug::GUI] << "QToc::tocModel(): no types available " << endl;
68 << "QToc: type_ " << type_
69 << " toc_models_.size() " << toc_models_.size()
72 BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
73 return toc_models_[type_];
77 QStandardItemModel * QToc::setTocModel(int type)
82 << "QToc: type_ " << type_
83 << " toc_models_.size() " << toc_models_.size()
86 BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
87 return toc_models_[type_];
91 QModelIndex const QToc::getCurrentIndex()
93 vector<string> const & types = getTypes();
94 TocIterator const it = getCurrentTocItem(types[type_]);
95 if (it == getContents(types[type_]).end() || !it->isValid()) {
96 lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
100 return toc_models_[type_]->modelIndex(it);
104 void QToc::goTo(QModelIndex const & index)
106 if (!index.isValid() || index.model() != tocModel()) {
108 << "QToc::goTo(): QModelIndex is invalid!"
113 TocIterator const it = toc_models_[type_]->tocIterator(index);
116 << "QToc::goTo " << lyx::to_utf8(it->str())
119 ControlToc::goTo(*it);
137 void QToc::updateType()
140 QStringList type_list;
142 vector<string> const & types = getTypes();
144 type_model_.setStringList(type_list);
146 lyxerr[Debug::GUI] << "QToc::updateType(): no types available " << endl;
150 string selected_type ;
151 if(params()["type"].empty()) //Then plain toc...
152 selected_type = params().getCmdName();
154 selected_type = to_ascii(params()["type"]);
157 for (size_t i = 0; i != types.size(); ++i) {
158 string const & type_str = types[i];
159 type_list.append(toqstr(getGuiName(type_str)));
160 if (type_str == selected_type)
164 << "QToc: new type " << type_str
165 << "\ttoc_models_.size() " << toc_models_.size()
169 type_model_.setStringList(type_list);
173 void QToc::updateToc()
176 vector<string> const & types = getTypes();
178 for (size_t i = 0; i != types.size(); ++i) {
180 toc_models_.push_back(new TocModel(getContents(types[i])));
186 } // namespace frontend
189 #include "QToc_moc.cpp"