using std::vector;
using std::string;
using std::make_pair;
+using std::max;
+using std::min;
namespace lyx {
namespace frontend {
-TocModel::TocModel(TocBackend::Toc const & toc)
+TocModel::TocModel(Toc const & toc)
{
populate(toc);
}
-TocModel const & TocModel::operator=(TocBackend::Toc const & toc)
+TocModel const & TocModel::operator=(Toc const & toc)
{
populate(toc);
return *this;
}
-void TocModel::populate(TocBackend::Toc const & toc)
+void TocModel::populate(Toc const & toc)
{
clear();
if (toc.empty())
return;
-
int current_row;
QModelIndex top_level_item;
TocIterator end = toc.end();
insertColumns(0, 1);
+ maxdepth_ = 0;
+ mindepth_ = INT_MAX;
while (iter != end) {
if (iter->isValid()) {
+ maxdepth_ = max(maxdepth_, iter->depth());
+ mindepth_ = min(mindepth_, iter->depth());
current_row = rowCount();
insertRows(current_row, 1);
top_level_item = QStandardItemModel::index(current_row, 0);
//setData(top_level_item, toqstr(iter->str()));
setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
- toc_map_[top_level_item] = iter;
+
+ // This looks like a gcc bug, in principle this should work:
+ //toc_map_[top_level_item] = iter;
+ // but it crashes with gcc-4.1 and 4.0.2
+ toc_map_.insert( TocPair(top_level_item, iter) );
model_map_[iter] = top_level_item;
- lyxerr[Debug::GUI]
+ LYXERR(Debug::GUI)
<< "Toc: at depth " << iter->depth()
- << ", added item " << lyx::to_utf8(iter->str())
+ << ", added item " << to_utf8(iter->str())
<< endl;
populate(iter, end, top_level_item);
QModelIndex const & parent)
{
int curdepth = iter->depth() + 1;
+
int current_row;
QModelIndex child_item;
return;
}
+ maxdepth_ = max(maxdepth_, iter->depth());
+ mindepth_ = min(mindepth_, iter->depth());
current_row = rowCount(parent);
insertRows(current_row, 1, parent);
child_item = QStandardItemModel::index(current_row, 0, parent);
//setData(child_item, toqstr(iter->str()));
setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
- toc_map_[child_item] = iter;
+
+ // This looks like a gcc bug, in principle this should work:
+ //toc_map_[child_item] = iter;
+ // but it crashes with gcc-4.1 and 4.0.2
+ toc_map_.insert( TocPair(child_item, iter) );
model_map_[iter] = child_item;
populate(iter, end, child_item);
}
}
+int TocModel::modelDepth()
+{
+ return maxdepth_ - mindepth_;
+}
+
} // namespace frontend
} // namespace lyx