Doxygen
Loading...
Searching...
No Matches
DocHtmlTable Class Reference

Node representing a HTML table. More...

#include <src/docnode.h>

+ Inheritance diagram for DocHtmlTable:
+ Collaboration diagram for DocHtmlTable:

Public Member Functions

 DocHtmlTable (DocParser *parser, DocNodeVariant *parent, const HtmlAttribList &attribs)
 
size_t numRows () const
 
bool hasCaption () const
 
const HtmlAttribListattribs () const
 
Token parse ()
 
Token parseXml ()
 
size_t numColumns () const
 
const DocNodeVariantcaption () const
 
const DocNodeVariantfirstRow () const
 
- Public Member Functions inherited from DocCompoundNode
 DocCompoundNode (DocParser *parser, DocNodeVariant *parent)
 
DocNodeListchildren ()
 
const DocNodeListchildren () const
 
- Public Member Functions inherited from DocNode
 DocNode (DocParser *parser, DocNodeVariant *parent)
 
 ~DocNode ()=default
 
DocNodeVariantparent ()
 
const DocNodeVariantparent () const
 
DocNodeVariantthisVariant ()
 
const DocNodeVariantthisVariant () const
 
void setThisVariant (DocNodeVariant *thisVariant)
 
DocParserparser ()
 
const DocParserparser () const
 
void setParent (DocNodeVariant *parent)
 
bool isPreformatted () const
 

Private Member Functions

void computeTableGrid ()
 determines the location of all cells in a grid, resolving row and column spans.
 

Private Attributes

std::unique_ptr< DocNodeVariantm_caption
 
HtmlAttribList m_attribs
 
size_t m_numCols = 0
 

Additional Inherited Members

- Protected Types inherited from DocNode
enum  RefType { Unknown , Anchor , Section , Table }
 
- Protected Member Functions inherited from DocNode
void setInsidePreformatted (bool p)
 

Detailed Description

Node representing a HTML table.

Definition at line 1262 of file docnode.h.

Constructor & Destructor Documentation

◆ DocHtmlTable()

DocHtmlTable::DocHtmlTable ( DocParser * parser,
DocNodeVariant * parent,
const HtmlAttribList & attribs )
inline

Definition at line 1265 of file docnode.h.

DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:140
const HtmlAttribList & attribs() const
Definition docnode.h:1269
HtmlAttribList m_attribs
Definition docnode.h:1279
DocParser * parser()
Definition docnode.h:97
DocNodeVariant * parent()
Definition docnode.h:89

References attribs(), DocCompoundNode::DocCompoundNode(), m_attribs, DocNode::parent(), and DocNode::parser().

Member Function Documentation

◆ attribs()

const HtmlAttribList & DocHtmlTable::attribs ( ) const
inline

Definition at line 1269 of file docnode.h.

1269{ return m_attribs; }

References m_attribs.

Referenced by DocHtmlTable(), HtmlDocVisitor::operator()(), and XmlDocVisitor::operator()().

◆ caption()

const DocNodeVariant * DocHtmlTable::caption ( ) const

◆ computeTableGrid()

void DocHtmlTable::computeTableGrid ( )
private

determines the location of all cells in a grid, resolving row and column spans.

For each the total number of visible cells is computed, and the total number of visible columns over all rows is stored.

Definition at line 2187 of file docnode.cpp.

2188{
2189 //printf("computeTableGrid()\n");
2190 RowSpanList rowSpans;
2191 uint32_t maxCols=0;
2192 uint32_t rowIdx=1;
2193 for (auto &rowNode : children())
2194 {
2195 uint32_t colIdx=1;
2196 uint32_t cells=0;
2197 DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2198 if (row)
2199 {
2200 for (auto &cellNode : row->children())
2201 {
2202 DocHtmlCell *cell = std::get_if<DocHtmlCell>(&cellNode);
2203 if (cell)
2204 {
2205 uint32_t rs = cell->rowSpan();
2206 uint32_t cs = cell->colSpan();
2207
2208 for (size_t i=0;i<rowSpans.size();i++)
2209 {
2210 if (rowSpans[i].rowsLeft>0 &&
2211 rowSpans[i].column==colIdx)
2212 {
2213 colIdx=rowSpans[i].column+1;
2214 cells++;
2215 }
2216 }
2217 if (rs>0) rowSpans.emplace_back(rs,colIdx);
2218 //printf("found cell at (%d,%d)\n",rowIdx,colIdx);
2219 cell->setRowIndex(rowIdx);
2220 cell->setColumnIndex(colIdx);
2221 colIdx+=cs;
2222 cells++;
2223 }
2224 }
2225 for (size_t i=0;i<rowSpans.size();i++)
2226 {
2227 if (rowSpans[i].rowsLeft>0) rowSpans[i].rowsLeft--;
2228 }
2229 row->setVisibleCells(cells);
2230 row->setRowIndex(rowIdx);
2231 rowIdx++;
2232 }
2233 if (colIdx-1>maxCols) maxCols=colIdx-1;
2234 }
2235 m_numCols = maxCols;
2236}
DocNodeList & children()
Definition docnode.h:142
void setColumnIndex(uint32_t idx)
Definition docnode.h:1211
void setRowIndex(uint32_t idx)
Definition docnode.h:1210
uint32_t rowSpan() const
Definition docnode.cpp:1808
uint32_t colSpan() const
Definition docnode.cpp:1820
void setVisibleCells(uint32_t n)
Definition docnode.h:1250
void setRowIndex(uint32_t idx)
Definition docnode.h:1255
size_t m_numCols
Definition docnode.h:1280
std::vector< ActiveRowSpan > RowSpanList
List of ActiveRowSpan classes.
Definition docnode.cpp:2181

