Jean-Marc Lasgouttes a écrit :
It is great, and I want it for 1.4.something.
Would it be possible to remember the scrollbar position and reset it
afterwards (if entry is still visible)? Currently the resetting of the
scroll bar is annoying.
Pfiouu... I just managed to compile the qt2 frontend... The up and down
operations are absolutely not fast under windows Martin. We absolutely
must disable the outline buttons when an outline operation is being
done. I managed to crash LyX by multiple clicking on the Up and Down
buttons.
I have a patch ready that use direct access methods in outline(). I have
not yet used the splice methods (they are commented out in the code)
because I am not sure of the logic of the code. Could you please have a
look?
I am afraid I have to stop developing for qt2. This simply takes too
long to compile and link... So either you take the hand on this (I know
you are busy ;-)) or I find some time to finish the qt4 TOC dialog which
is not soon.
Please find attached the two patches if you want to test that.
Patch 1: RandomAccessList convenience methods
Patch 2: Makes outline use these methods
It seems to work the same. The speed gain will come with use of splice.
And we definitely must optimize "updateCounter".
Thanks,
Abdel.
Index: support/RandomAccessList.h
===================================================================
--- support/RandomAccessList.h (revision 13525)
+++ support/RandomAccessList.h (working copy)
@@ -169,6 +169,17 @@
return *iterCont_[pos];
}
+ iterator operator()(size_type pos)
+ {
+ return iterCont_[pos];
+ }
+
+ ///
+ const_iterator operator()(size_type pos) const
+ {
+ return iterCont_[pos];
+ }
+
reference at(size_type pos)
{
return *iterCont_.at(pos);
@@ -260,6 +271,52 @@
iterCont_.clear();
}
+ // Convenience methods for direct access.
+
+ bool insert(size_type pos, T const & x)
+ {
+ typename Container::iterator it =
+ container_.insert(iterCont_[pos], x);
+ recreateVector();
+ return it != container_.end();
+ }
+
+ void insert(size_type pos,
+ RandomAccessList const & x, size_type first, size_type length)
+ {
+ container_.insert(iterCont_[pos], x(first), x(first + length));
+ recreateVector();
+ }
+
+ bool erase(size_type pos)
+ {
+ typename Container::iterator it =
+ container_.erase(iterCont_[pos]);
+ recreateVector();
+ return it != container_.end();
+ }
+
+ bool erase(size_type pos, size_type length)
+ {
+ typename Container::iterator it =
+ container_.erase(iterCont_[pos], iterCont_[pos+length]);
+ recreateVector();
+ return it != container_.end();
+ }
+
+ void splice(iterator position, iterator f, iterator l)
+ {
+ container_.splice(position, container_, f, l);
+ recreateVector();
+ }
+
+ void splice(size_type pos, size_type first, size_type length)
+ {
+ container_.splice(iterCont_[pos], container_,
+ iterCont_[first], iterCont_[first+length]);
+ recreateVector();
+ }
+
private:
void recreateVector()
{
Index: toc.C
===================================================================
--- toc.C (revision 13525)
+++ toc.C (working copy)
@@ -169,86 +169,102 @@
void Outline(OutlineOp mode, Buffer * buf, pit_type & pit)
{
ParagraphList & pars = buf->text().paragraphs();
- ParagraphList::iterator bgn = pars.begin();
- ParagraphList::iterator s = boost::next(bgn, pit);
- ParagraphList::iterator p = s;
- ParagraphList::iterator end = pars.end();
+ //ParagraphList::iterator bgn = pars.begin();
+ //ParagraphList::iterator s = boost::next(bgn, pit);
+ //ParagraphList::iterator p = s;
+ //ParagraphList::iterator end = pars.end();
+ pit_type s = pit;
+ pit_type p = s;
+ pit_type end = pars.size();
+
LyXTextClass::const_iterator lit =
buf->params().getLyXTextClass().begin();
LyXTextClass::const_iterator const lend =
buf->params().getLyXTextClass().end();
- int const thistoclevel = s->layout()->toclevel;
+ int const thistoclevel = pars[s].layout()->toclevel;
int toclevel;
switch (mode) {
case UP: {
if (p != end)
++p;
for (; p != end; ++p) {
- toclevel = p->layout()->toclevel;
+ toclevel = pars[p].layout()->toclevel;
if (toclevel != LyXLayout::NOT_IN_TOC
&& toclevel <= thistoclevel) {
break;
}
}
- ParagraphList::iterator q = s;
- if (q != bgn)
+ pit_type q = s;
+ if (q != 0)
--q;
else
break;
- for (; q != bgn; --q) {
- toclevel = q->layout()->toclevel;
+ for (; q != 0; --q) {
+ toclevel = pars[q].layout()->toclevel;
if (toclevel != LyXLayout::NOT_IN_TOC
&& toclevel <= thistoclevel) {
break;
}
}
- pit_type const newpit = std::distance(pars.begin(), q);
- pit_type const len = std::distance(s, p);
+ // This:
+ /*
+ pit_type const length = p - s;
+ pars.splice(q, s, length);
+ pit = q;
+ */
+ // should be an optimised version of this:
+ pit_type const newpit = q;
+ pit_type const len = p - s;
pit += len;
- pars.insert(q, s, p);
- s = boost::next(pars.begin(), pit);
- ParagraphList::iterator t = boost::next(s, len);
+ pars.insert(q, pars, s, len);
+ s = pit;
pit = newpit;
- pars.erase(s, t);
+ pars.erase(s, len);
break;
}
case DOWN: {
if (p != end)
++p;
for (; p != end; ++p) {
- toclevel = p->layout()->toclevel;
+ toclevel = pars[p].layout()->toclevel;
if (toclevel != LyXLayout::NOT_IN_TOC
&& toclevel <= thistoclevel) {
break;
}
}
- ParagraphList::iterator q = p;
+ pit_type q = p;
if (q != end)
++q;
else
break;
for (; q != end; ++q) {
- toclevel = q->layout()->toclevel;
+ toclevel = pars[q].layout()->toclevel;
if (toclevel != LyXLayout::NOT_IN_TOC
&& toclevel <= thistoclevel) {
break;
}
}
- pit_type const newpit = std::distance(pars.begin(), q);
- pit_type const len = std::distance(s, p);
- pars.insert(q, s, p);
- s = boost::next(pars.begin(), pit);
- ParagraphList::iterator t = boost::next(s, len);
+ // This:
+ /*
+ pit_type const length = p - s;
+ pars.splice(q, s, length);
+ pit = q - length;
+ */
+ // should be an optimised version of this:
+ pit_type const newpit = q;
+ pit_type const len = p - s;
+ pars.insert(q, pars, s, len);
+ s = pit;
pit = newpit - len;
- pars.erase(s, t);
+ pars.erase(s, len);
break;
}
case IN:
for (; lit != lend; ++lit) {
if ((*lit)->toclevel == thistoclevel + 1) {
- s->layout((*lit));
+ pars[s].layout((*lit));
break;
}
}
@@ -256,7 +272,7 @@
case OUT:
for (; lit != lend; ++lit) {
if ((*lit)->toclevel == thistoclevel - 1) {
- s->layout((*lit));
+ pars[s].layout((*lit));
break;
}
}