View Full Version : Advice for a new Project

17th April 2008, 18:40
I am implementing a simple CAD-like program for laying out basic house layouts. I would like to have a snap-to grid, the ability to add points, lines and form shapes etc.

I know that the scope of this is way beyond a help forum, but since I am going to be implementing it in QT, I'd like a general idea of which fundamental approach to take. There are many ways of going about it, and I'd hate to get 10,000 lines in before I realize I'm going down the wrong road.

So what fundamental architecture would you guys recommend for something like this? On my last similar project I used a big QWorkspace where I overloaded the paintevent and did a lot of manual drawing, and for my "entities" I directly inherited from QWidget and handled all of my own events.

I seem to remember something about a new flexible canvas widget in QT 4, but after a few searches I'm not seeing anything.

17th April 2008, 19:01
QGraphicsView framework?

17th April 2008, 22:16
I'd suggest using QGraphicsView and use things like
QGraphicsItem::itemChange() to handle snapping to grid and stuff. Should be pretty straightforward.

18th April 2008, 09:01
QGraphicsView (QGV) is a framework on top of QWidget/QPainter with a higher ( but not high ) level of abstraction. This can make your life easier, but also might limit your possibilities. As you already have implemented something similar with QWidget/QPainter you already know, that this isn't too difficult as well. IMHO using QGV is a fundamental decision you should spend more time with.

Your task is to implement a high level framework dealing with objects from your application domain. I would start to make a design for this first. IMHO the design of QGV is good inspiration.

Try to see QWidget/QPainter as the natural way to implement it. Then check your requirements, if QGV has something to offer, that makes your implementation easier. If you find enough useful features you need, go for it.

But in the end QGV inherits a couple of problems from QPainter/QWidget, that you need to solve regardless of your design decision. F.e. you might need to implement a lot of clipping code to get an acceptable performance for zooming in.