/**
* \file QToc.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
#include <stack>
-#include <qslider.h>
-#include <qlistview.h>
-#include <qpushbutton.h>
-#include <qcombobox.h>
-
-#include "QTocDialog.h"
-#include "QToc.h"
-#include "Qt2BC.h"
+#include "LyXView.h"
#include "gettext.h"
#include "support/lstrings.h"
#include "debug.h"
-#include "QtLyXView.h"
+#include "ControlToc.h"
+#include "QToc.h"
+#include "QTocDialog.h"
+#include "Qt2BC.h"
+
+#include <qslider.h>
+#include <qlistview.h>
+#include <qpushbutton.h>
+#include <qcombobox.h>
using std::endl;
using std::pair;
typedef Qt2CB<ControlToc, Qt2DB<QTocDialog> > base_class;
-QToc::QToc(ControlToc & c)
- : base_class(c, _("Table of contents"))
+QToc::QToc()
+ : base_class(_("Table of contents")), depth_(1)
{}
char const * str = dialog_->typeCO->currentText().latin1();
string type (str ? str : "");
- Buffer::SingleList const & contents = controller().getContents(type);
+ toc::Toc const & contents = controller().getContents(type);
// Check if all elements are the same.
if (newdepth == depth_ && toclist == contents) {
dialog_->tocLV->setUpdatesEnabled(false);
int curdepth = 0;
- stack< pair< QListViewItem *, QListViewItem *> > istack;
- QListViewItem *last = 0;
- QListViewItem *parent = 0;
- QListViewItem *item;
+ stack<pair<QListViewItem *, QListViewItem *> > istack;
+ QListViewItem * last = 0;
+ QListViewItem * parent = 0;
+ QListViewItem * item;
- // Yes, it is this ugly. Two reasons - root items must have a QListView parent,
- // rather than QListViewItem; and the TOC can move in and out an arbitrary number
- // of levels
+ // Yes, it is this ugly. Two reasons - root items must have
+ // a QListView parent, rather than QListViewItem; and the
+ // TOC can move in and out an arbitrary number of levels
- for (Buffer::SingleList::const_iterator iter = toclist.begin();
- iter != toclist.end(); ++iter) {
+ for (toc::Toc::const_iterator iter = toclist.begin();
+ iter != toclist.end(); ++iter) {
if (iter->depth == curdepth) {
// insert it after the last one we processed
if (!parent)
- item = (last) ? (new QListViewItem(dialog_->tocLV,last)) : (new QListViewItem(dialog_->tocLV));
+ item = (last ? new QListViewItem(dialog_->tocLV,last) : new QListViewItem(dialog_->tocLV));
else
- item = (last) ? (new QListViewItem(parent,last)) : (new QListViewItem(parent));
+ item = (last ? new QListViewItem(parent,last) : new QListViewItem(parent));
} else if (iter->depth > curdepth) {
int diff = iter->depth - curdepth;
// first save old parent and last
while (diff--)
istack.push(pair< QListViewItem *, QListViewItem * >(parent,last));
- item = (last) ? (new QListViewItem(last)) : (new QListViewItem(dialog_->tocLV));
+ item = (last ? new QListViewItem(last) : new QListViewItem(dialog_->tocLV));
parent = last;
} else {
int diff = curdepth - iter->depth;
- pair< QListViewItem *, QListViewItem * > top;
+ pair<QListViewItem *, QListViewItem * > top;
// restore context
while (diff--) {
top = istack.top();
last = top.second;
// insert it after the last one we processed
if (!parent)
- item = (last) ? (new QListViewItem(dialog_->tocLV,last)) : (new QListViewItem(dialog_->tocLV));
+ item = (last ? new QListViewItem(dialog_->tocLV,last) : new QListViewItem(dialog_->tocLV));
else
- item = (last) ? (new QListViewItem(parent,last)) : (new QListViewItem(parent));
+ item = (last ? new QListViewItem(parent,last) : new QListViewItem(parent));
}
- lyxerr[Debug::GUI] << "Table of contents" << endl << "Added item " << iter->str.c_str()
- << " at depth " << iter->depth << ", previous sibling \"" << (last ? last->text(0).latin1() : "0")
- << "\", parent \"" << (parent ? parent->text(0).latin1() : "0") << "\"" << endl;
+ lyxerr[Debug::GUI]
+ << "Table of contents\n"
+ << "Added item " << iter->str.c_str()
+ << " at depth " << iter->depth
+ << ", previous sibling \""
+ << (last ? last->text(0).latin1() : "0")
+ << "\", parent \""
+ << (parent ? parent->text(0).latin1() : "0") << '"'
+ << endl;
item->setText(0,iter->str.c_str());
item->setOpen(iter->depth < depth_);
curdepth = iter->depth;
void QToc::select(string const & text)
{
- Buffer::SingleList::const_iterator iter = toclist.begin();
+ toc::Toc::const_iterator iter = toclist.begin();
for (; iter != toclist.end(); ++iter) {
if (iter->str == text)
return;
}
- controller().Goto(iter->par->id());
+ controller().goTo(*iter);
}