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

Node representing a HTML table row. More...

#include <src/docnode.h>

Inheritance diagram for DocHtmlRow:
Collaboration diagram for DocHtmlRow:

Public Member Functions

 DocHtmlRow (DocParser *parser, DocNodeVariant *parent, const HtmlAttribList &attribs)
size_t numCells () const
const HtmlAttribList & attribs () const
Token parse ()
Token parseXml (bool header)
bool isHeading () const
void setVisibleCells (uint32_t n)
uint32_t visibleCells () const
uint32_t rowIndex () 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 setRowIndex (uint32_t idx)

Private Attributes

HtmlAttribList m_attribs
uint32_t m_visibleCells = 0
uint32_t m_rowIdx = static_cast<uint32_t>(-1)

Friends

class DocHtmlTable

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 row.

Definition at line 1250 of file docnode.h.

Constructor & Destructor Documentation

◆ DocHtmlRow()

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

Definition at line 1254 of file docnode.h.

DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:141
HtmlAttribList m_attribs
Definition docnode.h:1267
const HtmlAttribList & attribs() const
Definition docnode.h:1257
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 & DocHtmlRow::attribs ( ) const
inline

Definition at line 1257 of file docnode.h.

1257{ return m_attribs; }

References m_attribs.

Referenced by DocHtmlRow(), DocbookDocVisitor::operator()(), and HtmlDocVisitor::operator()().

◆ isHeading()

bool DocHtmlRow::isHeading ( ) const

Definition at line 2096 of file docnode.cpp.

2097{ // a row is a table heading if all cells are marked as such
2098 bool heading=true;
2099 for (const auto &n : children())
2100 {
2101 const DocHtmlCell *cell = std::get_if<DocHtmlCell>(&n);
2102 if (cell && !cell->isHeading())
2103 {
2104 heading = false;
2105 break;
2106 }
2107 }
2108 return !children().empty() && heading;
2109}
DocNodeList & children()
Definition docnode.h:143
bool isHeading() const
Definition docnode.h:1205
bool empty() const
checks whether the container is empty
Definition growvector.h:140

References DocCompoundNode::children(), GrowVector< T >::empty(), and DocHtmlCell::isHeading().

Referenced by DocHtmlTable::numberHeaderRows(), DocbookDocVisitor::operator()(), RTFDocVisitor::operator()(), parse(), and parseXml().

◆ numCells()

size_t DocHtmlRow::numCells ( ) const
inline

Definition at line 1256 of file docnode.h.

