PDA

View Full Version : Query in 40000 chip demo



aamer4yu
12th October 2006, 12:45
I am new to Qt and was exploring demos of Qt.
I was trying the 40000 chip demo code and faced some confusion

1) I want to know the significance of choosing -11000 to 11000 in the function void MainWindow::populateScene()

2) if i change the loop, the chip movemment gets slow


The loop in void MainWindow::populateScene() function is


for (int i = -11000; i < 11000; i += 110) {
++xx;
int yy = 0;
for (int j = -7000; j < 7000; j += 70) {
++yy;
qreal x = (i + 11000) / 22000.0;
qreal y = (j + 7000) / 14000.0;

QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
QGraphicsItem *item = new Chip(color, xx, yy);
item->setPos(QPointF(i, j));
scene->addItem(item);

++nitems;
}
}



If i replace the loop with


for (int i = 0; i < 22000; i += 110) {
++xx;
int yy = 0;
for (int j = 0; j < 14000; j += 70) {
++yy;
qreal x = (i) / 22000.0;
qreal y = (j) / 14000.0;

int w,h;
w= image.width();
h= image.height();
QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
QGraphicsItem *item = new Chip(color, xx, yy);
item->setPos(QPointF(i, j));
scene->addItem(item);


++nitems;
}
}





and move the chips in the view, the movement is much slow.

What am i missing here ???

aamer4yu
13th October 2006, 11:38
None to solve the logical problem ????:confused:

jacek
14th October 2006, 19:39
2) if i change the loop, the chip movemment gets slow
Is it still slow after you restore the original version and recompile it? Maybe you have disabled the optimization or you do a debug build?

wysota
14th October 2006, 19:56
1) I want to know the significance of choosing -11000 to 11000 in the function void MainWindow::populateScene()

The scene (0,0) coordinate is in the middle of the scene.

aamer4yu
16th October 2006, 11:14
@ Jacek
yes i tried rebuilding the application, using each loop

@wysota,
thx, even i guessed that it is in middle, in fact the aim of writing the new loop was to see how zoom would be affected if the middle is changed to top left

So I would like to know how changing the middle cordinate of the scenen si affecting the speed of dragging ??

Any help ?

aamer4yu
16th October 2006, 11:17
@jacek... sorry didnt annwer u completely..
well the original version runs fine when i restore to it.
And ia m not using any optimization,,,using the defaults when i open the project in Visual Studio.
The problem is occuring when i change the loop , making the middle cordinates as top left. :(

wysota
16th October 2006, 12:01
So I would like to know how changing the middle cordinate of the scenen si affecting the speed of dragging ??
Why would it affect the speed of dragging? It is important for rotation of the canvas (it is rotated around the centre), nothing else.

jacek
16th October 2006, 21:35
The problem is occuring when i change the loop , making the middle cordinates as top left.
Do I understand you correctly, that if you change that loop back to original version and recompile the example, it works faster?

aamer4yu
17th October 2006, 12:19
@wysota even i want to know why was it affetcing the speed while dragging the chips..
u can try urself...

@jacek u r right... the original works fine,,, but whne i change it, the dragging becomes slow .. i amnot able to logically make out why is it happening :(

wysota
17th October 2006, 12:39
@wysota even i want to know why was it affetcing the speed while dragging the chips..
u can try urself...

@jacek u r right... the original works fine,,, but whne i change it, the dragging becomes slow .. i amnot able to logically make out why is it happening :(

It works fine for me... I don't experience any slowdowns.

jacek
18th October 2006, 21:51
It works fine for me... I don't experience any slowdowns.
For me too. I have both versions running side by side and I don't see any difference.

wysota
19th October 2006, 02:01
Something else must have been changed in the code.

@aamer4yu: Could you make a diff of the source code to see if there are any other differences outside the loop?