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.
30 TocModel::TocModel(TocBackend::Toc const & toc)
36 TocModel const & TocModel::operator=(TocBackend::Toc const & toc)
43 TocIterator const TocModel::tocIterator(QModelIndex const & index) const
45 TocMap::const_iterator map_it = toc_map_.find(index);
46 BOOST_ASSERT(map_it != toc_map_.end());
47 return map_it->second;
51 QModelIndex const TocModel::modelIndex(TocIterator const & it) const
53 ModelMap::const_iterator map_it = model_map_.find(it);
54 //BOOST_ASSERT(it != model_map_.end());
56 if (map_it == model_map_.end())
59 return map_it->second;
63 void TocModel::clear()
65 QStandardItemModel::clear();
68 removeRows(0, rowCount());
69 removeColumns(0, columnCount());
73 void TocModel::populate(TocBackend::Toc const & toc)
81 QModelIndex top_level_item;
83 TocIterator iter = toc.begin();
84 TocIterator end = toc.end();
90 if (iter->depth() >= 0) {
92 current_row = rowCount();
93 insertRows(current_row, 1);
94 top_level_item = QStandardItemModel::index(current_row, 0);
95 //setData(top_level_item, toqstr(iter->str()));
96 setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
97 toc_map_.insert(make_pair(top_level_item, iter));
98 model_map_.insert(make_pair(iter, top_level_item));
101 << "Toc: at depth " << iter->depth()
102 << ", added item " << iter->str()
105 populate(iter, end, top_level_item);
114 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
115 // emit headerDataChanged();
119 void TocModel::populate(TocIterator & iter,
120 TocIterator const & end,
121 QModelIndex const & parent)
123 int curdepth = iter->depth() + 1;
125 QModelIndex child_item;
127 insertColumns(0, 1, parent);
128 while (iter != end) {
135 if (iter->depth() < curdepth) {
139 // if (iter->depth() > curdepth) {
143 current_row = rowCount(parent);
144 insertRows(current_row, 1, parent);
145 child_item = QStandardItemModel::index(current_row, 0, parent);
146 //setData(child_item, toqstr(iter->str()));
147 setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
148 toc_map_.insert(make_pair(child_item, iter));
149 model_map_.insert(make_pair(iter, child_item));
151 // lyxerr[Debug::GUI]
152 // << "Toc: at depth " << iter->depth()
153 // << ", added item " << iter->str()
156 populate(iter, end, child_item);
161 } // namespace frontend