InsetIndex: simplify the implementation of the has* methods.

This commit is contained in:
Thibaut Cuvelier 2022-04-25 03:40:06 +02:00
parent 5c80671740
commit 54a519a089

View File

@ -769,51 +769,47 @@ std::vector<docstring> InsetIndex::getSeeAlsoesAsText(OutputParams const & runpa
} }
bool InsetIndex::hasSubentries() const namespace {
bool hasInsetWithCode(const InsetIndex * const inset_index, const InsetCode code,
const std::set<InsetIndexMacroParams::Type> types = {})
{ {
Paragraph const & par = paragraphs().front(); Paragraph const & par = inset_index->paragraphs().front();
InsetList::const_iterator it = par.insetList().begin(); InsetList::const_iterator it = par.insetList().begin();
for (; it != par.insetList().end(); ++it) { for (; it != par.insetList().end(); ++it) {
Inset & inset = *it->inset; Inset & inset = *it->inset;
if (inset.lyxCode() == INDEXMACRO_CODE) { if (inset.lyxCode() == code) {
if (types.empty())
return true;
LASSERT(code == INDEXMACRO_CODE, return false);
InsetIndexMacro const & iim = InsetIndexMacro const & iim =
static_cast<InsetIndexMacro const &>(inset); static_cast<InsetIndexMacro const &>(inset);
if (iim.params().type == InsetIndexMacroParams::Subindex) if (types.find(iim.params().type) != types.end())
return true; return true;
} }
} }
return false; return false;
} }
} // namespace
bool InsetIndex::hasSubentries() const
{
return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::Subindex});
}
bool InsetIndex::hasSeeRef() const bool InsetIndex::hasSeeRef() const
{ {
Paragraph const & par = paragraphs().front(); return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::See, InsetIndexMacroParams::Seealso});
InsetList::const_iterator it = par.insetList().begin();
for (; it != par.insetList().end(); ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == INDEXMACRO_CODE) {
InsetIndexMacro const & iim =
static_cast<InsetIndexMacro const &>(inset);
if (iim.params().type == InsetIndexMacroParams::See
|| iim.params().type == InsetIndexMacroParams::Seealso)
return true;
}
}
return false;
} }
bool InsetIndex::hasSortKey() const bool InsetIndex::hasSortKey() const
{ {
Paragraph const & par = paragraphs().front(); return hasInsetWithCode(this, INDEXMACRO_SORTKEY_CODE);
InsetList::const_iterator it = par.insetList().begin();
for (; it != par.insetList().end(); ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == INDEXMACRO_SORTKEY_CODE)
return true;
}
return false;
} }