2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file QToc.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>
|
|
|
|
|
|
|
|
#include "QToc.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 "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "controllers/ControlToc.h"
|
|
|
|
|
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-04-07 00:04:38 +00:00
|
|
|
QToc::QToc(Dialog & dialog, QObject * parent)
|
|
|
|
: QObject(parent), ControlToc(dialog)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
bool QToc::canOutline(int type) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +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-03-16 14:14:55 +00:00
|
|
|
int QToc::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-03-16 14:14:55 +00:00
|
|
|
QStandardItemModel * QToc::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-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "QToc::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-03-16 14:14:55 +00:00
|
|
|
<< "QToc: 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-03-16 14:14:55 +00:00
|
|
|
QModelIndex const QToc::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-03-16 14:14:55 +00:00
|
|
|
return toc_models_[type]->modelIndex(getCurrentTocItem(type));
|
2006-04-19 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
void QToc::goTo(int type, QModelIndex const & index)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0 || !index.isValid()
|
|
|
|
|| index.model() != toc_models_[type]) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2006-04-18 09:57:47 +00:00
|
|
|
<< "QToc::goTo(): QModelIndex is invalid!"
|
|
|
|
<< 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);
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
LYXERR(Debug::GUI) << "QToc::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-04-03 13:07:38 +00:00
|
|
|
bool QToc::initialiseParams(std::string const & data)
|
|
|
|
{
|
|
|
|
if (!ControlToc::initialiseParams(data))
|
|
|
|
return false;
|
|
|
|
update();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QToc::update()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-11-16 12:37:55 +00:00
|
|
|
updateType();
|
|
|
|
updateToc();
|
2007-03-12 14:23:44 +00:00
|
|
|
modelReset();
|
2006-11-16 12:37:55 +00:00
|
|
|
}
|
2006-03-29 16:57:47 +00:00
|
|
|
|
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
void QToc::updateType()
|
|
|
|
{
|
|
|
|
QStringList type_list;
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
vector<docstring> const & type_names = typeNames();
|
|
|
|
BOOST_ASSERT(!type_names.empty());
|
|
|
|
for (size_t i = 0; i != type_names.size(); ++i)
|
|
|
|
type_list.append(toqstr(type_names[i]));
|
2006-10-16 08:51:55 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
type_model_.setStringList(type_list);
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
void QToc::updateToc()
|
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
|
|
|
|
|
|
|
#include "QToc_moc.cpp"
|