ReadFramework
rdf::Region Class Reference

#include <Elements.h>

Inheritance diagram for rdf::Region:
Collaboration diagram for rdf::Region:

Public Types

enum  Type {
  type_unknown = 0, type_root, type_table_region, type_table_cell,
  type_text_region, type_text_line, type_word, type_separator,
  type_image, type_graphic, type_chart, type_noise,
  type_end
}
 

Public Member Functions

 Region (const Type &type=Type::type_unknown, const QString &id="")
 Initializes a new instance of the Region class. The Region is the base class for all Region elements that are contained in the extended PAGE XML. More...
 
bool isEmpty () const
 
void setSelected (bool select)
 
bool selected () const
 
void setType (const Region::Type &type)
 Sets the Region type. More...
 
Region::Type type () const
 The Region's type (e.g. type_text_region). More...
 
void setId (const QString &id)
 Set a unique identifier to the region. More...
 
QString id () const
 Returns the Region's unique identifier. More...
 
void setCustom (const QString &c)
 
QString custom () const
 
void setPolygon (const Polygon &polygon)
 Set the polygon which enclosed the Region. The polygon's coordinates are w.r.t the image coordinates. More...
 
Polygon polygon () const
 The Region's polygon. More...
 
void scaleRegion (double scale)
 
void addChild (QSharedPointer< Region > child)
 Adds a child to the current Region. More...
 
bool reassignChild (QSharedPointer< Region > child)
 Reassigns the child w.r.t its ID. This function is needed if an element was converted (e.g. table cell to text block) but needs to be updated. If the child ID is found, the children of the existing region are replaced by those of child and true is returned. More...
 
void addUniqueChild (QSharedPointer< Region > child, bool update=false)
 Adds the child if it does not exist already. If update is true, the duplicate element is updated, otherwise nothing happens if the child exists already. More...
 
void removeChild (QSharedPointer< Region > child)
 Removes the child specified. More...
 
void removeAllChildren ()
 
void setChildren (const QVector< QSharedPointer< Region > > &children)
 Sets the child regions. More...
 
QVector< QSharedPointer< Region > > children () const
 Children of this instance. More...
 
virtual void draw (QPainter &p, const RegionTypeConfig &config) const
 Draws the Region to the Painter. More...
 
virtual QString toString (bool withChildren=false) const
 Returns a string discribing the Region. More...
 
virtual QString childrenToString () const
 Returns a string with all attributes of the Region's children. More...
 
virtual bool read (QXmlStreamReader &reader)
 Adds Attributes to the current region. More...
 
virtual void readAttributes (QXmlStreamReader &reader)
 
virtual void write (QXmlStreamWriter &writer) const
 Writes the Region to the XML stream. More...
 
virtual void writeChildren (QXmlStreamWriter &writer) const
 Writes the Region's children to the XML stream. More...
 
void createElement (QXmlStreamWriter &writer) const
 Creates the element. After a call to this method, attributes can be appended to the element. More...
 
void writePolygon (QXmlStreamWriter &writer) const
 Writes the polygon. This is a convenience function for derived classes. Typically writePolygon is called after all (additional) attributes of the current element are set. More...
 
virtual bool operator== (const Region &r1)
 Compare operator. Returns true if both regions have the same type and polygon. More...
 

Static Public Member Functions

static QVector< QSharedPointer< Region > > selectedRegions (const Region *root)
 
static QVector< QSharedPointer< Region > > allRegions (const Region *root)
 
static QVector< QSharedPointer< Region > > filter (const Region *root, const Region::Type &type)
 

Protected Member Functions

void collectRegions (QVector< QSharedPointer< Region > > &allRegions, const Region::Type &type=type_unknown) const
 
virtual bool readPoints (QXmlStreamReader &reader)
 

Protected Attributes

Type mType = Type::type_unknown
 
bool mSelected = false
 
QString mId
 
QString mCustom
 
Polygon mPoly
 
QVector< QSharedPointer< Region > > mChildren
 

Friends

DllCoreExport QDataStream & operator<< (QDataStream &s, const Region &r)
 Writes the Region r to the data stream s More...
 
DllCoreExport QDebug operator<< (QDebug d, const Region &r)
 Prints the Region r to the debug output. More...
 

Member Enumeration Documentation

Enumerator
type_unknown 
type_root 
type_table_region 
type_table_cell 
type_text_region 
type_text_line 
type_word 
type_separator 
type_image 
type_graphic 
type_chart 
type_noise 
type_end 

Constructor & Destructor Documentation

rdf::Region::Region ( const Type type = Type::type_unknown,
const QString &  id = "" 
)

Initializes a new instance of the Region class. The Region is the base class for all Region elements that are contained in the extended PAGE XML.

Member Function Documentation

void rdf::Region::addChild ( QSharedPointer< Region child)

Adds a child to the current Region.

Parameters
childThe child region.
void rdf::Region::addUniqueChild ( QSharedPointer< Region child,
bool  update = false 
)

Adds the child if it does not exist already. If update is true, the duplicate element is updated, otherwise nothing happens if the child exists already.

Parameters
childThe child to append.
updateif set to true, the existing child is updated.
QVector< QSharedPointer< Region > > rdf::Region::allRegions ( const Region root)
static

Here is the caller graph for this function:

QVector< QSharedPointer< Region > > rdf::Region::children ( ) const

Children of this instance.

Returns

Here is the caller graph for this function:

QString rdf::Region::childrenToString ( ) const
virtual

Returns a string with all attributes of the Region's children.

Returns

Here is the caller graph for this function:

void rdf::Region::collectRegions ( QVector< QSharedPointer< Region > > &  allRegions,
const Region::Type type = type_unknown 
) const
protected

