Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 10

Qt-interest Archive, March 2002
data consistency techniques


Message 1 in thread

I'd like to find a good solution to the following problem.

Suppose you have N spin-boxes, all of them showing the value of the same
variable X.
When the user interacts with any of the N spin-boxes, all the other N-1
should be updated consequently.

I found two ways to do that:

1) to write a slot for every spin-box. this slot is connected to the valueChanged(int)
signal and it updates the value of the remaining N-1 spin-boxes.
The main drawback is that if you add new spin-boxes (N increases) you will
have to add code to all the slots.

2) to write a single slot and connect all the valueChanged(int) signals
to it. In the slot there will be the code to update all the spin-boxes.
The main drawback is that the spin-box that has generated the signal won't
be distinguished from the others and its value will be changed twice (this
fact in a real implementation not as trivial as this one can be a problem...)
Probably, the slot could identify the signal sender (using QObject::sender())
and update only the right spin-boxes.

The latter solution seems to be better than the former but I don't think
it is very smart because of using sender() which, as said in Qt docs, violates
the object-oriented principle of modularity.

Can you imagine a better solution ?

greetings,

mow.



__________________________________________________________________
Abbonati a Tiscali!
Con Tiscali By Phone puoi anche ascoltare ed inviare email al telefono.
Chiama Tiscali By Phone all' 892 800        http://byphone.tiscali.it


Message 2 in thread

I would create a "state object" that would act as a server to all the spin 
boxes.  Each spin box sends a signal to the state object, and the state 
object in turn sends a signal back to the spin boxes.

I used this approach successfully with the design of a 3D CAD viewer, where 
my "state object" contained the translations (X, Y, Z) and rotations (RX, RY, 
RZ) of the view.  There were multiple ways of changing the view, and each of 
these connected to a master "view object," which in turn updated the 
on-screen view, values of sliders, etc.

A screen shot of the viewer may be found here (50K PNG figure):

   http://gemacs.gemacs.com/Framework/SmartView/SVscene1.html

Hope this helps.

Buddy Coffey
Advanced Electromagnetics

On Wednesday 27 March 2002 10:50, you wrote:
> I'd like to find a good solution to the following problem.
>
> Suppose you have N spin-boxes, all of them showing the value of the same
> variable X.
> When the user interacts with any of the N spin-boxes, all the other N-1
> should be updated consequently.
>
> I found two ways to do that:
>
> 1) to write a slot for every spin-box. this slot is connected to the
> valueChanged(int) signal and it updates the value of the remaining N-1
> spin-boxes.
> The main drawback is that if you add new spin-boxes (N increases) you will
> have to add code to all the slots.
>
> 2) to write a single slot and connect all the valueChanged(int) signals
> to it. In the slot there will be the code to update all the spin-boxes.
> The main drawback is that the spin-box that has generated the signal won't
> be distinguished from the others and its value will be changed twice (this
> fact in a real implementation not as trivial as this one can be a
> problem...) Probably, the slot could identify the signal sender (using
> QObject::sender()) and update only the right spin-boxes.
>
> The latter solution seems to be better than the former but I don't think
> it is very smart because of using sender() which, as said in Qt docs,
> violates the object-oriented principle of modularity.
>
> Can you imagine a better solution ?
>
> greetings,
>
> mow.
>
>
>
> __________________________________________________________________
> Abbonati a Tiscali!
> Con Tiscali By Phone puoi anche ascoltare ed inviare email al telefono.
> Chiama Tiscali By Phone all' 892 800        http://byphone.tiscali.it