
Originally Posted by
wysota
Designer might have used QDataStream to serialize all the objects, but its creators wanted the file format (ui) to be based on XML and not an internal format thus they had to provide operators for storing properties of those data objects in XML, hence the doubled work.
Sure, but I think if Qt provide some light-weighted base class for savable object and some Xml schemas, then we could reuse some of designer's codes. And designer itself could have a better looking parser. This would reduce a lot of code redundancy.
For instance
class QSavableClass {
public:
virtual ~QSavableClass();
};
class QXmlSchemaBase {
}
template <class Type>
class QXmlSchemaItem : public QXmlSchemaBase {
public:
typedef const Type& (QSavableClass::*Getter)() const;
typedef void (QSavableClass::*Setter)( const Type& );
QXmlSchemaItem( const QString& tag, QSavableClass& obj, Getter, Setter );
};
class QXmlSchema : public QXmlSchemaBase {
template <typename T>
void addSchemeItem( const QXmlSchemaItem& );
void addScheme( const QXmlSchema& );
};
Now it becomes easier for me:
class MyClass : public QSavableClass {
public:
const QString& str() const {
return _str;
}
void setString( const QString& str ) {
_str = str;
}
private:
}
class QSavableClass {
public:
virtual ~QSavableClass();
};
class QXmlSchemaBase {
}
template <class Type>
class QXmlSchemaItem : public QXmlSchemaBase {
public:
typedef const Type& (QSavableClass::*Getter)() const;
typedef void (QSavableClass::*Setter)( const Type& );
QXmlSchemaItem( const QString& tag, QSavableClass& obj, Getter, Setter );
};
class QXmlSchema : public QXmlSchemaBase {
template <typename T>
void addSchemeItem( const QXmlSchemaItem& );
void addScheme( const QXmlSchema& );
};
Now it becomes easier for me:
class MyClass : public QSavableClass {
public:
const QString& str() const {
return _str;
}
void setString( const QString& str ) {
_str = str;
}
private:
QString _str;
}
To copy to clipboard, switch view to plain text mode
I can now create a schema for MyClass by deriving from QXmlSchema and add the schema items accordingly, and much of the designer codes can be re-used and simplified...Any comments?
Also, looking at DomUI, I wonder why it has to parse the entire content first and then create the objects. Can we populate the objects while parsing the file? Is there a particular reason for what has been done in qdesigner's parser?
Bookmarks