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()
58 return toc_models_[type_]->modelDepth();
62 QStandardItemModel * QToc::tocModel()
64 if (toc_models_.empty()) {
65 lyxerr[Debug::GUI] << "QToc::tocModel(): no types available " << endl;
70 << "QToc: type_ " << type_
71 << " toc_models_.size() " << toc_models_.size()
74 BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
75 return toc_models_[type_];
79 QStandardItemModel * QToc::setTocModel(int type)
84 << "QToc: type_ " << type_
85 << " toc_models_.size() " << toc_models_.size()
88 BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
89 return toc_models_[type_];
93 QModelIndex const QToc::getCurrentIndex()
95 vector<string> const & types = getTypes();
96 if (types.empty() || type_ < 0)
99 TocIterator const it = getCurrentTocItem(types[type_]);
100 if (it == getContents(types[type_]).end() || !it->isValid()) {
101 lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
102 return QModelIndex();
105 return toc_models_[type_]->modelIndex(it);
109 void QToc::goTo(QModelIndex const & index)
111 if (!index.isValid() || index.model() != tocModel()) {
113 << "QToc::goTo(): QModelIndex is invalid!"
118 BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
120 TocIterator const it = toc_models_[type_]->tocIterator(index);
123 << "QToc::goTo " << lyx::to_utf8(it->str())
126 ControlToc::goTo(*it);
144 void QToc::updateType()
147 QStringList type_list;
149 vector<string> const & types = getTypes();
151 type_model_.setStringList(type_list);
153 lyxerr[Debug::GUI] << "QToc::updateType(): no types available " << endl;
157 string selected_type ;
158 if(params()["type"].empty()) //Then plain toc...
159 selected_type = params().getCmdName();
161 selected_type = to_ascii(params()["type"]);
165 for (size_t i = 0; i != types.size(); ++i) {
166 string const & type_str = types[i];
167 type_list.append(toqstr(getGuiName(type_str)));
168 if (type_str == selected_type)
172 << "QToc: new type " << type_str
173 << "\ttoc_models_.size() " << toc_models_.size()
177 type_model_.setStringList(type_list);
181 void QToc::updateToc()
184 vector<string> const & types = getTypes();
186 for (size_t i = 0; i != types.size(); ++i) {
188 toc_models_.push_back(new TocModel(getContents(types[i])));
194 } // namespace frontend
197 #include "QToc_moc.cpp"