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"
|
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 {
|
|
|
|
|
|
|
|
QToc::QToc(Dialog & parent)
|
2006-04-18 09:57:47 +00:00
|
|
|
: ControlToc(parent)
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
|
|
|
|
return ControlToc::canOutline(types[type_]);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
QStandardItemModel * QToc::tocModel()
|
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
|
|
|
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();
|
|
|
|
toc::TocItem const item = getCurrentTocItem(types[type_]);
|
|
|
|
if (item.id_ == -1) {
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
string toc_str = item.str;
|
|
|
|
toc_str.erase(0, toc_str.find(' ') + 1);
|
|
|
|
|
|
|
|
return toc_models_[type_]->index(toc_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QToc::goTo(QModelIndex const & index)
|
|
|
|
{
|
|
|
|
if (!index.isValid()) {
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc::goTo(): QModelIndex is invalid!"
|
|
|
|
<< endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "QToc::goTo " << toc_models_[type_]->item(index).str
|
|
|
|
<< endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
ControlToc::goTo(toc_models_[type_]->item(index));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
void QToc::update()
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
toc_models_.clear();
|
2006-03-29 16:57:47 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
QStringList type_list;
|
2006-03-29 16:57:47 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
type_ = 0;
|
|
|
|
|
|
|
|
vector<string> const & types = getTypes();
|
|
|
|
string const & selected_type = toc::getType(params().getCmdName());
|
|
|
|
lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
|
|
|
|
|
|
|
|
QString gui_names_;
|
|
|
|
for (size_t i = 0; i != types.size(); ++i) {
|
|
|
|
string const & type_str = types[i];
|
|
|
|
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;
|
|
|
|
|
|
|
|
toc_models_.push_back(new TocModel(getContents(types[i])));
|
|
|
|
}
|
|
|
|
type_model_.setStringList(type_list);
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QToc::updateToc(int type)
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
vector<string> const & choice = getTypes();
|
|
|
|
|
|
|
|
toc_models_[type] = new TocModel(getContents(choice[type]));
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
void QToc::move(toc::OutlineOp const operation, QModelIndex & index)
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
int toc_id = toc_models_[type_]->item(index).id_;
|
|
|
|
string toc_str = toc_models_[type_]->item(index).str;
|
|
|
|
toc_str.erase(0, toc_str.find(' ') + 1);
|
|
|
|
|
|
|
|
outline(operation);
|
|
|
|
updateToc(type_);
|
2006-03-29 16:57:47 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
lyxerr[Debug::GUI]
|
|
|
|
<< "Toc id " << toc_id
|
|
|
|
<< " Toc str " << toc_str
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
index = toc_models_[type_]->index(toc_str);
|
|
|
|
}
|
2006-03-29 16:57:47 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|