From 53acfb8351e09b1a5c137318b03eb7148613dd7e Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 29 Sep 2008 10:52:17 +0000 Subject: [PATCH] Dialogs: discourage non const access to buffer() and bufferview(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26620 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Dialog.cpp | 13 ------------- src/frontends/qt4/Dialog.h | 2 -- src/frontends/qt4/GuiDocument.cpp | 7 ++++--- src/frontends/qt4/GuiErrorList.cpp | 7 ++++--- src/frontends/qt4/GuiInfo.cpp | 6 ++++-- src/frontends/qt4/GuiSpellchecker.cpp | 12 +++++++----- src/frontends/qt4/GuiTabular.cpp | 4 ++-- src/frontends/qt4/GuiViewSource.cpp | 4 ++-- 8 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index ee2557abb3..a7e0b51df9 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -106,25 +106,12 @@ KernelDocType Dialog::docType() const } -BufferView * Dialog::bufferview() -{ - return lyxview_->view(); -} - - BufferView const * Dialog::bufferview() const { return lyxview_->view(); } -Buffer & Dialog::buffer() -{ - LASSERT(lyxview_->buffer(), /**/); - return *lyxview_->buffer(); -} - - Buffer const & Dialog::buffer() const { LASSERT(lyxview_->buffer(), /**/); diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h index e68812ca83..b69e963742 100644 --- a/src/frontends/qt4/Dialog.h +++ b/src/frontends/qt4/Dialog.h @@ -251,10 +251,8 @@ public: GuiView & lyxview() { return *lyxview_; } GuiView const & lyxview() const { return *lyxview_; } - Buffer & buffer(); Buffer const & buffer() const; - BufferView * bufferview(); BufferView const * bufferview() const; //@} diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 4d97a78cd4..622156603d 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -2216,7 +2216,7 @@ char const * GuiDocument::fontfamilies_gui[5] = { bool GuiDocument::initialiseParams(string const &) { - BufferView * view = bufferview(); + BufferView const * view = bufferview(); if (!view) { bp_ = BufferParams(); paramsToDialog(bp_); @@ -2305,7 +2305,7 @@ void GuiDocument::dispatchParams() support::onlyPath(buffer().absFileName())); if (isLyXFilename(master_file.absFilename())) { Buffer * master = checkAndLoadLyXFile(master_file); - buffer().setParent(master); + const_cast(buffer()).setParent(master); } } @@ -2328,7 +2328,8 @@ void GuiDocument::dispatchParams() "assign branch")); } // FIXME: If we used an LFUN, we would not need those two lines: - bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); + BufferView * bv = const_cast(bufferview()); + bv->processUpdateFlags(Update::Force | Update::FitCursor); } diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index b1ab7b414e..2b0834d0d4 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -104,7 +104,7 @@ bool GuiErrorList::goTo(int item) if (err.par_id == -1) return false; - Buffer & buf = buffer(); + Buffer const & buf = buffer(); DocIterator dit = buf.getParFromID(err.par_id); if (dit == doc_iterator_end(buf.inset())) { @@ -121,9 +121,10 @@ bool GuiErrorList::goTo(int item) pos_type const start = min(err.pos_start, end); pos_type const range = end - start; dit.pos() = start; - bufferview()->putSelectionAt(dit, range, false); + BufferView * bv = const_cast(bufferview()); // FIXME: If we used an LFUN, we would not need this line: - bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); + bv->putSelectionAt(dit, range, false); + bv->processUpdateFlags(Update::Force | Update::FitCursor); return true; } diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index 4a838cc0ac..352a36164c 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -100,8 +100,10 @@ void GuiInfo::applyView() dispatch(FuncRequest(LFUN_INSET_MODIFY, argument)); // FIXME: update the inset contents updateLabels(bufferview()->buffer()); - bufferview()->updateMetrics(); - bufferview()->buffer().changed(); + BufferView * bv = const_cast(bufferview()); + bv->updateMetrics(); + bv->buffer().changed(); + bv->buffer().markDirty(); } diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 561b99168f..4440262060 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -372,11 +372,12 @@ void GuiSpellchecker::check() int const size = cur.selEnd().pos() - cur.selBegin().pos(); cur.pos() -= size; - bufferview()->putSelectionAt(cur, size, false); + BufferView * bv = const_cast(bufferview()); + bv->putSelectionAt(cur, size, false); // FIXME: if we used a lfun like in find/replace, dispatch would do // that for us // FIXME: this Controller is very badly designed... - bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); + bv->processUpdateFlags(Update::Force | Update::FitCursor); // set suggestions if (res != SpellBase::OK && res != SpellBase::IGNORED_WORD) { @@ -427,10 +428,11 @@ void GuiSpellchecker::replace(docstring const & replacement) { LYXERR(Debug::GUI, "GuiSpellchecker::replace(" << to_utf8(replacement) << ")"); - cap::replaceSelectionWithString(bufferview()->cursor(), replacement, true); - buffer().markDirty(); + BufferView * bv = const_cast(bufferview()); + cap::replaceSelectionWithString(bv->cursor(), replacement, true); + bv->buffer().markDirty(); // If we used an LFUN, we would not need that - bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); + bv->processUpdateFlags(Update::Force | Update::FitCursor); // fix up the count --count_; check(); diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index 8b8c2dbaf4..d7217a5223 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -969,7 +969,7 @@ bool GuiTabular::initialiseParams(string const & data) return true; } - InsetTabular tmp(buffer()); + InsetTabular tmp(const_cast(buffer())); InsetTabular::string2params(data, tmp); tabular_ = Tabular(tmp.tabular); return true; @@ -978,7 +978,7 @@ bool GuiTabular::initialiseParams(string const & data) void GuiTabular::clearParams() { - InsetTabular tmp(buffer()); + InsetTabular tmp(const_cast(buffer())); tabular_ = tmp.tabular; active_cell_ = Tabular::npos; } diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 2d9ec85655..d0e057d229 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -70,7 +70,7 @@ ViewSourceWidget::ViewSourceWidget(GuiViewSource & controller) void ViewSourceWidget::updateView() { - BufferView * view = controller_.bufferview(); + BufferView const * view = controller_.bufferview(); if (!view) { document_->setPlainText(QString()); setEnabled(false); @@ -134,7 +134,7 @@ QString GuiViewSource::getContent(bool fullSource) pit_type par_begin; pit_type par_end; - BufferView * view = bufferview(); + BufferView const * view = bufferview(); if (!view->cursor().selection()) { par_begin = view->cursor().bottom().pit(); par_end = par_begin; -- 2.39.2