LibEngsas
Signals | Public Member Functions | Protected Slots | Protected Member Functions | Private Attributes | List of all members
EXmlItem Class Referenceabstract

An EXmlItem is used to handle XML tags and it's atrributes and or child tags. More...

#include <exmlitem.h>

+ Inheritance diagram for EXmlItem:
+ Collaboration diagram for EXmlItem:

Signals

void changed (EXmlItem *item)
 
void rowsAboutToBeInserted (EXmlItem *parent, int start, int end)
 
void rowsInserted ()
 
void rowsAboutToBeRemoved (EXmlItem *parent, int start, int end)
 
void rowsRemoved ()
 

Public Member Functions

 EXmlItem (QString tagName, EXmlItem *parent=0)
 
virtual ~EXmlItem ()
 
virtual bool load (const QDomElement element, QMap< QString, EXmlParserItem * > parser)=0
 
virtual bool save (QDomElement &useElem)
 
int rowCount () const
 
virtual QVariant data (int column, int role=Qt::DisplayRole) const =0
 used by EXmlModel::data() to retrieve the role data of this item. More...
 
virtual bool setData (int column, QVariant value, int role=Qt::EditRole)
 Called by EXmlModel::setData() to set the role data for this item to value. More...
 
virtual void setParent (EXmlItem *parent)
 Do not forget to call the base class implementation, when reimplementing this function. More...
 
EXmlItemparent () const
 
virtual bool addChild (int row, EXmlItem *item, bool emitInsertRows=true)
 Adds item as a child to this item at position row. More...
 
virtual bool removeChild (int row, bool emitRemoveRows=true)
 Removes and deletes the child at row. More...
 
EXmlItemchild (int row) const
 
int row (EXmlItem *child) const
 Returns the row of the child. More...
 
void setTagName (QString tagName)
 
QString tagName () const
 Return the tag name (in lowercase), which is handled by this EXmlItem. More...
 
virtual EXmlItemcopy () const =0
 Returns a pointer to a new element, copied from this one. More...
 

Protected Slots

virtual void changedByPass (EXmlItem *item)
 Just forwards the changed signal. More...
 
virtual void rowsAboutToBeInsertedByPass (EXmlItem *parent, int start, int end)
 Just forwards the rowsAboutToBeInserted() signal. More...
 
virtual void rowsInsertedByPass ()
 Just forwards the rowsInserted() signal. More...
 
virtual void rowsAboutToBeRemovedByPass (EXmlItem *parent, int start, int end)
 Just forwards the rowsAboutToBeRemoved() signal. More...
 
virtual void rowsRemovedByPass ()
 Just forwards the rowsRemoved() signal. More...
 

Protected Member Functions

virtual void copyBase (EXmlItem *target) const
 Copies all the standard stuff into target. More...
 

Private Attributes

EXmlItemmyParent
 
QList< EXmlItem * > childs
 
QString myTagName
 

Detailed Description

An EXmlItem is used to handle XML tags and it's atrributes and or child tags.

It must be registered to the model with help of EXmlModel::registerParser(), so that the model knows, which tagname can be parsed by which EXmlItem. The function used as a callback must be a static public function and must return a pointer to an EXmlItem. The function shown below should do it in nearly all cases:

static inline EXmlItem *create(EXmlModel *model){ return new MyClass(); }

The pointer to the currently used EXmlModel is provided, by the EXmlParserItem created by EXmlModel::registerParser() automatically. Therefore you may use this pointer within your item or creation method to access the model.

See also
EDependencyItem as an example implementation

Constructor & Destructor Documentation

EXmlItem::EXmlItem ( QString  tagName,
EXmlItem parent = 0 
)

+ Here is the call graph for this function:

EXmlItem::~EXmlItem ( )
virtual

Member Function Documentation

bool EXmlItem::addChild ( int  row,
EXmlItem item,
bool  emitInsertRows = true 
)
virtual

Adds item as a child to this item at position row.

It also sets the parent of item to this object.

Per default, also the signals layoutAboutToBeChanged() and layoutChanged() are emitted. To avoid those signals beeing emited, set emitLayoutChanges to false. It is useful to set it to false, if you want to insert a large amount of items. Therefore the changes shoudl not be emited within the load() function.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EXmlItem::changed ( EXmlItem item)
signal

+ Here is the caller graph for this function:

virtual void EXmlItem::changedByPass ( EXmlItem item)
inlineprotectedvirtualslot

Just forwards the changed signal.

To interupt the forwarding, reimplement this function.

+ Here is the caller graph for this function:

EXmlItem * EXmlItem::child ( int  row) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual EXmlItem* EXmlItem::copy ( ) const
pure virtual

Returns a pointer to a new element, copied from this one.

To copy all standard stuff, use the copyBase(EXmlItem*) function. So implement this function in all base classes like this:

YourClass *myCopy = new YourClass();
copyBase(myCopy);
// now set your custom values. e.g.:
myCopy->setCustomValue(customValue());
return myCopy;

Remember, that copyBase() does copy recursivly. That means, it adds copies of all children to the copy.

