title: QT: QUndocommand & Realtime editing
body: <p><strong>Qt::QUndoCommand problem and possible solutions.</strong></p>
  
  <p>We are developing an application of 3D editing in Qt.</p>
  
  <p>We need to implement a "stack of operations" which allow the user to call undo-redo on his operations.</p>
  
  <p>We are using QUndoStack with QUndoCommand Qt classes.</p>
  
  <p>The application is based on the MVC pattern so the View (QGLWidget) knows how to draw the scene structure.</p>
  
  <p>We have sliders (QSlider) to translate/rotate/scale the 3D objects (Meshes), and we need to show the effect of the transformations in real-time.</p>
  
  <p><em>For example if I have selected an object and I'm moving the "X Translation Slider" I want to see the object moving along the X axis while I'm dragging the slider.
  The problem is to get the real-time editing working with the stack of operations. In fact the "undoable" operation who should be pushed on the stack is the total slider movement (from the pression to the release of the slider).</em></p>
  
  <p><strong>We find out 2 ways of doing this:</strong></p>
  
  <ol>
  <li><p>While I'm dragging the slider (at every valueChanged signal) the
  transformations are applied to the model and the QGLWidget updates
  straight after every slider tick. At the release of the slider the
  command must be pushed in the stack. QUndoStack automatically calls
  the QUndoCommand::redo() action when a command is pushed. To prevent
  the operation to be executed twice (the first time to grant the
  real-time effect, the second at the QUndoStack::push() call), before
  the call of QUndoStack::push() The inverse transformation is applied
  to the object (obtained from the total slider movement) and then I
  push the command to the stack.</p></li>
  <li><p>QUndoStack tryes to merge command when they have the same result
  from a call to QUndoCommand::Id(). While I'm dragging the slider (at
  every valueChanged signal) a QUndoCommand is generated and
  immediately pushed on the stack, the stack merges it with the
  command at the top if they have the same Id(), then the stack calls
  the redo() for the command who is being inserted, then the QGLWidget
  updates and the real-time effect is obtained.</p></li>
  </ol>
  
  <p>With the second one an instance of the "Command" class is generated every slider tick, while with the first one the real-time operation get's reverted just to push a command and to stay in a consistent state.</p>
  
  <p><em>What solution is better in terms of "good programming"?What is better in terms of performance?</em></p>