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 ,
  Requirement
}
Protected Member Functions inherited from DocNode
void setInsidePreformatted (bool p)

Detailed Description

Node representing a HTML table.

Definition at line 1265 of file docnode.h.

Constructor & Destructor Documentation

◆ DocHtmlTable()

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

Definition at line 1268 of file docnode.h.

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

1272{ 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 2378 of file docnode.cpp.

2379{
2380 //printf("computeTableGrid()\n");
2381 RowSpanList rowSpans;
2382 uint32_t maxCols=0;
2383 uint32_t rowIdx=1;
2384 for (auto &rowNode : children())
2385 {
2386 uint32_t colIdx=1;
2387 uint32_t cells=0;
2388 DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2389 if (row)
2390 {
2391 for (auto &cellNode : row->children())
2392 {
2393 DocHtmlCell *cell = std::get_if<DocHtmlCell>(&cellNode);
2394 if (cell)
2395 {
2396 uint32_t rs = cell->rowSpan();
2397 uint32_t cs = cell->colSpan();
2398
2399 for (size_t i=0;i<rowSpans.size();i++)
2400 {
2401 if (rowSpans[i].rowsLeft>0 &&
2402 rowSpans[i].column==colIdx)
2403 {
2404 colIdx=rowSpans[i].column+1;
2405 cells++;
2406 }
2407 }
2408 if (rs>0) rowSpans.emplace_back(rs,colIdx);
2409 //printf("found cell at (%d,%d)\n",rowIdx,colIdx);
2410 cell->setRowIndex(rowIdx);
2411 cell->setColumnIndex(colIdx);
2412 colIdx+=cs;
2413 cells++;
2414 }
2415 }
2416 for (size_t i=0;i<rowSpans.size();i++)
2417 {
2418 if (rowSpans[i].rowsLeft>0) rowSpans[i].rowsLeft--;
2419 }
2420 row->setVisibleCells(cells);
2421 row->setRowIndex(rowIdx);
2422 rowIdx++;
2423 }
2424 if (colIdx-1>maxCols) maxCols=colIdx-1;
2425 }
2426 m_numCols = maxCols;
2427}
DocNodeList & children()
Definition docnode.h:143
void setColumnIndex(uint32_t idx)
Definition docnode.h:1214
void setRowIndex(uint32_t idx)
Definition docnode.h:1213
uint32_t rowSpan() const
Definition docnode.cpp:1876
uint32_t colSpan() const
Definition docnode.cpp:1888
void setVisibleCells(uint32_t n)
Definition docnode.h:1253
void setRowIndex(uint32_t idx)
Definition docnode.h:1258
size_t m_numCols
Definition docnode.h:1283
std::vector< ActiveRowSpan > RowSpanList
List of ActiveRowSpan classes.
Definition docnode.cpp:2372

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

2204{
2205 return m_caption!=nullptr;
2206}

References m_caption.

◆ numberHeaderRows()

size_t DocHtmlTable::numberHeaderRows ( ) const

Definition at line 2213 of file docnode.cpp.

2214{
2215 size_t hl = 0;
2216 for (auto &rowNode : children())
2217 {
2218 const DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2219 if (row)
2220 {
2221 if (!row->isHeading()) break;
2222 hl++;
2223 }
2224 }
2225 return hl;
2226}
bool isHeading() const
Definition docnode.cpp:1960

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

1270{ 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 2228 of file docnode.cpp.

2229{
2230 AUTO_TRACE();
2231 Token retval = Token::make_RetVal_OK();
2232 auto ns = AutoNodeStack(parser(),thisVariant());
2233
2234getrow:
2235 // skip whitespace and tbody, thead and tfoot tags
2236 Token tok = skipSpacesForTable(parser());
2237 // should find a html tag now
2238 if (tok.is(TokenRetval::TK_HTMLTAG))
2239 {
2240 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2241 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag) // found <tr> tag
2242 {
2243 // no caption, just rows
2244 retval = Token::make_RetVal_TableRow();
2245 }
2246 else if (tagId==HtmlTagType::HTML_CAPTION && !parser()->context.token->endTag) // found <caption> tag
2247 {
2248 if (m_caption)
2249 {
2250 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"table already has a caption, found another one");
2251 }
2252 else
2253 {
2254 m_caption = createDocNode<DocHtmlCaption>(parser(),thisVariant(),parser()->context.token->attribs);
2255 retval=std::get<DocHtmlCaption>(*m_caption).parse();
2256
2257 if (retval.is(TokenRetval::RetVal_OK)) // caption was parsed ok
2258 {
2259 goto getrow;
2260 }
2261 }
2262 }
2263 else // found wrong token
2264 {
2265 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or <caption> tag but "
2266 "found <{}{}> instead!", parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2267 }
2268 }
2269 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2270 {
2271 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2272 " for a <tr> or <caption> tag");
2273 }
2274 else // token other than html token
2275 {
2276 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> tag but found {} token instead!",
2277 tok.to_string());
2278 }
2279
2280 // parse one or more rows
2281 while (retval.is(TokenRetval::RetVal_TableRow))
2282 {
2284 retval = children().get_last<DocHtmlRow>()->parse();
2285 //printf("DocHtmlTable::retval=%s\n",retval.to_string());
2286 if (retval.is(TokenRetval::RetVal_EndTableRow))
2287 {
2288 // get next token
2289 retval = skipSpacesForTable(parser());
2290 //printf("DocHtmlTable::retval= next=%s name=%s endTag=%d\n",retval.to_string(),qPrint(parser()->context.token->name),parser()->context.token->endTag);
2291 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2292 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag)
2293 {
2294 retval = Token::make_RetVal_TableRow();
2295 }
2296 else if (tagId==HtmlTagType::HTML_TABLE && parser()->context.token->endTag)
2297 {
2298 retval = Token::make_RetVal_EndTable();
2299 }
2300 else if (retval.is(TokenRetval::TK_HTMLTAG)) // some other HTML tag
2301 {
2302 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or </table> tag but "
2303 "found <{}> instead!",parser()->context.token->name);
2304 parser()->tokenizer.pushBackHtmlTag(parser()->context.token->name);
2305 }
2306 else // found some other tag
2307 {
2308 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or </table> tag but "
2309 "found token {} instead!",retval.to_string());
2310 retval=Token::make_RetVal_OK();
2311 break;
2312 }
2313 }
2314 }
2315
2317
2318 return retval.is(TokenRetval::RetVal_EndTable) ? Token::make_RetVal_OK() : retval;
2319}
Token parse()
Definition docnode.cpp:2228
void computeTableGrid()
determines the location of all cells in a grid, resolving row and column spans.
Definition docnode.cpp:2378
DocNodeVariant * thisVariant()
Definition docnode.h:93
DocTokenizer tokenizer
DocParserContext context
void pushBackHtmlTag(const QCString &tag)
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:170
#define AUTO_TRACE(...)
Definition docnode.cpp:47
static Token skipSpacesForTable(DocParser *parser)
Definition docnode.cpp:1975
std::unique_ptr< DocNodeVariant > createDocNode(Args &&...args)
Definition docnode.h:1492
#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:1396
T * get_last()
Returns a pointer to the last element in the list if that element exists and holds a T,...
Definition docnode.h:1407
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(), 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 2321 of file docnode.cpp.

