LibEngsas
Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Private Slots | Private Member Functions | Private Attributes | List of all members
EXmlModel Class Reference

ExmlModel is a base class to handle XML files very easily. More...

#include <exmlmodel.h>

+ Inheritance diagram for EXmlModel:
+ Collaboration diagram for EXmlModel:

Signals

void modified (bool status)
- Signals inherited from EAbstractItemModel
void error (QString msg)
void warning (QString msg)
void information (QString msg)
void eRowsInserted (const QModelIndex &parent, int start, int end)
 Replacement of private signal rowsInserted().
void eRowsRemoved (const QModelIndex &parent, int start, int end)
 Replacement of private signal rowsRemoved().

Public Member Functions

 EXmlModel (QUrl validationUrl, QObject *parent=0)
virtual ~EXmlModel ()
bool load (QDomElement element)
 Loads the XML structure below and including element.
bool load (QDomDocument document)
 Overladed of load(QDomElement)
bool load (QFile *file)
 Overladed of load(QDomDocument)
bool load (QString file)
 Overladed of load(QFile*)
bool load (QByteArray data)
 Overloaded of load(QDomDocument).
bool save (QDomElement &useElem)
bool save (QFile *file)
bool save (QString file)
QDomDocument save ()
 The model contained in a QDomDocument.
bool isValidXML ()
EXmlItemitemFromIndex (QModelIndex index) const
QModelIndex indexFromItem (EXmlItem *item) const
bool removeItem (QModelIndex index)
 Removes and deletes the item with index index.
bool removeItem (EXmlItem *item)
 Removes and deletes the item item.
virtual void setRootItem (EXmlItem *item)
 Replaces or sets the current root item to item.
EXmlItemrootItem () const
bool isModified () const
 Returns true, if the model has been modified since the last save.
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
int columnCount (const QModelIndex &parent=QModelIndex()) const
int rowCount (const QModelIndex &parent=QModelIndex()) const
QModelIndex parent (const QModelIndex &child) const
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
- Public Member Functions inherited from EAbstractItemModel
 EAbstractItemModel (QObject *parent=0)
virtual ~EAbstractItemModel ()

Protected Slots

virtual void itemChanged (EXmlItem *item)
 Reimplement this slot, if you want to recieve EXmlItem::changed() signals.
virtual void itemRowsAboutToBeInserted (EXmlItem *parent, int start, int end)
 Called by rootItem() signal EXmlItem::rowsAboutToBeInserted().
virtual void itemRowsInserted ()
 Called by rootItem() signal EXmlItem::rowsInserted().
virtual void itemRowsAboutToBeRemoved (EXmlItem *parent, int start, int end)
 Called by rootItem() signal EXmlItem::rowsAboutToBeRemoved().
virtual void itemRowsRemoved ()
 Called by rootItem() signal EXmlItem::rowsRemoved().
- Protected Slots inherited from EAbstractItemModel
virtual void errorByPass (const QString &message)
virtual void warningByPass (const QString &message)
virtual void informationByPass (const QString &message)

Protected Member Functions

bool registerParser (EXmlItem *(*createCallback)(EXmlModel *))
void setValidationSchema (QUrl url)
virtual bool prepareForSaving ()
 Called by save(QDomElement) to prepare model for saving.

Protected Attributes

QStringList headerList

Private Slots

void setModified (bool status)

Private Member Functions

QModelIndex indexFromItem (EXmlItem *find, EXmlItem *parent) const

Private Attributes

QUrl validationUrl
QMap< QString, EXmlParserItem * > parsers
EXmlItemmyRootItem
bool _isModified

Additional Inherited Members

- Static Public Member Functions inherited from EAbstractItemModel
static void connectByPass (QObject *parent, EAbstractItemModel *child)
static void connectByPass (EAbstractItemModel *parent, QObject *child)

Detailed Description

ExmlModel is a base class to handle XML files very easily.

To get an working XMl Model, you only have to subclass it and create an Constructor. Inside the constructor, append you header strings to headerList and register your subclassed EXmlItem's with help of registerParser().

To hide the rootItem, use QAbstractItemView::setRootIndex() and set it to the index of the rootItem.

If your model needs to be prepared before it could be saved, implement prepareForSaving() in your subclass.

To copy the complete model, create a new empty model and set a copy of the original root item as the new root item.

EXmlModel *newModel = new EXmlModel();
newModel->setRootItem(oldModel->rootItem()->copy());
Note
All tagnames used here are turned into lowercase.
See Also
EXmlItem
EXmlStandardRootItem
headerList

Constructor & Destructor Documentation

EXmlModel::EXmlModel ( QUrl  validationUrl,
QObject *  parent = 0 
)

validationUrl can point to a local file via file:// (e.g. file:///tmp/xmlschema.xsd) or to a url (e.g. http://www.example.org/example.dtd)

See Also
EDependencyModel as an example implementation

+ Here is the call graph for this function:

EXmlModel::~EXmlModel ( )
virtual

Member Function Documentation

int EXmlModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

+ Here is the caller graph for this function:

QVariant EXmlModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QVariant EXmlModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
QModelIndex EXmlModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QModelIndex EXmlModel::indexFromItem ( EXmlItem item) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QModelIndex EXmlModel::indexFromItem ( EXmlItem find,
EXmlItem parent 
) const
private

+ Here is the call graph for this function:

