0

I use Qt jambi 4.7.1 for my project. I have made a abstract class named Component who extends QGraphicsRectItem. I've set my Component flags with the purpose to move it into a same QGraphicsScene.

public abstract class Component extends QGraphicsRectItem{

 public Signal1<QPoint>  componentMoved = new Signal1<QPoint>();
 private int id;
 private int nextId;
 private List<Route> routes = new ArrayList<Route>();
 protected QPixmap image;
 protected static QSizeF size = new QSizeF(100, 100);    

public Component(int pointX1, int pointY1, int id) {

    super(new QRectF(new QPointF(pointX1,pointY1),size));       
    this.id = id;


    //this.setFlag(GraphicsItemFlag.ItemIsSelectable, true);
    this.setFlag(GraphicsItemFlag.ItemIsMovable,true);

    this.setFlag(GraphicsItemFlag.ItemSendsGeometryChanges, true);      
    this.setCacheMode(CacheMode.DeviceCoordinateCache,new QSize(1024,1024));

}

public void drawComponent(){
    new QGraphicsPixmapItem(image.scaled(size.toSize()), this);     
}   

@Override
public void mousePressEvent(QGraphicsSceneMouseEvent e){
    this.setTransformOriginPoint(e.scenePos());
}

@Override
public Object itemChange(GraphicsItemChange change, Object value){
    switch (change) {
    case ItemPositionHasChanged:

        QPointF currentPos = this.scenePos();
        componentMoved.emit(currentPos.toPoint());              
        break;
    default:
        break;
    }       
    return super.itemChange(change, value);
}

public int getId(){
    return id;
}

public int getNextId(){
    return nextId;
}   

public QPixmap getImage(){
    return image;
}

public List<Route> getRoutes(){
    return routes;
}

public QSizeF getSize(){
    return size;
}

public void addRoute(Component nextComponent){
    //routes.add(new Route(this, nextComponent));
}

So it work, now I can move my Component in my scene with a mouse click. But, I have a bug when I move my Component it always return to its initial position before each drag. I'm sure it's just a simple thing but I've searched a long time on internet and I've found nothing.

Sorry for my bad english! :P

  • Could you attach more code? I’d guess you have somewhere an initializer that is run too often or something, but that’s just guessing. – Smar Jul 11 '12 at 04:18
  • I add the code of the whole class! If you want, I can add other part of my code! The concrete classes who extends Component redefine method drawComponent() only. – Junior Gregoire Jul 11 '12 at 14:39
  • Are you sure you are using Jambi 4.5? GraphicsItemFlag.ItemSendsGeometryChanges was introduced in Qt 4.6, so it won’t be in 4.5. – Smar Jul 11 '12 at 15:49
  • No I use Jambi 4.7.1 but the eclipse plugin use Jambi 4.5.0! So that's the reason I mistake the version sorry! – Junior Gregoire Jul 11 '12 at 16:02
  • Is there any way I could test your application (doing a very simple few-class version of it I could compile and inspect in timely manner)? As Jambi dev, I’m wondering if there is actual bug or not, the item class looks ok, so my next suspect would be view usage. – Smar Jul 12 '12 at 07:10
  • The strange bug is vanished for a unknown reason! Now my components move without trouble. If I find the cause of this strange bug, I will update the status. Thank for help! – Junior Gregoire Jul 16 '12 at 18:48
  • Ok :) Maybe you should answer this as an answer and accept your answer, so this is cleaner to read? :) – Smar Jul 16 '12 at 20:53

1 Answers1

0

The bug is not occurred anymore for unknown reason! I think my components didn't update their position correctly to the graphicsscene. So I probably modify some codes in relation with the display of my components and resolve the bug by accident. If I'll find what exactly cause this bug, I will update this post!