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

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 HtmlAttribList & attribs () const
Token parse ()
Token parseXml ()
size_t numColumns () const
const DocNodeVariant * caption () const
size_t numberHeaderRows () const
Public Member Functions inherited from DocCompoundNode
 DocCompoundNode (DocParser *parser, DocNodeVariant *parent)
DocNodeList & children ()
const DocNodeList & children () const
Public Member Functions inherited from DocNode
 DocNode (DocParser *parser, DocNodeVariant *parent)
 ~DocNode ()=default
DocNodeVariant * parent ()
const DocNodeVariant * parent () const
DocNodeVariant * thisVariant ()
const DocNodeVariant * thisVariant () const
void setThisVariant (DocNodeVariant *thisVariant)
DocParser * parser ()
const DocParser * parser () 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< DocNodeVariant > m_caption
HtmlAttribList m_attribs
size_t m_numCols = 0

Additional Inherited Members

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

Detailed Description

Node representing a HTML table.

Definition at line 1273 of file docnode.h.

Constructor & Destructor Documentation

◆ DocHtmlTable()

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

Definition at line 1276 of file docnode.h.

DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:141
const HtmlAttribList & attribs() const
Definition docnode.h:1280
HtmlAttribList m_attribs
Definition docnode.h:1290
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 1280 of file docnode.h.

1280{ 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 2514 of file docnode.cpp.

2515{
2516 //printf("computeTableGrid()\n");
2517 RowSpanList rowSpans;
2518 uint32_t maxCols=0;
2519 uint32_t rowIdx=1;
2520 for (auto &rowNode : children())
2521 {
2522 uint32_t colIdx=1;
2523 uint32_t cells=0;
2524 DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2525 if (row)
2526 {
2527 for (auto &cellNode : row->children())
2528 {
2529 DocHtmlCell *cell = std::get_if<DocHtmlCell>(&cellNode);
2530 if (cell)
2531 {
2532 uint32_t rs = cell->rowSpan();
2533 uint32_t cs = cell->colSpan();
2534
2535 for (size_t i=0;i<rowSpans.size();i++)
2536 {
2537 if (rowSpans[i].rowsLeft>0 &&
2538 rowSpans[i].column==colIdx)
2539 {
2540 colIdx=rowSpans[i].column+1;
2541 cells++;
2542 }
2543 }
2544 if (rs>0) rowSpans.emplace_back(rs,colIdx);
2545 //printf("found cell at (%d,%d)\n",rowIdx,colIdx);
2546 cell->setRowIndex(rowIdx);
2547 cell->setColumnIndex(colIdx);
2548 colIdx+=cs;
2549 cells++;
2550 }
2551 }
2552 for (size_t i=0;i<rowSpans.size();i++)
2553 {
2554 if (rowSpans[i].rowsLeft>0) rowSpans[i].rowsLeft--;
2555 }
2556 row->setVisibleCells(cells);
2557 row->setRowIndex(rowIdx);
2558 rowIdx++;
2559 }
2560 if (colIdx-1>maxCols) maxCols=colIdx-1;
2561 }
2562 m_numCols = maxCols;
2563}
DocNodeList & children()
Definition docnode.h:143
void setColumnIndex(uint32_t idx)
Definition docnode.h:1222
void setRowIndex(uint32_t idx)
Definition docnode.h:1221
uint32_t rowSpan() const
Definition docnode.cpp:2012
uint32_t colSpan() const
Definition docnode.cpp:2024
void setVisibleCells(uint32_t n)
Definition docnode.h:1261
void setRowIndex(uint32_t idx)
Definition docnode.h:1266
size_t m_numCols
Definition docnode.h:1291
std::vector< ActiveRowSpan > RowSpanList
List of ActiveRowSpan classes.
Definition docnode.cpp:2508

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 2339 of file docnode.cpp.

2340{
2341 return m_caption!=nullptr;
2342}

References m_caption.

◆ numberHeaderRows()

size_t DocHtmlTable::numberHeaderRows ( ) const

Definition at line 2349 of file docnode.cpp.

2350{
2351 size_t hl = 0;
2352 for (auto &rowNode : children())
2353 {
2354 const DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2355 if (row)
2356 {
2357 if (!row->isHeading()) break;
2358 hl++;
2359 }
2360 }
2361 return hl;
2362}
bool isHeading() const
Definition docnode.cpp:2096

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 1278 of file docnode.h.

1278{ 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 2364 of file docnode.cpp.

2365{
2366 AUTO_TRACE();
2367 Token retval = Token::make_RetVal_OK();
2368 auto ns = AutoNodeStack(parser(),thisVariant());
2369
2370getrow:
2371 // skip whitespace and tbody, thead and tfoot tags
2372 Token tok = skipSpacesForTable(parser());
2373 // should find a html tag now
2374 if (tok.is(TokenRetval::TK_HTMLTAG))
2375 {
2376 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2377 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag) // found <tr> tag
2378 {
2379 // no caption, just rows
2380 retval = Token::make_RetVal_TableRow();
2381 }
2382 else if (tagId==HtmlTagType::HTML_CAPTION && !parser()->context.token->endTag) // found <caption> tag
2383 {
2384 if (m_caption)
2385 {
2386 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"table already has a caption, found another one");
2387 }
2388 else
2389 {
2390 m_caption = createDocNode<DocHtmlCaption>(parser(),thisVariant(),parser()->context.token->attribs);
2391 retval=std::get<DocHtmlCaption>(*m_caption).parse();
2392
2393 if (retval.is(TokenRetval::RetVal_OK)) // caption was parsed ok
2394 {
2395 goto getrow;
2396 }
2397 }
2398 }
2399 else // found wrong token
2400 {
2401 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or <caption> tag but "
2402 "found <{}{}> instead!", parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2403 }
2404 }
2405 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2406 {
2407 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2408 " for a <tr> or <caption> tag");
2409 }
2410 else // token other than html token
2411 {
2412 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> tag but found {} token instead!",
2413 tok.to_string());
2414 }
2415
2416 // parse one or more rows
2417 while (retval.is(TokenRetval::RetVal_TableRow))
2418 {
2420 retval = children().get_last<DocHtmlRow>()->parse();
2421 //printf("DocHtmlTable::retval=%s\n",retval.to_string());
2422 if (retval.is(TokenRetval::RetVal_EndTableRow))
2423 {
2424 // get next token
2425 retval = skipSpacesForTable(parser());
2426 //printf("DocHtmlTable::retval= next=%s name=%s endTag=%d\n",retval.to_string(),qPrint(parser()->context.token->name),parser()->context.token->endTag);
2427 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2428 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag)
2429 {
2430 retval = Token::make_RetVal_TableRow();
2431 }
2432 else if (tagId==HtmlTagType::HTML_TABLE && parser()->context.token->endTag)
2433 {
2434 retval = Token::make_RetVal_EndTable();
2435 }
2436 else if (retval.is(TokenRetval::TK_HTMLTAG)) // some other HTML tag
2437 {
2438 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or </table> tag but "
2439 "found <{}> instead!",parser()->context.token->name);
2440 parser()->tokenizer.pushBackHtmlTag(parser()->context.token->name);
2441 }
2442 else // found some other tag
2443 {
2444 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or </table> tag but "
2445 "found token {} instead!",retval.to_string());
2446 retval=Token::make_RetVal_OK();
2447 break;
2448 }
2449 }
2450 }
2451
2453
2454 return retval.is(TokenRetval::RetVal_EndTable) ? Token::make_RetVal_OK() : retval;
2455}
Token parse()
Definition docnode.cpp:2364
void computeTableGrid()
determines the location of all cells in a grid, resolving row and column spans.
Definition docnode.cpp:2514
DocNodeVariant * thisVariant()
Definition docnode.h:92
void append(Args &&... args)
Append a new DocNodeVariant to the list by constructing it with type T and parameters Args.
Definition docnode.h:1404
T * get_last()
Returns a pointer to the last element in the list if that element exists and holds a T,...
Definition docnode.h:1415
DocTokenizer tokenizer
DocParserContext context
void pushBackHtmlTag(const DString &tag)
bool is(TokenRetval rv) const
TOKEN_SPECIFICATIONS RETVAL_SPECIFICATIONS const char * to_string() const
bool is_any_of(ARGS... args) const
HtmlAttribList attribs
HtmlTagType
Definition cmdmapper.h:174
#define AUTO_TRACE(...)
Definition docnode.cpp:53
static Token skipSpacesForTable(DocParser *parser)
Definition docnode.cpp:2111
std::unique_ptr< DocNodeVariant > createDocNode(Args &&...args)
Definition docnode.h:1500
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
const Mapper< HtmlTagType > * htmlTagMapper
TokenInfo * token
Definition docparser_p.h:94

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(), DocTokenizer::pushBackHtmlTag(), skipSpacesForTable(), DocNode::thisVariant(), Token::to_string(), DocParserContext::token, DocParser::tokenizer, and warn_doc_error.

