PersistentWidgets.dox 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. \page PersistentWidgets Persistent Widgets
  3. With the QCAD Application Framework you can easily create a dialog or widget
  4. that can store and restore its user input.
  5. In this tutorial we will create a dialog with two input widgets:
  6. <em>X Position</em> and <em>Y Position</em>.
  7. \section folder Creating the Folder Structure
  8. Create a new action called "PersistentWidgets" as described in \ref CreatingActions.
  9. \section ui_file Creating the UI file
  10. With Qt Designer we create the UI file for the dialog called "PersistentWidgets.ui".
  11. \image html memorize_dialog/position_dialog.png
  12. - Set the object name of the dialog to "PersistentWidgets".
  13. - Set the object name of the upper \c QLineEdit widget to "PositionX".
  14. - Set the object name of the lower \c QLineEdit widget to "PositionY".
  15. - All input widgets should have meaningful default values.
  16. In this example set both values to "0.00".
  17. \section save_restore Saving and Restoring User Input
  18. Thanks to the introspection facilities of Qt, storing and restoring
  19. dialog data is a one-liner.
  20. \snippet PersistentWidgets.jsd include
  21. \snippet PersistentWidgets.jsd beginEvent
  22. Start QCAD and choose <em>Persistent Widgets</em> from the menu <em>Examples</em>.
  23. Enter numeric values e.g. for x "0.1" and for y "0.2".
  24. Then close the dialog and start the same action again.
  25. The input fields now shows <em>0.1</em> for x resp. <em>0.2</em> for y.
  26. You can also quit QCAD, restart it and start the action again.
  27. The dialog input fields are set to the last used valued.
  28. \section behind Behind the Scene
  29. The Widget Factory uses QSettings to save or restore values.
  30. The values set above are stored in a file called "QCAD3.conf" located in the
  31. QCAD configuration folder ($HOME/.config/RibbonSoft under Unix systems including
  32. Linux and Mac OS X or HKEY_CURRENT_USER\Software\RibbonSoft under Windows).
  33. Inside this file our dialog has its own group where values are stored.
  34. By definition the name of the group is the same as the dialog object
  35. name set in Qt Designer: \a PersistentWidgets.
  36. The same applies to the widget values. They are named after the object name set
  37. in Qt Designer.
  38. \code
  39. ...
  40. [PersistentWidgets]
  41. PositionX=0.1
  42. PositionY=0.2
  43. ...
  44. \endcode
  45. In this tutorial a \c QDialog is used as top level widget.
  46. However you can use a simple \c QWidget, a \c QDockWidget or any other widget.
  47. The mechanism and procedure are always the same.
  48. Always make sure that WidgetFactory.restoreState() is called before the widget
  49. is shown, and analogically WidgetFactory.saveState() is called before the
  50. widget is destroyed.
  51. \section complete_script The Complete Script
  52. \snippet PersistentWidgets.jsd main
  53. <p>&nbsp;</p>
  54. */