add some safeguards (while investigating bug 3152).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17421 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-03-12 17:03:42 +00:00
parent e69f006911
commit 566d80d064

View File

@ -53,6 +53,8 @@ bool QToc::canOutline()
int QToc::getTocDepth() int QToc::getTocDepth()
{ {
if (type_ < 0)
return 0;
return toc_models_[type_]->modelDepth(); return toc_models_[type_]->modelDepth();
} }
@ -91,6 +93,9 @@ QStandardItemModel * QToc::setTocModel(int type)
QModelIndex const QToc::getCurrentIndex() QModelIndex const QToc::getCurrentIndex()
{ {
vector<string> const & types = getTypes(); vector<string> const & types = getTypes();
if (types.empty() || type_ < 0)
return QModelIndex();
TocIterator const it = getCurrentTocItem(types[type_]); TocIterator const it = getCurrentTocItem(types[type_]);
if (it == getContents(types[type_]).end() || !it->isValid()) { if (it == getContents(types[type_]).end() || !it->isValid()) {
lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl; lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
@ -110,6 +115,8 @@ void QToc::goTo(QModelIndex const & index)
return; return;
} }
BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
TocIterator const it = toc_models_[type_]->tocIterator(index); TocIterator const it = toc_models_[type_]->tocIterator(index);
lyxerr[Debug::GUI] lyxerr[Debug::GUI]
@ -154,6 +161,7 @@ void QToc::updateType()
selected_type = to_ascii(params()["type"]); selected_type = to_ascii(params()["type"]);
QString gui_names_; QString gui_names_;
type_ = -1;
for (size_t i = 0; i != types.size(); ++i) { for (size_t i = 0; i != types.size(); ++i) {
string const & type_str = types[i]; string const & type_str = types[i];
type_list.append(toqstr(getGuiName(type_str))); type_list.append(toqstr(getGuiName(type_str)));