diff --git a/examples/ex_script_dialog.qml b/examples/ex_script_dialog.qml new file mode 100644 index 00000000..2f881714 --- /dev/null +++ b/examples/ex_script_dialog.qml @@ -0,0 +1,59 @@ +// Example script with all the different widgets managed by ScriptDialog showing how to set/get data + +import Script 1.0 + +ScriptDialog { + id: root + + // Function called at startup, once the dialog is setup + function init() { + // Initializing widget data + data.lineEdit = "Initialization text" + // Define checkBox as unchecked and radioButton as checked + data.checkBox = false + data.radioButton = true + data.spinBox = 1 + data.doubleSpinBox = 4.2 + // Defined the possible choices for the comboBoxfine + data.comboBoxModel = ["1", "2", "3"] + data.comboBox = "2" + } + + function showData() { + Message.log("OK button is clicked") + Message.log("LineEdit data: " + data.lineEdit) + Message.log("CheckBox data: " + data.checkBox) + Message.log("RadioButton data: " + data.radioButton) + Message.log("SpinBox data: " + data.spinBox) + Message.log("DoubleSpinBox data: " + data.doubleSpinBox) + Message.log("ComboBox data: " + data.comboBox) + } + + // Function called when the user click on the OK button + onAccepted: { + // Logging the state of each widget when OK is clicked + showData(); + } + + // Function called when the user click on the Cancel button + onRejected: { + // Logging when the Cancel button is clicked + Message.log("Cancel button is clicked") + } + + // Function called when a button is clicked + onClicked:(name)=>{ + if (name == "pushButton"){ + Message.log("PushButton is clicked") + } + else if (name == "toolButton"){ + Message.log("ToolButton is clicked") + } + } + // Function to automatically test the script, useful for automated testing + // It runs the script without user interaction + function test() { + showData(); + close(); + } +} diff --git a/examples/ex_script_dialog.ui b/examples/ex_script_dialog.ui new file mode 100644 index 00000000..a368f9eb --- /dev/null +++ b/examples/ex_script_dialog.ui @@ -0,0 +1,151 @@ + + + Form + + + + 0 + 0 + 407 + 374 + + + + Form + + + + + + pushButton + + + + + + + PushButton + + + + + + + lineEdit: + + + + + + + + + + + + + + checkBox + + + + + + + CheckBox + + + + + + + radioButton + + + + + + + RadioButton + + + + + + + spinBox + + + + + + + + + + doubleSpinBox + + + + + + + + + + comboBox + + + + + + + + + + Qt::Vertical + + + + 20 + 249 + + + + + + + + dialogButtonBox + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + true + + + ToolButton + + + + + + + toolButton + + + + + + + + diff --git a/tests/tst_knut.cpp b/tests/tst_knut.cpp index 8222aa04..85becfc5 100644 --- a/tests/tst_knut.cpp +++ b/tests/tst_knut.cpp @@ -80,6 +80,7 @@ private slots: KNUT_EXAMPLE(ex_gui_interactive) KNUT_EXAMPLE(ex_gui_progressbar) + KNUT_EXAMPLE(ex_script_dialog) }; QTEST_MAIN(TestKnut)