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.)
This commit is contained in:
Guillaume Munch 2016-06-06 20:02:49 +01:00
parent 8cf138e173
commit d1dddde6d8
10 changed files with 45 additions and 57 deletions

View File

@ -529,16 +529,14 @@ void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer,
Toc::iterator it = TocBackend::findItem(*change_list, 0, author); Toc::iterator it = TocBackend::findItem(*change_list, 0, author);
if (it == change_list->end()) { if (it == change_list->end()) {
change_list->push_back(TocItem(dit, 0, author, true)); change_list->push_back(TocItem(dit, 0, author, true));
change_list->push_back(TocItem(dit, 1, str, output_active, change_list->push_back(TocItem(dit, 1, str, output_active));
support::wrapParas(str, 4)));
continue; continue;
} }
for (++it; it != change_list->end(); ++it) { for (++it; it != change_list->end(); ++it) {
if (it->depth() == 0 && it->str() != author) if (it->depth() == 0 && it->str() != author)
break; break;
} }
change_list->insert(it, TocItem(dit, 1, str, output_active, change_list->insert(it, TocItem(dit, 1, str, output_active));
support::wrapParas(str, 4)));
} }
} }

View File

@ -49,8 +49,8 @@ namespace lyx {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
TocItem::TocItem(DocIterator const & dit, int d, docstring const & s, TocItem::TocItem(DocIterator const & dit, int d, docstring const & s,
bool output_active, docstring const & t, FuncRequest action) bool output_active, FuncRequest action)
: dit_(dit), depth_(d), str_(s), tooltip_(t), output_(output_active), : dit_(dit), depth_(d), str_(s), output_(output_active),
action_(action) 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 docstring const TocItem::asString() const
{ {
static char_type const cross = 0x2716; // ✖ U+2716 HEAVY MULTIPLICATION X static char_type const cross = 0x2716; // ✖ U+2716 HEAVY MULTIPLICATION X

View File

@ -76,8 +76,8 @@ public:
int depth, int depth,
docstring const & s, docstring const & s,
bool output_active, bool output_active,
docstring const & t = docstring(), FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)); );
/// ///
~TocItem() {} ~TocItem() {}
/// ///
@ -88,8 +88,6 @@ public:
docstring const & str() const { return str_; } docstring const & str() const { return str_; }
/// ///
void str(docstring const & s) { str_ = s; } void str(docstring const & s) { str_ = s; }
///
docstring const & tooltip() const;
/// String for display, e.g. it has a mark if output is inactive /// String for display, e.g. it has a mark if output is inactive
docstring const asString() const; docstring const asString() const;
/// ///
@ -110,8 +108,6 @@ private:
int depth_; int depth_;
/// Full item string /// Full item string
docstring str_; docstring str_;
/// The tooltip string
docstring tooltip_;
/// Is this item in a note, inactive branch, etc? /// Is this item in a note, inactive branch, etc?
bool output_; bool output_;
/// Custom action /// Custom action

View File

@ -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) void TocModel::updateItem(DocIterator const & dit)
{ {
QModelIndex index = modelIndex(dit); QModelIndex const index = modelIndex(dit);
TocItem const & toc_item = tocItem(index); setString(tocItem(index), index);
model_->setData(index, toqstr(toc_item.asString()), Qt::DisplayRole);
model_->setData(index, toqstr(toc_item.tooltip()), Qt::ToolTipRole);
} }
@ -177,9 +184,8 @@ void TocModel::reset(shared_ptr<Toc const> toc)
int current_row = model_->rowCount(); int current_row = model_->rowCount();
model_->insertRows(current_row, 1); model_->insertRows(current_row, 1);
QModelIndex top_level_item = model_->index(current_row, 0); 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, index, Qt::UserRole);
model_->setData(top_level_item, toqstr(item.tooltip()), Qt::ToolTipRole);
LYXERR(Debug::GUI, "Toc: at depth " << item.depth() LYXERR(Debug::GUI, "Toc: at depth " << item.depth()
<< ", added item " << item.asString()); << ", added item " << item.asString());
@ -218,9 +224,8 @@ void TocModel::populate(unsigned int & index, QModelIndex const & parent)
int current_row = model_->rowCount(parent); int current_row = model_->rowCount(parent);
model_->insertRows(current_row, 1, parent); model_->insertRows(current_row, 1, parent);
child_item = model_->index(current_row, 0, 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, index, Qt::UserRole);
model_->setData(child_item, toqstr(item.tooltip()), Qt::ToolTipRole);
populate(index, child_item); populate(index, child_item);
if (index >= end) if (index >= end)
break; break;