bool EXmlModel::isModified ( ) const

Returns true, if the model has been modified since the last save.

If the model is modified for the first time after a save() or load(), isModified() is set to true and also the signal modified(true) is emitted. Saving the model with save() resets the modified state to false (emits also modified(false) and the process starts over again.

To detect those changes, EXmlItem::changed() is monitored by the model and also row inserts and removes are observed.

bool EXmlModel::isValidXML ( )

checks the actual structure validation against the scheme at validationUrl

Returns
true if the structure is valid.

+ Here is the call graph for this function:

void EXmlModel::itemChanged ( EXmlItem item)
protectedvirtualslot

Reimplement this slot, if you want to recieve EXmlItem::changed() signals.

This default implementation emits the dataChanged() signal for the complete row represented by item.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EXmlItem * EXmlModel::itemFromIndex ( QModelIndex  index) const

+ Here is the caller graph for this function:

void EXmlModel::itemRowsAboutToBeInserted ( EXmlItem parent,
int  start,
int  end 
)
protectedvirtualslot

Called by rootItem() signal EXmlItem::rowsAboutToBeInserted().

It converts the recieved data to call beginInsertRows().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EXmlModel::itemRowsAboutToBeRemoved ( EXmlItem parent,
int  start,
int  end 
)
protectedvirtualslot

Called by rootItem() signal EXmlItem::rowsAboutToBeRemoved().

It calls beginRemoveRows() with converted recieved data.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EXmlModel::itemRowsInserted ( )
protectedvirtualslot

Called by rootItem() signal EXmlItem::rowsInserted().

It calls endInsertRows().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EXmlModel::itemRowsRemoved ( )
protectedvirtualslot

Called by rootItem() signal EXmlItem::rowsRemoved().

It calls endRemoveRows().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlModel::load ( QDomElement  element)

Loads the XML structure below and including element.

Returns true if everything went fine (e.g. every tag could be parsed)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlModel::load ( QDomDocument  document)

Overladed of load(QDomElement)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlModel::load ( QFile *  file)

Overladed of load(QDomDocument)

+ Here is the call graph for this function:

bool EXmlModel::load ( QString  file)

Overladed of load(QFile*)

+ Here is the call graph for this function:

bool EXmlModel::load ( QByteArray  data)

Overloaded of load(QDomDocument).

Constructs a QDomDocument out of the QByteArray.

+ Here is the call graph for this function:

void EXmlModel::modified ( bool  status)
signal

+ Here is the caller graph for this function:

QModelIndex EXmlModel::parent ( const QModelIndex &  child) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual bool EXmlModel::prepareForSaving ( )
inlineprotectedvirtual

Called by save(QDomElement) to prepare model for saving.

Reimplement this function, if anything needs to be done before the model can be saved.

+ Here is the caller graph for this function:

bool EXmlModel::registerParser ( EXmlItem *(*)(EXmlModel *)  createCallback)
protected

call this function to register your subclass of EXmlItem. Your subclass should contain a public static function to create the needed function pointer createCallback. This Function pointer is called during loading the structure, to create instances of your subclass and parse the given XML structure

Returns
true if the createCallback could be registered to handle tags with name tagName.
false, if not. This can be the case, if tagName is empty, or createCallback is NULL

The created EXmlParserItem by this function automatically provides the pointer to this EXmlModel, when calling the createCallback.

See Also
EXmlItem
EDependencyItem as an example implementation

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlModel::removeItem ( QModelIndex  index)

Removes and deletes the item with index index.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlModel::removeItem ( EXmlItem item)

Removes and deletes the item item.

Conveniance function for removeItem(QModelIndex())

+ Here is the call graph for this function:

bool EXmlModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)

+ Here is the call graph for this function:

EXmlItem * EXmlModel::rootItem ( ) const

+ Here is the caller graph for this function:

int EXmlModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool EXmlModel::save ( QDomElement &  useElem)

The model is stored into useElem. But be aware, that useElem will contain the rootItem of this model. Therefore useElem should be an empty element (but not a null element)

+ Here is the call graph for this function:

bool EXmlModel::save ( QFile *  file)

overladed of save(QDomElement)

+ Here is the call graph for this function:

bool EXmlModel::save ( QString  file)

overladed of save(QFile*)

+ Here is the call graph for this function:

QDomDocument EXmlModel::save ( )

The model contained in a QDomDocument.

The document is in utf-8 encoding. If an error occurs, an empty QDomDocument is returned.

+ Here is the caller graph for this function:

bool EXmlModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)

+ Here is the call graph for this function:

void EXmlModel::setModified ( bool  status)
privateslot

+ Here is the caller graph for this function:

void EXmlModel::setRootItem ( EXmlItem item)
virtual

Replaces or sets the current root item to item.

If an existing item is replaced, the signals modelAboutToBeReset() and modelReset() are emitted. Otherwise the signals layoutAboutToBeChanged() and layoutChanged() are emited.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EXmlModel::setValidationSchema ( QUrl  url)
protected

+ Here is the caller graph for this function:

Member Data Documentation

bool EXmlModel::_isModified
private
QStringList EXmlModel::headerList
protected

append strings to this list, to get more columns

EXmlItem* EXmlModel::myRootItem
private
QMap<QString, EXmlParserItem*> EXmlModel::parsers
private
QUrl EXmlModel::validationUrl
private

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