Relacs Widgets Library  0.9.8
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends | List of all members
OptWidget Class Reference

#include <optwidget.h>

Inheritance diagram for OptWidget:
Inheritance graph
[legend]
Collaboration diagram for OptWidget:
Collaboration graph
[legend]

Public Slots

void accept (bool clearchanged)
 
void accept (void)
 
void acceptGet (void)
 
void acceptNotify (bool clearchanged)
 
void reset (void)
 
void resetDefault (void)
 
void updateValue (const string &name)
 
void updateValues (void)
 
void updateValues (int flag, bool delflags=true)
 
void updateSettings (const string &name)
 
void updateSettings (void)
 
void updateSettings (int flag, bool delflags=true)
 

Signals

void valuesChanged (void)
 
void valueChanged (const Parameter &p)
 

Public Member Functions

 OptWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 
 OptWidget (Options *o, QMutex *mutex=0, QWidget *parent=0, Qt::WindowFlags f=0)
 
 OptWidget (Options *o, int selectmask, int romask, bool contupdate, int style, QMutex *mutex=0, string *tabhotkeys=0, QWidget *parent=0, Qt::WindowFlags f=0)
 
 ~OptWidget (void)
 
OptWidgetoperator= (Options *o)
 
OptWidgetassign (Options *o, int selectmask=0, int romask=0, bool contupdate=false, int style=0, QMutex *mutex=0, string *tabhotkeys=0)
 
bool tabs (void) const
 
int lines (void) const
 
void setVerticalSpacing (int pixel)
 
void setHorizontalSpacing (int pixel)
 
void setMargins (int pixel)
 
void setMargins (int left, int top, int right, int bottom)
 
QWidget * firstWidget (void) const
 
QWidget * lastWidget (void) const
 
int selectMask (void) const
 
int readOnlyMask (void) const
 
bool continuousUpdate (void) const
 
int style (void) const
 
Optionsoptions (void) const
 
void setMutex (QMutex *mutex)
 
void lockMutex (void)
 
bool tryLockMutex (int timeout=1)
 
void unlockMutex (void)
 

Static Public Member Functions

static int changedFlag (void)
 
static string tabLabel (string label, string *tabhotkeys)
 

Static Public Attributes

static const long LabelNormal = 0x00000000
 
static const long LabelSmall = 0x00000001
 
static const long LabelLarge = 0x00000002
 
static const long LabelHuge = 0x00000003
 
static const long LabelBold = 0x00000004
 
static const long LabelItalic = 0x00000008
 
static const long LabelBlack = 0x00000000
 
static const long LabelRed = 0x00000010
 
static const long LabelGreen = 0x00000020
 
static const long LabelBlue = 0x00000030
 
static const long LabelBack = 0x00000000
 
static const long LabelBackBlack = 0x00000040
 
static const long LabelBackWhite = 0x00000080
 
static const long ValueNormal = 0x00000000
 
static const long ValueSmall = 0x00001000
 
static const long ValueLarge = 0x00002000
 
static const long ValueHuge = 0x00003000
 
static const long ValueBold = 0x00004000
 
static const long ValueItalic = 0x00008000
 
static const long ValueBlack = 0x00000000
 
static const long ValueRed = 0x00010000
 
static const long ValueGreen = 0x00020000
 
static const long ValueBlue = 0x00030000
 
static const long ValueBack = 0x00000000
 
static const long ValueBackBlack = 0x00040000
 
static const long ValueBackWhite = 0x00080000
 
static const long Normal = LabelNormal + ValueNormal
 
static const long Small = LabelSmall + ValueSmall
 
static const long Large = LabelLarge + ValueLarge
 
static const long Huge = LabelHuge + ValueHuge
 
static const long Bold = LabelBold + ValueBold
 
static const long Italic = LabelItalic + ValueItalic
 
static const long Black = LabelBlack + ValueBlack
 
static const long Red = LabelRed + ValueRed
 
static const long Green = LabelGreen + ValueGreen
 
static const long Blue = LabelBlue + ValueBlue
 
static const long Back = LabelBack + ValueBack
 
static const long BackBlack = LabelBackBlack + ValueBackBlack
 
