]> git.lyx.org Git - lyx.git/commitdiff
add some safeguards (while investigating bug 3152).
authorAbdelrazak Younes <younes@lyx.org>
Mon, 12 Mar 2007 17:03:42 +0000 (17:03 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 12 Mar 2007 17:03:42 +0000 (17:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17421 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/QToc.C

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