2322{
2323 AUTO_TRACE();
2324 Token retval = Token::make_RetVal_OK();
2325 auto ns = AutoNodeStack(parser(),thisVariant());
2326
2327 // get next token
2328 Token tok=parser()->tokenizer.lex();
2329 // skip whitespace
2330 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2331 // should find a html tag now
2333 bool isHeader=FALSE;
2334 if (tok.is(TokenRetval::TK_HTMLTAG))
2335 {
2336 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2337 if (tagId==HtmlTagType::XML_ITEM && !parser()->context.token->endTag) // found <item> tag
2338 {
2339 retval = Token::make_RetVal_TableRow();
2340 }
2341 if (tagId==HtmlTagType::XML_LISTHEADER && !parser()->context.token->endTag) // found <listheader> tag
2342 {
2343 retval = Token::make_RetVal_TableRow();
2344 isHeader=TRUE;
2345 }
2346 }
2347
2348 // parse one or more rows
2349 while (retval.is(TokenRetval::RetVal_TableRow))
2350 {
2352 DocHtmlRow *tr = children().get_last<DocHtmlRow>();
2353 retval=tr->parseXml(isHeader);
2354 isHeader=FALSE;
2355 }
2356
2358
2359 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2360 return tagId==HtmlTagType::XML_LIST && parser()->context.token->endTag ? Token::make_RetVal_OK() : retval;
2361}
#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 1282 of file docnode.h.

Referenced by attribs(), and DocHtmlTable().

◆ m_caption

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

Definition at line 1281 of file docnode.h.

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

◆ m_numCols

size_t DocHtmlTable::m_numCols = 0
private

Definition at line 1283 of file docnode.h.

Referenced by computeTableGrid(), and numColumns().


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