]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/TocModel.cpp
do what the FIXME suggested
[lyx.git] / src / frontends / qt4 / TocModel.cpp
index 08f1d12419dab609a3b530fde574eb657aacf44a..2f8fadc5039b8e40e7ab144f3f52272a003856d7 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file QTocDialog.C
+ * \file TocModel.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 
 #include "TocModel.h"
 
-#include "debug.h"
+#include "support/debug.h"
 
-#include <vector>
-#include <string>
+#include <boost/assert.hpp>
+#include <climits>
 
-using std::endl;
-using std::pair;
-using std::map;
-using std::vector;
-using std::string;
-using std::make_pair;
-using std::max;
-using std::min;
+using namespace std;
 
 namespace lyx {
 namespace frontend {
@@ -91,30 +84,24 @@ 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()) {
-
-                       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);
-
-                       // 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;
+               // 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;
+               LYXERR(Debug::GUI, "Toc: at depth " << iter->depth()
+                       << ", added item " << to_utf8(iter->str()));
 
-                       populate(iter, end, top_level_item);
-               }
+               populate(iter, end, top_level_item);
 
                if (iter == end)
                        break;
@@ -127,9 +114,8 @@ void TocModel::populate(Toc const & toc)
 }
 
 
-void TocModel::populate(TocIterator & iter,
-                                               TocIterator const & end,
-                                               QModelIndex const & parent)
+void TocModel::populate(TocIterator & iter, TocIterator const & end,
+       QModelIndex const & parent)
 {
        int curdepth = iter->depth() + 1;
 
@@ -167,7 +153,7 @@ void TocModel::populate(TocIterator & iter,
 }
 
 
-int TocModel::modelDepth()
+int TocModel::modelDepth() const
 {
        return maxdepth_ - mindepth_;
 }