2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QToc.C
|
|
|
|
* 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
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QToc::QToc(Dialog & parent)
|
2006-04-18 09:57:47 +00:00
|
|
|
: ControlToc(parent)
|
|
|
|
{
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
bool QToc::canOutline()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
vector<string> const & types = getTypes();
|
|
|
|
|
2006-10-16 08:51:55 +00:00
|
|
|
if (types.empty())
|
|
|
|
return false;
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
|
|
|
|
return ControlToc::canOutline(types[type_]);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-25 22:16:22 +00:00
|
|
|
int QToc::getTocDepth()
|
|
|
|
{
|
|
|
|
return toc_models_[type_]->modelDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
QStandardItemModel * QToc::tocModel()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-01-03 22:03:26 +00:00
|
|
|
if (toc_models_.empty()) {
|
2006-12-30 14:50:45 +00:00
|
|
|
lyxerr[Debug::GUI] << "QToc::tocModel(): no types available " << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc: type_ " << type_
|
|
|
|
<< " toc_models_.size() " << toc_models_.size()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
|
|
|
|
return toc_models_[type_];
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
QStandardItemModel * QToc::setTocModel(int type)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
type_ = type;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc: type_ " << type_
|
|
|
|
<< " toc_models_.size() " << toc_models_.size()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
|
|
|
|
return toc_models_[type_];
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2006-04-19 14:48:22 +00:00
|
|
|
QModelIndex const QToc::getCurrentIndex()
|
|
|
|
{
|
|
|
|
vector<string> const & types = getTypes();
|
2006-04-22 18:48:28 +00:00
|
|
|
TocIterator const it = getCurrentTocItem(types[type_]);
|
2007-01-30 13:54:28 +00:00
|
|
|
if (it == getContents(types[type_]).end() || !it->isValid()) {
|
2006-04-22 18:48:28 +00:00
|
|
|
lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
|
2006-04-19 14:48:22 +00:00
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
return toc_models_[type_]->modelIndex(it);
|
2006-04-19 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QToc::goTo(QModelIndex const & index)
|
|
|
|
{
|
2007-01-19 22:17:01 +00:00
|
|
|
if (!index.isValid() || index.model() != tocModel()) {
|
2006-04-18 09:57:47 +00:00
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc::goTo(): QModelIndex is invalid!"
|
|
|
|
<< endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-22 18:48:28 +00:00
|
|
|
|
|
|
|
TocIterator const it = toc_models_[type_]->tocIterator(index);
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
lyxerr[Debug::GUI]
|
2006-10-11 19:40:50 +00:00
|
|
|
<< "QToc::goTo " << lyx::to_utf8(it->str())
|
2006-04-18 09:57:47 +00:00
|
|
|
<< 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
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
int QToc::getType()
|
|
|
|
{
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
vector<string> const & types = getTypes();
|
2006-10-19 14:35:06 +00:00
|
|
|
if (types.empty()) {
|
|
|
|
type_model_.setStringList(type_list);
|
|
|
|
toc_models_.clear();
|
2006-12-30 14:50:45 +00:00
|
|
|
lyxerr[Debug::GUI] << "QToc::updateType(): no types available " << endl;
|
2006-10-16 08:51:55 +00:00
|
|
|
return;
|
2006-10-19 14:35:06 +00:00
|
|
|
}
|
2006-10-16 08:51:55 +00:00
|
|
|
|
2006-11-16 12:37:55 +00:00
|
|
|
string selected_type ;
|
|
|
|
if(params()["type"].empty()) //Then plain toc...
|
|
|
|
selected_type = params().getCmdName();
|
|
|
|
else
|
|
|
|
selected_type = to_ascii(params()["type"]);
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
QString gui_names_;
|
|
|
|
for (size_t i = 0; i != types.size(); ++i) {
|
2007-01-04 19:44:49 +00:00
|
|
|
string const & type_str = types[i];
|
2006-04-18 09:57:47 +00:00
|
|
|
type_list.append(toqstr(getGuiName(type_str)));
|
|
|
|
if (type_str == selected_type)
|
|
|
|
type_ = i;
|
|
|
|
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc: new type " << type_str
|
|
|
|
<< "\ttoc_models_.size() " << toc_models_.size()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
vector<string> const & types = getTypes();
|
|
|
|
|
|
|
|
for (size_t i = 0; i != types.size(); ++i) {
|
|
|
|
|
|
|
|
toc_models_.push_back(new TocModel(getContents(types[i])));
|
|
|
|
}
|
|
|
|
|
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"
|