static const long BackWhite = LabelBackWhite + ValueBackWhite
 
static const long SelectText = Parameter::SelectText
 
static const int MultipleSelection = Parameter::MultipleSelection
 
static const long ComboAutoCompletion = 0x04000000
 
static const long BrowseExisting = 0x08000000
 
static const long BrowseAny = 0x10000000
 
static const long BrowseDirectory = 0x20000000
 
static const long Browse = BrowseExisting + BrowseAny + BrowseDirectory
 
static const long BrowseAbsolute = 0x40000000
 
static const long ValueLCD = 0x01000000
 
static const long SpecialInfinite = 0x10000000
 
static const long SpecialNone = 0x20000000
 
static const long TabSection = Options::TabSection
 
static const long MathLabel = 0x08000000
 
static const int BreakLinesStyle = 0x0001
 
static const int ExtraSpaceStyle = 0x0002
 
static const int TabSectionStyle = 0x0004
 
static const int NameFrontStyle = 0x0008
 
static const int NameBehindStyle = 0x0010
 
static const int HighlightNameStyle = 0x0020
 
static const int BoldSectionsStyle = 0x0040
 
static const int HideStyle = 0x0080
 

Protected Member Functions

virtual void customEvent (QEvent *e)
 

Friends

class OptWidgetBase
 
class OptWidgetText
 
class OptWidgetMultiText
 
class OptWidgetNumber
 
class OptWidgetBoolean
 
class OptWidgetDate
 
class OptWidgetTime
 
class OptWidgetSection
 
class OptWidgetMultipleValues
 
class ComboItemDelegate
 

Detailed Description

A Widget for modifying Options.

Author
Jan Benda
Bug:
OptWidgetDate input widget is crashing. Error in QDateEdit?

This widget is an input form for Options that can be used to interactively edit the values of Options. If you want a dialog-window, use OptDialog, which is based on OptWidget.

The OptWidget supports simple text editing for text-options with a single value, combo-boxes for text-options with multiple values, spin-boxes for number and integer options, check boxes for boolean options, labels, and separators (a horizontal line).

Here is an example:

optwidget.png

It was created with the following code:

#include <relacs/options.h>
using namespace relacs;
...
Options opt;
opt.newSection( "Timing" );
opt.addNumber( "duration", "Duration of Signal", 0.3527, 0.01, 1.0, 0.0001, "seconds", "ms" );
opt.addNumber( "pause", "Pause between Signals", 0.2, 0.0, 1.0, 0.01, "seconds", "ms", "%g", 1 );
opt.setNumber( "pause", 0.180 );
opt.newSection( "Flow Control" );
opt.addInteger( "repeats", "Repeats", 8, 0, 100 );
opt.addBoolean( "loop", "Loop", true );
opt.newSection( "General" );
opt.addText( "color", "Color", "red|green|blue");
opt.addText( "comment", "Comments", "no comment" );
...
OptWidget ow( this );
ow.assign( &opt, 0, 1 );
ow.setVerticalSpacing( 4 );
ow.setMargins( 10 );
...

First you have to create some Options by either defining them explicitely as in the example with the addNumber(), addText(), ... functions, or you load them from a file with the load( istream& ) function. See the documentation for Options for more details. Then you construct the OptWidget. Either the Options are passed directly to OptWidget via the constructor, or they are assigned later on with assign(). Both ways you can specify a select-mask to select a subset of the Options and a readonly-mask to specify which Options are not editable (in the example the "pause" options is not editable).

Normally the new values entered by the user are assigned to the Options by calling the accept() function. If you want the values of the Options to be continuosly updated, set the contupdate argument in the constructor or the assign() function to true. Each time a new value is entered in the widget the corresponding option gets this value set. You can react to the change by reimplementing the Options::notify() function. The option whose value has changed will have the changedFlag() set. This flag is automatically cleared after notify() was called.

reset() sets the values in the input form to their initial values. resetDefault() sets them to the Options' default values. If the values or properties of the Options are changed, use the update functions updateValue(), updateValues(), updateSettings() to update the input form of the OptWidget.

Options whose values were changed via the OptWidget get the changedFlag() in their flags() set.