References DocCompoundNode::children(), DocHtmlCell::colSpan(), m_numCols, DocHtmlCell::rowSpan(), DocHtmlCell::setColumnIndex(), DocHtmlCell::setRowIndex(), DocHtmlRow::setRowIndex(), and DocHtmlRow::setVisibleCells().

Referenced by parse(), and parseXml().

◆ firstRow()

const DocNodeVariant * DocHtmlTable::firstRow ( ) const

Definition at line 2043 of file docnode.cpp.

2044{
2045 if (!children().empty() && std::holds_alternative<DocHtmlRow>(children().front()))
2046 {
2047 return &children().front();
2048 }
2049 return nullptr;
2050}
T & front()
access the first element
Definition growvector.h:130

References DocCompoundNode::children(), and GrowVector< T >::front().

Referenced by LatexDocVisitor::operator()().

◆ hasCaption()

bool DocHtmlTable::hasCaption ( ) const

Definition at line 2033 of file docnode.cpp.

2034{
2035 return m_caption!=nullptr;
2036}

References m_caption.

◆ numColumns()

size_t DocHtmlTable::numColumns ( ) const
inline

◆ numRows()

size_t DocHtmlTable::numRows ( ) const
inline

Definition at line 1267 of file docnode.h.

1267{ return children().size(); }
size_t size() const
returns the number of elements
Definition growvector.h:93

References DocCompoundNode::children(), and GrowVector< T >::size().

Referenced by PerlModDocVisitor::operator()(), PrintDocVisitor::operator()(), and XmlDocVisitor::operator()().

◆ parse()

Token DocHtmlTable::parse ( )

Definition at line 2052 of file docnode.cpp.

2053{
2054 AUTO_TRACE();
2055 Token retval = Token::make_RetVal_OK();
2056 auto ns = AutoNodeStack(parser(),thisVariant());
2057
2058getrow:
2059 // get next token
2060 Token tok=parser()->tokenizer.lex();
2061 // skip whitespace
2062 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2063 // should find a html tag now
2064 if (tok.is(TokenRetval::TK_HTMLTAG))
2065 {
2066 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2067 if (tagId==HtmlTagType::HTML_THEAD && !parser()->context.token->endTag) // found <thead> tag
2068 {
2069 goto getrow;
2070 }
2071 else if (tagId==HtmlTagType::HTML_TBODY && !parser()->context.token->endTag) // found <tbody> tag
2072 {
2073 goto getrow;
2074 }
2075 else if (tagId==HtmlTagType::HTML_TFOOT && !parser()->context.token->endTag) // found <tfoot> tag
2076 {
2077 goto getrow;
2078 }
2079 else if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag) // found <tr> tag
2080 {
2081 // no caption, just rows
2082 retval = Token::make_RetVal_TableRow();
2083 }
2084 else if (tagId==HtmlTagType::HTML_CAPTION && !parser()->context.token->endTag) // found <caption> tag
2085 {
2086 if (m_caption)
2087 {
2088 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"table already has a caption, found another one");
2089 }
2090 else
2091 {
2092 m_caption = createDocNode<DocHtmlCaption>(parser(),thisVariant(),parser()->context.token->attribs);
2093 retval=std::get<DocHtmlCaption>(*m_caption).parse();
2094
2095 if (retval.is(TokenRetval::RetVal_OK)) // caption was parsed ok
2096 {
2097 goto getrow;
2098 }
2099 }
2100 }
2101 else // found wrong token
2102 {
2103 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or <caption> tag but "
2104 "found <{}{}> instead!", parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2105 }
2106 }
2107 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2108 {
2109 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2110 " for a <tr> or <caption> tag");
2111 }
2112 else // token other than html token
2113 {
2114 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> tag but found {} token instead!",
2115 tok.to_string());
2116 }
2117
2118 // parse one or more rows
2119 while (retval.is(TokenRetval::RetVal_TableRow))
2120 {
2122 retval = children().get_last<DocHtmlRow>()->parse();
2123 }
2124
2126
2127 return retval.is(TokenRetval::RetVal_EndTable) ? Token::make_RetVal_OK() : retval;
2128}
Token parse()
Definition docnode.cpp:2052
void computeTableGrid()
determines the location of all cells in a grid, resolving row and column spans.
Definition docnode.cpp:2187
DocNodeVariant * thisVariant()
Definition docnode.h:92
DocTokenizer tokenizer
DocParserContext context
bool is(TokenRetval rv) const
TOKEN_SPECIFICATIONS RETVAL_SPECIFICATIONS const char * to_string() const
bool is_any_of(ARGS... args) const
HtmlTagType
Definition cmdmapper.h:169
#define AUTO_TRACE(...)
Definition docnode.cpp:46
std::unique_ptr< DocNodeVariant > createDocNode(Args &&...args)
Definition docnode.h:1485
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
const Mapper< HtmlTagType > * htmlTagMapper
void append(Args &&... args)
Append a new DocNodeVariant to the list by constructing it with type T and parameters Args.
Definition docnode.h:1393
T * get_last()
Returns a pointer to the last element in the list if that element exists and holds a T,...
Definition docnode.h:1404
TokenInfo * token
Definition docparser_p.h:92
HtmlAttribList attribs

References DocNodeList::append(), TokenInfo::attribs, AUTO_TRACE, DocCompoundNode::children(), computeTableGrid(), DocParser::context, createDocNode(), DocNodeList::get_last(), HTML_CAPTION, HTML_TBODY, HTML_TFOOT, HTML_THEAD, HTML_TR, Mappers::htmlTagMapper, Token::is(), Token::is_any_of(), DocTokenizer::lex(), m_caption, parse(), DocNode::parser(), DocNode::thisVariant(), Token::to_string(), DocParserContext::token, DocParser::tokenizer, and warn_doc_error.

Referenced by parse().

◆ parseXml()

Token DocHtmlTable::parseXml ( )

Definition at line 2130 of file docnode.cpp.

2131{
2132 AUTO_TRACE();
2133 Token retval = Token::make_RetVal_OK();
2134 auto ns = AutoNodeStack(parser(),thisVariant());
2135
2136 // get next token
2137 Token tok=parser()->tokenizer.lex();
2138 // skip whitespace
2139 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2140 // should find a html tag now
2142 bool isHeader=FALSE;
2143 if (tok.is(TokenRetval::TK_HTMLTAG))
2144 {
2145 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2146 if (tagId==HtmlTagType::XML_ITEM && !parser()->context.token->endTag) // found <item> tag
2147 {
2148 retval = Token::make_RetVal_TableRow();
2149 }
2150 if (tagId==HtmlTagType::XML_LISTHEADER && !parser()->context.token->endTag) // found <listheader> tag
2151 {
2152 retval = Token::make_RetVal_TableRow();
2153 isHeader=TRUE;
2154 }
2155 }
2156
2157 // parse one or more rows
2158 while (retval.is(TokenRetval::RetVal_TableRow))
2159 {
2161 DocHtmlRow *tr = children().get_last<DocHtmlRow>();
2162 retval=tr->parseXml(isHeader);
2163 isHeader=FALSE;
2164 }
2165
2167
2168 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2169 return tagId==HtmlTagType::XML_LIST && parser()->context.token->endTag ? Token::make_RetVal_OK() : retval;
2170}
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

References DocNodeList::append(), TokenInfo::attribs, AUTO_TRACE, DocCompoundNode::children(), computeTableGrid(), DocParser::context, TokenInfo::endTag, FALSE, DocNodeList::get_last(), Mappers::htmlTagMapper, Token::is(), Token::is_any_of(), DocTokenizer::lex(), DocNode::parser(), DocNode::thisVariant(), DocParserContext::token, DocParser::tokenizer, TRUE, UNKNOWN, XML_ITEM, XML_LIST, and XML_LISTHEADER.

Member Data Documentation

◆ m_attribs

HtmlAttribList DocHtmlTable::m_attribs
private

Definition at line 1279 of file docnode.h.

Referenced by attribs(), and DocHtmlTable().

◆ m_caption

std::unique_ptr<DocNodeVariant> DocHtmlTable::m_caption
private

Definition at line 1278 of file docnode.h.

Referenced by caption(), hasCaption(), and parse().

◆ m_numCols

size_t DocHtmlTable::m_numCols = 0
private

Definition at line 1280 of file docnode.h.

Referenced by computeTableGrid(), and numColumns().


The documentation for this class was generated from the following files: