Results 1 to 4 of 4

Thread: Casting QGraphicsItem child from QGraphicsItem

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Casting QGraphicsItem child from QGraphicsItem

    Why on qt4.4 i can not qgraphicsitem_cast child item?
    on other lower version is possibel ... is this a Bug?


    d:/qt4.4/include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h: In function `
    T qgraphicsitem_cast(QGraphicsItem*) [with T = AbsoluteLayer*]':
    textapi\Layer_Auto_Extended.cpp:226: instantiated from here
    d:/qt4.4/include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:945: error: ag
    gregate value used where an integer was expected
    d:/qt4.4/include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:945: error: ag
    gregate value used where an integer was expected
    mingw32-make[1]: *** [build/.obj/Layer_Auto_Extended.o] Error 1
    mingw32-make[1]: Leaving directory `C:/_dev2/luxor_svn/fop_miniscribus.2.0.r1/sr
    c'
    mingw32-make: *** [debug] Error 2
    this is the error code piece....

    Qt Code:
    1. /* check if absolute layer need a new page document */
    2. void TextLayer::childAreaCheck()
    3. {
    4. /////// qDebug() << "### childArea ";
    5. AbsoluteLayer *itemabsolute = 0;
    6. QList<QGraphicsItem *> subLevelItems = childItems();
    7. qreal lastdown = 400.0; /* A4:2 */
    8.  
    9. for (int i = 0; i < subLevelItems.size(); ++i) {
    10.  
    11. if (itemabsolute = qgraphicsitem_cast<AbsoluteLayer *>(subLevelItems[i]) ) {
    12. itemabsolute->UpdatePageFormat();
    13. lastdown = qMax (lastdown,itemabsolute->pos().y());
    14. }
    15.  
    16. }
    17.  
    18. QPointF lastpoint(50.,lastdown);
    19. ////////qDebug() << "### childArea lastpoint " << lastpoint;
    20. const QRectF allpageRect = boundingRect();
    21. if (!allpageRect.contains(lastpoint)) {
    22. QTextCursor Tcursor = textCursor();
    23. Tcursor.movePosition(QTextCursor::End);
    24. Tcursor.beginEditBlock();
    25. Tcursor.insertText(" \t");
    26. Tcursor.setBlockFormat(PageBreackBlock());
    27. Tcursor.endEditBlock();
    28. }
    29. }
    30.  
    31. /* type is declared */
    32.  
    33. enum { Typex = UserType + 3 };
    34. int type() const { return Typex; }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Casting QGraphicsItem child from QGraphicsItem

    The docs say:
    To enable use of qgraphicsitem_cast() with a custom item, reimplement this function and declare a Type enum value equal to your custom item's type.
    You don't have the Type enum, but Typex.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Casting QGraphicsItem child from QGraphicsItem

    I solved on other Type to makeit readable ....


    Qt Code:
    1. enum { Layer = 1 };
    2. int type() const {return Layer;}
    3.  
    4.  
    5. template <class T> inline T layer_cast(QGraphicsItem *item)
    6. {
    7. return int(static_cast<T>(0)->Layer) == int(AbsoluteLayer::Layer)
    8. || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
    9. }
    10.  
    11. template <class T> inline T layer_cast(const QGraphicsItem *item)
    12. {
    13. return int(static_cast<T>(0)->Layer) == int(AbsoluteLayer::Layer)
    14. || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
    15. }
    16.  
    17.  
    18.  
    19. AbsText::AbsText()
    20. : device(0)
    21. {
    22.  
    23. }
    24. /* only one connect */
    25. LayerText *AbsText::txtControl() const
    26. {
    27. if (!device) {
    28. AbsoluteLayer *that = layer_cast<AbsoluteLayer *>(q);
    29. device = new LayerText(); /* text-api all event */
    30. connect(device, SIGNAL(q_cursor_newPos() ),q, SLOT(cursor_wake_up()));
    31. connect(device, SIGNAL(q_update(QRect) ),q, SLOT(updatearea(QRect)));
    32. connect(device, SIGNAL(q_visible(QRectF) ),q, SLOT(ensureVisible(QRectF)));
    33. ///////connect(device, SIGNAL(q_update_scene()),q, SLOT(SceneReload()));
    34. }
    35. return device;
    36. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Casting QGraphicsItem child from QGraphicsItem

    You have to change Type to Layer in lines #8 and #14 too.

Similar Threads

  1. Replies: 9
    Last Post: 22nd June 2008, 23:26
  2. Casting QGraphicsItem
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2007, 00:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.