1256{ 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 RTFDocVisitor::operator()().

◆ parse()

Token DocHtmlRow::parse ( )

Definition at line 2171 of file docnode.cpp.

2172{
2173 AUTO_TRACE();
2174 Token retval = Token::make_RetVal_OK();
2175 auto ns = AutoNodeStack(parser(),thisVariant());
2176
2177 bool isHeading=false;
2178 bool isFirst=true;
2179 DocHtmlCell *cell=nullptr;
2180
2181 Token tok = skipSpacesForTable(parser());
2182 // should find a html tag now
2183 if (tok.is(TokenRetval::TK_HTMLTAG))
2184 {
2185 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2186 if (tagId==HtmlTagType::HTML_TD && !parser()->context.token->endTag) // found <td> tag
2187 {
2188 }
2189 else if (tagId==HtmlTagType::HTML_TH && !parser()->context.token->endTag) // found <th> tag
2190 {
2191 isHeading=true;
2192 }
2193 else // found some other tag
2194 {
2195 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <td> or <th> tag but "
2196 "found <{}{}> instead!",parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2197 parser()->tokenizer.pushBackHtmlTag(parser()->context.token->name);
2198 goto endrow;
2199 }
2200 }
2201 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2202 {
2203 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2204 " for a html description title");
2205 goto endrow;
2206 }
2207 else // token other than html token
2208 {
2209 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <td> or <th> tag but found {} token instead!",
2210 tok.to_string());
2211 goto endrow;
2212 }
2213
2214 // parse one or more cells
2215 do
2216 {
2217 children().append<DocHtmlCell>(parser(),thisVariant(),
2219 isHeading);
2220 cell = children().get_last<DocHtmlCell>();
2221 cell->markFirst(isFirst);
2222 isFirst=false;
2223 retval=cell->parse();
2224 isHeading = retval.is(TokenRetval::RetVal_TableHCell);
2225 //printf("DocHtmlRow:retval=%s\n",retval.to_string());
2226 if (retval.is(TokenRetval::RetVal_EndTableCell))
2227 {
2228 // get next token
2229 retval = skipSpacesForTable(parser());
2230 //printf("DocHtmlRow:retval= next=%s name=%s endTag=%d\n",retval.to_string(),qPrint(parser()->context.token->name),parser()->context.token->endTag);
2231 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2232 if (tok.is(TokenRetval::TK_HTMLTAG))
2233 {
2234 if ((tagId==HtmlTagType::HTML_TD || tagId==HtmlTagType::HTML_TH) &&
2235 !parser()->context.token->endTag) // found new <td> or <td> tag
2236 {
2237 retval = Token::make_RetVal_TableCell();
2239 }
2240 else if (tagId==HtmlTagType::HTML_TR)
2241 {
2242 if (parser()->context.token->endTag) // found </tr> tag
2243 {
2244 retval = Token::make_RetVal_EndTableRow();
2245 }
2246 else // found <tr> tag
2247 {
2248 retval = Token::make_RetVal_TableRow();
2249 }
2250 }
2251 else if (tagId==HtmlTagType::HTML_TABLE && parser()->context.token->endTag) // found </table>
2252 {
2253 retval = Token::make_RetVal_EndTable();
2254 }
2255 else // found some other tag
2256 {
2257 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <td>, <th> or <tr> tag but "
2258 "found <{}{}> instead!",parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2259 parser()->tokenizer.pushBackHtmlTag(parser()->context.token->name);
2260 goto endrow;
2261 }
2262 }
2263 else // token other than html token
2264 {
2265 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <td>, <th> or <tr> tag but found {} token instead!",
2266 tok.to_string());
2267 goto endrow;
2268 }
2269 }
2270 }
2271 while (retval.is_any_of(TokenRetval::RetVal_TableCell,TokenRetval::RetVal_TableHCell));
2272 cell->markLast(true);
2273
2274endrow:
2275 return retval;
2276}
void markLast(bool v=true)
Definition docnode.h:1209
void markFirst(bool v=true)
Definition docnode.h:1208
Token parse()
Definition docnode.cpp:1944
bool isHeading() const
Definition docnode.cpp:2096
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
#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(), DocParser::context, DocNodeList::get_last(), HTML_TABLE, HTML_TD, HTML_TH, HTML_TR, Mappers::htmlTagMapper, Token::is(), Token::is_any_of(), isHeading(), DocHtmlCell::markFirst(), DocHtmlCell::markLast(), DocHtmlCell::parse(), DocNode::parser(), DocTokenizer::pushBackHtmlTag(), skipSpacesForTable(), DocNode::thisVariant(), Token::to_string(), DocParserContext::token, DocParser::tokenizer, and warn_doc_error.

◆ parseXml()

Token DocHtmlRow::parseXml ( bool header)

Definition at line 2278 of file docnode.cpp.

