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"
21 #include "insets/InsetCommand.h"
24 #include "qt_helpers.h"
27 #include "BufferView.h"
28 #include "BufferParams.h"
29 #include "FloatList.h"
30 #include "FuncRequest.h"
31 #include "TextClass.h"
33 #include "support/convert.h"
34 #include "support/debug.h"
35 #include "support/gettext.h"
37 #include <boost/assert.hpp>
46 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
47 : DockView(parent, "toc", qt_("Outline"), area, flags)
49 widget_ = new TocWidget(*this, &parent);
61 void GuiToc::clearTocModels()
63 const unsigned int size = toc_models_.size();
64 for (unsigned int i = 0; i < size; ++i) {
65 delete toc_models_[i];
71 int GuiToc::getTocDepth(int type)
75 return toc_models_[type]->modelDepth();
79 QStandardItemModel * GuiToc::tocModel(int type)
84 if (toc_models_.empty()) {
85 LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
89 LYXERR(Debug::GUI, "GuiToc: type " << type
90 << " toc_models_.size() " << toc_models_.size());
92 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
93 return toc_models_[type];
97 QModelIndex GuiToc::currentIndex(int type) const
100 return QModelIndex();
102 return toc_models_[type]->modelIndex(currentTocItem(type));
106 void GuiToc::goTo(int type, QModelIndex const & index)
108 if (type < 0 || !index.isValid()
109 || index.model() != toc_models_[type]) {
110 LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
114 BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
116 TocIterator const it = toc_models_[type]->tocIterator(index);
118 LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
120 string const tmp = convert<string>(it->id());
121 dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
125 void GuiToc::updateView()
127 widget_->updateView();
131 TocList const & GuiToc::tocs() const
133 return buffer().masterBuffer()->tocBackend().tocs();
137 bool GuiToc::initialiseParams(string const & data)
139 LYXERR(Debug::GUI, data);
140 QString str = QString::fromUtf8(data.c_str());
142 if (str.contains("tableofcontents"))
143 new_type = "tableofcontents";
144 else if (str.contains("floatlist")) {
145 if (str.contains("\"figure"))
147 else if (str.contains("\"table"))
149 else if (str.contains("\"algorithm"))
150 new_type = "algorithm";
151 } else if (!data.empty())
152 new_type = toqstr(data);
154 // Default to Outliner.
155 new_type = "tableofcontents";
160 TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
161 TocList::const_iterator it = tocs.begin();
162 TocList::const_iterator end = tocs.end();
163 for (; it != end; ++it) {
164 types_.push_back(toqstr(it->first));
165 type_names_.push_back(toqstr(guiName(it->first)));
166 toc_models_.push_back(new TocModel(it->second));
169 int selected_type = -1;
170 for (int i = 0; i != types_.size(); ++i) {
171 if (new_type == types_[i]) {
176 widget_->updateGui(selected_type);
182 bool GuiToc::canOutline(int type) const
184 return types_[type] == "tableofcontents";
188 void GuiToc::outlineUp()
190 dispatch(FuncRequest(LFUN_OUTLINE_UP));
194 void GuiToc::outlineDown()
196 dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
200 void GuiToc::outlineIn()
202 dispatch(FuncRequest(LFUN_OUTLINE_IN));
206 void GuiToc::outlineOut()
208 dispatch(FuncRequest(LFUN_OUTLINE_OUT));
212 void GuiToc::updateBackend()
214 buffer().masterBuffer()->tocBackend().update();
215 buffer().structureChanged();
219 TocIterator GuiToc::currentTocItem(int type) const
221 BOOST_ASSERT(bufferview());
222 ParConstIterator it(bufferview()->cursor());
223 return buffer().masterBuffer()->tocBackend().item(fromqstr(types_[type]), it);
227 docstring GuiToc::guiName(string const & type) const
229 if (type == "tableofcontents")
230 return _("Table of Contents");
232 return _("Child Documents");
233 if (type == "embedded")
234 return _("Embedded Files");
235 if (type == "graphics")
236 return _("List of Graphics");
237 if (type == "equation")
238 return _("List of Equations");
239 if (type == "footnote")
240 return _("List of Foot notes");
241 if (type == "listing")
242 return _("List of Listings");
244 return _("List of Indexes");
245 if (type == "marginalnote")
246 return _("List of Marginal notes");
248 return _("List of Notes");
249 if (type == "citation")
250 return _("List of Citations");
252 return _("Labels and References");
254 FloatList const & floats = buffer().params().documentClass().floats();
255 if (floats.typeExist(type))
256 return _(floats.getType(type).listName());
262 void GuiToc::dispatchParams()
267 Dialog * createGuiToc(GuiView & lv)
269 GuiView & guiview = static_cast<GuiView &>(lv);
271 // On Mac show as a drawer at the right
272 return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
274 return new GuiToc(guiview);
279 } // namespace frontend
282 #include "GuiToc_moc.cpp"