Class Reference dialog

a custom dialog to input values More...

Member

dialog()
int addCheckBox(string label,bool state=false)
int addComboBox(stringList item, string defaultitem="")
int addLabel(string)
int addLayer( int defaulLayer)
int addLineEdit(string defaultText)
int addSpinBox(int defaultValue, int minValue, int maxValue )
int addDoubleSpinBox(double defaultValue, double minValue, double maxValue, double step, double decimals )
int exec()
bool getBool(int id)
double getDouble(int id)
int getInt(int id)
string getString(int id)
void setWindowTitle(string s)

Detailed Description

A dialog is a local input window you construct in a C++ macro: dialog d; then add widgets line by line. addLabel, addLineEdit, addSpinBox, addComboBox, addCheckBox, addLayer, and addDoubleSpinBox each return an integer id. exec shows the dialog and pauses the macro until the user closes it; that return value is the button used to close. After exec, getString, getInt, getBool, and getDouble read the widget with that id. setWindowTitle sets the text in the title bar. It exists only for LayoutEditor C++ macros; Python scripts use the dialog facilities of that language.

Example:

Dialog example

 dialog d;
 d.setWindowTitle("Window Title");
 d.addLabel("My text can be entered here!");
 d.addLabel("Next line of text....");
 stringList sl;sl.append("item1");sl.append("item2");sl.append("item3");
 int cb=d.addComboBox(sl,"item3");
 d.addLabel("Please enter a number");
 int sb=d.addSpinBox(10,2,30);
 d.addLabel("Please enter a text:");
 int le=d.addLineEdit("text");
 int ret= d.exec();

 debug.clear();
 debug("comboBox selection was:");
 debug(d.getString(cb));
 debug("spinBox number was:");
 debug(d.getInt(sb));
 debug("lineEdit text was:");
 debug(d.getString(le));

 debug("dialog closed with button:");
 debug(ret);
 debug.show();

Member Function Documentation


dialog::dialog()

Creates a new empty dialog. Widgets are added afterwards; nothing is shown until exec.


int dialog::addCheckBox(string label,bool state=false)

Adds a check box with caption label and initial state. Store the returned id and pass it to getBool after exec. (introduced with release 20220602)

Returns: the widget id.

Parameter:
label label
state state

int dialog::addComboBox(stringList item, string defaultitem="")

Adds a combo box filled from item. defaultitem is selected if it is in the list.

Parameter:
item entries shown in the combo box
defaultitem initial selection; empty selects the first item

Returns: the widget id for getString after exec.


int dialog::addLabel(string)

Adds a label line to the dialog.

Returns: the widget id.


int dialog::addLayer( int defaulLayer)

Adds a layer picker. defaulLayer is the layer number shown first. After exec, getInt is the layer number and getString is the layer name. (introduced with release 20220712)

Returns: the widget id.

Example:

 dialog d;
 d.setWindowTitle("Window Title");
 d.addLabel("Please enter a layer:");
 int ll=d.addLayer(5);
 int ret= d.exec();

 debug.clear();
 debug("comboBox selection was:");
 debug("layer entry was:");
 debug(d.getString(ll)+" ("+d.getInt(ll)+")"); // outputs: layername (layernumber)
 debug.show();

layer_dialog


int dialog::addLineEdit(string defaultText)

Adds a single-line text field with defaultText. After exec, getString returns the text.

Returns: the widget id.


int dialog::addSpinBox(int defaultValue, int minValue, int maxValue )

Adds a spin box for an integer between minValue and maxValue, starting at defaultValue.

Parameter:
defaultValue initial value
minValue lower limit
maxValue upper limit

Returns: the widget id for getInt after exec.

Example:

 dialog d;
 d.setWindowTitle("Window Title");
 d.addLabel("Please enter a number between 1 and 10:");
 int ll=d.addSpinBox(5,1,10);
 int ret= d.exec();

spin_box


int dialog::addDoubleSpinBox(double defaultValue, double minValue, double maxValue, double step, double decimals )

Adds a spin box for a floating-point number. (introduced with release 20240301)

Parameter:
defaultValue initial value
minValue lower limit
maxValue upper limit
step increment of the spin buttons
decimals number of digits after the decimal point

Returns: the widget id for getDouble after exec.


int dialog::exec()

Shows the dialog and pauses the macro until it is closed.

Returns: the button used to close the dialog.


bool dialog::getBool(int id)

Returns: the state of the check box with id. (introduced with release 20220602)


double dialog::getDouble(int id)

Returns: the value of a double spin box with id. If id is a string widget, the text is converted to a double. (introduced with release 20240301)


int dialog::getInt(int id)

Returns: the value of an integer spin box with id. If id is a string widget, the text is converted to an integer.


string dialog::getString(int id)

Returns: the string of the widget with id. Integer values are converted to a string.


void dialog::setWindowTitle(string s)

Sets the title shown in the dialog's top bar to s.