2279{
2280 AUTO_TRACE();
2281 Token retval = Token::make_RetVal_OK();
2282 auto ns = AutoNodeStack(parser(),thisVariant());
2283
2284 bool isFirst=true;
2285 DocHtmlCell *cell=nullptr;
2286
2287 // get next token
2288 Token tok=parser()->tokenizer.lex();
2289 // skip whitespace
2290 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2291 // should find a html tag now
2292 if (tok.is(TokenRetval::TK_HTMLTAG))
2293 {
2294 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2295 if (tagId==HtmlTagType::XML_TERM && !parser()->context.token->endTag) // found <term> tag
2296 {
2297 }
2298 else if (tagId==HtmlTagType::XML_DESCRIPTION && !parser()->context.token->endTag) // found <description> tag
2299 {
2300 }
2301 else // found some other tag
2302 {
2303 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <term> or <description> tag but "
2304 "found <{}> instead!",parser()->context.token->name);
2305 parser()->tokenizer.pushBackHtmlTag(parser()->context.token->name);
2306 goto endrow;
2307 }
2308 }
2309 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2310 {
2311 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2312 " for a html description title");
2313 goto endrow;
2314 }
2315 else // token other than html token
2316 {
2317 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <td> or <th> tag but found {} token instead!",
2318 tok.to_string());
2319 goto endrow;
2320 }
2321
2322 do
2323 {
2325 cell = children().get_last<DocHtmlCell>();
2326 cell->markFirst(isFirst);
2327 isFirst=false;
2328 retval=cell->parseXml();
2329 }
2330 while (retval.is_any_of(TokenRetval::RetVal_TableCell,TokenRetval::RetVal_TableHCell));
2331 cell->markLast(true);
2332
2333endrow:
2334 return retval;
2335}
Token parseXml()
Definition docnode.cpp:1978

References DocNodeList::append(), TokenInfo::attribs, AUTO_TRACE, DocCompoundNode::children(), DocParser::context, DocNodeList::get_last(), Mappers::htmlTagMapper, Token::is(), Token::is_any_of(), isHeading(), DocTokenizer::lex(), DocHtmlCell::markFirst(), DocHtmlCell::markLast(), DocNode::parser(), DocHtmlCell::parseXml(), DocTokenizer::pushBackHtmlTag(), DocNode::thisVariant(), Token::to_string(), DocParserContext::token, DocParser::tokenizer, warn_doc_error, XML_DESCRIPTION, and XML_TERM.

◆ rowIndex()

uint32_t DocHtmlRow::rowIndex ( ) const
inline

Definition at line 1263 of file docnode.h.

1263{ return m_rowIdx; }
uint32_t m_rowIdx
Definition docnode.h:1269

References m_rowIdx.

◆ setRowIndex()

void DocHtmlRow::setRowIndex ( uint32_t idx)
inlineprivate

Definition at line 1266 of file docnode.h.

1266{ m_rowIdx = idx; }

References m_rowIdx.

Referenced by DocHtmlTable::computeTableGrid().

◆ setVisibleCells()

void DocHtmlRow::setVisibleCells ( uint32_t n)
inline

Definition at line 1261 of file docnode.h.

1261{ m_visibleCells = n; }
uint32_t m_visibleCells
Definition docnode.h:1268

References m_visibleCells.

Referenced by DocHtmlTable::computeTableGrid().

◆ visibleCells()

uint32_t DocHtmlRow::visibleCells ( ) const
inline

Definition at line 1262 of file docnode.h.

1262{ return m_visibleCells; }

References m_visibleCells.

◆ DocHtmlTable

friend class DocHtmlTable
friend

Definition at line 1252 of file docnode.h.

References DocHtmlTable.

Referenced by DocHtmlTable.

Member Data Documentation

◆ m_attribs

HtmlAttribList DocHtmlRow::m_attribs
private

Definition at line 1267 of file docnode.h.

Referenced by attribs(), and DocHtmlRow().

◆ m_rowIdx

uint32_t DocHtmlRow::m_rowIdx = static_cast<uint32_t>(-1)
private

Definition at line 1269 of file docnode.h.

Referenced by rowIndex(), and setRowIndex().

◆ m_visibleCells

uint32_t DocHtmlRow::m_visibleCells = 0
private

Definition at line 1268 of file docnode.h.

Referenced by setVisibleCells(), and visibleCells().


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