Cosmetics.

* TocItem:
  - add a default constructor instead of default initialisation.
  - delete unneeded and not really used isValid() method.

* TocBackend:
  - updateItem(): re-add debug info erased previously.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18749 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-06-12 12:29:19 +00:00
parent ac92fbbd8a
commit 37333444c0
3 changed files with 29 additions and 68 deletions

View File

@ -26,12 +26,9 @@
#include "support/convert.h"
namespace lyx {
using std::vector;
using std::string;
namespace lyx {
///////////////////////////////////////////////////////////////////////////
// TocItem implementation
@ -40,38 +37,6 @@ TocItem::TocItem(ParConstIterator const & par_it, int d,
docstring const & s)
: par_it_(par_it), depth_(d), str_(s)
{
/*
if (!uid_.empty())
return;
size_t pos = s.find(" ");
if (pos == string::npos) {
// Non labelled item
uid_ = s;
return;
}
string s2 = s.substr(0, pos);
if (s2 == "Chapter" || s2 == "Part") {
size_t pos2 = s.find(" ", pos + 1);
if (pos2 == string::npos) {
// Unnumbered Chapter?? This should not happen.
uid_ = s.substr(pos + 1);
return;
}
// Chapter or Part
uid_ = s.substr(pos2 + 1);
return;
}
// Numbered Item.
uid_ = s.substr(pos + 1);
*/
}
bool const TocItem::isValid() const
{
return depth_ != -1;
}
@ -105,9 +70,6 @@ FuncRequest TocItem::action() const
}
///////////////////////////////////////////////////////////////////////////
// TocBackend implementation
@ -123,10 +85,13 @@ Toc const & TocBackend::toc(std::string const & type) const
void TocBackend::updateItem(ParConstIterator const & par_it)
{
// TODO should not happen,
// a call to TocBackend::update() is missing somewhere
if (toc("tableofcontents").empty())
if (toc("tableofcontents").empty()) {
// FIXME: should not happen,
// a call to TocBackend::update() is missing somewhere
lyxerr << "TocBackend::updateItem called but the TOC is empty!"
<< std::endl;
return;
}
BufferParams const & bufparams = buffer_->params();
const int min_toclevel = bufparams.getTextClass().min_toclevel();

View File

@ -38,16 +38,16 @@ class TocItem
friend class TocBackend;
public:
/// Default constructor for STL containers.
TocItem() {}
///
TocItem(ParConstIterator const & par_it = ParConstIterator(),
int d = -1,
docstring const & s = docstring()
TocItem(ParConstIterator const & par_it,
int depth,
docstring const & s
);
///
~TocItem() {}
///
bool const isValid() const;
///
int const id() const;
///
int const depth() const;

View File

@ -91,30 +91,26 @@ void TocModel::populate(Toc const & toc)
mindepth_ = INT_MAX;
while (iter != end) {
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);
if (iter->isValid()) {
// 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;
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);
LYXERR(Debug::GUI)
<< "Toc: at depth " << iter->depth()
<< ", added item " << to_utf8(iter->str())
<< endl;
// 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)
<< "Toc: at depth " << iter->depth()
<< ", added item " << to_utf8(iter->str())
<< endl;
populate(iter, end, top_level_item);
}
populate(iter, end, top_level_item);
if (iter == end)
break;