Referenced by parse().

◆ parseXml()

Token DocHtmlTable::parseXml ( )

Definition at line 2457 of file docnode.cpp.

2458{
2459 AUTO_TRACE();
2460 Token retval = Token::make_RetVal_OK();
2461 auto ns = AutoNodeStack(parser(),thisVariant());
2462
2463 // get next token
2464 Token tok=parser()->tokenizer.lex();
2465 // skip whitespace
2466 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2467 // should find a html tag now
2469 bool isHeader=false;
2470 if (tok.is(TokenRetval::TK_HTMLTAG))
2471 {
2472 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2473 if (tagId==HtmlTagType::XML_ITEM && !parser()->context.token->endTag) // found <item> tag
2474 {
2475 retval = Token::make_RetVal_TableRow();
2476 }
2477 if (tagId==HtmlTagType::XML_LISTHEADER && !parser()->context.token->endTag) // found <listheader> tag
2478 {
2479 retval = Token::make_RetVal_TableRow();
2480 isHeader=true;
2481 }
2482 }
2483
2484 // parse one or more rows
2485 while (retval.is(TokenRetval::RetVal_TableRow))
2486 {
2488 DocHtmlRow *tr = children().get_last<DocHtmlRow>();
2489 retval=tr->parseXml(isHeader);
2490 isHeader=false;
2491 }
2492
2494
2495 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2496 return tagId==HtmlTagType::XML_LIST && parser()->context.token->endTag ? Token::make_RetVal_OK() : retval;
2497}

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

Member Data Documentation

◆ m_attribs

HtmlAttribList DocHtmlTable::m_attribs
private

Definition at line 1290 of file docnode.h.

Referenced by attribs(), and DocHtmlTable().

◆ m_caption

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

Definition at line 1289 of file docnode.h.

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

◆ m_numCols

size_t DocHtmlTable::m_numCols = 0
private

Definition at line 1291 of file docnode.h.

Referenced by computeTableGrid(), and numColumns().


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