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"
28 #include "support/debug.h"
29 #include "FloatList.h"
30 #include "FuncRequest.h"
31 #include "support/gettext.h"
32 #include "TextClass.h"
34 #include "support/convert.h"
43 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
44 : DockView(parent, "toc", qt_("Outline"), area, flags)
46 widget_ = new TocWidget(*this);
58 void GuiToc::clearTocModels()
60 const unsigned int size = toc_models_.size();
61 for (unsigned int i = 0; i < size; ++i) {
62 delete toc_models_[i];
68 int GuiToc::getTocDepth(int type)
72 return toc_models_[type]->modelDepth();
76 QStandardItemModel * GuiToc::tocModel(int type)
81 if (toc_models_.empty()) {
82 LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
86 LYXERR(Debug::GUI, "GuiToc: type " << type
87 << " toc_models_.size() " << toc_models_.size());
89 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
90 return toc_models_[type];
94 QModelIndex GuiToc::currentIndex(int type) const
99 // FIXME: The TocBackend infrastructure is not ready for LOF and LOT
100 // This is because a proper ParConstIterator is not constructed in
101 // InsetCaption::addToToc()
102 if(!canOutline(type))
103 return QModelIndex();
105 return toc_models_[type]->modelIndex(currentTocItem(type));
109 void GuiToc::goTo(int type, QModelIndex const & index)
111 if (type < 0 || !index.isValid()
112 || index.model() != toc_models_[type]) {
113 LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
117 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
119 TocIterator const it = toc_models_[type]->tocIterator(index);
121 LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
123 string const tmp = convert<string>(it->id());
124 dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
128 void GuiToc::updateView()
130 widget_->updateView();
134 TocList const & GuiToc::tocs() const
136 return buffer().masterBuffer()->tocBackend().tocs();
140 bool GuiToc::initialiseParams(string const & data)
142 LYXERR(Debug::GUI, data);
143 QString str = QString::fromUtf8(data.c_str());
145 if (str.contains("tableofcontents"))
146 new_type = "tableofcontents";
147 else if (str.contains("floatlist")) {
148 if (str.contains("\"figure"))
150 else if (str.contains("\"table"))
152 else if (str.contains("\"algorithm"))
153 new_type = "algorithm";
159 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
160 TocList::const_iterator it = tocs.begin();
161 TocList::const_iterator end = tocs.end();
162 for (; it != end; ++it) {
163 types_.push_back(it->first);
164 type_names_.push_back(guiName(it->first));
165 toc_models_.push_back(new TocModel(it->second));
168 int selected_type = -1;
169 for (size_t i = 0; i != types_.size(); ++i) {
170 if (new_type == types_[i]) {
175 widget_->updateGui(selected_type);
181 bool GuiToc::canOutline(int type) const
183 return types_[type] == "tableofcontents";
187 void GuiToc::outlineUp()
189 dispatch(FuncRequest(LFUN_OUTLINE_UP));
193 void GuiToc::outlineDown()
195 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
199 void GuiToc::outlineIn()
201 dispatch(FuncRequest(LFUN_OUTLINE_IN));
205 void GuiToc::outlineOut()
207 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
211 void GuiToc::updateBackend()
213 buffer().masterBuffer()->tocBackend().update();
214 buffer().structureChanged();
218 TocIterator GuiToc::currentTocItem(int type) const
220 BOOST_ASSERT(bufferview());
221 ParConstIterator it(bufferview()->cursor());
222 return buffer().masterBuffer()->tocBackend().item(types_[type], it);
226 docstring GuiToc::guiName(string const & type) const
228 if (type == "tableofcontents")
229 return _("Table of Contents");
230 if (type == "footnote")
231 return _("List of Foot notes");
232 if (type == "listing")
233 return _("List of Listings");
235 return _("List of Indexes");
236 if (type == "marginalnote")
237 return _("List of Marginal notes");
239 return _("List of Notes");
241 FloatList const & floats = buffer().params().getTextClass().floats();
242 if (floats.typeExist(type))
243 return _(floats.getType(type).listName());
249 void GuiToc::dispatchParams()
254 Dialog * createGuiToc(GuiView & lv)
256 GuiView & guiview = static_cast<GuiView &>(lv);
258 // On Mac show as a drawer at the right
259 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
261 return new GuiToc(guiview);
266 } // namespace frontend
269 #include "GuiToc_moc.cpp"