Grantlee
0.2.0
|
The MarkupDirector class controls and instructs a builder object to create markup output. More...
#include <grantlee/markupdirector.h>
Public Member Functions | |
MarkupDirector (AbstractMarkupBuilder *builder) | |
virtual | ~MarkupDirector () |
virtual QTextFrame::iterator | processBlock (QTextFrame::iterator it, const QTextBlock &block) |
virtual QTextFrame::iterator | processBlockContents (QTextFrame::iterator it, const QTextBlock &block) |
virtual QPair < QTextFrame::iterator, QTextBlock > | processBlockGroup (QTextFrame::iterator it, const QTextBlock &block, QTextBlockGroup *textBlockGroup) |
virtual QTextBlock::iterator | processCharTextObject (QTextBlock::iterator it, const QTextFragment &fragment, QTextObject *textObject) |
virtual void | processCustomFragment (const QTextFragment &fragment, QTextDocument const *doc) |
virtual void | processDocument (QTextDocument *doc) |
virtual QTextBlock::iterator | processFragment (QTextBlock::iterator it, const QTextFragment &fragment, QTextDocument const *doc) |
virtual QTextFrame::iterator | processFrame (QTextFrame::iterator it, QTextFrame *frame) |
virtual QTextBlock::iterator | processImage (QTextBlock::iterator it, const QTextImageFormat &imageFormat, QTextDocument *doc) |
virtual QPair < QTextFrame::iterator, QTextBlock > | processList (QTextFrame::iterator it, const QTextBlock &block, QTextList *textList) |
virtual QTextFrame::iterator | processObject (QTextFrame::iterator it, const QTextBlock &block, QTextObject *textObject) |
virtual QTextFrame::iterator | processTable (QTextFrame::iterator it, QTextTable *table) |
virtual void | processTableCell (const QTextTableCell &tableCell, QTextTable *table) |
Protected Types | |
enum | OpenElementValues { None, SuperScript, SubScript, Anchor, SpanForeground, SpanBackground, SpanFontFamily, SpanFontPointSize, Strong, Emph, Underline, StrikeOut } |
Protected Member Functions | |
virtual QSet< int > | getElementsToClose (QTextBlock::iterator it) const |
virtual QList< int > | getElementsToOpen (QTextBlock::iterator it) |
virtual void | processClosingElements (QTextBlock::iterator it) |
void | processDocumentContents (QTextFrame::iterator begin, QTextFrame::iterator end) |
virtual void | processOpeningElements (QTextBlock::iterator it) |
QPair< QTextFrame::iterator, QTextBlock > | skipBlockGroup (QTextFrame::iterator it, const QTextBlock &_block, QTextBlockGroup *blockGroup) |
QList< int > | sortOpeningOrder (QSet< int > openingTags, QTextBlock::iterator it) const |
Protected Attributes | |
AbstractMarkupBuilder * | m_builder |
The MarkupDirector is used with a subclass of AbstractMarkupBuilder to create a marked up document output.
Usage can be quite simple.
QTextDocument *doc = editor->document(); // editor is a QTextEdit AbstractMarkupBuilder *builder = new HTMLBuilder(); MarkupDirector *md = new MarkupDirector(builder); md->processDocument(doc); browser->setHtml(builder->getResult()); // browser is a QTextBrowser.
Or with a different builder:
AbstractMarkupBuilder *builder = new PlainTextMarkupBuilder(); MarkupDirector *md = new MarkupDirector(builder); md->processDocument(doc); browser->setPlainText(builder->getResult());
The MarkupDirector also provides API for processing just part of a QTextDocument, such as a QTextFrame or a QTextBlock. The appropriate method may then be called with an invalid iterator as appropriate.
// ... Do some processing to get a QTextFrame. QTextFrame *frame = getFrame(); AbstractMarkupBuilder *builder = new PlainTextMarkupBuilder(); MarkupDirector *md = new MarkupDirector(builder); // Create output from only the frame. md->processFrame(QTextFrame::iterator(), frame); browser->setPlainText(builder->getResult());
The behaviour of the MarkupDirector can be customized by subclassing. Support for custom types can also be added by implementing the processCustomFragment method.
enum Grantlee::MarkupDirector::OpenElementValues [protected] |
Flags for the tags that may be open.
Definition at line 225 of file markupdirector.h.
Grantlee::MarkupDirector::MarkupDirector | ( | AbstractMarkupBuilder * | builder | ) |
Construct a new MarkupDirector
virtual Grantlee::MarkupDirector::~MarkupDirector | ( | ) | [virtual] |
Destructor
virtual QSet< int > Grantlee::MarkupDirector::getElementsToClose | ( | QTextBlock::iterator | it | ) | const [protected, virtual] |
Returns the tags that should be closed at the position of it
.
virtual QList< int > Grantlee::MarkupDirector::getElementsToOpen | ( | QTextBlock::iterator | it | ) | [protected, virtual] |
Returns the tags that should be opened at the position of it
.
virtual QTextFrame::iterator Grantlee::MarkupDirector::processBlock | ( | QTextFrame::iterator | it, |
const QTextBlock & | block | ||
) | [virtual] |
Directs the builder to create output for the single block
. If calling this method directly, an invalid QTextFrame::iterator may be used.
This method does not process the contents of the block
, but uses the processBlockContents method to do so.
virtual QTextFrame::iterator Grantlee::MarkupDirector::processBlockContents | ( | QTextFrame::iterator | it, |
const QTextBlock & | block | ||
) | [virtual] |
Directs the builder to create output for the contents of the single block
. If calling this method directly, an invalid QTextFrame::iterator may be used.
virtual QPair<QTextFrame::iterator, QTextBlock> Grantlee::MarkupDirector::processBlockGroup | ( | QTextFrame::iterator | it, |
const QTextBlock & | block, | ||
QTextBlockGroup * | textBlockGroup | ||
) | [virtual] |
Directs the builder to create output for the single textBlockGroup
. If calling this method directly, an invalid QTextFrame::iterator may be used.
The block block
is the first block in the textBlockGroup
.
virtual QTextBlock::iterator Grantlee::MarkupDirector::processCharTextObject | ( | QTextBlock::iterator | it, |
const QTextFragment & | fragment, | ||
QTextObject * | textObject | ||
) | [virtual] |
Directs the builder to create output for the contents of the single textObject
. The textObject
is represented in the QTextDocument with the QTextFragment fragment
.
If calling this method directly, an invalid QTextBlock::iterator may be used.
virtual void Grantlee::MarkupDirector::processClosingElements | ( | QTextBlock::iterator | it | ) | [protected, virtual] |
Directs the builder to close the appropriate tags at the position of it
.
virtual void Grantlee::MarkupDirector::processCustomFragment | ( | const QTextFragment & | fragment, |
QTextDocument const * | doc | ||
) | [virtual] |
Hook for instructing the builder to create output for the fragemnt
with a custom type. doc
is the document the fragment is in.
virtual void Grantlee::MarkupDirector::processDocument | ( | QTextDocument * | doc | ) | [virtual] |
Constructs the output by directing the builder to create the markup.
void Grantlee::MarkupDirector::processDocumentContents | ( | QTextFrame::iterator | begin, |
QTextFrame::iterator | end | ||
) | [protected] |
Processes the document between begin
and end
virtual QTextBlock::iterator Grantlee::MarkupDirector::processFragment | ( | QTextBlock::iterator | it, |
const QTextFragment & | fragment, | ||
QTextDocument const * | doc | ||
) | [virtual] |
Directs the builder to create output for the contents of the single fragment
. If calling this method directly, an invalid QTextBlock::iterator may be used. doc
is the document the fragment is in.
virtual QTextFrame::iterator Grantlee::MarkupDirector::processFrame | ( | QTextFrame::iterator | it, |
QTextFrame * | frame | ||
) | [virtual] |
Directs the builder to create output for the single frame
. If calling this method directly, an invalid QTextFrame::iterator may be used.
virtual QTextBlock::iterator Grantlee::MarkupDirector::processImage | ( | QTextBlock::iterator | it, |
const QTextImageFormat & | imageFormat, | ||
QTextDocument * | doc | ||
) | [virtual] |
Directs the builder to create output for the image represented by the imageFormat
.
If calling this method directly, an invalid QTextBlock::iterator may be used. doc
is the document the fragment is in.
virtual QPair<QTextFrame::iterator, QTextBlock> Grantlee::MarkupDirector::processList | ( | QTextFrame::iterator | it, |
const QTextBlock & | block, | ||
QTextList * | textList | ||
) | [virtual] |
Directs the builder to create output for the single textList
. If calling this method directly, an invalid QTextFrame::iterator may be used.
The block block
is the first block in the textList
.
virtual QTextFrame::iterator Grantlee::MarkupDirector::processObject | ( | QTextFrame::iterator | it, |
const QTextBlock & | block, | ||
QTextObject * | textObject | ||
) | [virtual] |
Directs the builder to create output for the single textObject
. If calling this method directly, an invalid QTextFrame::iterator may be used.
The block block
is the container of the textObject
.
virtual void Grantlee::MarkupDirector::processOpeningElements | ( | QTextBlock::iterator | it | ) | [protected, virtual] |
Directs the builder to open the appropriate tags at the position of it
.
virtual QTextFrame::iterator Grantlee::MarkupDirector::processTable | ( | QTextFrame::iterator | it, |
QTextTable * | table | ||
) | [virtual] |
Directs the builder to create output for the contents of the single table
.
If calling this method directly, an invalid QTextFrame::iterator may be used.
virtual void Grantlee::MarkupDirector::processTableCell | ( | const QTextTableCell & | tableCell, |
QTextTable * | table | ||
) | [virtual] |
Directs the builder to create output for the contents of the single tableCell
. The tableCell is in the table
.
QPair<QTextFrame::iterator, QTextBlock> Grantlee::MarkupDirector::skipBlockGroup | ( | QTextFrame::iterator | it, |
const QTextBlock & | _block, | ||
QTextBlockGroup * | blockGroup | ||
) | [protected] |
Iterates the iterator it
to the first block after blockGroup
. _block
is any block in the blockGroup
.
The return pair is the iterator pointing after the end of blockGroup
and the first block after blockGroup
.
QList< int > Grantlee::MarkupDirector::sortOpeningOrder | ( | QSet< int > | openingTags, |
QTextBlock::iterator | it | ||
) | const [protected] |
Returns a list of tags contained in openingTags
sorted so they can be opened in order and will be closed in the correct order.
openingTags
should be a set of tags opened at the fragment pointed to by it
.
AbstractMarkupBuilder* Grantlee::MarkupDirector::m_builder [protected] |
The builder this MarkupDirector is operating on. This is available when subclassing to customize behaviour.
Definition at line 248 of file markupdirector.h.