Alfredo Braunstein wrote:
Abdelrazak Younes wrote:

Alfredo Braunstein wrote:

[*] in other words, if you iterate with DocIterator, the inset * member
[of
CUrsorSlice will never point to a tabular owned insettext but to the
tabular inset.
I didn't know that, thanks. But this is bad and inconsistent IMHO. We
should change that and implement a new virtual method in Inset:

It is inconsistent only if you think about InsetText as an inset.

Which it is.

Think
about InsetText as a helper class. It should probably change name (e.g.
TextCell). It is comfortable to have it inside the Inset hierarchy in order to
inherit from it in insets that have only one cell: it saves a great deal of
forwarding...



/// \return the Inset at position idx or "this" if the Inset contains
/// no cell.
virtual Inset & cell(idx_type idx);

I don't see where this would really help much (could you give some example
in which it's useful?).

By implementing this virtual method I reckon that we will save some code. For example:

Inset * DocIterator::realInset() const
{
        BOOST_ASSERT(inTexted());
        // if we are in a tabular, we need the cell
        if (inset().lyxCode() == Inset::TABULAR_CODE) {
                InsetTabular & tabular = static_cast<InsetTabular&>(inset());
                return tabular.cell(idx()).get();
        }
        return &inset();
}


Would become:


Inset * DocIterator::realInset() const
{
        return *inset().cell(idx());
}


And this would work in texted, tabular and mathed indiferently. But then the need for this method would be void I think.

Inset::getText() should go as well as one could cast the cell if needed.


Note that we have already something similar with
DocIterator::Text() (there's 1 to 1 correspondence Text <-> InsetText)

Yes, I know that.


I see that InsetMath already contains a cell() method which returns a
MathData. We should merge that with Inset::cell(); either by making
MathData a proper Inset or by returning the englobing InsetMathNest (I
am not sure there is one).

My knowledge about the mathed hierarchy is feeble so I can't help you
here...

AFAIU, creating this virtual method would help the long standing merging of Inset and InsetMath. InsetMathGrid and InsetTabular could for example share some code. A lot of methods in DocIterator could be merged also:

- cell() (of course)
- col() and row()
- prev and nextAtom()
- etc

Abdel.

Reply via email to