NDEVR
API Documentation
QCustomComboBox

A compact way to present a list of options to the user. More...

Inheritance diagram for QCustomComboBox:
[legend]
Collaboration diagram for QCustomComboBox:
[legend]

Public Member Functions

 QCustomComboBox (QWidget *parent=nullptr)
 Constructs a QCustomComboBox with the given parent widget.
template<class t_type>
void add (const t_type &value, const TranslatedString &display_value, bool refresh_widget=false)
 Adds a value and its display string to the combo box.
void clearValue ()
 Clears the current selection and value.
TranslatedString currentDisplayValue () const
 Returns the currently displayed translated string.
QCustomValidatorcustomValidator ()
 Returns a mutable reference to the custom validator used for input validation.
const QCustomValidatorcustomValidator () const
 Returns a const reference to the custom validator used for input validation.
const Buffer< TranslatedString > & displayValues () const
 Returns the translated display values of the combo box.
void edited ()
 Emitted when the combo box value is edited by the user.
bool event (QEvent *event) override
 Handles generic events for the combo box, including tooltip and theme updates.
void focusInEvent (QFocusEvent *e) override
 Handles focus-in events for the combo box.
template<class t_type>
t_type getAs () const
 Returns the current value converted to the requested type.
template<class t_type>
t_type getAs (uint04 index) const
 Returns the value at the given index converted to the requested type.
Angle< fltp08getUnitAngle () const
 Returns the current value as an Angle in internal representation.
fltp08 getUnitValue () const
 Returns the current value as a floating-point number in user-facing units.
void hidePopup () override
 Hides the popup list of items.
bool isUsingCustom () const
 Returns whether the combo box is currently using a custom (user-entered) value.
void lockInCustomValue ()
 Locks in the current custom value as the definitive selection.
QSize minimumSizeHint () const override
 Returns the minimum size hint for layout purposes.
void paintEvent (QPaintEvent *) override
 Custom paint event for rendering the combo box.
void refresh ()
 Refreshes the widget contents and updates its geometry.
template<class t_type>
void remove (const t_type &value, bool refresh_widget=false)
 Removes a value and its corresponding display string from the combo box.
void resizeEvent (QResizeEvent *event) override
 Handles widget resize events.
template<class t_enum>
std::enable_if< ObjectInfo< t_enum >::Enum >::type set (t_enum value)
 Sets the current selection to the given enum value.
void setAllowCustom (bool allow_custom)
 Sets whether the user can enter a custom value not in the predefined list.
void setAutoFormat (bool auto_format)
 Sets whether the combo box should automatically format display values.
void setConstantUnit (const ConstPointer< Unit > &unit, uint01 dimension=Constant< uint01 >::Invalid)
 Sets a constant unit for value formatting and conversion.
void setCustomUnit (const StringView &unit, UnitCategory fallback_unit, uint01 dimension=Constant< uint01 >::Invalid)
 Sets a custom unit string with a fallback unit category.
void setCustomValidator (const QCustomValidator &validator)
 Sets the custom validator used for input validation and formatting.
void setSuffix (const TranslatedString &suffix)
 Sets a suffix appended to each display value.
void setTitle (const TranslatedString &title)
 Sets the display title for the combo box.
void setToolTip (const TranslatedString &tooltip)
 Sets the tooltip text for the combo box.
void setUnitType (UnitCategory unit, uint01 dimension=Constant< uint01 >::Invalid)
 Sets the unit type used for value formatting and conversion.
void setUnitValue (fltp08 value, uint01 unit_dimension=0)
 Sets the value as a floating-point number in user-facing units.
template<class t_object>
void setup (const TranslatedString &title, const Buffer< std::pair< String, t_object > > &items)
 Sets up the combo box from a buffer of String/value pairs.
template<class t_object>
void setup (const TranslatedString &title, const Buffer< std::pair< TranslatedString, t_object > > &items)
 Sets up the combo box from a buffer of TranslatedString/value pairs.
void setup (const TranslatedString &title, const Buffer< String > &values, const Buffer< TranslatedString > &display_values)
 Sets up the combo box with a title, raw values, and corresponding translated display values.
