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?
Quote:
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....
Code:
/* check if absolute layer need a new page document */
void TextLayer::childAreaCheck()
{
/////// qDebug() << "### childArea ";
AbsoluteLayer *itemabsolute = 0;
QList<QGraphicsItem *> subLevelItems = childItems();
qreal lastdown = 400.0; /* A4:2 */
for (int i = 0; i < subLevelItems.size(); ++i) {
if (itemabsolute = qgraphicsitem_cast<AbsoluteLayer *>(subLevelItems[i]) ) {
itemabsolute->UpdatePageFormat();
lastdown = qMax (lastdown,itemabsolute->pos().y());
}
}
////////qDebug() << "### childArea lastpoint " << lastpoint;
const QRectF allpageRect
= boundingRect
();
if (!allpageRect.contains(lastpoint)) {
Tcursor.beginEditBlock();
Tcursor.insertText(" \t");
Tcursor.setBlockFormat(PageBreackBlock());
Tcursor.endEditBlock();
}
}
/* type is declared */
enum { Typex = UserType + 3 };
int type() const { return Typex; }
Re: Casting QGraphicsItem child from QGraphicsItem
The docs say:
Quote:
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.
Re: Casting QGraphicsItem child from QGraphicsItem
I solved on other Type to makeit readable ....
Code:
enum { Layer = 1 };
int type() const {return Layer;}
{
return int(static_cast<T>(0)->Layer) == int(AbsoluteLayer::Layer)
|| (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
}
template <class T>
inline T layer_cast
(const QGraphicsItem *item
) {
return int(static_cast<T>(0)->Layer) == int(AbsoluteLayer::Layer)
|| (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
}
AbsText::AbsText()
: device(0)
{
}
/* only one connect */
LayerText *AbsText::txtControl() const
{
if (!device) {
AbsoluteLayer *that = layer_cast<AbsoluteLayer *>(q);
device = new LayerText(); /* text-api all event */
connect(device, SIGNAL(q_cursor_newPos() ),q, SLOT(cursor_wake_up()));
connect(device,
SIGNAL(q_update
(QRect) ),q,
SLOT(updatearea
(QRect)));
connect(device,
SIGNAL(q_visible
(QRectF) ),q,
SLOT(ensureVisible
(QRectF)));
///////connect(device, SIGNAL(q_update_scene()),q, SLOT(SceneReload()));
}
return device;
}
Re: Casting QGraphicsItem child from QGraphicsItem
You have to change Type to Layer in lines #8 and #14 too.