commit d1dddde6d800834eb6b8c7626da4d251e7c74f08
Author: Guillaume Munch <[email protected]>
Date: Mon Jun 6 20:02:49 2016 +0100
Remove tooltips from the data of Toc Items
After the previous commit, tooltip in the outliner are formatted
automatically,
along with the other tooltips. A previous commit had already removed the
expensive call to tooltipText() that, although it gave a better rendering,
was
very expensive (cf64064). This patch finishes to remove the custom tooltip
from the model data in the outliner.
(It would be nice to reintroduce a tooltip based on tooltipText(), but there
seemed to be a consensus that in that case one would prefer a less expensive
approach that computes the tooltip on the fly.)
---
src/Changes.cpp | 6 ++----
src/TocBackend.cpp | 10 ++--------
src/TocBackend.h | 14 +++++---------
src/frontends/qt4/TocModel.cpp | 21 +++++++++++++--------
src/frontends/qt4/TocModel.h | 2 ++
src/insets/InsetBranch.cpp | 14 ++++++--------
src/insets/InsetFoot.cpp | 9 ++++-----
src/insets/InsetMarginal.cpp | 9 +++------
src/insets/InsetNote.cpp | 13 ++++++-------
src/insets/InsetText.cpp | 4 ++--
10 files changed, 45 insertions(+), 57 deletions(-)
diff --git a/src/Changes.cpp b/src/Changes.cpp
index d83d782..fc05d1c 100644
--- a/src/Changes.cpp
+++ b/src/Changes.cpp
@@ -529,16 +529,14 @@ void Changes::addToToc(DocIterator const & cdit, Buffer
const & buffer,
Toc::iterator it = TocBackend::findItem(*change_list, 0,
author);
if (it == change_list->end()) {
change_list->push_back(TocItem(dit, 0, author, true));
- change_list->push_back(TocItem(dit, 1, str,
output_active,
- support::wrapParas(str, 4)));
+ change_list->push_back(TocItem(dit, 1, str,
output_active));
continue;
}
for (++it; it != change_list->end(); ++it) {
if (it->depth() == 0 && it->str() != author)
break;
}
- change_list->insert(it, TocItem(dit, 1, str, output_active,
- support::wrapParas(str, 4)));
+ change_list->insert(it, TocItem(dit, 1, str, output_active));
}
}
diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
index 2bbdab3..2b13d1f 100644
--- a/src/TocBackend.cpp
+++ b/src/TocBackend.cpp
@@ -49,8 +49,8 @@ namespace lyx {
///////////////////////////////////////////////////////////////////////////
TocItem::TocItem(DocIterator const & dit, int d, docstring const & s,
- bool output_active, docstring const & t, FuncRequest action)
- : dit_(dit), depth_(d), str_(s), tooltip_(t), output_(output_active),
+ bool output_active, FuncRequest action)
+ : dit_(dit), depth_(d), str_(s), output_(output_active),
action_(action)
{
}
@@ -62,12 +62,6 @@ int TocItem::id() const
}
-docstring const & TocItem::tooltip() const
-{
- return tooltip_.empty() ? str_ : tooltip_;
-}
-
-
docstring const TocItem::asString() const
{
static char_type const cross = 0x2716; // ✖ U+2716 HEAVY MULTIPLICATION
X
diff --git a/src/TocBackend.h b/src/TocBackend.h
index 0671f04..10bfff1 100644
--- a/src/TocBackend.h
+++ b/src/TocBackend.h
@@ -73,11 +73,11 @@ public:
TocItem() : dit_(0), depth_(0), output_(false) {}
///
TocItem(DocIterator const & dit,
- int depth,
- docstring const & s,
- bool output_active,
- docstring const & t = docstring(),
- FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION));
+ int depth,
+ docstring const & s,
+ bool output_active,
+ FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
+ );
///
~TocItem() {}
///
@@ -88,8 +88,6 @@ public:
docstring const & str() const { return str_; }
///
void str(docstring const & s) { str_ = s; }
- ///
- docstring const & tooltip() const;
/// String for display, e.g. it has a mark if output is inactive
docstring const asString() const;
///
@@ -110,8 +108,6 @@ private:
int depth_;
/// Full item string
docstring str_;
- /// The tooltip string
- docstring tooltip_;
/// Is this item in a note, inactive branch, etc?
bool output_;
/// Custom action
diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp
index eb6e610..96711e6 100644
--- a/src/frontends/qt4/TocModel.cpp
+++ b/src/frontends/qt4/TocModel.cpp
@@ -144,12 +144,19 @@ void TocModel::reset()
}
+void TocModel::setString(TocItem const & item, QModelIndex index)
+{
+ // Use implicit sharing of QStrings
+ QString str = toqstr(item.asString());
+ model_->setData(index, str, Qt::DisplayRole);
+ model_->setData(index, str, Qt::ToolTipRole);
+}
+
+
void TocModel::updateItem(DocIterator const & dit)
{
- QModelIndex index = modelIndex(dit);
- TocItem const & toc_item = tocItem(index);
- model_->setData(index, toqstr(toc_item.asString()), Qt::DisplayRole);
- model_->setData(index, toqstr(toc_item.tooltip()), Qt::ToolTipRole);
+ QModelIndex const index = modelIndex(dit);
+ setString(tocItem(index), index);
}
@@ -177,9 +184,8 @@ void TocModel::reset(shared_ptr<Toc const> toc)
int current_row = model_->rowCount();
model_->insertRows(current_row, 1);
QModelIndex top_level_item = model_->index(current_row, 0);
- model_->setData(top_level_item, toqstr(item.asString()),
Qt::DisplayRole);
+ setString(item, top_level_item);
model_->setData(top_level_item, index, Qt::UserRole);
- model_->setData(top_level_item, toqstr(item.tooltip()),
Qt::ToolTipRole);
LYXERR(Debug::GUI, "Toc: at depth " << item.depth()
<< ", added item " << item.asString());
@@ -218,9 +224,8 @@ void TocModel::populate(unsigned int & index, QModelIndex
const & parent)
int current_row = model_->rowCount(parent);
model_->insertRows(current_row, 1, parent);
child_item = model_->index(current_row, 0, parent);
- model_->setData(child_item, toqstr(item.asString()),
Qt::DisplayRole);
+ setString(item, child_item);
model_->setData(child_item, index, Qt::UserRole);
- model_->setData(child_item, toqstr(item.tooltip()),
Qt::ToolTipRole);
populate(index, child_item);
if (index >= end)
break;
diff --git a/src/frontends/qt4/TocModel.h b/src/frontends/qt4/TocModel.h
index 7b22ce6..f7d54e8 100644
--- a/src/frontends/qt4/TocModel.h
+++ b/src/frontends/qt4/TocModel.h
@@ -65,6 +65,8 @@ private:
///
void populate(unsigned int & index, QModelIndex const & parent);
///
+ void setString(TocItem const & item, QModelIndex index);
+ ///
TocTypeModel * model_;
///
QSortFilterProxyModel * sorted_model_;
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index 1dc1567..026dffa 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -358,15 +358,13 @@ void InsetBranch::addToToc(DocIterator const & cpit, bool
output_active,
{
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
-
- docstring tooltip;
- text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
- docstring str = params_.branch + ": " + tooltip;
- tooltip = support::wrapParas(tooltip, 0, 60, 2);
-
+
+ docstring str;
+ text().forOutliner(str, TOC_ENTRY_LENGTH);
+ str = params_.branch + ": " + str;
shared_ptr<Toc> toc = buffer().tocBackend().toc("branch");
- toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
-
+ toc->push_back(TocItem(pit, 0, str, output_active));
+
// Proceed with the rest of the inset.
bool const doing_output = output_active && isBranchSelected();
InsetCollapsable::addToToc(cpit, doing_output, utype);
diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp
index 7008fda..e87de41 100644
--- a/src/insets/InsetFoot.cpp
+++ b/src/insets/InsetFoot.cpp
@@ -81,13 +81,12 @@ void InsetFoot::addToToc(DocIterator const & cpit, bool
output_active,
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
- docstring tooltip;
- text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
- docstring str = custom_label_ + ": " + tooltip;
- tooltip = support::wrapParas(tooltip, 0, 60, 2);
+ docstring str;
+ text().forOutliner(str, TOC_ENTRY_LENGTH);
+ str = custom_label_ + ": " + str;
shared_ptr<Toc> toc = buffer().tocBackend().toc("footnote");
- toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
+ toc->push_back(TocItem(pit, 0, str, output_active));
// Proceed with the rest of the inset.
InsetFootlike::addToToc(cpit, output_active, utype);
diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp
index 9aba39a..1c1df32 100644
--- a/src/insets/InsetMarginal.cpp
+++ b/src/insets/InsetMarginal.cpp
@@ -58,13 +58,10 @@ void InsetMarginal::addToToc(DocIterator const & cpit, bool
output_active,
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetMarginal &>(*this)));
- docstring tooltip;
- text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
- docstring const str = tooltip;
- tooltip = support::wrapParas(tooltip, 0, 60, 2);
-
+ docstring str;
+ text().forOutliner(str, TOC_ENTRY_LENGTH);
std::shared_ptr<Toc> toc = buffer().tocBackend().toc("marginalnote");
- toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
+ toc->push_back(TocItem(pit, 0, str, output_active));
// Proceed with the rest of the inset.
InsetFootlike::addToToc(cpit, output_active, utype);
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index e483cf2..a2916fd 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -213,15 +213,14 @@ void InsetNote::addToToc(DocIterator const & cpit, bool
output_active,
{
DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));
-
+
InsetLayout const & il = getLayout();
- docstring tooltip;
- text().forOutliner(tooltip, TOC_ENTRY_LENGTH);
- docstring str = translateIfPossible(il.labelstring()) + ": " + tooltip;
- tooltip = support::wrapParas(tooltip, 0, 60, 2);
-
+ docstring str;
+ text().forOutliner(str, TOC_ENTRY_LENGTH);
+ str = translateIfPossible(il.labelstring()) + ": " + str;
+
shared_ptr<Toc> toc = buffer().tocBackend().toc("note");
- toc->push_back(TocItem(pit, 0, str, output_active, tooltip));
+ toc->push_back(TocItem(pit, 0, str, output_active));
// Proceed with the rest of the inset.
bool doing_output = output_active && producesOutput();
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 216b9c9..d34c8d2 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -857,9 +857,9 @@ void InsetText::iterateForToc(DocIterator const & cdit,
bool output_active,
par.forOutliner(tocstring, length);
dit.pos() = 0;
toc->push_back(TocItem(dit, toclevel - min_toclevel,
- tocstring,
doing_output, tocstring));
+ tocstring, doing_output));
}
-
+
// And now the list of changes.
par.addChangesToToc(dit, buffer(), doing_output);
}