template<class t_object>
std::enable_if<!ObjectInfo< t_object >::Enum &&!ObjectInfo< t_object >::Number >::type setup (const TranslatedString &title, const Buffer< t_object > &items)
 Sets up the combo box from a buffer of non-enum, non-number values using display strings.
template<class t_object>
std::enable_if< ObjectInfo< t_object >::Number >::type setup (const TranslatedString &title, const Buffer< t_object > &items)
 Sets up the combo box from a buffer of numeric values, formatting each with the validator.
template<class t_object>
std::enable_if< ObjectInfo< t_object >::Enum >::type setup (const TranslatedString &title, const Buffer< t_object > &items)
 Sets up the combo box from a buffer of enum values, using display strings for each.
void setup (const TranslatedString &title, const Buffer< TranslatedString > &values)
 Sets up the combo box with a title and a list of translated display values.
template<class t_enum>
std::enable_if< ObjectInfo< t_enum >::Enum >::type setup (const TranslatedString &title, t_enum first, t_enum last)
 Sets up the combo box with a range of enum values from first to last (inclusive).
template<class t_enum>
std::enable_if< ObjectInfo< t_enum >::Enum >::type setup (const TranslatedString &title, uint04 size)
 Sets up the combo box with all values of an enum type, given the total count.
template<class t_type>
void setupResource (const TranslatedString &title, Resource< t_type > &resource)
 Sets up two-way binding between this combo box and a Resource.
void setValue (const String &value)
 Sets the current value from a raw String.
template<class t_type>
void setValue (const t_type &t_value)
 Sets the current value of the combo box.
void setValue (const TranslatedString &t_value)
 Sets the current value from a TranslatedString.
void showPopup () override
 Shows the popup list of items.
QSize sizeHint () const override
 Returns the recommended size for layout purposes.
void sortAlphabetically (uint04 start=0, uint04 size=Constant< uint04 >::Invalid)
 Sorts the combo box entries alphabetically by display value.
const TranslatedStringsuffix () const
 Returns the current suffix appended to display values.
void updateFontSize ()
 Updates the font size to match the current application theme settings.
const Buffer< String > & values () const
 Returns the internal string values of the combo box.
void wheelEvent (QWheelEvent *e) override
 Handles mouse wheel events, typically to scroll through values.

Protected Member Functions

void adjustLineEditSize ()
 Adjusts the embedded line edit size to fit the current combo box dimensions.
void onChange ()
 Slot invoked when the selected index changes.
void onEdit ()
 Slot invoked when the user finishes editing the custom line edit.
void onEditTextChangedSlot ()
 Slot invoked when the editable line edit text changes.
virtual void onSorted (const Buffer< uint04 > &swap_indices)
 Called after sorting to allow subclasses to react to reordered indices.
void refreshWidget ()
 Rebuilds the widget contents from the internal value and display buffers.

Protected Attributes

Dictionary< uint04, uint04enum_to_index
 Maps enum numeric values to combo box indices.
Dictionary< uint04, uint04index_to_enum
 Maps combo box indices to enum numeric values.
bool m_allow_custom
 Whether custom user-entered values are permitted.
bool m_auto_format
 Whether values are automatically formatted before display.
String m_current_custom
 The current custom value entered by the user.
uint04 m_custom_index
 The index of the custom value entry in the list.
Buffer< TranslatedStringm_display_values
 The translated display strings for each option.
bool m_is_changing = false
 Whether the selection is currently being changed programmatically.
bool m_is_refreshing = false
 Whether the widget is currently being refreshed.
bool m_is_showing_popup = false
 Whether the popup list is currently visible.
uint04 m_last_index
 The last selected index before the current change.
QCustomLineEditm_line_edit
 The embedded line edit for custom value entry.
QTResourceListenerm_resource_changed_listener
 Listener for external resource changes.
bool m_sort_alphabetically = false
 Whether items should be sorted alphabetically.
uint04 m_sort_offset = 0
 The starting index offset for alphabetical sorting.
