]> git.lyx.org Git - features.git/commitdiff
Don't store row and col in cursor, add some documentation about idx
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 6 Jul 2005 07:28:16 +0000 (07:28 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 6 Jul 2005 07:28:16 +0000 (07:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10135 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/cursor_slice.h
src/dociterator.h
src/insets/ChangeLog
src/insets/insettabular.C
src/mathed/ChangeLog
src/mathed/math_gridinset.C

index ae5b5be7929030d2c13e4a9292be7f2e86d8bdc6..498dedaa62479146200b4ba7c6c21d43f9f3501e 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-06  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * cursor_slice.h, dociterator.h: add some documentation
+       * cursor_slice.h, dociterator.h (idxSave, idxLoad): remove
+
 2005-07-06  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * text.C (leftMargin): do not add identation to display() style
index d9f69f755edcffb07141a9dc0573c26a2dc7dabf..6d3508ef34f37d4194113a23912ecdb97acede16 100644 (file)
@@ -62,10 +62,6 @@ public:
        idx_type idx() const { return idx_; }
        /// return the cell this cursor is in
        idx_type & idx() { return idx_; }
-       /// Save current cursor idx as row, col
-       void idxSave() { col_ = idx_ % ncols(); row_ = idx_ / ncols(); }
-       /// update idx to correspond to row, col
-       void idxLoad() { idx_ = col_ + ncols() * row_; }
        /// return the last cell in this inset
        idx_type lastidx() const { return nargs() - 1; }
        /// return the offset of the paragraph this cursor is in
@@ -84,31 +80,43 @@ public:
        pos_type lastpos() const;
        /// return the number of embedded cells
        size_t nargs() const;
-       /// return the number of columns
+       /*!
+        * \return the number of columns.
+        * This does only make sense in grid like insets.
+        */
        size_t ncols() const;
-       /// return the number of rows
+       /*!
+        * \return the number of rows.
+        * This does only make sense in grid like insets.
+        */
        size_t nrows() const;
-       /// return the grid row of the current cell
+       /*!
+        * \return the grid row of the current cell.
+        * This does only make sense in grid like insets.
+        */
        row_type row() const;
-       /// return the grid column of the current cell
+       /*!
+        * \return the grid column of the current cell.
+        * This does only make sense in grid like insets.
+        */
        col_type col() const;
 
        ///
        /// texted specific stuff
        ///
-       /// see comment for the member
+       /// \sa boundary_
        bool boundary() const { return boundary_; }
-       /// see comment for the member
+       /// \sa boundary_
        bool & boundary() { return boundary_; }
-       ///
+       /// returns text corresponding to this position
        LyXText * text();
-       ///
+       /// returns text corresponding to this position
        LyXText const * text() const;
-       ///
+       /// returns the owning inset if it is an UpdatableInset, else 0
        UpdatableInset * asUpdatableInset() const;
-       ///
+       /// paragraph in this cell
        Paragraph & paragraph();
-       ///
+       /// paragraph in this cell
        Paragraph const & paragraph() const;
 
        ///
@@ -116,29 +124,40 @@ public:
        ///
        /// returns cell corresponding to this position
        MathArray & cell() const;
-       ///
+       /// returns the owning inset if it is a MathInset, else 0
        MathInset * asMathInset() const;
 
-       ///
+       /// write some debug information to \p os
        friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
 public:
        /// pointer to 'owning' inset. This is some kind of cache.
        InsetBase * inset_;
 private:
-       /// cell index of a position in this inset
+       /*!
+        * Cell index of a position in this inset.
+        * This is the primary cell information also for grid like insets,
+        * although we have the convenience functions row() and col() for
+        * those.
+        * This means that the corresponding idx_ of a cell in a given row
+        * and column changes every time the number of columns or number of
+        * rows changes. Normally the cursor should stay in the same cell,
+        * so these changes should typically be performed like the following:
+        * \code
+        * row_type const r = cur.row();
+        * col_type const c = cur.col();
+        * // change nrows() and/or ncols()
+        * cur.idx = index(r, c);
+        * \endcode
+        */
        idx_type idx_;
-       /// row position in inset
-       row_type row_;
-       /// column position in inset
-       col_type col_;
        /// paragraph in this cell (used by texted)
        pit_type pit_;
-       /// true of 'pit' was properly initialized
+       /// true if 'pit' was properly initialized
        bool pit_valid_;
        /// position in this cell
        pos_type pos_;
        /**
-        * When the cursor position is i, is the cursor is after the i-th char
+        * When the cursor position is i, is the cursor after the i-th char
         * or before the i+1-th char ? Normally, these two interpretations are
         * equivalent, except when the fonts of the i-th and i+1-th char
         * differ.
index 9106f8dde924acdddaca555d512a075e3e8947fd..393af2791e97a8f3cc3e3980cc3b290ff7c10716 100644 (file)
@@ -54,10 +54,12 @@ public:
        ///
        explicit DocIterator(InsetBase & inset);
 
+       /// access slice at position \p i
        CursorSlice const & operator[](size_t i) const {
                return slices_[i];
        }
 
+       /// access slice at position \p i
        CursorSlice & operator[](size_t i) {
                return slices_[i];
        }
@@ -70,6 +72,7 @@ public:
        /// is this iterator invalid?
        bool operator!() const { return empty(); }
 
+       /// does this iterator have any content?
        bool empty() const { return slices_.empty(); }
 
        //
@@ -81,7 +84,7 @@ public:
        CursorSlice const & top() const { return slices_.back(); }
        /// access to outermost slice
        CursorSlice & bottom() { return slices_.front(); }
-       /// access to  outermost slicetip
+       /// access to outermost slice
        CursorSlice const & bottom() const { return slices_.front(); }
        /// how many nested insets do we have?
        size_t depth() const { return slices_.size(); }
@@ -91,10 +94,6 @@ public:
        idx_type idx() const { return top().idx(); }
        /// return the cell of the inset this cursor is in
        idx_type & idx() { return top().idx(); }
-       ///
-       void idxSave() { top().idxSave(); }
-       ///
-       void idxLoad() { top().idxLoad(); }
        /// return the last possible cell in this inset
        idx_type lastidx() const;
        /// return the paragraph this cursor is in
@@ -155,9 +154,9 @@ public:
        //
        // text-specific part
        //
-       /// see comment for boundary_ below
+       /// \sa boundary_
        bool boundary() const { return top().boundary(); }
-       /// see comment for boundary_ below
+       /// \sa boundary_
        bool & boundary() { return top().boundary(); }
        /// the paragraph we're in
        Paragraph & paragraph();
index 09535f509ab3c4566449725d8df36d414d9d516e..99c4b8e026568208f1b61cecf1846feb4b35e497 100644 (file)
@@ -1,3 +1,7 @@
+2005-07-06  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * insettabular.C (tabularFeatures): adjust cursor after adding a column
+
 2005-07-05  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * insetbranch.C (setButtonLabel): Make label prefix translatable.
index f703f966f11b225b670252a99138e07bc3dab8b5..4ccb70b76854dab25c1c55ecfc919b68e35daad9 100644 (file)
@@ -1448,6 +1448,7 @@ void InsetTabular::tabularFeatures(LCursor & cur,
        case LyXTabular::APPEND_COLUMN:
                // append the column into the tabular
                tabular.appendColumn(bv.buffer()->params(), cur.idx());
+               cur.idx() = tabular.getCellNumber(row, column);
                break;
 
        case LyXTabular::DELETE_ROW:
index 86e75283a97a8b0e5e62d1d43665399700ff223f..bf6420f5de5412c91f11036fd326144aaefb3d0e 100644 (file)
@@ -1,3 +1,6 @@
+2005-07-06  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * math_gridinset.C (doDispatch): better fix for the assertion
 
 2005-06-29  Martin Vermeer  <martin.vermeer@hut.fi>
 
index 8f7152e56e29b65304fdfff9c37d50961470aa8b..4946fdf576832ed8b0ea4905e72b73c82ff92350 100644 (file)
@@ -780,7 +780,7 @@ bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
                        return false;
                cur.idx() -= ncols();
        } else {
-               if (cur.idx() >= ncols() * (nrows() - 1))
+               if (cur.row() >= nrows())
                        return false;
                cur.idx() += ncols();
        }
@@ -1111,17 +1111,18 @@ void MathGridInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                else if (s == "copy-row") {
                        // Here (as later) we save the cursor col/row 
                        // in order to restore it after operation. 
-                       cur.idxSave();
+                       row_type const r = cur.row();
+                       col_type const c = cur.col();
                        for (int i = 0, n = extractInt(is); i < n; ++i)
                                copyRow(cur.row());
-                       cur.idxLoad();
-                       }
+                       cur.idx() = index(r, c);
+               }
                else if (s == "swap-row") {
                        swapRow(cur.row());
                        // Trick to suppress same-idx-means-different-cell 
                        // assertion crash:
                        cur.pos() = 0; 
-                       }
+               }
                else if (s == "add-hline-above")
                        rowinfo_[cur.row()].lines_++;
                else if (s == "add-hline-below")
@@ -1130,29 +1131,30 @@ void MathGridInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                        rowinfo_[cur.row()].lines_--;
                else if (s == "delete-hline-below")
                        rowinfo_[cur.row()+1].lines_--;
-               else if (s == "append-column")
-                       for (int i = 0, n = extractInt(is); i < n; ++i) {
-                               cur.idxSave();
+               else if (s == "append-column") {
+                       row_type const r = cur.row();
+                       col_type const c = cur.col();
+                       for (int i = 0, n = extractInt(is); i < n; ++i)
                                addCol(cur.col());
-                               cur.idxLoad();
-                       }
-               else if (s == "delete-column")
-                       for (int i = 0, n = extractInt(is); i < n; ++i) {
-                               cur.idxSave();
+                       cur.idx() = index(r, c);
+               }
+               else if (s == "delete-column") {
+                       row_type const r = cur.row();
+                       col_type const c = cur.col();
+                       for (int i = 0, n = extractInt(is); i < n; ++i)
                                delCol(col(cur.idx()));
-                               cur.idxLoad();
-                               if (cur.idx() > nargs())
-                                       cur.idx() -= ncols();
-                       }
+                       cur.idx() = index(r, min(c, cur.ncols() - 1));
+               }
                else if (s == "copy-column") {
-                       cur.idxSave();
+                       row_type const r = cur.row();
+                       col_type const c = cur.col();
                        copyCol(cur.col());
-                       cur.idxLoad();
-                       }
+                       cur.idx() = index(r, c);
+               }
                else if (s == "swap-column") {
                        swapCol(cur.col());
                        cur.pos() = 0; // trick, see above
-                       }
+               }
                else if (s == "add-vline-left")
                        colinfo_[cur.col()].lines_++;
                else if (s == "add-vline-right")