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);
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));
}
}

View File

@ -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

View File

@ -76,8 +76,8 @@ public:
int depth,
docstring const & s,
bool output_active,
docstring const & t = docstring(),
FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION));
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

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)
{
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;

View File

@ -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_;

View File

@ -359,13 +359,11 @@ 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();

View File

@ -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);

View File

@ -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);

View File

@ -215,13 +215,12 @@ void InsetNote::addToToc(DocIterator const & cpit, bool output_active,
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();

View File

@ -857,7 +857,7 @@ 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.