📄 dochandler.cpp
字号:
/****************************************************************************** * * $Id: $ * * * Copyright (C) 1997-2001 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * */#include "dochandler.h"#include <qmap.h>class TypeNameMapper{ public: TypeNameMapper() { m_typeNameMap.insert("see", SimpleSectHandler::See); m_typeNameMap.insert("return", SimpleSectHandler::Return); m_typeNameMap.insert("author", SimpleSectHandler::Author); m_typeNameMap.insert("version", SimpleSectHandler::Version); m_typeNameMap.insert("since", SimpleSectHandler::Since); m_typeNameMap.insert("date", SimpleSectHandler::Date); m_typeNameMap.insert("bug", SimpleSectHandler::Bug); m_typeNameMap.insert("note", SimpleSectHandler::Note); m_typeNameMap.insert("warning", SimpleSectHandler::Warning); m_typeNameMap.insert("par", SimpleSectHandler::Par); m_typeNameMap.insert("deprecated",SimpleSectHandler::Deprecated); m_typeNameMap.insert("pre", SimpleSectHandler::Pre); m_typeNameMap.insert("post", SimpleSectHandler::Post); m_typeNameMap.insert("invariant", SimpleSectHandler::Invar); m_typeNameMap.insert("remark", SimpleSectHandler::Remark); m_typeNameMap.insert("attention", SimpleSectHandler::Attention); m_typeNameMap.insert("todo", SimpleSectHandler::Todo); m_typeNameMap.insert("test", SimpleSectHandler::Test); m_typeNameMap.insert("rcs", SimpleSectHandler::RCS); m_typeNameMap.insert("enumvalues",SimpleSectHandler::EnumValues); m_typeNameMap.insert("examples", SimpleSectHandler::Examples); } SimpleSectHandler::Types stringToType(const QString &typeStr) { return m_typeNameMap[typeStr]; } private: QMap<QString,SimpleSectHandler::Types> m_typeNameMap;};static TypeNameMapper g_typeMapper; //----------------------------------------------------------------------// MarkupHandler//----------------------------------------------------------------------MarkupHandler::MarkupHandler(QList<DocNode> &children,QString &curString) : m_children(children), m_curString(curString), m_curMarkup(DocNode::Normal){ addStartHandler("bold",this,&MarkupHandler::startBold); addEndHandler("bold",this,&MarkupHandler::endBold); addStartHandler("emphasis",this,&MarkupHandler::startEmphasis); addEndHandler("emphasis",this,&MarkupHandler::endEmphasis); addStartHandler("computeroutput",this,&MarkupHandler::startComputerOutput); addEndHandler("computeroutput",this,&MarkupHandler::endComputerOutput); addStartHandler("center",this,&MarkupHandler::startCenter); addEndHandler("center",this,&MarkupHandler::endCenter); addStartHandler("small",this,&MarkupHandler::startSmallFont); addEndHandler("small",this,&MarkupHandler::endSmallFont); addStartHandler("subscript",this,&MarkupHandler::startSubscript); addEndHandler("subscript",this,&MarkupHandler::endSubscript); addStartHandler("superscript",this,&MarkupHandler::startSuperscript); addEndHandler("superscript",this,&MarkupHandler::endSuperscript);}MarkupHandler::~MarkupHandler(){}void MarkupHandler::addTextNode(){ if (!m_curString.isEmpty()) { m_children.append(new TextNode(m_curString,m_curMarkup)); printf("addTextNode() text=%s markup=%x\n",m_curString.data(),m_curMarkup); m_curString=""; }}void MarkupHandler::startBold(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Bold,TRUE)); m_curMarkup |= DocNode::Bold;}void MarkupHandler::endBold(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Bold,FALSE)); m_curMarkup &= ~DocNode::Bold;}void MarkupHandler::startEmphasis(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Emphasis,TRUE)); m_curMarkup |= DocNode::Emphasis;}void MarkupHandler::endEmphasis(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Emphasis,FALSE)); m_curMarkup &= ~DocNode::Emphasis;}void MarkupHandler::startComputerOutput(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::ComputerOutput,TRUE)); m_curMarkup |= DocNode::ComputerOutput;}void MarkupHandler::endComputerOutput(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::ComputerOutput,FALSE)); m_curMarkup &= ~DocNode::ComputerOutput;}void MarkupHandler::startCenter(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Center,TRUE)); m_curMarkup |= DocNode::Center;}void MarkupHandler::endCenter(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Center,FALSE)); m_curMarkup &= ~DocNode::Center;}void MarkupHandler::startSmallFont(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::SmallFont,TRUE)); m_curMarkup |= DocNode::SmallFont;}void MarkupHandler::endSmallFont(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::SmallFont,FALSE)); m_curMarkup &= ~DocNode::SmallFont;}void MarkupHandler::startSubscript(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Subscript,TRUE)); m_curMarkup |= DocNode::Subscript;}void MarkupHandler::endSubscript(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Subscript,FALSE)); m_curMarkup &= ~DocNode::Subscript;}void MarkupHandler::startSuperscript(const QXmlAttributes & /*attrib*/){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Superscript,TRUE)); m_curMarkup |= DocNode::Superscript;}void MarkupHandler::endSuperscript(){ addTextNode(); m_children.append(new MarkupModifierNode(DocNode::Superscript,FALSE)); m_curMarkup &= ~DocNode::Superscript;}//----------------------------------------------------------------------// ListItemHandler//----------------------------------------------------------------------ListItemHandler::ListItemHandler(IBaseHandler *parent) : DocNode(ListItem), m_parent(parent){ m_children.setAutoDelete(TRUE); addEndHandler("listitem",this,&ListItemHandler::endListItem); addStartHandler("para",this,&ListItemHandler::startParagraph);}ListItemHandler::~ListItemHandler(){}void ListItemHandler::startListItem(const QXmlAttributes& /*attrib*/){ m_parent->setDelegate(this); printf("start list item handler\n");}void ListItemHandler::endListItem(){ printf("end list item handler\n"); m_parent->setDelegate(0);}void ListItemHandler::startParagraph(const QXmlAttributes& attrib){ ParagraphHandler *parHandler = new ParagraphHandler(this); parHandler->startParagraph(attrib); m_children.append(parHandler);}//----------------------------------------------------------------------// ListHandler//----------------------------------------------------------------------ListHandler::ListHandler(NodeKind k,IBaseHandler *parent) : DocNode(k), m_parent(parent){ m_children.setAutoDelete(TRUE); const char *endListName=0; switch(k) { case ItemizedList : endListName="itemizedlist"; break; case OrderedList : endListName="orderedlist"; break; default: ASSERT(0); } addEndHandler(endListName,this,&ListHandler::endList); addStartHandler("listitem",this,&ListHandler::startListItem);}ListHandler::~ListHandler(){}void ListHandler::startList(const QXmlAttributes& /*attrib*/){ m_parent->setDelegate(this);}void ListHandler::endList(){ m_parent->setDelegate(0);}void ListHandler::startListItem(const QXmlAttributes& attrib){ ListItemHandler *liHandler = new ListItemHandler(this); liHandler->startListItem(attrib); m_children.append(liHandler);}//----------------------------------------------------------------------// ParameterHandler//----------------------------------------------------------------------ParameterHandler::ParameterHandler(IBaseHandler *parent) : DocNode(Parameter), m_parent(parent), m_description(0){ addEndHandler("parametername",this,&ParameterHandler::endParameterName); addEndHandler("parameterdescription",this,&ParameterHandler::endParameterDescription); addStartHandler("para",this,&ParameterHandler::startParagraph);}ParameterHandler::~ParameterHandler(){ delete m_description;}void ParameterHandler::startParameterName(const QXmlAttributes& /*attrib*/){ m_parent->setDelegate(this);}void ParameterHandler::endParameterName(){ m_name = m_curString; printf("parameter %s\n",m_name.data()); m_curString=""; m_parent->setDelegate(0);}void ParameterHandler::startParameterDescription(const QXmlAttributes& /*attrib*/){ m_parent->setDelegate(this);}void ParameterHandler::endParameterDescription(){ m_parent->setDelegate(0);}void ParameterHandler::startParagraph(const QXmlAttributes& attrib){ ASSERT(m_description==0); m_description = new ParagraphHandler(this); m_description->startParagraph(attrib);}//----------------------------------------------------------------------// ParameterListHandler//----------------------------------------------------------------------ParameterListHandler::ParameterListHandler(IBaseHandler *parent) : DocNode(ParameterList), m_parent(parent){ addEndHandler("parameterlist",this,&ParameterListHandler::endParameterList); addStartHandler("parametername",this,&ParameterListHandler::startParameterName); addStartHandler("parameterdescription",this,&ParameterListHandler::startParameterDescription); addStartHandler("title"); addEndHandler("title"); m_parameters.setAutoDelete(TRUE); m_curParam=0;}ParameterListHandler::~ParameterListHandler(){}void ParameterListHandler::startParameterList(const QXmlAttributes& attrib){ QString kind = attrib.value("kind"); if (kind=="retval") m_type=RetVal; else if (kind=="exception") m_type=Exception; else if (kind=="param") m_type=Param; else { printf("Error: invalid parameterlist type: %s\n",kind.data()); } printf("parameterlist kind=%s\n",kind.data()); m_parent->setDelegate(this);}void ParameterListHandler::endParameterList(){ m_parent->setDelegate(0);}void ParameterListHandler::startParameterName(const QXmlAttributes& attrib){ m_curParam = new ParameterHandler(this); m_parameters.append(m_curParam); m_curParam->startParameterName(attrib);}void ParameterListHandler::startParameterDescription(const QXmlAttributes& attrib){ ASSERT(m_curParam!=0); m_curParam->startParameterDescription(attrib);}//----------------------------------------------------------------------// LinkHandler//----------------------------------------------------------------------LinkHandler::LinkHandler(IBaseHandler *parent) : DocNode(Link), m_parent(parent){ addEndHandler("link",this,&LinkHandler::endLink);}LinkHandler::~LinkHandler(){}void LinkHandler::startLink(const QXmlAttributes& attrib){ m_parent->setDelegate(this); printf("Start link\n"); m_ref = attrib.value("linkend"); m_curString="";}void LinkHandler::endLink(){ m_text = m_curString; m_curString=""; m_parent->setDelegate(0); printf("End link\n");}//----------------------------------------------------------------------// EMailHandler//----------------------------------------------------------------------EMailHandler::EMailHandler(IBaseHandler *parent) : DocNode(EMail), m_parent(parent){ addEndHandler("email",this,&EMailHandler::endEMail);}EMailHandler::~EMailHandler(){}void EMailHandler::startEMail(const QXmlAttributes& /*attrib*/){ m_parent->setDelegate(this); printf("Start email\n"); m_curString="";}void EMailHandler::endEMail(){ m_address = m_curString; m_curString=""; m_parent->setDelegate(0); printf("End email\n");}//----------------------------------------------------------------------// ULinkHandler//----------------------------------------------------------------------ULinkHandler::ULinkHandler(IBaseHandler *parent) : DocNode(ULink), m_parent(parent){ addEndHandler("ulink",this,&ULinkHandler::endULink);}ULinkHandler::~ULinkHandler(){}void ULinkHandler::startULink(const QXmlAttributes& attrib){ m_parent->setDelegate(this); printf("Start ulink\n"); m_url = attrib.value("url"); m_curString="";}void ULinkHandler::endULink(){ m_text = m_curString;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -