3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
34 TocModel::TocModel(Toc const & toc)
40 TocModel const & TocModel::operator=(Toc const & toc)
47 TocIterator const TocModel::tocIterator(QModelIndex const & index) const
49 TocMap::const_iterator map_it = toc_map_.find(index);
50 BOOST_ASSERT(map_it != toc_map_.end());
51 return map_it->second;
55 QModelIndex const TocModel::modelIndex(TocIterator const & it) const
57 ModelMap::const_iterator map_it = model_map_.find(it);
58 //BOOST_ASSERT(it != model_map_.end());
60 if (map_it == model_map_.end())
63 return map_it->second;
67 void TocModel::clear()
69 QStandardItemModel::clear();
72 removeRows(0, rowCount());
73 removeColumns(0, columnCount());
77 void TocModel::populate(Toc const & toc)
84 QModelIndex top_level_item;
86 TocIterator iter = toc.begin();
87 TocIterator end = toc.end();
94 maxdepth_ = max(maxdepth_, iter->depth());
95 mindepth_ = min(mindepth_, iter->depth());
96 current_row = rowCount();
97 insertRows(current_row, 1);
98 top_level_item = QStandardItemModel::index(current_row, 0);
99 //setData(top_level_item, toqstr(iter->str()));
100 setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
102 // This looks like a gcc bug, in principle this should work:
103 //toc_map_[top_level_item] = iter;
104 // but it crashes with gcc-4.1 and 4.0.2
105 toc_map_.insert( TocPair(top_level_item, iter) );
106 model_map_[iter] = top_level_item;
109 << "Toc: at depth " << iter->depth()
110 << ", added item " << to_utf8(iter->str())
113 populate(iter, end, top_level_item);
121 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
122 // emit headerDataChanged();
126 void TocModel::populate(TocIterator & iter,
127 TocIterator const & end,
128 QModelIndex const & parent)
130 int curdepth = iter->depth() + 1;
133 QModelIndex child_item;
135 insertColumns(0, 1, parent);
136 while (iter != end) {
143 if (iter->depth() < curdepth) {
148 maxdepth_ = max(maxdepth_, iter->depth());
149 mindepth_ = min(mindepth_, iter->depth());
150 current_row = rowCount(parent);
151 insertRows(current_row, 1, parent);
152 child_item = QStandardItemModel::index(current_row, 0, parent);
153 //setData(child_item, toqstr(iter->str()));
154 setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
156 // This looks like a gcc bug, in principle this should work:
157 //toc_map_[child_item] = iter;
158 // but it crashes with gcc-4.1 and 4.0.2
159 toc_map_.insert( TocPair(child_item, iter) );
160 model_map_[iter] = child_item;
161 populate(iter, end, child_item);
166 int TocModel::modelDepth()
168 return maxdepth_ - mindepth_;
171 } // namespace frontend
174 #include "TocModel_moc.cpp"