The spacing between two input lines can be adjusted with setVerticalSpacing(). The spacing between the widget margins and its content are set with setMargins().

Constructor & Destructor Documentation

OptWidget ( QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
)

Constructs an empty OptWidget. To add Options to the widget use assign().

OptWidget ( Options o,
QMutex *  mutex = 0,
QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
)

Constructs an OptWidget for the Options o. All Options are displayed and are editable.

See Also
assign()

References OptWidget::assign().

OptWidget ( Options o,
int  selectmask,
int  romask,
bool  contupdate,
int  style,
QMutex *  mutex = 0,
string *  tabhotkeys = 0,
QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
)

Constructs an OptWidget for the Options o. Only Options with their flags() & selectmask > 0 are displayed. If selectmask ist less or equal to zero, all Options o are displayed. Options with their flags() & romask > 0 are not editable. If romask equals zero all Options o are editable. If romask is negative none of the Options o is editable. If contupdate equals true, inputs by the user are immediately applied to the Options o. Otherwise, accept() has to be called in order to apply the changes to the Options o. tabhotkeys can point to a string that contains hotkey-characters that are already in use. This information is used to choose hotkeys for tabs. The new hotkeys are added to the string.

References OptWidget::assign().

~OptWidget ( void  )

Destructs the OptWidget.

Member Function Documentation

OptWidget & operator= ( Options o)

Assigns Options o to the widget. All Options are displayed and are editable.

References OptWidget::assign().

OptWidget & assign ( Options o,
int  selectmask = 0,
int  romask = 0,
bool  contupdate = false,
int  style = 0,
QMutex *  mutex = 0,
string *  tabhotkeys = 0 
)

Assigns Options o to the widget. Only Options with their flags() & selectmask > 0 are displayed. If selectmask ist less or equal to zero, all Options o are displayed. Options with their flags() & romask > 0 are not editable. If romask equals zero all Options o are editable. If romask() is negative none of the Options o is editable. If contupdate equals true, inputs by the user are immediately applied to the Options o. Otherwise, accept() has to be called in order to apply the changes to the Options o. The standard layout style = 0 puts each option into a separate line. If style = 1 then the option's name is in one line and the options value and unit is in the following line. mutex is a mutex that is used by OptWidget to lock access to the options o while they are accessed from OptWidget functions. In particular during calls of the notify() function this mutex will be locked. tabhotkeys can point to a string that contains hotkey-characters that are already in use. This information is used to choose hotkeys for tabs. The new hotkeys are added to the string.

References OptWidget::lockMutex(), OptWidget::style(), OptWidget::tabLabel(), OptWidget::TabSection, OptWidget::TabSectionStyle, and OptWidget::unlockMutex().

Referenced by OptWidget::operator=(), and OptWidget::OptWidget().

bool tabs ( void  ) const

Returns true if tabbed widgets are used.

int lines ( void  ) const

The maximum number of lines in a single tab.

Referenced by ConfigDialog::dialogOptions().

void setVerticalSpacing ( int  pixel)

Set the spacing between the lines to pixel pixel.

See Also
setHorizontalSpacing(), setMargins()
void setHorizontalSpacing ( int  pixel)

Set the horizontal spacing to pixel pixel.

See Also
setVerticalSpacing(), setMargins()
void setMargins ( int  pixel)

Set the spacing between the widget margins and its content to pixel pixel.

See Also
setVerticalSpacing(), setHorizontalSpacing()
void setMargins ( int  left,
int  top,
int  right,
int  bottom 
)

Set the spacing between the widget margins and its content to all sides individually.

See Also
setVerticalSpacing(), setHorizontalSpacing()
QWidget * firstWidget ( void  ) const

A pointer to the first editable widget in OptWidget. Is null, if there isn't any editable widget. Can be used to set the tab order.

QWidget * lastWidget ( void  ) const

A pointer to the last editable widget in OptWidget. Is null, if there isn't any editable widget. Can be used to set the tab order.

int selectMask ( void  ) const

The mask that was used to select single options.

See Also
assign(), readOnlyMask()
int readOnlyMask ( void  ) const

The mask that was used to decide whether an option should be editable or not.

