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();
95 if (iter->isValid()) {
97 maxdepth_ = max(maxdepth_, iter->depth());
98 mindepth_ = min(mindepth_, iter->depth());
99 current_row = rowCount();
100 insertRows(current_row, 1);
101 top_level_item = QStandardItemModel::index(current_row, 0);
102 //setData(top_level_item, toqstr(iter->str()));
103 setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
105 // This looks like a gcc bug, in principle this should work:
106 //toc_map_[top_level_item] = iter;
107 // but it crashes with gcc-4.1 and 4.0.2
108 toc_map_.insert( TocPair(top_level_item, iter) );
109 model_map_[iter] = top_level_item;
112 << "Toc: at depth " << iter->depth()
113 << ", added item " << to_utf8(iter->str())
116 populate(iter, end, top_level_item);
125 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
126 // emit headerDataChanged();
130 void TocModel::populate(TocIterator & iter,
131 TocIterator const & end,
132 QModelIndex const & parent)
134 int curdepth = iter->depth() + 1;
137 QModelIndex child_item;
139 insertColumns(0, 1, parent);
140 while (iter != end) {
147 if (iter->depth() < curdepth) {
152 maxdepth_ = max(maxdepth_, iter->depth());
153 mindepth_ = min(mindepth_, iter->depth());
154 current_row = rowCount(parent);
155 insertRows(current_row, 1, parent);
156 child_item = QStandardItemModel::index(current_row, 0, parent);
157 //setData(child_item, toqstr(iter->str()));
158 setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
160 // This looks like a gcc bug, in principle this should work:
161 //toc_map_[child_item] = iter;
162 // but it crashes with gcc-4.1 and 4.0.2
163 toc_map_.insert( TocPair(child_item, iter) );
164 model_map_[iter] = child_item;
165 populate(iter, end, child_item);
170 int TocModel::modelDepth()
172 return maxdepth_ - mindepth_;
175 } // namespace frontend
178 #include "TocModel_moc.cpp"