From: Georg Baum Date: Wed, 6 Jul 2005 07:28:16 +0000 (+0000) Subject: Don't store row and col in cursor, add some documentation about idx X-Git-Tag: 1.6.10~14175 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7fdf13d5455c679ac0731b017c5bab26d51960b8;p=features.git Don't store row and col in cursor, add some documentation about idx git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10135 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index ae5b5be792..498dedaa62 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-07-06 Georg Baum + + * cursor_slice.h, dociterator.h: add some documentation + * cursor_slice.h, dociterator.h (idxSave, idxLoad): remove + 2005-07-06 Jürgen Spitzmüller * text.C (leftMargin): do not add identation to display() style diff --git a/src/cursor_slice.h b/src/cursor_slice.h index d9f69f755e..6d3508ef34 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -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. diff --git a/src/dociterator.h b/src/dociterator.h index 9106f8dde9..393af2791e 100644 --- a/src/dociterator.h +++ b/src/dociterator.h @@ -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(); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 09535f509a..99c4b8e026 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2005-07-06 Georg Baum + + * insettabular.C (tabularFeatures): adjust cursor after adding a column + 2005-07-05 Jürgen Spitzmüller * insetbranch.C (setButtonLabel): Make label prefix translatable. diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index f703f966f1..4ccb70b768 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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: diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 86e75283a9..bf6420f5de 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,6 @@ +2005-07-06 Georg Baum + + * math_gridinset.C (doDispatch): better fix for the assertion 2005-06-29 Martin Vermeer diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 8f7152e56e..4946fdf576 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -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")