TranslatedString m_suffix
 A suffix appended to each display value.
TranslatedString m_title
 The display title of the combo box.
TranslatedString m_tooltip
 The tooltip text for the combo box.
bool m_using_custom
 Whether the current selection is a custom value.
Buffer< Stringm_values
 The internal string values for each option.

Detailed Description

A compact way to present a list of options to the user.


A combobox is a selection widget that shows the current item, and pops up a list of selectable items when clicked. Comboboxes can contain lists of translated data alongside of their program-values.

See also
QCustomLineEdit, QCustomLabel

Definition at line 54 of file QCustomCombobox.h.

Constructor & Destructor Documentation

◆ QCustomComboBox()

QCustomComboBox::QCustomComboBox ( QWidget * parent = nullptr)

Constructs a QCustomComboBox with the given parent widget.

Parameters
[in]parentThe parent widget.

Referenced by DesignObjectComboWidget::DesignObjectComboWidget().

Member Function Documentation

◆ add()

template<class t_type>
void QCustomComboBox::add ( const t_type & value,
const TranslatedString & display_value,
bool refresh_widget = false )
inline

Adds a value and its display string to the combo box.

Parameters
[in]valueThe internal value to add.
[in]display_valueThe translated string shown to the user.
[in]refresh_widgetWhether to refresh the widget immediately after adding.

Definition at line 231 of file QCustomCombobox.h.

References m_display_values, m_values, and refresh().

◆ currentDisplayValue()

TranslatedString QCustomComboBox::currentDisplayValue ( ) const

Returns the currently displayed translated string.

Returns
The current display value as a TranslatedString.

◆ customValidator() [1/2]

QCustomValidator & QCustomComboBox::customValidator ( )

Returns a mutable reference to the custom validator used for input validation.

Returns
A mutable reference to the QCustomValidator.

◆ customValidator() [2/2]

const QCustomValidator & QCustomComboBox::customValidator ( ) const

Returns a const reference to the custom validator used for input validation.

Returns
A const reference to the QCustomValidator.

Referenced by DesignObjectComboWidget::setNDPO(), setup(), and setupResource().

◆ displayValues()

const Buffer< TranslatedString > & QCustomComboBox::displayValues ( ) const
inline

Returns the translated display values of the combo box.

Returns
A const reference to the buffer of display values.

Definition at line 461 of file QCustomCombobox.h.

References m_display_values.

◆ event()

bool QCustomComboBox::event ( QEvent * event)
override

Handles generic events for the combo box, including tooltip and theme updates.

Parameters
[in]eventThe event to handle.
Returns
True if the event was handled, false otherwise.

References event().

Referenced by event(), and resizeEvent().

◆ focusInEvent()

void QCustomComboBox::focusInEvent ( QFocusEvent * e)
override

Handles focus-in events for the combo box.

Parameters
[in]eThe focus event.

◆ getAs() [1/2]

template<class t_type>
t_type QCustomComboBox::getAs ( ) const
inline

Returns the current value converted to the requested type.

Returns
The current combo box value converted to t_type.

Definition at line 313 of file QCustomCombobox.h.

References cast(), getAs(), m_current_custom, m_using_custom, and m_values.

Referenced by getAs(), getAs(), ModelChooserCombo::isNewSelected(), ModelChooserCombo::selectedID(), DesignObjectComboWidget::sendCommand(), DesignObjectComboWidget::setNDPO(), DesignObjectComboWidget::setTitle(), and setupResource().

◆ getAs() [2/2]

template<class t_type>
t_type QCustomComboBox::getAs ( uint04 index) const
inline

Returns the value at the given index converted to the requested type.

Parameters
[in]indexThe index of the value to retrieve.
Returns
The value at the specified index converted to t_type.

Definition at line 325 of file QCustomCombobox.h.

References getAs(), and m_values.

◆ getUnitAngle()

Angle< fltp08 > QCustomComboBox::getUnitAngle ( ) const

Returns the current value as an Angle in internal representation.

Returns
The unit-converted angle value.

◆ getUnitValue()

