QG_GraphicView::paintEvent conditions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

QG_GraphicView::paintEvent conditions

ravas
if (redrawMethod & RS2::RedrawGrid)
...
if (redrawMethod & RS2::RedrawDrawing)
...
if (redrawMethod & RS2::RedrawOverlay)
...

RedrawNone = 0
RedrawGrid = 1
RedrawOverlay = 2
RedrawDrawing = 4
RedrawAll = 0xffff

https://en.wikipedia.org/wiki/Bitwise_operation#AND

I don't understand the point of these expressions.
If 0xffff & 2 evaluates to true, then 0xffff alone will evaluate to true.
If 0 & 2 evaluates to false, then 0 alone will evaluate to false.
Isn't the right side superfluous?
In otherwords, can't we just simplify it to one condition: if (redrawMethod) ?
Reply | Threaded
Open this post in threaded view
|

Re: QG_GraphicView::paintEvent conditions

R. van Twisk
Administrator

On Oct 12, 2015, at 9:20 PM, ravas [via LibreCAD] <[hidden email]> wrote:

if (redrawMethod & RS2::RedrawGrid)
...
if (redrawMethod & RS2::RedrawDrawing)
...
if (redrawMethod & RS2::RedrawOverlay)
...

RedrawNone = 0
RedrawGrid = 1
RedrawOverlay = 2
RedrawDrawing = 4
RedrawAll = 0xffff

https://en.wikipedia.org/wiki/Bitwise_operation#AND

I don't understand the point of these expressions.
If 0xffff & 2 evaluates to true,

It evaluates to 2, not to true

then 0xffff alone will evaluate to true.

0xffff & 0 evaluates to 0, there is no 0xffff alone here

If 0 & 2 evaluates to false, then 0 alone will evaluate to false.
Isn't the right side superfluous?
In otherwords, can't we just simplify it to one condition: if (redrawMethod) ?


If one method says 

redrawMethod = redrawMethod | RS2::RedrawGrid
and a other methods says:

redrawMethod = redrawMethod | RS2::RedrawOverlay

Then only these two get executed, but not redraw of the drawing.

makes sense?

Reply | Threaded
Open this post in threaded view
|

Re: QG_GraphicView::paintEvent conditions

ravas
Thanks for the reply.

I misunderstood how the & operator worked before;
however, I still don't see the need for bitwise operators.
It seems like this system was written so that the least amount of people could understand it.
There has to be a way to simplify this to three bool member variables;
although, I'm not sure if it would be worth the effort to rewrite everything.

Something I noticed in testing is that the "if (redrawMethod & RS2::RedrawOverlay)" block
is processed when the mouse is moved in the drawing area in the default selection mode.
Reply | Threaded
Open this post in threaded view
|

Re: QG_GraphicView::paintEvent conditions

dxli
using binary flags makes sense, as the flags are supposed to support any combination of on/off flags.

Binary flags are common implementation in Qt, for example:

http://doc.qt.io/qt-5/qsizepolicy.html#PolicyFlag-enum

ravas wrote
Thanks for the reply.

I misunderstood how the & operator worked before;
however, I still don't see the need for bitwise operators.
It seems like this system was written so that the least amount of people could understand it.
There has to be a way to simplify this to three bool member variables;
although, I'm not sure if it would be worth the effort to rewrite everything.

Something I noticed in testing is that the "if (redrawMethod & RS2::RedrawOverlay)" block
is processed when the mouse is moved in the drawing area in the default selection mode.