|
QCAD Application Framework
CAD Application Development and Automation.
|
With the QCAD Application Framework you can easily create a dialog or widget that can store and restore its user input. In this tutorial we will create a dialog with two input widgets: X Position and Y Position.
Create a new action called "PersistentWidgets" as described in CreatingActions.
With Qt Designer we create the UI file for the dialog called "PersistentWidgets.ui".
QLineEdit widget to "PositionX".QLineEdit widget to "PositionY".Thanks to the introspection facilities of Qt, storing and restoring dialog data is a one-liner.
Start QCAD and choose Persistent Widgets from the menu Examples. Enter numeric values e.g. for x "0.1" and for y "0.2". Then close the dialog and start the same action again. The input fields now shows 0.1 for x resp. 0.2 for y. You can also quit QCAD, restart it and start the action again. The dialog input fields are set to the last used valued.
The Widget Factory uses QSettings to save or restore values. The values set above are stored in a file called "QCAD3.conf" located in the QCAD configuration folder ($HOME/.config/RibbonSoft under Unix systems including Linux and Mac OS X or HKEY_CURRENT_USER under Windows).
Inside this file our dialog has its own group where values are stored. By definition the name of the group is the same as the dialog object name set in Qt Designer: PersistentWidgets. The same applies to the widget values. They are named after the object name set in Qt Designer.
In this tutorial a QDialog is used as top level widget. However you can use a simple QWidget, a QDockWidget or any other widget. The mechanism and procedure are always the same. Always make sure that WidgetFactory.restoreState() is called before the widget is shown, and analogically WidgetFactory.saveState() is called before the widget is destroyed.