fltp08 QCustomComboBox::getUnitValue ( ) const

Returns the current value as a floating-point number in user-facing units.

Returns
The unit-converted floating-point value.

Referenced by setupResource().

◆ isUsingCustom()

bool QCustomComboBox::isUsingCustom ( ) const
inline

Returns whether the combo box is currently using a custom (user-entered) value.

Returns
True if a custom value is active, false otherwise.

Definition at line 95 of file QCustomCombobox.h.

References m_using_custom.

Referenced by setValue().

◆ minimumSizeHint()

QSize QCustomComboBox::minimumSizeHint ( ) const
override

Returns the minimum size hint for layout purposes.

Returns
The minimum size hint.

◆ onSorted()

virtual void QCustomComboBox::onSorted ( const Buffer< uint04 > & swap_indices)
protectedvirtual

Called after sorting to allow subclasses to react to reordered indices.

Parameters
[in]swap_indicesA mapping from old indices to new indices after sorting.

Reimplemented in ModelChooserCombo.

◆ paintEvent()

void QCustomComboBox::paintEvent ( QPaintEvent * )
override

Custom paint event for rendering the combo box.

Parameters
[in]eventThe paint event.

◆ remove()

template<class t_type>
void QCustomComboBox::remove ( const t_type & value,
bool refresh_widget = false )
inline

Removes a value and its corresponding display string from the combo box.

Parameters
[in]valueThe internal value to remove.
[in]refresh_widgetWhether to refresh the widget immediately after removal.

Definition at line 244 of file QCustomCombobox.h.

References IsValid(), m_display_values, m_values, and refresh().

◆ resizeEvent()

void QCustomComboBox::resizeEvent ( QResizeEvent * event)
override

Handles widget resize events.

Parameters
[in]eventThe resize event.

References event().

◆ set()

template<class t_enum>
std::enable_if< ObjectInfo< t_enum >::Enum >::type QCustomComboBox::set ( t_enum value)
inline

Sets the current selection to the given enum value.

Parameters
[in]valueThe enum value to select.

Definition at line 304 of file QCustomCombobox.h.

References cast(), and enum_to_index.

◆ setAllowCustom()

void QCustomComboBox::setAllowCustom ( bool allow_custom)
inline

Sets whether the user can enter a custom value not in the predefined list.

Parameters
[in]allow_customWhether to allow custom values.

Definition at line 420 of file QCustomCombobox.h.

References m_allow_custom, and refreshWidget().

◆ setAutoFormat()

void QCustomComboBox::setAutoFormat ( bool auto_format)
inline

Sets whether the combo box should automatically format display values.

Parameters
[in]auto_formatWhether to enable auto-formatting.

Definition at line 298 of file QCustomCombobox.h.

References m_auto_format.

◆ setConstantUnit()

void QCustomComboBox::setConstantUnit ( const ConstPointer< Unit > & unit,
uint01 dimension = Constantuint01 >::Invalid )

Sets a constant unit for value formatting and conversion.

Parameters
[in]unitThe constant unit pointer to use.
[in]dimensionThe specific unit dimension, or Invalid for default.

◆ setCustomUnit()

void QCustomComboBox::setCustomUnit ( const StringView & unit,
UnitCategory fallback_unit,
uint01 dimension = Constantuint01 >::Invalid )

Sets a custom unit string with a fallback unit category.

Parameters
[in]unitThe custom unit string.
[in]fallback_unitThe fallback unit category if the custom unit is not recognized.
[in]dimensionThe specific unit dimension, or Invalid for default.

◆ setCustomValidator()

void QCustomComboBox::setCustomValidator ( const QCustomValidator & validator)

Sets the custom validator used for input validation and formatting.

Parameters
[in]validatorThe validator to apply.

Referenced by DesignObjectComboWidget::setNDPO().

◆ setSuffix()

void QCustomComboBox::setSuffix ( const TranslatedString & suffix)
inline

Sets a suffix appended to each display value.

Parameters
[in]suffixThe suffix text to append.

Definition at line 425 of file QCustomCombobox.h.

References m_suffix, refreshWidget(), and suffix().