View File

@ -65,6 +65,8 @@ private:
/// ///
void populate(unsigned int & index, QModelIndex const & parent); void populate(unsigned int & index, QModelIndex const & parent);
/// ///
void setString(TocItem const & item, QModelIndex index);
///
TocTypeModel * model_; TocTypeModel * model_;
/// ///
QSortFilterProxyModel * sorted_model_; QSortFilterProxyModel * sorted_model_;

View File

@ -359,13 +359,11 @@ void InsetBranch::addToToc(DocIterator const & cpit, bool output_active,
DocIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this))); pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
docstring tooltip; docstring str;
text().forOutliner(tooltip, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
docstring str = params_.branch + ": " + tooltip; str = params_.branch + ": " + str;
tooltip = support::wrapParas(tooltip, 0, 60, 2);
shared_ptr<Toc> toc = buffer().tocBackend().toc("branch"); 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. // Proceed with the rest of the inset.
bool const doing_output = output_active && isBranchSelected(); bool const doing_output = output_active && isBranchSelected();

View File

@ -81,13 +81,12 @@ void InsetFoot::addToToc(DocIterator const & cpit, bool output_active,
DocIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this))); pit.push_back(CursorSlice(const_cast<InsetFoot &>(*this)));
docstring tooltip; docstring str;
text().forOutliner(tooltip, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
docstring str = custom_label_ + ": " + tooltip; str = custom_label_ + ": " + str;
tooltip = support::wrapParas(tooltip, 0, 60, 2);
shared_ptr<Toc> toc = buffer().tocBackend().toc("footnote"); 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. // Proceed with the rest of the inset.
InsetFootlike::addToToc(cpit, output_active, utype); InsetFootlike::addToToc(cpit, output_active, utype);

View File

@ -58,13 +58,10 @@ void InsetMarginal::addToToc(DocIterator const & cpit, bool output_active,
DocIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(CursorSlice(const_cast<InsetMarginal &>(*this))); pit.push_back(CursorSlice(const_cast<InsetMarginal &>(*this)));
docstring tooltip; docstring str;
text().forOutliner(tooltip, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
docstring const str = tooltip;
tooltip = support::wrapParas(tooltip, 0, 60, 2);
std::shared_ptr<Toc> toc = buffer().tocBackend().toc("marginalnote"); 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. // Proceed with the rest of the inset.
InsetFootlike::addToToc(cpit, output_active, utype); InsetFootlike::addToToc(cpit, output_active, utype);

View File

@ -215,13 +215,12 @@ void InsetNote::addToToc(DocIterator const & cpit, bool output_active,
pit.push_back(CursorSlice(const_cast<InsetNote &>(*this))); pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));
InsetLayout const & il = getLayout(); InsetLayout const & il = getLayout();
docstring tooltip; docstring str;
text().forOutliner(tooltip, TOC_ENTRY_LENGTH); text().forOutliner(str, TOC_ENTRY_LENGTH);
docstring str = translateIfPossible(il.labelstring()) + ": " + tooltip; str = translateIfPossible(il.labelstring()) + ": " + str;
tooltip = support::wrapParas(tooltip, 0, 60, 2);
shared_ptr<Toc> toc = buffer().tocBackend().toc("note"); 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. // Proceed with the rest of the inset.
bool doing_output = output_active && producesOutput(); bool doing_output = output_active && producesOutput();

View File

@ -857,7 +857,7 @@ void InsetText::iterateForToc(DocIterator const & cdit, bool output_active,
par.forOutliner(tocstring, length); par.forOutliner(tocstring, length);
dit.pos() = 0; dit.pos() = 0;
toc->push_back(TocItem(dit, toclevel - min_toclevel, toc->push_back(TocItem(dit, toclevel - min_toclevel,
tocstring, doing_output, tocstring)); tocstring, doing_output));
} }
// And now the list of changes. // And now the list of changes.