mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 06:15:16 +00:00
Remove unneccessary uses of dynamic_cast from the code.
A dynamic_cast is necessary when: - the object to be casted is from an external library because we can't add Qxxx::asXxxx() to Qt e.g.: * QAbstractListModel to GuiIdListModel, * QValidator to PathValidator, * QWidget to TabWorkArea, * QWidget to GuiWorkArea; - the object is to be casted from an interface to the implementing class, because the Interface does not know by whom it is implemented: * ProgressInterface to GuiProgress, * Application to GuiApplication. A dynamic_cast can be replaced by: - already existing as***Inset() functions, e.g.: * asHullInset(), * asInsetMath()->asMacro(), * asInsetText(); - a static_cast when we are sure this can't go wrong, e.g.: * we are sure that CellData::inset->clone() is an InsetTableCell, * in cases where we explicitly check it->lyxCode(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35855 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8d10d82392
commit
573500dd04
@ -2085,7 +2085,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
|
||||
bool success = false;
|
||||
for (; it != end; ++it) {
|
||||
if (it->lyxCode() == BRANCH_CODE) {
|
||||
InsetBranch & ins = dynamic_cast<InsetBranch &>(*it);
|
||||
InsetBranch & ins = static_cast<InsetBranch &>(*it);
|
||||
if (ins.branch() == oldname) {
|
||||
undo().recordUndo(it);
|
||||
ins.rename(newname);
|
||||
@ -2830,7 +2830,7 @@ void Buffer::getUsedBranches(std::list<docstring> & result, bool const from_mast
|
||||
InsetIterator const end = inset_iterator_end(inset());
|
||||
for (; it != end; ++it) {
|
||||
if (it->lyxCode() == BRANCH_CODE) {
|
||||
InsetBranch & br = dynamic_cast<InsetBranch &>(*it);
|
||||
InsetBranch & br = static_cast<InsetBranch &>(*it);
|
||||
docstring const name = br.branch();
|
||||
if (!from_master && !params().branchlist().find(name))
|
||||
result.push_back(name);
|
||||
|
@ -272,7 +272,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
|
||||
|
||||
case LABEL_CODE: {
|
||||
// check for duplicates
|
||||
InsetLabel & lab = dynamic_cast<InsetLabel &>(*it);
|
||||
InsetLabel & lab = static_cast<InsetLabel &>(*it);
|
||||
docstring const oldname = lab.getParam("name");
|
||||
lab.updateCommand(oldname, false);
|
||||
// We need to update the buffer reference cache.
|
||||
@ -310,7 +310,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
|
||||
|
||||
case BIBITEM_CODE: {
|
||||
// check for duplicates
|
||||
InsetBibitem & bib = dynamic_cast<InsetBibitem &>(*it);
|
||||
InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
|
||||
docstring const oldkey = bib.getParam("key");
|
||||
bib.updateCommand(oldkey, false);
|
||||
// We need to update the buffer reference cache.
|
||||
|
@ -91,7 +91,7 @@ DocIterator DocIterator::clone(Buffer * buffer) const
|
||||
|
||||
bool DocIterator::inRegexped() const
|
||||
{
|
||||
InsetMathHull * i = dynamic_cast<InsetMathHull *>(inset().asInsetMath());
|
||||
InsetMathHull * i = inset().asInsetMath()->asHullInset();
|
||||
return i && i->getType() == hullRegexp;
|
||||
}
|
||||
|
||||
|
@ -268,10 +268,10 @@ static bool doInsertInset(Cursor & cur, Text * text,
|
||||
cur.buffer()->errors("Paste");
|
||||
cur.clearSelection(); // bug 393
|
||||
cur.finishUndo();
|
||||
InsetText * insetText = dynamic_cast<InsetText *>(inset);
|
||||
if (insetText) {
|
||||
insetText->fixParagraphsFont();
|
||||
if (!insetText->allowMultiPar() || cur.lastpit() == 0) {
|
||||
InsetText * inset_text = inset->asInsetText();
|
||||
if (inset_text) {
|
||||
inset_text->fixParagraphsFont();
|
||||
if (!inset_text->allowMultiPar() || cur.lastpit() == 0) {
|
||||
// reset first par to default
|
||||
cur.text()->paragraphs().begin()
|
||||
->setPlainOrDefaultLayout(bparams.documentClass());
|
||||
|
@ -580,7 +580,7 @@ Tabular::CellData::CellData(CellData const & cs)
|
||||
rotate(cs.rotate),
|
||||
align_special(cs.align_special),
|
||||
p_width(cs.p_width),
|
||||
inset(dynamic_cast<InsetTableCell *>(cs.inset->clone()))
|
||||
inset(static_cast<InsetTableCell *>(cs.inset->clone()))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1011,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
|
||||
case LFUN_REGEXP_MODE: {
|
||||
InsetMathHull * i = dynamic_cast<InsetMathHull *>(cur.inset().asInsetMath());
|
||||
InsetMathHull * i = cur.inset().asInsetMath()->asHullInset();
|
||||
if (i && i->getType() == hullRegexp) {
|
||||
cur.message(_("Already in regular expression mode"));
|
||||
break;
|
||||
|
@ -164,7 +164,7 @@ bool MathMacro::editMode(BufferView const * bv) const {
|
||||
// look if there is no other macro in edit mode above
|
||||
++i;
|
||||
for (; i != cur.depth(); ++i) {
|
||||
MathMacro const * macro = dynamic_cast<MathMacro const *>(&cur[i].inset());
|
||||
MathMacro const * macro = cur[i].asInsetMath()->asMacro();
|
||||
if (macro && macro->displayMode() == DISPLAY_NORMAL)
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user