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.
36 TocModel::TocModel(Toc const & toc)
42 TocModel const & TocModel::operator=(Toc const & toc)
49 TocIterator const TocModel::tocIterator(QModelIndex const & index) const
51 TocMap::const_iterator map_it = toc_map_.find(index);
52 BOOST_ASSERT(map_it != toc_map_.end());
53 return map_it->second;
57 QModelIndex const TocModel::modelIndex(TocIterator const & it) const
59 ModelMap::const_iterator map_it = model_map_.find(it);
60 //BOOST_ASSERT(it != model_map_.end());
62 if (map_it == model_map_.end())
65 return map_it->second;
69 void TocModel::clear()
71 QStandardItemModel::clear();
74 removeRows(0, rowCount());
75 removeColumns(0, columnCount());
79 void TocModel::populate(Toc const & toc)
86 QModelIndex top_level_item;
88 TocIterator iter = toc.begin();
89 TocIterator end = toc.end();
96 maxdepth_ = max(maxdepth_, iter->depth());
97 mindepth_ = min(mindepth_, iter->depth());
98 current_row = rowCount();
99 insertRows(current_row, 1);
100 top_level_item = QStandardItemModel::index(current_row, 0);
101 //setData(top_level_item, toqstr(iter->str()));
102 setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
104 // This looks like a gcc bug, in principle this should work:
105 //toc_map_[top_level_item] = iter;
106 // but it crashes with gcc-4.1 and 4.0.2
107 toc_map_.insert( TocPair(top_level_item, iter) );
108 model_map_[iter] = top_level_item;
111 << "Toc: at depth " << iter->depth()
112 << ", added item " << to_utf8(iter->str())
115 populate(iter, end, top_level_item);
123 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
124 // emit headerDataChanged();
128 void TocModel::populate(TocIterator & iter,
129 TocIterator const & end,
130 QModelIndex const & parent)
132 int curdepth = iter->depth() + 1;
135 QModelIndex child_item;
137 insertColumns(0, 1, parent);
138 while (iter != end) {
145 if (iter->depth() < curdepth) {
150 maxdepth_ = max(maxdepth_, iter->depth());
151 mindepth_ = min(mindepth_, iter->depth());
152 current_row = rowCount(parent);
153 insertRows(current_row, 1, parent);
154 child_item = QStandardItemModel::index(current_row, 0, parent);
155 //setData(child_item, toqstr(iter->str()));
156 setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
158 // This looks like a gcc bug, in principle this should work:
159 //toc_map_[child_item] = iter;
160 // but it crashes with gcc-4.1 and 4.0.2
161 toc_map_.insert( TocPair(child_item, iter) );
162 model_map_[iter] = child_item;
163 populate(iter, end, child_item);
168 int TocModel::modelDepth()
170 return maxdepth_ - mindepth_;
173 } // namespace frontend
176 #include "TocModel_moc.cpp"