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.
32 TocModel::TocModel(TocBackend::Toc const & toc)
38 TocModel const & TocModel::operator=(TocBackend::Toc const & toc)
45 TocIterator const TocModel::tocIterator(QModelIndex const & index) const
47 TocMap::const_iterator map_it = toc_map_.find(index);
48 BOOST_ASSERT(map_it != toc_map_.end());
49 return map_it->second;
53 QModelIndex const TocModel::modelIndex(TocIterator const & it) const
55 ModelMap::const_iterator map_it = model_map_.find(it);
56 //BOOST_ASSERT(it != model_map_.end());
58 if (map_it == model_map_.end())
61 return map_it->second;
65 void TocModel::clear()
67 QStandardItemModel::clear();
70 removeRows(0, rowCount());
71 removeColumns(0, columnCount());
75 void TocModel::populate(TocBackend::Toc const & toc)
83 QModelIndex top_level_item;
85 TocIterator iter = toc.begin();
86 TocIterator end = toc.end();
92 if (iter->isValid()) {
94 current_row = rowCount();
95 insertRows(current_row, 1);
96 top_level_item = QStandardItemModel::index(current_row, 0);
97 //setData(top_level_item, toqstr(iter->str()));
98 setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
100 // This looks like a gcc bug, in principle this should work:
101 //toc_map_[top_level_item] = iter;
102 // but it crashes with gcc-4.1 and 4.0.2
103 toc_map_.insert( TocPair(top_level_item, iter) );
104 model_map_[iter] = top_level_item;
107 << "Toc: at depth " << iter->depth()
108 << ", added item " << lyx::to_utf8(iter->str())
111 populate(iter, end, top_level_item);
120 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
121 // emit headerDataChanged();
125 void TocModel::populate(TocIterator & iter,
126 TocIterator const & end,
127 QModelIndex const & parent)
129 int curdepth = iter->depth() + 1;
131 QModelIndex child_item;
133 insertColumns(0, 1, parent);
134 while (iter != end) {
141 if (iter->depth() < curdepth) {
146 current_row = rowCount(parent);
147 insertRows(current_row, 1, parent);
148 child_item = QStandardItemModel::index(current_row, 0, parent);
149 //setData(child_item, toqstr(iter->str()));
150 setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
152 // This looks like a gcc bug, in principle this should work:
153 //toc_map_[child_item] = iter;
154 // but it crashes with gcc-4.1 and 4.0.2
155 toc_map_.insert( TocPair(child_item, iter) );
156 model_map_[iter] = child_item;
157 populate(iter, end, child_item);
162 } // namespace frontend
165 #include "TocModel_moc.cpp"