Here is the caller graph for this function:

void rdf::Region::createElement ( QXmlStreamWriter &  writer) const

Creates the element. After a call to this method, attributes can be appended to the element.

Parameters
writerThe XML stream at the position where the region should be written.

Here is the caller graph for this function:

QString rdf::Region::custom ( ) const
void rdf::Region::draw ( QPainter &  p,
const RegionTypeConfig config 
) const
virtual

Draws the Region to the Painter.

Parameters
pThe painter.
configThe configuration containing colors etc.

Reimplemented in rdf::TextRegion, and rdf::TextLine.

Here is the caller graph for this function:

QVector< QSharedPointer< Region > > rdf::Region::filter ( const Region root,
const Region::Type type 
)
static

Here is the caller graph for this function:

QString rdf::Region::id ( ) const

Returns the Region's unique identifier.

Returns

Here is the caller graph for this function:

bool rdf::Region::isEmpty ( ) const

Here is the caller graph for this function:

bool rdf::Region::operator== ( const Region r1)
virtual

Compare operator. Returns true if both regions have the same type and polygon.

Parameters
r1The region to be compared.
Returns
true if both regions have the same type and polygon.

Reimplemented in rdf::SeparatorRegion, and rdf::TableRegion.

Polygon rdf::Region::polygon ( ) const

The Region's polygon.

Returns

Here is the caller graph for this function:

bool rdf::Region::read ( QXmlStreamReader &  reader)
virtual

Adds Attributes to the current region.

Parameters
readerXML reader set to the current line (inside a region type).
Returns
false if an opening tag is unknown

Reimplemented in rdf::TextRegion, rdf::TextLine, and rdf::TableCell.

Here is the caller graph for this function:

void rdf::Region::readAttributes ( QXmlStreamReader &  reader)
virtual

Reimplemented in rdf::TableCell, and rdf::TableRegion.

Here is the caller graph for this function:

bool rdf::Region::readPoints ( QXmlStreamReader &  reader)
protectedvirtual

Here is the caller graph for this function:

bool rdf::Region::reassignChild ( QSharedPointer< Region child)

Reassigns the child w.r.t its ID. This function is needed if an element was converted (e.g. table cell to text block) but needs to be updated. If the child ID is found, the children of the existing region are replaced by those of child and true is returned.

Parameters
childA region that was potentially created from an existing region.
Returns
false if the child cannot be reassigned
void rdf::Region::removeAllChildren ( )
void rdf::Region::removeChild ( QSharedPointer< Region child)

Removes the child specified.

Parameters
childThe child region.
void rdf::Region::scaleRegion ( double  scale)

Here is the caller graph for this function:

bool rdf::Region::selected ( ) const

Here is the caller graph for this function:

QVector< QSharedPointer< Region > > rdf::Region::selectedRegions ( const Region root)
static

Here is the caller graph for this function:

void rdf::Region::setChildren ( const QVector< QSharedPointer< Region > > &  children)

Sets the child regions.

Parameters
childrenThe child regions.
void rdf::Region::setCustom ( const QString &  c)

Here is the caller graph for this function:

void rdf::Region::setId ( const QString &  id)

Set a unique identifier to the region.

Parameters
idA unique identifier.

Here is the caller graph for this function:

void rdf::Region::setPolygon ( const Polygon polygon)

Set the polygon which enclosed the Region. The polygon's coordinates are w.r.t the image coordinates.

Parameters
polygonA polygon that represents the Region.

Here is the caller graph for this function:

void rdf::Region::setSelected ( bool  select)
void rdf::Region::setType ( const Region::Type type)

Sets the Region type.

Parameters
typeThe type.
QString rdf::Region::toString ( bool  withChildren = false) const
virtual

Returns a string discribing the Region.

Returns

Reimplemented in rdf::TextRegion, and rdf::TextLine.

Here is the caller graph for this function:

Region::Type rdf::Region::type ( ) const

The Region's type (e.g. type_text_region).

Returns

Here is the caller graph for this function:

void rdf::Region::write ( QXmlStreamWriter &  writer) const
virtual

Writes the Region to the XML stream.

Parameters
writerThe XML stream at the position where the region should be written.
withChildrenif set to true the Region's children are written too.
closeif set to true the element's close tag is appended.

Reimplemented in rdf::TextRegion, rdf::TextLine, and rdf::TableCell.

void rdf::Region::writeChildren ( QXmlStreamWriter &  writer) const
virtual

Writes the Region's children to the XML stream.

Parameters
writerThe XML stream.

Here is the caller graph for this function:

void rdf::Region::writePolygon ( QXmlStreamWriter &  writer) const

Writes the polygon. This is a convenience function for derived classes. Typically writePolygon is called after all (additional) attributes of the current element are set.

Parameters
writerThe XML stream at the position where the region should be written.

Here is the caller graph for this function:

Friends And Related Function Documentation

DllCoreExport QDataStream& operator<< ( QDataStream &  s,
const Region r 
)
friend

Writes the Region r to the data stream s

Parameters
sA data stream.
rA region r.
Returns
The data stream with the current region.
DllCoreExport QDebug operator<< ( QDebug  d,
const Region r 
)
friend

Prints the Region r to the debug output.

Parameters
dA Debug output.
rThe Region to be printed.
Returns
The debug output with the current Region.

Member Data Documentation

QVector<QSharedPointer<Region> > rdf::Region::mChildren
protected
QString rdf::Region::mCustom
protected
QString rdf::Region::mId
protected
Polygon rdf::Region::mPoly
protected
bool rdf::Region::mSelected = false
protected
Type rdf::Region::mType = Type::type_unknown
protected

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