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(toc::Toc const & toc_list)
36 TocModel const & TocModel::operator=(toc::Toc const & toc_list)
42 toc::TocItem const TocModel::item(QModelIndex const & index) const
44 ItemMap::const_iterator it = item_map_.find(index);
45 BOOST_ASSERT(it != item_map_.end());
50 QModelIndex const TocModel::index(string const & toc_str) const
52 IndexMap::const_iterator it = index_map_.find(toc_str);
53 //BOOST_ASSERT(it != index_map_.end());
55 if (it == index_map_.end())
61 void TocModel::clear()
63 QStandardItemModel::clear();
66 removeRows(0, rowCount());
67 removeColumns(0, columnCount());
71 void TocModel::populate(toc::Toc const & toc_list)
79 QModelIndex top_level_item;
81 toc::Toc::const_iterator iter = toc_list.begin();
82 toc::Toc::const_iterator end = toc_list.end();
88 if (iter->depth == 1) {
90 current_row = rowCount();
91 insertRows(current_row, 1);
92 top_level_item = QStandardItemModel::index(current_row, 0);
93 //setData(top_level_item, toqstr(iter->str));
94 setData(top_level_item, toqstr(iter->str), Qt::DisplayRole);
95 item_map_.insert(make_pair(top_level_item, *iter));
96 index_map_.insert(make_pair(
97 iter->str.substr(iter->str.find(' ') + 1), top_level_item));
100 << "Toc: at depth " << iter->depth
101 << ", added item " << iter->str
104 populate(iter, end, top_level_item);
113 setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
114 // emit headerDataChanged();
118 void TocModel::populate(toc::Toc::const_iterator & iter,
119 toc::Toc::const_iterator const & end,
120 QModelIndex const & parent)
122 int curdepth = iter->depth + 1;
124 QModelIndex child_item;
126 insertColumns(0, 1, parent);
127 while (iter != end) {
134 if (iter->depth < curdepth) {
138 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 item_map_.insert(make_pair(child_item, *iter));
148 index_map_.insert(make_pair(
149 iter->str.substr(iter->str.find(' ') + 1), child_item));
151 // lyxerr[Debug::GUI]
152 // << "Toc: at depth " << iter->depth
153 // << ", added item " << iter->str
156 populate(iter, end, child_item);
160 } // namespace frontend