34#include <NDEVR/QCustomValidator.h>
35#include <NDEVR/QCustomLineEdit.h>
36#include <NDEVR/QTTools.h>
37#include <NDEVR/ObjectInfo.h>
38#include <NDEVR/Dictionary.h>
39#include <NDEVR/String.h>
40#include <NDEVR/Resource.h>
44 class QCustomValidator;
45 class QCustomLineEdit;
64 template<
class t_
object>
69 for (
uint04 i = 0; i < items.size(); i++)
72 display_values.
add(items[i].first);
74 setup(title, values, display_values);
76 template<
class t_
object>
84 display_values.
add(String::DisplayString(items[i]));
86 setup(title, values, display_values);
88 template<
class t_
object>
99 setup(title, values, display_values);
101 template<
class t_enum>
106 index_to_enum.clear();
107 for (
uint04 i = 0; i < size; i++)
109 m_values.add(
String(cast<t_enum>(i)));
110 m_display_values.add(String::DisplayString(cast<t_enum>(i)));
111 index_to_enum[i] = i;
112 enum_to_index[i] = i;
116 template<
class t_
object>
124 display_values.
add(String::DisplayString(items[i]));
126 setup(title, values, display_values);
128 template<
class t_enum>
129 typename std::enable_if<ObjectInfo<t_enum>::Enum>::type
setup(
const TranslatedString& title, t_enum first, t_enum last)
133 for (
uint04 i = 0; i <= cast<uint04>(last) - cast<uint04>(first); i++)
135 m_values.add(
String(cast<t_enum>(i + cast<uint04>(first))));
136 m_display_values.add(String::DisplayString(cast<t_enum>(i + cast<uint04>(first))));
137 index_to_enum[i] = i + cast<uint04>(first);
138 enum_to_index[i + cast<uint04>(first)] = i;
142 template<
class t_type>
145 m_values.add(
String(value));
146 m_display_values.add(display_value);
150 template<
class t_type>
151 void remove(
const t_type& value,
bool refresh_widget =
false)
156 m_values.removeIndex(index);
157 m_display_values.removeIndex(index);
167 template<
class t_type>
171 connect(
this, &QCustomComboBox::edited,
this, [
this, &resource]
173 if (!customValidator().unit().isNull())
176 resource.
set(getAs<t_type>());
178 if (m_resource_changed_listener)
179 delete m_resource_changed_listener;
182 if (!customValidator().unit().isNull())
185 setValue(resource.
get());
191 template<
class t_enum>
192 typename std::enable_if<ObjectInfo<t_enum>::Enum>::type
set(t_enum value)
194 setCurrentIndex(enum_to_index[cast<uint04>(value)]);
196 template<
class t_type>
199 if(m_using_custom || currentIndex() == -1 || m_values.size() <= cast<uint04>(currentIndex()))
200 return m_current_custom.template getAs<t_type>();
201 return m_values[currentIndex()].template getAs<t_type>();
203 template<
class t_type>
206 return m_values[index].template getAs<t_type>();
208 template<
class t_type>
211 setValue(
String(t_value));
215 setValue(
String(t_value));
216 lib_assert(!isUsingCustom(),
"unexpect custom translated string");
230 void setAllowCustom(
bool allow_custom) { m_allow_custom = allow_custom; refreshWidget(); }
256 bool m_is_refreshing =
false;
257 bool m_is_changing =
false;
261 bool m_sort_alphabetically =
false;
262 bool m_is_showing_popup =
false;
#define lib_assert(expression, message)
Definition LibAssert.h:61
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:186
constexpr t_index_type size() const
Definition Buffer.hpp:823
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition GraphicsPipeline.h:42
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
A compact way to present a list of options to the user.
Definition QCustomCombobox.h:53
QCustomComboBox(QWidget *parent=nullptr)
void setup(const TranslatedString &title, const Buffer< String > &values, const Buffer< TranslatedString > &display_values)
QSize minimumSizeHint() const override
void paintEvent(QPaintEvent *) override
Buffer< String > m_values
Definition QCustomCombobox.h:266
void setUnitType(UnitCategory unit, uint01 dimension=Constant< uint01 >::Invalid)
void setup(const TranslatedString &title, const Buffer< std::pair< TranslatedString, t_object > > &items)
Definition QCustomCombobox.h:65
bool m_using_custom
Definition QCustomCombobox.h:259
const TranslatedString & suffix() const
Definition QCustomCombobox.h:232
void focusInEvent(QFocusEvent *e) override
void hidePopup() override
void showPopup() override
t_type getAs(uint04 index) const
Definition QCustomCombobox.h:204
String m_current_custom
Definition QCustomCombobox.h:268
TranslatedString m_suffix
Definition QCustomCombobox.h:269
void setValue(const TranslatedString &t_value)
Definition QCustomCombobox.h:213
QSize sizeHint() const override
void adjustLineEditSize()
std::enable_if< ObjectInfo< t_enum >::Enum >::type set(t_enum value)
Definition QCustomCombobox.h:192
void setAutoFormat(bool auto_format)
Definition QCustomCombobox.h:190
void setCustomUnit(const String &unit, UnitCategory fallback_unit, uint01 dimension=Constant< uint01 >::Invalid)
void setTitle(const TranslatedString &title)
uint04 m_last_index
Definition QCustomCombobox.h:265
const QCustomValidator & customValidator() const
void setValue(const t_type &t_value)
Definition QCustomCombobox.h:209
bool event(QEvent *event) override
Dictionary< uint04, uint04 > enum_to_index
Definition QCustomCombobox.h:271
bool m_auto_format
Definition QCustomCombobox.h:260
bool isUsingCustom() const
Definition QCustomCombobox.h:62
void remove(const t_type &value, bool refresh_widget=false)
Definition QCustomCombobox.h:151
const Buffer< String > & values() const
Definition QCustomCombobox.h:237
void sortAlphabetically(uint04 start=0, uint04 size=Constant< uint04 >::Invalid)
void refresh()
Definition QCustomCombobox.h:162
virtual void onSorted(const Buffer< uint04 > &swap_indices)
std::enable_if< ObjectInfo< t_object >::Number >::type setup(const TranslatedString &title, const Buffer< t_object > &items)
Definition QCustomCombobox.h:89
void setup(const TranslatedString &title, const Buffer< TranslatedString > &values)
std::enable_if<!ObjectInfo< t_object >::Enum &&!ObjectInfo< t_object >::Number >::type setup(const TranslatedString &title, const Buffer< t_object > &items)
Definition QCustomCombobox.h:117
void setToolTip(const TranslatedString &tooltip)
void wheelEvent(QWheelEvent *e) override
void setSuffix(const TranslatedString &suffix)
Definition QCustomCombobox.h:231
void setAllowCustom(bool allow_custom)
Definition QCustomCombobox.h:230
fltp08 getUnitValue() const
std::enable_if< ObjectInfo< t_enum >::Enum >::type setup(const TranslatedString &title, uint04 size)
Definition QCustomCombobox.h:102
Buffer< TranslatedString > m_display_values
Definition QCustomCombobox.h:267
void setCustomValidator(const QCustomValidator &validator)
void resizeEvent(QResizeEvent *event) override
void add(const t_type &value, const TranslatedString &display_value, bool refresh_widget=false)
Definition QCustomCombobox.h:143
Angle< fltp08 > getUnitAngle() const
bool m_allow_custom
Definition QCustomCombobox.h:258
QTResourceListener * m_resource_changed_listener
Definition QCustomCombobox.h:273
t_type getAs() const
Definition QCustomCombobox.h:197
const Buffer< TranslatedString > & displayValues() const
Definition QCustomCombobox.h:238
std::enable_if< ObjectInfo< t_enum >::Enum >::type setup(const TranslatedString &title, t_enum first, t_enum last)
Definition QCustomCombobox.h:129
Dictionary< uint04, uint04 > index_to_enum
Definition QCustomCombobox.h:272
void setUnitValue(fltp08 value, uint01 unit_dimension=0)
QCustomLineEdit * m_line_edit
Definition QCustomCombobox.h:270
QCustomValidator & customValidator()
std::enable_if< ObjectInfo< t_object >::Enum >::type setup(const TranslatedString &title, const Buffer< t_object > &items)
Definition QCustomCombobox.h:77
void setConstantUnit(const ConstPointer< Unit > &unit, uint01 dimension=Constant< uint01 >::Invalid)
uint04 m_custom_index
Definition QCustomCombobox.h:263
void onEditTextChangedSlot()
void setValue(const String &value)
void setupResource(const TranslatedString &title, Resource< t_type > &resource)
Definition QCustomCombobox.h:168
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
Definition QCustomLineEdit.h:56
Responsible on most user input fields for correcting the input when possible or allerting the user th...
Definition QCustomValidator.h:47
ResourceListener * addListener(ResourceListener *listener) const
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
const T & get() const
Definition Resource.h:71
void set(const T &info, bool check_equal=true)
Definition Resource.h:53
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
UnitCategory
A category of unit describing what it relates to. Any category can have some number of units defined ...
Definition Unit.h:14
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Information about the object.
Definition ObjectInfo.h:54