See Also
assign(), selectMask().

Referenced by OptWidgetBase::OptWidgetBase().

bool continuousUpdate ( void  ) const

True if changes by the user are immediately applied to the Options values.

See Also
assign().
int style ( void  ) const

Returns the style flags of the widget.

Referenced by OptWidgetBase::activateOption(), and OptWidget::assign().

int changedFlag ( void  )
static
Options * options ( void  ) const

Returns a pointer to the Options on which this widgets works on.

void setMutex ( QMutex *  mutex)

Provide a mutex that is used by OptWidget to lock access to the options while they are accessed. Passing a '0' disables the mutex.

void lockMutex ( void  )
bool tryLockMutex ( int  timeout = 1)

Try to lock the data mutex for reading. Returns true if the lock was obtained within timeout milliseconds.

See Also
lockMutex(), setMutex()

Referenced by OptWidget::customEvent().

void unlockMutex ( void  )
string tabLabel ( string  label,
string *  tabhotkeys 
)
static
Returns
Find for label a hotkey that is not already contained in tabhotkeys and mark it by inserting '&'. The new hotkey is added to tabhotkeys.

References Str::low().

Referenced by OptDialog::addTabOptions(), OptDialog::addTabWidget(), and OptWidget::assign().

void accept ( bool  clearchanged)
slot

Set values of the Options according to the changes entered by the user via the OptWidget. Each options whose value was changed by the user gets the changedFlag() set. Then the Options::notify() function is called and the signal valuesChanged() is emitted. Finally the changedFlag() is cleared if clearchanged is set to true. If a mutex was provided it is locked within this function and consequently during notify() and valuesChanged(). This function can only be called from the GUI thread. Same as a successive execution of acceptGet() and acceptNotify().

See Also
reset(), resetDefault(), setMutex()

References OptWidget::changedFlag(), OptWidget::lockMutex(), OptWidget::unlockMutex(), and OptWidget::valuesChanged().

void accept ( void  )
slot

Same as accept( bool ) with clearchanged set to true.

void acceptGet ( void  )
slot

Set values of the Options according to the changes entered by the user via the OptWidget. Each options whose value was changed by the user gets the changedFlag() set. If a mutex was provided it is locked within this function and consequently during notify() and valuesChanged(). This function can only be called from the GUI thread. Identical to the first part of the accept() function.

See Also
reset(), resetDefault(), setMutex()

References OptWidget::lockMutex(), and OptWidget::unlockMutex().

void acceptNotify ( bool  clearchanged)
slot

Calls the Options::notify() function and emits signal valuesChanged(). Finally the changedFlag() is cleared if clearchanged is set to true. If a mutex was provided it is locked within this function and consequently during notify() and valuesChanged(). This function can only be called from the GUI thread. Identical to the second part of the accept() function.

See Also
reset(), resetDefault(), setMutex()

References OptWidget::changedFlag(), OptWidget::lockMutex(), OptWidget::unlockMutex(), and OptWidget::valuesChanged().

void reset ( void  )
slot

Reset all input fields to their initial values. If a mutex was provided it is locked within this function. This function can only be called from the GUI thread.

See Also
resetDefault(), accept(), setMutex()

References OptWidget::lockMutex(), and OptWidget::unlockMutex().

void resetDefault ( void  )
slot

Reset all input fields to the Options default values. If a mutex was provided it is locked within this function. This function can only be called from the GUI thread.

See Also
reset(), accept(), setMutex()

References OptWidget::lockMutex(), and OptWidget::unlockMutex().

void updateValue ( const string &  name)
slot

Read out the value of the option with name name and update the input field accordingly. Can be called from any thread. If a mutex was provided it is locked while the options are accessed. In a multithreaded program this is usually after this function returns.

See Also
updateValues(), updateSettings(), setMutex()

References OptWidget::customEvent().

void updateValues ( void  )
slot

Read out the values of all options and update their input fields accordingly. If a mutex was provided it is locked while the options are accessed. In a multithreaded program this is usually after this function returns.

See Also
updateValue(), updateSettings(), setMutex()

References OptWidget::customEvent().

void updateValues ( int  flag,
bool  delflags = true 
)
slot

