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);
99 toc_map_[top_level_item] = iter;
100 model_map_[iter] = top_level_item;
103 << "Toc: at depth " << iter->depth()
104 << ", added item " << iter->str()
107 populate(iter, end, top_level_item);
116 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
117 // emit headerDataChanged();
121 void TocModel::populate(TocIterator & iter,
122 TocIterator const & end,
123 QModelIndex const & parent)
125 int curdepth = iter->depth() + 1;
127 QModelIndex child_item;
129 insertColumns(0, 1, parent);
130 while (iter != end) {
137 if (iter->depth() < curdepth) {
142 current_row = rowCount(parent);
143 insertRows(current_row, 1, parent);
144 child_item = QStandardItemModel::index(current_row, 0, parent);
145 //setData(child_item, toqstr(iter->str()));
146 setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
147 toc_map_[child_item] = iter;
148 model_map_[iter] = child_item;
149 populate(iter, end, child_item);
154 } // namespace frontend
157 #include "TocModel_moc.cpp"