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"
45 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
46 : DockView(parent, "toc", area, flags), params_(TOC_CODE)
48 widget_ = new TocWidget(*this);
50 setWindowTitle(widget_->windowTitle());
60 int GuiToc::getTocDepth(int type)
64 return toc_models_[type]->modelDepth();
68 QStandardItemModel * GuiToc::tocModel(int type)
73 if (toc_models_.empty()) {
74 LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
78 LYXERR(Debug::GUI, "GuiToc: type " << type
79 << " toc_models_.size() " << toc_models_.size());
81 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
82 return toc_models_[type];
86 QModelIndex GuiToc::currentIndex(int type) const
91 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
92 // This is because a proper ParConstIterator is not constructed in
93 // InsetCaption::addToToc()
97 return toc_models_[type]->modelIndex(currentTocItem(type));
101 void GuiToc::goTo(int type, QModelIndex const & index)
103 if (type < 0 || !index.isValid()
104 || index.model() != toc_models_[type]) {
105 LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
109 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
111 TocIterator const it = toc_models_[type]->tocIterator(index);
113 LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
115 string const tmp = convert<string>(it->id());
116 lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
120 void GuiToc::updateView()
122 widget_->updateView();
126 TocList const & GuiToc::tocs() const
128 return buffer().masterBuffer()->tocBackend().tocs();
132 bool GuiToc::initialiseParams(string const & data)
134 InsetCommandMailer::string2params("toc", data, params_);
139 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
140 TocList::const_iterator it = tocs.begin();
141 TocList::const_iterator end = tocs.end();
142 for (; it != end; ++it) {
143 types_.push_back(it->first);
144 type_names_.push_back(guiName(it->first));
145 toc_models_.push_back(new TocModel(it->second));
148 string selected_type ;
149 if (params_["type"].empty()) //Then plain toc...
150 selected_type = params_.getCmdName();
152 selected_type = to_ascii(params_["type"]);
154 for (size_t i = 0; i != types_.size(); ++i) {
155 if (selected_type == types_[i]) {
166 bool GuiToc::canOutline(int type) const
168 return types_[type] == "tableofcontents";
172 void GuiToc::outlineUp()
174 dispatch(FuncRequest(LFUN_OUTLINE_UP));
178 void GuiToc::outlineDown()
180 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
184 void GuiToc::outlineIn()
186 dispatch(FuncRequest(LFUN_OUTLINE_IN));
190 void GuiToc::outlineOut()
192 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
196 void GuiToc::updateBackend()
198 buffer().masterBuffer()->tocBackend().update();
199 buffer().structureChanged();
203 TocIterator GuiToc::currentTocItem(int type) const
205 BOOST_ASSERT(bufferview());
206 ParConstIterator it(bufferview()->cursor());
207 return buffer().masterBuffer()->tocBackend().item(types_[type], it);
211 docstring GuiToc::guiName(string const & type) const
213 if (type == "tableofcontents")
214 return _("Table of Contents");
216 FloatList const & floats = buffer().params().getTextClass().floats();
217 if (floats.typeExist(type))
218 return _(floats.getType(type).listName());
224 void GuiToc::dispatchParams()
227 InsetCommandMailer::params2string("toc", params_);
228 dispatch(FuncRequest(getLfun(), lfun));
232 Dialog * createGuiToc(GuiView & lv)
234 GuiView & guiview = static_cast<GuiView &>(lv);
236 // On Mac show as a drawer at the right
237 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
239 return new GuiToc(guiview);
244 } // namespace frontend
247 #include "GuiToc_moc.cpp"