[Interest] How to create a custom Model
Knut Krause
knut.krause at lagom.de
Fri Nov 16 16:56:17 CET 2012
Hi,
As a beginners project (I'm quite new to both C++ and Qt) I thought about
developing a little GPS application since there'd be a lot to play around
(XML, Model/View, QWT, OpenGL and son on ;-) )
Now my first question: How would you implement the underlying model? Since main
gpx structure (the interests me in the beginning) is
gpx
trk
trkseg
trkpt
as seen at [1] my model is going to be a tree. So AFAIK two approaches would
be valid: QAbstractItemModel and QStandardItemModel.
The first approach would be somehow like [2] I think but since it's so simple
it lacks write functionality I'm not sure yet how I'd implement that in
semantically correct way. I found other people pointing out the advantages of
QStandardItemModel at [3].
Now if I create the model I'd like to keep the semantic in the gpx data. It'd
be great if I could call functions like "QDateTime TrackPoint::time()" and so
on later so the Views can use the QModelIndex approach and I myself can access
the model in a more intuitive way in my code when I want to smooth the whole
track for example or find the highest point and so on.
How would you implement such a model?
regards
Knut
[1] https://en.wikipedia.org/wiki/GPS_eXchange_Format#Sample_GPX_document
[2] http://doc.qt.digia.com/4.8-snapshot/itemviews-simpletreemodel.html
[3] https://invalidmagic.wordpress.com/2010/09/20/qabstractitemmodel-vs-
qstandarditemmodel/
More information about the Interest
mailing list