Read out the values of all options that have flag set and update their input fields accordingly. The flag is automatically removed from all options if delflags is set true. If a mutex was provided it is locked while the options are accessed. In a multithreaded program this is usually after this function returns.

See Also
updateValue(), updateSettings(), setMutex()

References OptWidget::customEvent().

void updateSettings ( const string &  name)
slot

Read out the value, range, stepsize, and unit of the option with name name and update the input field accordingly. If a mutex was provided it is locked while the options are accessed. In a multithreaded program this is usually after this function returns.

See Also
updateValue(), updateValues(), setMutex()

References OptWidget::customEvent().

void updateSettings ( void  )
slot

Read out the value, range, stepsize, and unit of all options and update their input fields accordingly. If a mutex was provided it is locked while the options are accessed. In a multithreaded program this is usually after this function returns.

See Also
updateValue(), updateValues(), setMutex()

References OptWidget::customEvent().

void updateSettings ( int  flag,
bool  delflags = true 
)
slot

Read out the value, range, stepsize, and unit of all options that have flag set and update their input fields accordingly. The flag is automatically removed from all options if delflags is set true. If a mutex was provided it is locked while the options are accessed. In a multithreaded program this is usually after this function returns.

See Also
updateValue(), updateValues(), setMutex()

References OptWidget::customEvent().

void valuesChanged ( void  )
signal

This signal is emitted by accept().

Referenced by OptWidget::accept(), and OptWidget::acceptNotify().

void valueChanged ( const Parameter p)
signal

This signal is emitted whenever a widget changes its value. p contains the name of the corresponding Parameter and the new value from the widget.

void customEvent ( QEvent *  e)
protectedvirtual

Friends And Related Function Documentation

friend class OptWidgetBase
friend
friend class OptWidgetText
friend
friend class OptWidgetMultiText
friend
friend class OptWidgetNumber
friend
friend class OptWidgetBoolean
friend
friend class OptWidgetDate
friend
friend class OptWidgetTime
friend
friend class OptWidgetSection
friend
friend class OptWidgetMultipleValues
friend
friend class ComboItemDelegate
friend

Member Data Documentation

const long LabelNormal = 0x00000000
static

Use normal sized font for the label.

const long LabelSmall = 0x00000001
static

Use small sized font for the label.

const long LabelLarge = 0x00000002
static

Use large sized font for the label.

const long LabelHuge = 0x00000003
static

Use huge sized font for the label.

const long LabelBold = 0x00000004
static

Use bold font for label.

const long LabelItalic = 0x00000008
static

Use italic font for label.

const long LabelBlack = 0x00000000
static

Use black color for label.

const long LabelRed = 0x00000010
static

Use red color for label.

const long LabelGreen = 0x00000020
static

Use green color for label.

const long LabelBlue = 0x00000030
static

Use blue color for label.

const long LabelBack = 0x00000000
static

Use standard background for label.

const long LabelBackBlack = 0x00000040
static

Use black background for label.

const long LabelBackWhite = 0x00000080
static

Use white background for label.

const long ValueNormal = 0x00000000
static

Use normal sized font for the value.

const long ValueSmall = 0x00001000
static

Use small sized font for the value.

Referenced by OptWidgetNumber::OptWidgetNumber().

const long ValueLarge = 0x00002000
static

Use large sized font for the value.

Referenced by OptWidgetNumber::OptWidgetNumber().

const long ValueHuge = 0x00003000
static

Use huge sized font for the value.

Referenced by OptWidgetNumber::OptWidgetNumber().

const long ValueBold = 0x00004000
static

Use bold font for value.

const long ValueItalic = 0x00008000
static

Use italic font for value.

const long ValueBlack = 0x00000000
static

Use black color for value.

const long ValueRed = 0x00010000
static

Use red color for value.

const long ValueGreen = 0x00020000
static

Use green color for value.

const long ValueBlue = 0x00030000
static

Use blue color for value.

const long ValueBack = 0x00000000
static

Use standard background for value.

const long ValueBackBlack = 0x00040000
static

Use black background for value.

const long ValueBackWhite = 0x00080000
static

Use white background for value.

