Results 1 to 6 of 6

Thread: How to design?

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default How to design?

    Hi,

    I have a common QGraphicsItem which I use it in several other classes. The question is;

    Does these classes should be QGraphicsItem too or not? Which is better than the other?


    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to design?

    can you please be a little bit more precise, because I don't get your question. How do your classes look like? (= important are the base classes of them)

    Qt Code:
    1. MyItem : public QGraphicsItem
    To copy to clipboard, switch view to plain text mode 

    ...and then?

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How to design?

    Hi again,

    Sure I can,

    you have an item like;

    Qt Code:
    1. class LineItem : public QGraphicsItem { ... }
    To copy to clipboard, switch view to plain text mode 

    and you need to use this LineItem for example in a class to form different type of shapes such as rectangle, triangle or more complex shapes like a star. So how should we implement the shape class( f.e.: RectangleItem, StarItem)? Should they inherit QGraphicsItem as well?

    Hope you catch the point now.

  4. #4
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to design?

    you better have a abstract class (may be CShapeitem) which is derived QGraphicsItem and put all the common code which are part of its descendant. from there u can derive ur respective classes and in main ui, it will be very convenient you to access objects of derived class using CShapeItem.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to design?

    Ok, as I understand you now, you want to build a class like rectangleItem out of four of your LineItems.

    If so (which is in most cases not the best way) you have two options:

    • Your class rectangleItem has no base class. But then you have to set a pointer to the scene and add the lines manually to the scene, since you can't add rectangleItem to it since it is no real graphics item.
    • Use QGraphicsItem as a base class for rectangleItem. Now when creating the line items use the instance of rectangleItem as parent. Then the lines will automatically move, if you move your rectangleItem. (<- this way I would prefer, if you don't want to use navi1084 variant and do the "line drawing" in each shape in the corresponding class itself.)

  6. #6
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How to design?

    What about using QGraphicsItemGroup to be derived by the rectangleItem? And if I use QGraphicsItemGroup method( if it's appropriate), do I need extra doing for the rectangleItem's shape() and boundingRect() functions which I reimplemented both of them in LineItem?

Similar Threads

  1. a design problem in multithread programming
    By ryen in forum Qt Programming
    Replies: 4
    Last Post: 4th April 2009, 13:46
  2. Replies: 3
    Last Post: 5th October 2008, 23:41
  3. Multiplatform Video Viewer Application Design Options
    By PhilippB in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2008, 09:38
  4. Need some help on design and implementation
    By cool_qt in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2008, 21:19
  5. Dialog and code design issue
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2006, 17:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.