diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index db72abdff3..03f3a7433f 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -26,12 +26,9 @@ #include "support/convert.h" - -namespace lyx { - -using std::vector; using std::string; +namespace lyx { /////////////////////////////////////////////////////////////////////////// // TocItem implementation @@ -40,38 +37,6 @@ TocItem::TocItem(ParConstIterator const & par_it, int d, docstring const & s) : par_it_(par_it), depth_(d), str_(s) { -/* - if (!uid_.empty()) - return; - - size_t pos = s.find(" "); - if (pos == string::npos) { - // Non labelled item - uid_ = s; - return; - } - - string s2 = s.substr(0, pos); - - if (s2 == "Chapter" || s2 == "Part") { - size_t pos2 = s.find(" ", pos + 1); - if (pos2 == string::npos) { - // Unnumbered Chapter?? This should not happen. - uid_ = s.substr(pos + 1); - return; - } - // Chapter or Part - uid_ = s.substr(pos2 + 1); - return; - } - // Numbered Item. - uid_ = s.substr(pos + 1); - */ -} - -bool const TocItem::isValid() const -{ - return depth_ != -1; } @@ -105,9 +70,6 @@ FuncRequest TocItem::action() const } - - - /////////////////////////////////////////////////////////////////////////// // TocBackend implementation @@ -123,10 +85,13 @@ Toc const & TocBackend::toc(std::string const & type) const void TocBackend::updateItem(ParConstIterator const & par_it) { - // TODO should not happen, - // a call to TocBackend::update() is missing somewhere - if (toc("tableofcontents").empty()) + if (toc("tableofcontents").empty()) { + // FIXME: should not happen, + // a call to TocBackend::update() is missing somewhere + lyxerr << "TocBackend::updateItem called but the TOC is empty!" + << std::endl; return; + } BufferParams const & bufparams = buffer_->params(); const int min_toclevel = bufparams.getTextClass().min_toclevel(); diff --git a/src/TocBackend.h b/src/TocBackend.h index 75f0ea4ffd..25b39c9538 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -38,16 +38,16 @@ class TocItem friend class TocBackend; public: + /// Default constructor for STL containers. + TocItem() {} /// - TocItem(ParConstIterator const & par_it = ParConstIterator(), - int d = -1, - docstring const & s = docstring() + TocItem(ParConstIterator const & par_it, + int depth, + docstring const & s ); /// ~TocItem() {} /// - bool const isValid() const; - /// int const id() const; /// int const depth() const; diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index 08f1d12419..0e88f91a70 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -91,30 +91,26 @@ void TocModel::populate(Toc const & toc) mindepth_ = INT_MAX; while (iter != end) { + maxdepth_ = max(maxdepth_, iter->depth()); + mindepth_ = min(mindepth_, iter->depth()); + current_row = rowCount(); + insertRows(current_row, 1); + top_level_item = QStandardItemModel::index(current_row, 0); + //setData(top_level_item, toqstr(iter->str())); + setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole); - if (iter->isValid()) { + // This looks like a gcc bug, in principle this should work: + //toc_map_[top_level_item] = iter; + // but it crashes with gcc-4.1 and 4.0.2 + toc_map_.insert( TocPair(top_level_item, iter) ); + model_map_[iter] = top_level_item; - maxdepth_ = max(maxdepth_, iter->depth()); - mindepth_ = min(mindepth_, iter->depth()); - current_row = rowCount(); - insertRows(current_row, 1); - top_level_item = QStandardItemModel::index(current_row, 0); - //setData(top_level_item, toqstr(iter->str())); - setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole); + LYXERR(Debug::GUI) + << "Toc: at depth " << iter->depth() + << ", added item " << to_utf8(iter->str()) + << endl; - // This looks like a gcc bug, in principle this should work: - //toc_map_[top_level_item] = iter; - // but it crashes with gcc-4.1 and 4.0.2 - toc_map_.insert( TocPair(top_level_item, iter) ); - model_map_[iter] = top_level_item; - - LYXERR(Debug::GUI) - << "Toc: at depth " << iter->depth() - << ", added item " << to_utf8(iter->str()) - << endl; - - populate(iter, end, top_level_item); - } + populate(iter, end, top_level_item); if (iter == end) break;