3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
18 #include "TocWidget.h"
19 #include "FuncRequest.h"
20 #include "insets/InsetCommand.h"
23 #include "qt_helpers.h"
26 #include "BufferView.h"
27 #include "BufferParams.h"
29 #include "FloatList.h"
30 #include "FuncRequest.h"
32 #include "TextClass.h"
34 #include "support/convert.h"
44 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
45 : DockView(parent, "toc", area, flags), params_(TOC_CODE)
47 widget_ = new TocWidget(*this);
49 setWindowTitle(widget_->windowTitle());
59 int GuiToc::getTocDepth(int type)
63 return toc_models_[type]->modelDepth();
67 QStandardItemModel * GuiToc::tocModel(int type)
72 if (toc_models_.empty()) {
73 LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
77 LYXERR(Debug::GUI, "GuiToc: type " << type
78 << " toc_models_.size() " << toc_models_.size());
80 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
81 return toc_models_[type];
85 QModelIndex GuiToc::currentIndex(int type) const
90 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
91 // This is because a proper ParConstIterator is not constructed in
92 // InsetCaption::addToToc()
96 return toc_models_[type]->modelIndex(currentTocItem(type));
100 void GuiToc::goTo(int type, QModelIndex const & index)
102 if (type < 0 || !index.isValid()
103 || index.model() != toc_models_[type]) {
104 LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
108 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
110 TocIterator const it = toc_models_[type]->tocIterator(index);
112 LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
114 string const tmp = convert<string>(it->id());
115 dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
119 void GuiToc::updateView()
121 widget_->updateView();
125 TocList const & GuiToc::tocs() const
127 return buffer().masterBuffer()->tocBackend().tocs();
131 bool GuiToc::initialiseParams(string const & data)
133 InsetCommandMailer::string2params("toc", data, params_);
138 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
139 TocList::const_iterator it = tocs.begin();
140 TocList::const_iterator end = tocs.end();
141 for (; it != end; ++it) {
142 types_.push_back(it->first);
143 type_names_.push_back(guiName(it->first));
144 toc_models_.push_back(new TocModel(it->second));
147 string selected_type ;
148 if (params_["type"].empty()) //Then plain toc...
149 selected_type = params_.getCmdName();
151 selected_type = to_ascii(params_["type"]);
153 for (size_t i = 0; i != types_.size(); ++i) {
154 if (selected_type == types_[i]) {
165 bool GuiToc::canOutline(int type) const
167 return types_[type] == "tableofcontents";
171 void GuiToc::outlineUp()
173 dispatch(FuncRequest(LFUN_OUTLINE_UP));
177 void GuiToc::outlineDown()
179 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
183 void GuiToc::outlineIn()
185 dispatch(FuncRequest(LFUN_OUTLINE_IN));
189 void GuiToc::outlineOut()
191 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
195 void GuiToc::updateBackend()
197 buffer().masterBuffer()->tocBackend().update();
198 buffer().structureChanged();
202 TocIterator GuiToc::currentTocItem(int type) const
204 BOOST_ASSERT(bufferview());
205 ParConstIterator it(bufferview()->cursor());
206 return buffer().masterBuffer()->tocBackend().item(types_[type], it);
210 docstring GuiToc::guiName(string const & type) const
212 if (type == "tableofcontents")
213 return _("Table of Contents");
215 FloatList const & floats = buffer().params().getTextClass().floats();
216 if (floats.typeExist(type))
217 return _(floats.getType(type).listName());
223 void GuiToc::dispatchParams()
226 InsetCommandMailer::params2string("toc", params_);
227 dispatch(FuncRequest(getLfun(), lfun));
231 Dialog * createGuiToc(GuiView & lv)
233 GuiView & guiview = static_cast<GuiView &>(lv);
235 // On Mac show as a drawer at the right
236 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
238 return new GuiToc(guiview);
243 } // namespace frontend
246 #include "GuiToc_moc.cpp"