tdf#137104 Added a check for headings in tables
New check checks if a node is a heading and if it is in a table.
Change-Id: I53938ddb57573f80c7823b05bff2d1dd2cee1b8c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103014
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sw/inc/AccessibilityCheckStrings.hrc b/sw/inc/AccessibilityCheckStrings.hrc
index 5583d0fa6..73ac504 100644
--- a/sw/inc/AccessibilityCheckStrings.hrc
+++ b/sw/inc/AccessibilityCheckStrings.hrc
@@ -25,6 +25,7 @@
#define STR_TEXT_FORMATTING_CONVEYS_MEANING NC_("STR_TEXT_FORMATTING_CONVEYS_MEANING", "The text formatting conveys additional meaning.")
#define STR_NON_INTERACTIVE_FORMS NC_("STR_NON_INTERACTIVE_FORMS", "An input form is not interactive.")
#define STR_FLOATING_TEXT NC_("STR_FLOATING_TEXT", "Avoid floating text.")
#define STR_HEADING_IN_TABLE NC_("STR_HEADING_IN_TABLE", "Tables must not contain headings.")
#define STR_DOCUMENT_DEFAULT_LANGUAGE NC_("STR_DOCUMENT_DEFAULT_LANGUAGE", "Document default language is not set")
#define STR_STYLE_NO_LANGUAGE NC_("STR_STYLE_NO_LANGUAGE", "Style '%STYLE_NAME%' has no language set")
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index ea80341..1127f95 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -691,6 +691,40 @@ public:
}
};
/// Heading paragraphs (with outline levels > 0) are not allowed in tables
class TableHeadingCheck : public NodeCheck
{
private:
// Boolean indicaing if heading-in-table warning is already triggered.
bool bPrevPassed;
public:
TableHeadingCheck(sfx::AccessibilityIssueCollection& rIssueCollection)
: NodeCheck(rIssueCollection)
, bPrevPassed(true)
{
}
void check(SwNode* pCurrent) override
{
if (!bPrevPassed)
return;
const SwTextNode* textNode = pCurrent->GetTextNode();
if (textNode && textNode->GetAttrOutlineLevel() != 0)
{
const SwTableNode* parentTable = pCurrent->FindTableNode();
if (parentTable)
{
bPrevPassed = false;
lclAddIssue(m_rIssueCollection, SwResId(STR_HEADING_IN_TABLE));
}
}
}
};
class DocumentCheck : public BaseCheck
{
public:
@@ -843,6 +877,7 @@ void AccessibilityCheck::check()
aNodeChecks.push_back(std::make_unique<TextFormattingCheck>(m_aIssueCollection));
aNodeChecks.push_back(std::make_unique<NonInteractiveFormCheck>(m_aIssueCollection));
aNodeChecks.push_back(std::make_unique<FloatingTextCheck>(m_aIssueCollection));
aNodeChecks.push_back(std::make_unique<TableHeadingCheck>(m_aIssueCollection));
auto const& pNodes = m_pDoc->GetNodes();
SwNode* pNode = nullptr;