2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiToc.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc.h"
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include "TocModel.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
#include "ControlToc.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
using std::pair;
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiToc::GuiToc(Dialog & dialog, QObject * parent)
|
2007-04-07 00:04:38 +00:00
|
|
|
: QObject(parent), ControlToc(dialog)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiToc::canOutline(int type) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
if (type < 0)
|
2006-10-16 08:51:55 +00:00
|
|
|
return false;
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
return ControlToc::canOutline(type);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
int GuiToc::getTocDepth(int type)
|
2006-11-25 22:16:22 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
2007-03-12 17:03:42 +00:00
|
|
|
return 0;
|
2007-03-16 14:14:55 +00:00
|
|
|
return toc_models_[type]->modelDepth();
|
2006-11-25 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QStandardItemModel * GuiToc::tocModel(int type)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-01-03 22:03:26 +00:00
|
|
|
if (toc_models_.empty()) {
|
2007-08-31 05:53:55 +00:00
|
|
|
LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
|
2006-12-30 14:50:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2007-08-31 05:53:55 +00:00
|
|
|
<< "GuiToc: type " << type
|
2006-04-18 09:57:47 +00:00
|
|
|
<< " toc_models_.size() " << toc_models_.size()
|
|
|
|
<< endl;
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
|
|
|
|
return toc_models_[type];
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QModelIndex const GuiToc::getCurrentIndex(int type) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
2007-03-12 17:03:42 +00:00
|
|
|
return QModelIndex();
|
|
|
|
|
2007-05-15 18:01:22 +00:00
|
|
|
// FIXME: The TocBackend infrastructure is not ready for LOF and LOT
|
|
|
|
// This is because a proper ParConstIterator is not constructed in
|
|
|
|
// InsetCaption::addToToc()
|
|
|
|
if(!canOutline(type))
|
|
|
|
return QModelIndex();
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
return toc_models_[type]->modelIndex(getCurrentTocItem(type));
|
2006-04-19 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiToc::goTo(int type, QModelIndex const & index)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
if (type < 0 || !index.isValid()
|
2007-03-16 14:14:55 +00:00
|
|
|
|| index.model() != toc_models_[type]) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2007-08-31 05:53:55 +00:00
|
|
|
<< "GuiToc::goTo(): QModelIndex is invalid!"
|
2006-04-18 09:57:47 +00:00
|
|
|
<< endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
|
2007-03-12 17:03:42 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
TocIterator const it = toc_models_[type]->tocIterator(index);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-11 00:35:14 +00:00
|
|
|
ControlToc::goTo(*it);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiToc::initialiseParams(std::string const & data)
|
2007-04-03 13:07:38 +00:00
|
|
|
{
|
|
|
|
if (!ControlToc::initialiseParams(data))
|
|
|
|
return false;
|
|
|
|
update();
|
2007-05-10 16:25:11 +00:00
|
|
|
modelReset();
|
2007-04-03 13:07:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiToc::update()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-11-16 12:37:55 +00:00
|
|
|
toc_models_.clear();
|
2007-03-16 14:14:55 +00:00
|
|
|
TocList::const_iterator it = tocs().begin();
|
|
|
|
TocList::const_iterator end = tocs().end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
toc_models_.push_back(new TocModel(it->second));
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc_moc.cpp"
|