const long Normal = LabelNormal + ValueNormal
static

Use normal sized font for the label and the value.

const long Small = LabelSmall + ValueSmall
static

Use small sized font for the label and the value.

const long Large = LabelLarge + ValueLarge
static

Use large sized font for the label and the value.

const long Huge = LabelHuge + ValueHuge
static

Use huge sized font for the label and the value.

const long Bold = LabelBold + ValueBold
static

Use bold font for label and the value.

const long Italic = LabelItalic + ValueItalic
static

Use italic font for label and the value.

const long Black = LabelBlack + ValueBlack
static

Use black color for label and the value.

const long Red = LabelRed + ValueRed
static

Use red color for label and the value.

const long Green = LabelGreen + ValueGreen
static

Use green color for label and the value.

const long Blue = LabelBlue + ValueBlue
static

Use blue color for label and the value.

const long Back = LabelBack + ValueBack
static

Use standard background for label and the value.

const long BackBlack = LabelBackBlack + ValueBackBlack
static

Use black background for label and the value.

const long BackWhite = LabelBackWhite + ValueBackWhite
static

Use white background for label and the value.

const long SelectText = Parameter::SelectText
static

If set you can only select from text options with multiple values, but not add new values.

Referenced by ComboItemDelegate::createEditor(), OptWidgetMultiText::OptWidgetMultiText(), and OptWidgetText::OptWidgetText().

const int MultipleSelection = Parameter::MultipleSelection
static

Allow mutliple values to be selected.

const long ComboAutoCompletion = 0x04000000
static

Enables auto completion mode of editable combo boxes.

Referenced by ComboItemDelegate::createEditor(), and OptWidgetMultiText::OptWidgetMultiText().

const long BrowseExisting = 0x08000000
static

Browse for existing file.

Referenced by OptWidgetText::browse().

const long BrowseAny = 0x10000000
static

Browse for any file.

Referenced by OptWidgetText::browse().

const long BrowseDirectory = 0x20000000
static

Browse for directories.

Referenced by OptWidgetText::browse(), and OptWidgetText::doBrowse().

const long Browse = BrowseExisting + BrowseAny + BrowseDirectory
static

Browse for some file or directory.

Referenced by OptWidgetText::OptWidgetText().

const long BrowseAbsolute = 0x40000000
static

Do not strip the current working directory from the path.

Referenced by OptWidgetText::doBrowse().

const long ValueLCD = 0x01000000
static

Use LCD numbers to display a number.

Referenced by OptWidgetNumber::OptWidgetNumber(), and OptWidgetNumber::reset().

const long SpecialInfinite = 0x10000000
static

For number options: instead of minimum value display "infinite".

Referenced by NumberItemDelegate::createEditor(), and OptWidgetNumber::OptWidgetNumber().

const long SpecialNone = 0x20000000
static

For number options: instead of minimum value display "none".

Referenced by NumberItemDelegate::createEditor(), and OptWidgetNumber::OptWidgetNumber().

const long TabSection = Options::TabSection
static

Section is a new tab.

Referenced by OptWidget::assign().

const long MathLabel = 0x08000000
static

Try to format label as a mathematical equation.

Referenced by OptWidgetSection::OptWidgetSection().

const int BreakLinesStyle = 0x0001
static

Put request string and value in separate lines.

const int ExtraSpaceStyle = 0x0002
static

Insert extra space between two options.

const int TabSectionStyle = 0x0004
static

Top level sections are introducing new tabs.

Referenced by OptWidget::assign().

const int NameFrontStyle = 0x0008
static

Print the options name in front of the request string.

const int NameBehindStyle = 0x0010
static

Print the options name behind the request string.

Referenced by ConfigDialog::ConfigDialog().

const int HighlightNameStyle = 0x0020
static

Use a different font for the option's name. Only used in combination with NameFrontStyle or NameBehindStyle.

Referenced by ConfigDialog::ConfigDialog().

const int BoldSectionsStyle = 0x0040
static

Display all section names using a bold font.

const int HideStyle = 0x0080
static

Hide inactivated options.

Referenced by OptWidgetBase::activateOption().


The documentation for this class was generated from the following files: