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
size_t numberHeaderRows () 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 1268 of file docnode.h.

Constructor & Destructor Documentation

◆ DocHtmlTable()

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

Definition at line 1271 of file docnode.h.

DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:141
const HtmlAttribList & attribs() const
Definition docnode.h:1275
HtmlAttribList m_attribs
Definition docnode.h:1285
DocParser * parser()
Definition docnode.h:98
DocNodeVariant * parent()
Definition docnode.h:90

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

Member Function Documentation

◆ attribs()

const HtmlAttribList & DocHtmlTable::attribs ( ) const
inline

Definition at line 1275 of file docnode.h.

1275{ 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 2346 of file docnode.cpp.

2347{
2348 //printf("computeTableGrid()\n");
2349 RowSpanList rowSpans;
2350 uint32_t maxCols=0;
2351 uint32_t rowIdx=1;
2352 for (auto &rowNode : children())
2353 {
2354 uint32_t colIdx=1;
2355 uint32_t cells=0;
2356 DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2357 if (row)
2358 {
2359 for (auto &cellNode : row->children())
2360 {
2361 DocHtmlCell *cell = std::get_if<DocHtmlCell>(&cellNode);
2362 if (cell)
2363 {
2364 uint32_t rs = cell->rowSpan();
2365 uint32_t cs = cell->colSpan();
2366
2367 for (size_t i=0;i<rowSpans.size();i++)
2368 {
2369 if (rowSpans[i].rowsLeft>0 &&
2370 rowSpans[i].column==colIdx)
2371 {
2372 colIdx=rowSpans[i].column+1;
2373 cells++;
2374 }
2375 }
2376 if (rs>0) rowSpans.emplace_back(rs,colIdx);
2377 //printf("found cell at (%d,%d)\n",rowIdx,colIdx);
2378 cell->setRowIndex(rowIdx);
2379 cell->setColumnIndex(colIdx);
2380 colIdx+=cs;
2381 cells++;
2382 }
2383 }
2384 for (size_t i=0;i<rowSpans.size();i++)
2385 {
2386 if (rowSpans[i].rowsLeft>0) rowSpans[i].rowsLeft--;
2387 }
2388 row->setVisibleCells(cells);
2389 row->setRowIndex(rowIdx);
2390 rowIdx++;
2391 }
2392 if (colIdx-1>maxCols) maxCols=colIdx-1;
2393 }
2394 m_numCols = maxCols;
2395}
DocNodeList & children()
Definition docnode.h:143
void setColumnIndex(uint32_t idx)
Definition docnode.h:1217
void setRowIndex(uint32_t idx)
Definition docnode.h:1216
uint32_t rowSpan() const
Definition docnode.cpp:1850
uint32_t colSpan() const
Definition docnode.cpp:1862
void setVisibleCells(uint32_t n)
Definition docnode.h:1256
void setRowIndex(uint32_t idx)
Definition docnode.h:1261
size_t m_numCols
Definition docnode.h:1286
std::vector< ActiveRowSpan > RowSpanList
List of ActiveRowSpan classes.
Definition docnode.cpp:2340

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

Referenced by parse(), and parseXml().

◆ hasCaption()

bool DocHtmlTable::hasCaption ( ) const

Definition at line 2177 of file docnode.cpp.

2178{
2179 return m_caption!=nullptr;
2180}

References m_caption.

◆ numberHeaderRows()

size_t DocHtmlTable::numberHeaderRows ( ) const

Definition at line 2187 of file docnode.cpp.

2188{
2189 size_t hl = 0;
2190 for (auto &rowNode : children())
2191 {
2192 const DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2193 if (row)
2194 {
2195 if (!row->isHeading()) break;
2196 hl++;
2197 }
2198 }
2199 return hl;
2200}
bool isHeading() const
Definition docnode.cpp:1934

References DocCompoundNode::children(), and DocHtmlRow::isHeading().

Referenced by LatexDocVisitor::operator()().

◆ numColumns()

size_t DocHtmlTable::numColumns ( ) const
inline

◆ numRows()

size_t DocHtmlTable::numRows ( ) const
inline

Definition at line 1273 of file docnode.h.

1273{ 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 2202 of file docnode.cpp.

2203{
2204 AUTO_TRACE();
2205 Token retval = Token::make_RetVal_OK();
2206 auto ns = AutoNodeStack(parser(),thisVariant());
2207
2208getrow:
2209 // skip whitespace and tbody, thead and tfoot tags
2210 Token tok = skipSpacesForTable(parser());
2211 // should find a html tag now
2212 if (tok.is(TokenRetval::TK_HTMLTAG))
2213 {
2214 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2215 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag) // found <tr> tag
2216 {
2217 // no caption, just rows
2218 retval = Token::make_RetVal_TableRow();
2219 }
2220 else if (tagId==HtmlTagType::HTML_CAPTION && !parser()->context.token->endTag) // found <caption> tag
2221 {
2222 if (m_caption)
2223 {
2224 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"table already has a caption, found another one");
2225 }
2226 else
2227 {
2228 m_caption = createDocNode<DocHtmlCaption>(parser(),thisVariant(),parser()->context.token->attribs);
2229 retval=std::get<DocHtmlCaption>(*m_caption).parse();
2230
2231 if (retval.is(TokenRetval::RetVal_OK)) // caption was parsed ok
2232 {
2233 goto getrow;
2234 }
2235 }
2236 }
2237 else // found wrong token
2238 {
2239 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or <caption> tag but "
2240 "found <{}{}> instead!", parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2241 }
2242 }
2243 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2244 {
2245 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2246 " for a <tr> or <caption> tag");
2247 }
2248 else // token other than html token
2249 {
2250 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> tag but found {} token instead!",
2251 tok.to_string());
2252 }
2253
2254 // parse one or more rows
2255 while (retval.is(TokenRetval::RetVal_TableRow))
2256 {
2258 retval = children().get_last<DocHtmlRow>()->parse();
2259 //printf("DocHtmlTable::retval=%s\n",retval.to_string());
2260 if (retval.is(TokenRetval::RetVal_EndTableRow))
2261 {
2262 // get next token
2263 retval = skipSpacesForTable(parser());
2264 //printf("DocHtmlTable::retval= next=%s name=%s endTag=%d\n",retval.to_string(),qPrint(parser()->context.token->name),parser()->context.token->endTag);
2265 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2266 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag)
2267 {
2268 retval = Token::make_RetVal_TableRow();
2269 }
2270 else if (tagId==HtmlTagType::HTML_TABLE && parser()->context.token->endTag)
2271 {
2272 retval = Token::make_RetVal_EndTable();
2273 }
2274 else // found some other tag
2275 {
2276 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or </table> tag but "
2277 "found token {} instead!",retval.to_string());
2278 retval=Token::make_RetVal_OK();
2279 break;
2280 }
2281 }
2282 }
2283
2285
2286 return retval.is(TokenRetval::RetVal_EndTable) ? Token::make_RetVal_OK() : retval;
2287}
Token parse()
Definition docnode.cpp:2202
void computeTableGrid()
determines the location of all cells in a grid, resolving row and column spans.
Definition docnode.cpp:2346
DocNodeVariant * thisVariant()
Definition docnode.h:93
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
static Token skipSpacesForTable(DocParser *parser)
Definition docnode.cpp:1949
std::unique_ptr< DocNodeVariant > createDocNode(Args &&...args)
Definition docnode.h:1495
#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:1399
T * get_last()
Returns a pointer to the last element in the list if that element exists and holds a T,...
Definition docnode.h:1410
TokenInfo * token
Definition docparser_p.h:93
HtmlAttribList attribs

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