◆ setTitle()

void QCustomComboBox::setTitle ( const TranslatedString & title)

Sets the display title for the combo box.

Parameters
[in]titleThe title to display.

Referenced by setup(), setup(), and setupResource().

◆ setToolTip()

void QCustomComboBox::setToolTip ( const TranslatedString & tooltip)

Sets the tooltip text for the combo box.

Parameters
[in]tooltipThe tooltip text to display.

◆ setUnitType()

void QCustomComboBox::setUnitType ( UnitCategory unit,
uint01 dimension = Constantuint01 >::Invalid )

Sets the unit type used for value formatting and conversion.

Parameters
[in]unitThe unit category to use.
[in]dimensionThe specific unit dimension, or Invalid for default.

◆ setUnitValue()

void QCustomComboBox::setUnitValue ( fltp08 value,
uint01 unit_dimension = 0 )

Sets the value as a floating-point number in user-facing units.

Parameters
[in]valueThe unit value to set.
[in]unit_dimensionThe unit dimension index.

Referenced by setupResource().

◆ setup() [1/9]

template<class t_object>
void QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< std::pair< String, t_object > > & items )
inline

Sets up the combo box from a buffer of String/value pairs.

Parameters
[in]titleThe display title for the combo box.
[in]itemsA buffer of pairs mapping string labels to their values.

Definition at line 120 of file QCustomCombobox.h.

References Buffer< t_type, t_memory_manager >::add(), TranslatedString::DirectString(), setup(), and values().

◆ setup() [2/9]

template<class t_object>
void QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< std::pair< TranslatedString, t_object > > & items )
inline

Sets up the combo box from a buffer of TranslatedString/value pairs.

Parameters
[in]titleThe display title for the combo box.
[in]itemsA buffer of pairs mapping translated display strings to their values.

Definition at line 103 of file QCustomCombobox.h.

References Buffer< t_type, t_memory_manager >::add(), setup(), and values().

◆ setup() [3/9]

void QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< String > & values,
const Buffer< TranslatedString > & display_values )

Sets up the combo box with a title, raw values, and corresponding translated display values.

Parameters
[in]titleThe display title for the combo box.
[in]valuesThe internal string values.
[in]display_valuesThe translated strings displayed to the user.

References values().

◆ setup() [4/9]

template<class t_object>
std::enable_if<!ObjectInfo< t_object >::Enum &&!ObjectInfo< t_object >::Number >::type QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< t_object > & items )
inline

Sets up the combo box from a buffer of non-enum, non-number values using display strings.

Parameters
[in]titleThe display title for the combo box.
[in]itemsA buffer of values.

Definition at line 193 of file QCustomCombobox.h.

References Buffer< t_type, t_memory_manager >::add(), String::DisplayString(), setup(), and values().

◆ setup() [5/9]

template<class t_object>
std::enable_if< ObjectInfo< t_object >::Number >::type QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< t_object > & items )
inline

Sets up the combo box from a buffer of numeric values, formatting each with the validator.

Parameters
[in]titleThe display title for the combo box.
[in]itemsA buffer of numeric values.

Definition at line 154 of file QCustomCombobox.h.

References Buffer< t_type, t_memory_manager >::add(), customValidator(), setup(), and values().

◆ setup() [6/9]

template<class t_object>
std::enable_if< ObjectInfo< t_object >::Enum >::type QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< t_object > & items )
inline

Sets up the combo box from a buffer of enum values, using display strings for each.

Parameters
[in]titleThe display title for the combo box.
[in]itemsA buffer of enum values.

Definition at line 137 of file QCustomCombobox.h.

References Buffer< t_type, t_memory_manager >::add(), String::DisplayString(), setup(), and values().

◆ setup() [7/9]

void QCustomComboBox::setup ( const TranslatedString & title,
const Buffer< TranslatedString > & values )

Sets up the combo box with a title and a list of translated display values.

Parameters
[in]titleThe display title for the combo box.
[in]valuesThe list of translated string options.

References values().

Referenced by MeasurePointTypeCombo::Setup(), setup(), setup(), and setup().

◆ setup() [8/9]

template<class t_enum>
std::enable_if< ObjectInfo< t_enum >::Enum >::type QCustomComboBox::setup ( const TranslatedString & title,
t_enum first,
t_enum last )
inline

Sets up the combo box with a range of enum values from first to last (inclusive).

Parameters
[in]titleThe display title for the combo box.
[in]firstThe first enum value in the range.
[in]lastThe last enum value in the range.

Definition at line 211 of file QCustomCombobox.h.

References cast(), String::DisplayString(), enum_to_index, index_to_enum, m_display_values, m_values, refreshWidget(), and setTitle().

◆ setup() [9/9]

template<class t_enum>
std::enable_if< ObjectInfo< t_enum >::Enum >::type QCustomComboBox::setup ( const TranslatedString & title,
uint04 size )
inline

Sets up the combo box with all values of an enum type, given the total count.

Parameters
[in]titleThe display title for the combo box.
[in]sizeThe number of enum values to populate.

Definition at line 173 of file QCustomCombobox.h.

References cast(), String::DisplayString(), enum_to_index, index_to_enum, m_display_values, m_values, refreshWidget(), and setTitle().

◆ setupResource()

template<class t_type>
void QCustomComboBox::setupResource ( const TranslatedString & title,
Resource< t_type > & resource )
inline

Sets up two-way binding between this combo box and a Resource.

When the combo box value changes, the resource is updated. When the resource changes externally, the combo box display is updated.

Parameters
[in]titleThe display title for the combo box.
[in]resourceThe resource to bind to.

Definition at line 272 of file QCustomCombobox.h.

References ResourceBase::addListener(), customValidator(), edited(), Resource< T >::get(), getAs(), getUnitValue(), m_resource_changed_listener, Resource< T >::set(), setTitle(), setUnitValue(), and setValue().

◆ setValue() [1/3]

void QCustomComboBox::setValue ( const String & value)

Sets the current value from a raw String.

Parameters
[in]valueThe string value to set.

◆ setValue() [2/3]

template<class t_type>
void QCustomComboBox::setValue ( const t_type & t_value)
inline

Sets the current value of the combo box.

Parameters
[in]t_valueThe value to set.

Definition at line 334 of file QCustomCombobox.h.

References setValue().

Referenced by DesignObjectComboWidget::onObjectUpdatedSlot(), ModelChooserCombo::setToNew(), setupResource(), setValue(), and setValue().

◆ setValue() [3/3]

void QCustomComboBox::setValue ( const TranslatedString & t_value)
inline

Sets the current value from a TranslatedString.

Parameters
[in]t_valueThe translated string value to set.

Definition at line 342 of file QCustomCombobox.h.

References isUsingCustom(), and setValue().

◆ sizeHint()

QSize QCustomComboBox::sizeHint ( ) const
override

Returns the recommended size for layout purposes.

Returns
The size hint.

◆ sortAlphabetically()

void QCustomComboBox::sortAlphabetically ( uint04 start = 0,
uint04 size = Constantuint04 >::Invalid )

Sorts the combo box entries alphabetically by display value.

Parameters
[in]startThe starting index for the sort range.
[in]sizeThe number of items to sort, or Invalid for all remaining items.

◆ suffix()

const TranslatedString & QCustomComboBox::suffix ( ) const
inline

Returns the current suffix appended to display values.

Returns
A const reference to the suffix TranslatedString.

Definition at line 430 of file QCustomCombobox.h.

References m_suffix.

Referenced by setSuffix().

◆ values()

const Buffer< String > & QCustomComboBox::values ( ) const
inline

Returns the internal string values of the combo box.

Returns
A const reference to the buffer of internal values.

Definition at line 456 of file QCustomCombobox.h.

References m_values.

Referenced by setup(), setup(), setup(), setup(), and setup().

◆ wheelEvent()

void QCustomComboBox::wheelEvent ( QWheelEvent * e)
override

Handles mouse wheel events, typically to scroll through values.

Parameters
[in]eThe wheel event.

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