Implemented in EXmlStandardRootItem, and EDependencyItem.

+ Here is the caller graph for this function:

void EXmlItem::copyBase ( EXmlItem target) const
protectedvirtual

Copies all the standard stuff into target.

Call this function from copy(). Remember that this function copies recursivly. That means, it adds copies of all children to target.

When subclassing, it can be useful to reimplement this function, to allow copy & paste code from copy() help at the subclasses of your subclasses. In this case, you should remamber to call the base implementation at the appropriate place:

// copy your base stuff

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual QVariant EXmlItem::data ( int  column,
int  role = Qt::DisplayRole 
) const
pure virtual

used by EXmlModel::data() to retrieve the role data of this item.

Implement this function to return data to the view

See also
EDependencyItem::data()

Implemented in EXmlStandardRootItem, and EDependencyItem.

+ Here is the caller graph for this function:

virtual bool EXmlItem::load ( const QDomElement  element,
QMap< QString, EXmlParserItem * >  parser 
)
pure virtual

Is called from the Model or the parent item, to load the content of element. Therefore this function must also create child EXmlItem's, if child tags are found, which can not be handled by it's own. For this purpose the mapping parser is given. The key of this map is the tagName which belongs to the parser item. If the found tag is not in the list, return false. If it is found, call the EXmlParseritem::load(QDomElement, EXmlItem *, QMap<QString, EXmlParserItem*>) function to process underlaying data. But create a new QDomElement as a child.

Note
If adding childs with addChild(), set emitLayoutChanges to false, to avoid emitting not needed layout changed signals.
See also
EDependencyItem::load() as an implementation example

Implemented in EXmlStandardRootItem, and EDependencyItem.

+ Here is the caller graph for this function:

EXmlItem * EXmlItem::parent ( ) const

+ Here is the caller graph for this function:

bool EXmlItem::removeChild ( int  row,
bool  emitRemoveRows = true 
)
virtual

Removes and deletes the child at row.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int EXmlItem::row ( EXmlItem child) const

Returns the row of the child.

If the child is not found or any other error occurs -1 is returned.

+ Here is the caller graph for this function:

int EXmlItem::rowCount ( ) const

+ Here is the caller graph for this function:

void EXmlItem::rowsAboutToBeInserted ( EXmlItem parent,
int  start,
int  end 
)
signal

+ Here is the caller graph for this function:

virtual void EXmlItem::rowsAboutToBeInsertedByPass ( EXmlItem parent,
int  start,
int  end 
)
inlineprotectedvirtualslot

Just forwards the rowsAboutToBeInserted() signal.

To interupt the forwarding, reimplement this function.

+ Here is the caller graph for this function:

void EXmlItem::rowsAboutToBeRemoved ( EXmlItem parent,
int  start,
int  end 
)
signal

+ Here is the caller graph for this function:

virtual void EXmlItem::rowsAboutToBeRemovedByPass ( EXmlItem parent,
int  start,
int  end 
)
inlineprotectedvirtualslot

Just forwards the rowsAboutToBeRemoved() signal.

To interupt the forwarding, reimplement this function.

+ Here is the caller graph for this function:

void EXmlItem::rowsInserted ( )
signal

+ Here is the caller graph for this function:

virtual void EXmlItem::rowsInsertedByPass ( )
inlineprotectedvirtualslot

Just forwards the rowsInserted() signal.

To interupt the forwarding, reimplement this function.

+ Here is the caller graph for this function:

void EXmlItem::rowsRemoved ( )
signal

+ Here is the caller graph for this function:

virtual void EXmlItem::rowsRemovedByPass ( )
inlineprotectedvirtualslot

Just forwards the rowsRemoved() signal.

To interupt the forwarding, reimplement this function.

+ Here is the caller graph for this function:

bool EXmlItem::save ( QDomElement &  useElem)
virtual

This function should convert the current handled data back into a QDomElement. The given useElem should be used to store the own data into. Your childs should be appended to childs of useElem. These can be done by calling this base implementation after processing your part.

Returns
false, if useElem is a null element or something other went wrong.
See also
EDependencyItem::save() for an example implementation

Reimplemented in EXmlStandardRootItem, and EDependencyItem.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlItem::setData ( int  column,
QVariant  value,
int  role = Qt::EditRole 
)
virtual

Called by EXmlModel::setData() to set the role data for this item to value.

The default implementation returns just false. So implement it, if you want to provide editable items.

+ Here is the caller graph for this function:

void EXmlItem::setParent ( EXmlItem parent)
virtual

Do not forget to call the base class implementation, when reimplementing this function.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EXmlItem::setTagName ( QString  tagName)

+ Here is the caller graph for this function:

QString EXmlItem::tagName ( ) const

Return the tag name (in lowercase), which is handled by this EXmlItem.

Note
tagName() is turned into lowercase.

+ Here is the caller graph for this function:

Member Data Documentation

QList<EXmlItem*> EXmlItem::childs
private
EXmlItem* EXmlItem::myParent
private
QString EXmlItem::myTagName
private

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