Referenced by parse().

◆ parseXml()

Token DocHtmlTable::parseXml ( )

Definition at line 2289 of file docnode.cpp.

2290{
2291 AUTO_TRACE();
2292 Token retval = Token::make_RetVal_OK();
2293 auto ns = AutoNodeStack(parser(),thisVariant());
2294
2295 // get next token
2296 Token tok=parser()->tokenizer.lex();
2297 // skip whitespace
2298 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2299 // should find a html tag now
2301 bool isHeader=FALSE;
2302 if (tok.is(TokenRetval::TK_HTMLTAG))
2303 {
2304 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2305 if (tagId==HtmlTagType::XML_ITEM && !parser()->context.token->endTag) // found <item> tag
2306 {
2307 retval = Token::make_RetVal_TableRow();
2308 }
2309 if (tagId==HtmlTagType::XML_LISTHEADER && !parser()->context.token->endTag) // found <listheader> tag
2310 {
2311 retval = Token::make_RetVal_TableRow();
2312 isHeader=TRUE;
2313 }
2314 }
2315
2316 // parse one or more rows
2317 while (retval.is(TokenRetval::RetVal_TableRow))
2318 {
2320 DocHtmlRow *tr = children().get_last<DocHtmlRow>();
2321 retval=tr->parseXml(isHeader);
2322 isHeader=FALSE;
2323 }
2324
2326
2327 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2328 return tagId==HtmlTagType::XML_LIST && parser()->context.token->endTag ? Token::make_RetVal_OK() : retval;
2329}
DocTokenizer tokenizer
#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 1285 of file docnode.h.

Referenced by attribs(), and DocHtmlTable().

◆ m_caption

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

Definition at line 1284 of file docnode.h.

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

◆ m_numCols

size_t DocHtmlTable::m_numCols = 0
private

Definition at line 1286 of file docnode.h.

Referenced by computeTableGrid(), and numColumns().


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