]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QToc.C
better selection and scrolling behaviour
[lyx.git] / src / frontends / qt2 / QToc.C
index 5792b208b01c2c0d48d5b6e682ee6b7ded73c89e..c25e578af679da8e47040f338148c436d81f0de7 100644 (file)
@@ -1,9 +1,11 @@
 /**
  * \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>
@@ -19,6 +21,7 @@
 #include "support/lstrings.h"
 #include "debug.h"
 
+#include "ControlToc.h"
 #include "QToc.h"
 #include "QTocDialog.h"
 #include "Qt2BC.h"
@@ -35,8 +38,8 @@ using std::vector;
 
 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)
 {}
 
 
@@ -79,7 +82,7 @@ void QToc::updateToc(int newdepth)
        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) {
@@ -98,33 +101,33 @@ void QToc::updateToc(int newdepth)
        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();
@@ -134,14 +137,20 @@ void QToc::updateToc(int newdepth)
                        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;
@@ -155,7 +164,7 @@ void QToc::updateToc(int newdepth)
 
 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)
@@ -168,7 +177,7 @@ void QToc::select(string const & text)
                return;
        }
 
-       controller().Goto(iter->par->id());
+       controller().goTo(*iter);
 }