X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FTocModel.cpp;h=4eaafb4bedda336c6936b6580e447ad800713f1d;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=8bb33f9258c8fb23f7f06c380023337d1448d45a;hpb=4b8f0d359c29620fdbe54d06f2f2afb3f89e23db;p=lyx.git diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index 8bb33f9258..4eaafb4bed 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -21,7 +21,6 @@ #include "LyXFunc.h" #include "TocBackend.h" -#include "support/convert.h" #include "support/debug.h" #include "support/lassert.h" @@ -34,7 +33,14 @@ using namespace std; namespace lyx { namespace frontend { -TocTypeModel::TocTypeModel(QObject * parent): QStandardItemModel(parent) +/////////////////////////////////////////////////////////////////////////////// +// +// TocTypeModel +// +/////////////////////////////////////////////////////////////////////////////// + +TocTypeModel::TocTypeModel(QObject * parent) + : QStandardItemModel(parent) { } @@ -45,6 +51,12 @@ void TocTypeModel::reset() } +/////////////////////////////////////////////////////////////////////////////// +// +// TocModel +// +/////////////////////////////////////////////////////////////////////////////// + TocModel::TocModel(QObject * parent) : model_(new TocTypeModel(parent)), sorted_model_(new QSortFilterProxyModel(parent)), @@ -88,6 +100,7 @@ void TocModel::sort(bool sort_it) sorted_model_->sort(0); } + TocItem const & TocModel::tocItem(QModelIndex const & index) const { return (*toc_)[model()->data(index, Qt::UserRole).toUInt()]; @@ -116,6 +129,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; @@ -127,8 +148,6 @@ void TocModel::reset(Toc const & toc) } model_->blockSignals(true); - int current_row; - QModelIndex top_level_item; model_->insertColumns(0, 1); maxdepth_ = 0; mindepth_ = INT_MAX; @@ -138,9 +157,9 @@ void TocModel::reset(Toc const & toc) TocItem const & item = (*toc_)[index]; maxdepth_ = max(maxdepth_, item.depth()); mindepth_ = min(mindepth_, item.depth()); - current_row = model_->rowCount(); + int current_row = model_->rowCount(); model_->insertRows(current_row, 1); - top_level_item = model_->index(current_row, 0); + QModelIndex top_level_item = model_->index(current_row, 0); model_->setData(top_level_item, toqstr(item.str()), Qt::DisplayRole); model_->setData(top_level_item, index, Qt::UserRole); @@ -194,16 +213,19 @@ void TocModel::populate(unsigned int & index, QModelIndex const & parent) int TocModel::modelDepth() const { int const d = maxdepth_ - mindepth_; - LASSERT(d >= 0 && d <= 100, /* */); + LASSERT(d >= 0 && d <= 100, return 0); return d; } /////////////////////////////////////////////////////////////////////////////// -// TocModels implementation. +// +// TocModels +// /////////////////////////////////////////////////////////////////////////////// -TocModels::TocModels(): bv_(0) +TocModels::TocModels() + : bv_(0) { names_ = new TocTypeModel(this); names_sorted_ = new QSortFilterProxyModel(this); @@ -215,7 +237,7 @@ TocModels::TocModels(): bv_(0) } -void TocModels::clear() +void TocModels::clear() { names_->blockSignals(true); names_->clear(); @@ -276,6 +298,20 @@ void TocModels::goTo(QString const & type, QModelIndex const & index) const } +TocItem const TocModels::currentItem(QString const & type, + QModelIndex const & index) const +{ + const_iterator it = models_.find(type); + if (it == models_.end() || !index.isValid()) { + LYXERR(Debug::GUI, "TocModels::currentItem(): QModelIndex is invalid!"); + return TocItem(); + } + LASSERT(index.model() == it.value()->model(), return TocItem()); + + return it.value()->tocItem(index); +} + + void TocModels::updateBackend() const { bv_->buffer().masterBuffer()->tocBackend().update(); @@ -283,6 +319,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; @@ -345,4 +387,4 @@ void TocModels::sort(QString const & type, bool sort_it) } // namespace frontend } // namespace lyx -#include "TocModel_moc.cpp" +#include "moc_TocModel.cpp"