I would probably go with the Model and View pattern. The view being the QGLWidget and the model a tree of objects.
Example:
+------------------+
| MyGlModel |
| |
| Rootitem | +-------------+
| | | | MyGlView |
| +- Item | | |
| | |----->| setModel() |
| +- Item | | |
| | | | |
| + Item | +-------------+
| |
+------------------+
+------------------+ +-------------------+
| MyGlView | | MyGlItem |
| | | |
| paintGl() | | drawItem(context) |
| | |----->| |
| +- iterate | | |
| over model | +-------------------+
| |
+------------------+
void MyGlView::drawGl()
{
// recursive call each item in the model tree
// For each item:
item->drawItem(context(), /*maybe other stuff*/);
}
void MyGlItem
::drawItem(QGLContext *context,
/*maybe other things*/) {
// Do the GL Painting for this item based on the context.
}
+------------------+
| MyGlModel |
| |
| Rootitem | +-------------+
| | | | MyGlView |
| +- Item | | |
| | |----->| setModel() |
| +- Item | | |
| | | | |
| + Item | +-------------+
| |
+------------------+
+------------------+ +-------------------+
| MyGlView | | MyGlItem |
| | | |
| paintGl() | | drawItem(context) |
| | |----->| |
| +- iterate | | |
| over model | +-------------------+
| |
+------------------+
void MyGlView::drawGl()
{
// recursive call each item in the model tree
// For each item:
item->drawItem(context(), /*maybe other stuff*/);
}
void MyGlItem::drawItem(QGLContext *context, /*maybe other things*/)
{
// Do the GL Painting for this item based on the context.
}
To copy to clipboard, switch view to plain text mode
Bookmarks