From 7bd33462a0de8e84cd0e6f7fa0213605f403087d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 30 Sep 2008 09:50:54 +0000 Subject: [PATCH] Avoid a complete Toc reset in case when only a toc item update is needed. * Buffer: new updateTocItem() signal (with Delegates and GuiView associates). * TocBackend: take care of the signal emission instead of the Cursor::checkBufferStructure() * TocModel: new updateTocItem() method. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26636 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 8 ++++++++ src/Buffer.h | 2 ++ src/Cursor.cpp | 3 +-- src/TocBackend.cpp | 3 +++ src/frontends/Delegates.h | 3 +++ src/frontends/qt4/GuiView.cpp | 6 ++++++ src/frontends/qt4/GuiView.h | 1 + src/frontends/qt4/TocModel.cpp | 14 ++++++++++++++ src/frontends/qt4/TocModel.h | 4 ++++ 9 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e653438736..434f56103a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2158,6 +2158,14 @@ ErrorList & Buffer::errorList(string const & type) const } +void Buffer::updateTocItem(std::string const & type, + DocIterator const & dit) const +{ + if (gui_) + gui_->updateTocItem(type, dit); +} + + void Buffer::structureChanged() const { if (gui_) diff --git a/src/Buffer.h b/src/Buffer.h index 2e1f1e4121..d73bf1ef09 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -420,6 +420,8 @@ public: /// This function is called when the buffer is changed. void changed() const; + /// + void updateTocItem(std::string const &, DocIterator const &) const; /// This function is called when the buffer structure is changed. void structureChanged() const; /// This function is called when some parsing error shows up. diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 7c2fa75818..a51c98b8b4 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -2193,8 +2193,7 @@ void Cursor::recordUndoSelection() const void Cursor::checkBufferStructure() { Buffer const * master = buffer().masterBuffer(); - if (master->tocBackend().updateItem(*this)) - master->structureChanged(); + master->tocBackend().updateItem(*this); } diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp index 6ce5f4044b..85a4a8a707 100644 --- a/src/TocBackend.cpp +++ b/src/TocBackend.cpp @@ -106,6 +106,8 @@ Toc & TocBackend::toc(string const & type) bool TocBackend::updateItem(DocIterator const & dit) { +// Inset * inset = dit.paragraph().inInset(); +// inset->addToToc(dit); if (dit.paragraph().layout().toclevel == Layout::NOT_IN_TOC) return false; @@ -149,6 +151,7 @@ bool TocBackend::updateItem(DocIterator const & dit) const_cast(*toc_item).str_ = tocstring; + buffer_->updateTocItem("tableofcontents", dit); return true; } diff --git a/src/frontends/Delegates.h b/src/frontends/Delegates.h index c1ef6556a4..519a285fbf 100644 --- a/src/frontends/Delegates.h +++ b/src/frontends/Delegates.h @@ -17,6 +17,7 @@ namespace lyx { class Buffer; +class DocIterator; class Inset; namespace frontend { @@ -61,6 +62,8 @@ public: virtual ~GuiBufferDelegate() {} /// This function is called when the buffer structure is changed. virtual void structureChanged() = 0; + /// This function is called when the buffer structure has been updated. + virtual void updateTocItem(std::string const &, DocIterator const &) = 0; /// This function is called when some parsing error shows up. virtual void errors(std::string const &) = 0; /// This function is called when some message shows up. diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index d38c5b48f1..8b595ae173 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1042,6 +1042,12 @@ void GuiView::errors(string const & error_type) } +void GuiView::updateTocItem(std::string const & type, DocIterator const & dit) +{ + d.toc_models_.updateItem(toqstr(type), dit); +} + + void GuiView::structureChanged() { d.toc_models_.reset(view()); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index c89f56de2b..fdb4bdae96 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -106,6 +106,7 @@ public: void resetAutosaveTimers(); void errors(std::string const &); void structureChanged(); + void updateTocItem(std::string const &, DocIterator const &); ///@} /// diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index 73e20c6590..c43a98be54 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -130,6 +130,14 @@ void TocModel::reset() } +void TocModel::updateItem(DocIterator const & dit) +{ + QModelIndex index = modelIndex(dit); + TocItem const & toc_item = tocItem(index); + model_->setData(index, toqstr(toc_item.str()), Qt::DisplayRole); +} + + void TocModel::reset(Toc const & toc) { toc_ = &toc; @@ -298,6 +306,12 @@ void TocModels::updateBackend() const } +void TocModels::updateItem(QString const & type, DocIterator const & dit) +{ + models_[type]->updateItem(dit); +} + + void TocModels::reset(BufferView const * bv) { bv_ = bv; diff --git a/src/frontends/qt4/TocModel.h b/src/frontends/qt4/TocModel.h index 6385a586b5..c8c8c46bf4 100644 --- a/src/frontends/qt4/TocModel.h +++ b/src/frontends/qt4/TocModel.h @@ -53,6 +53,8 @@ public: /// void reset(); /// + void updateItem(DocIterator const & dit); + /// void clear(); /// QAbstractItemModel * model(); @@ -111,6 +113,8 @@ public: /// void updateBackend() const; /// + void updateItem(QString const & type, DocIterator const & dit); + /// void sort(QString const & type, bool sort_it); /// bool isSorted(QString const & type) const;