LibEngsas
|
ExmlModel is a base class to handle XML files very easily. More...
#include <exmlmodel.h>
Signals | |
void | modified (bool status) |
![]() | |
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(). More... | |
void | eRowsRemoved (const QModelIndex &parent, int start, int end) |
Replacement of private signal rowsRemoved(). More... | |
Public Member Functions | |
EXmlModel (QUrl validationUrl, QObject *parent=0) | |
virtual | ~EXmlModel () |
bool | load (QDomElement element) |
Loads the XML structure below and including element . More... | |
bool | load (QDomDocument document) |
Overladed of load(QDomElement) More... | |
bool | load (QFile *file) |
Overladed of load(QDomDocument) More... | |
bool | load (QString file) |
Overladed of load(QFile*) More... | |
bool | load (QByteArray data) |
Overloaded of load(QDomDocument). More... | |
bool | save (QDomElement &useElem) |
bool | save (QFile *file) |
bool | save (QString file) |
QDomDocument | save () |
The model contained in a QDomDocument. More... | |
bool | isValidXML () |
EXmlItem * | itemFromIndex (QModelIndex index) const |
QModelIndex | indexFromItem (EXmlItem *item) const |
bool | removeItem (QModelIndex index) |
Removes and deletes the item with index index . More... | |
bool | removeItem (EXmlItem *item) |
Removes and deletes the item item . More... | |
virtual void | setRootItem (EXmlItem *item) |
Replaces or sets the current root item to item . More... | |
EXmlItem * | rootItem () const |
bool | isModified () const |
Returns true, if the model has been modified since the last save. More... | |
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()) |
![]() | |
EAbstractItemModel (QObject *parent=0) | |
virtual | ~EAbstractItemModel () |
Protected Slots | |
virtual void | itemChanged (EXmlItem *item) |
Reimplement this slot, if you want to recieve EXmlItem::changed() signals. More... | |
virtual void | itemRowsAboutToBeInserted (EXmlItem *parent, int start, int end) |
Called by rootItem() signal EXmlItem::rowsAboutToBeInserted(). More... | |
virtual void | itemRowsInserted () |
Called by rootItem() signal EXmlItem::rowsInserted(). More... | |
virtual void | itemRowsAboutToBeRemoved (EXmlItem *parent, int start, int end) |
Called by rootItem() signal EXmlItem::rowsAboutToBeRemoved(). More... | |
virtual void | itemRowsRemoved () |
Called by rootItem() signal EXmlItem::rowsRemoved(). More... | |
![]() | |
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. More... | |
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 |
EXmlItem * | myRootItem |
bool | _isModified |
Additional Inherited Members | |
![]() | |
static void | connectByPass (QObject *parent, EAbstractItemModel *child) |
static void | connectByPass (EAbstractItemModel *parent, QObject *child) |
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::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)
|
virtual |
int EXmlModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
QVariant EXmlModel::data | ( | const QModelIndex & | index, |
int | role = Qt::DisplayRole |
||
) | const |
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 |
QModelIndex EXmlModel::indexFromItem | ( | EXmlItem * | item | ) | const |
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
|
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
.
EXmlItem * EXmlModel::itemFromIndex | ( | QModelIndex | index | ) | const |
|
protectedvirtualslot |
Called by rootItem() signal EXmlItem::rowsAboutToBeInserted().
It converts the recieved data to call beginInsertRows().
|
protectedvirtualslot |
Called by rootItem() signal EXmlItem::rowsAboutToBeRemoved().
It calls beginRemoveRows() with converted recieved data.
|
protectedvirtualslot |
Called by rootItem() signal EXmlItem::rowsInserted().
It calls endInsertRows().
|
protectedvirtualslot |
Called by rootItem() signal EXmlItem::rowsRemoved().
It calls endRemoveRows().
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)
bool EXmlModel::load | ( | QDomDocument | document | ) |
Overladed of load(QDomElement)
bool EXmlModel::load | ( | QFile * | file | ) |
bool EXmlModel::load | ( | QString | file | ) |
bool EXmlModel::load | ( | QByteArray | data | ) |
Overloaded of load(QDomDocument).
Constructs a QDomDocument out of the QByteArray.
|
signal |
QModelIndex EXmlModel::parent | ( | const QModelIndex & | child | ) | const |
|
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.
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
createCallback
could be registered to handle tags with name tagName
. tagName
is empty, or createCallback
is NULLThe created EXmlParserItem by this function automatically provides the pointer to this EXmlModel, when calling the createCallback
.
bool EXmlModel::removeItem | ( | QModelIndex | index | ) |
Removes and deletes the item with index index
.
bool EXmlModel::removeItem | ( | EXmlItem * | item | ) |
Removes and deletes the item item
.
Conveniance function for removeItem(QModelIndex())
bool EXmlModel::removeRows | ( | int | row, |
int | count, | ||
const QModelIndex & | parent = QModelIndex() |
||
) |
EXmlItem * EXmlModel::rootItem | ( | ) | const |
int EXmlModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
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)
bool EXmlModel::save | ( | QFile * | file | ) |
overladed of save(QDomElement)
bool EXmlModel::save | ( | QString | file | ) |
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.
bool EXmlModel::setData | ( | const QModelIndex & | index, |
const QVariant & | value, | ||
int | role = Qt::EditRole |
||
) |
|
privateslot |
|
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.
|
protected |
|
private |
|
protected |
append strings to this list, to get more columns
|
private |
|
private |
|
private |