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;
58 template<
class t_
object>
63 for (
uint04 i = 0; i < items.size(); i++)
66 display_values.
add(items[i].first);
68 setup(title, values, display_values);
70 template<
class t_
object>
78 display_values.
add(String::DisplayString(items[i]));
80 setup(title, values, display_values);
82 template<
class t_
object>
93 setup(title, values, display_values);
95 template<
class t_enum>
100 index_to_enum.clear();
101 for (
uint04 i = 0; i < size; i++)
103 m_values.add(
String(cast<t_enum>(i)));
104 m_display_values.add(String::DisplayString(cast<t_enum>(i)));
105 index_to_enum[i] = i;
106 enum_to_index[i] = i;
110 template<
class t_
object>
118 display_values.
add(String::DisplayString(items[i]));
120 setup(title, values, display_values);
122 template<
class t_enum>
123 typename std::enable_if<ObjectInfo<t_enum>::Enum>::type
setup(
const TranslatedString& title, t_enum first, t_enum last)
127 for (
uint04 i = 0; i <= cast<uint04>(last) - cast<uint04>(first); i++)
129 m_values.add(
String(cast<t_enum>(i + cast<uint04>(first))));
130 m_display_values.add(String::DisplayString(cast<t_enum>(i + cast<uint04>(first))));
131 index_to_enum[i] = i + cast<uint04>(first);
132 enum_to_index[i + cast<uint04>(first)] = i;
136 template<
class t_type>
139 m_values.add(
String(value));
140 m_display_values.add(display_value);
144 template<
class t_type>
145 void remove(
const t_type& value,
bool refresh_widget =
false)
150 m_values.removeIndex(index);
151 m_display_values.removeIndex(index);
161 template<
class t_type>
165 connect(
this, &QCustomComboBox::edited,
this, [
this, &resource]
167 if (!customValidator().unit().isNull())
170 resource.
set(getAs<t_type>());
172 if (m_resource_changed_listener)
173 delete m_resource_changed_listener;
176 if (!customValidator().unit().isNull())
179 setValue(resource.
get());
185 template<
class t_enum>
186 typename std::enable_if<ObjectInfo<t_enum>::Enum>::type
set(t_enum value)
188 setCurrentIndex(enum_to_index[cast<uint04>(value)]);
190 template<
class t_type>
193 if(m_using_custom || currentIndex() == -1 || m_values.size() <= cast<uint04>(currentIndex()))
194 return m_current_custom.template getAs<t_type>();
195 return m_values[currentIndex()].template getAs<t_type>();
197 template<
class t_type>
200 return m_values[index].template getAs<t_type>();
202 template<
class t_type>
205 setValue(
String(t_value));
209 setValue(
String(t_value));
210 lib_assert(!isUsingCustom(),
"unexpect custom translated string");
214 QSize minimumSizeHint()
const override;
215 QSize sizeHint()
const override;
216 fltp08 getUnitValue()
const;
218 void setValue(
const String& value);
223 void setUnitValue(
fltp08 value,
uint01 unit_dimension = 0);
224 void setAllowCustom(
bool allow_custom) { m_allow_custom = allow_custom; refreshWidget(); }
227 void focusInEvent(QFocusEvent* e)
override;
228 void updateFontSize();
229 bool event(QEvent* event)
override;
233 void showPopup()
override;
234 void hidePopup()
override;
235 void resizeEvent(QResizeEvent* event)
override;
236 void paintEvent(QPaintEvent*)
override;
237 void wheelEvent(QWheelEvent* e)
override;
238 void lockInCustomValue();
240 void refreshWidget();
241 void adjustLineEditSize();
245 void onEditTextChangedSlot();
250 bool m_is_refreshing =
false;
251 bool m_is_changing =
false;
255 bool m_sort_alphabetically =
false;
256 bool m_is_showing_popup =
false;
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Stores an angle in an optimized format.
Definition StringStream.h:408
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
void add(t_type &&object)
Definition Buffer.hpp:222
constexpr t_index_type size() const
Definition Buffer.hpp:1507
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.
Definition Dictionary.h:59
Definition QCustomCombobox.h:47
Buffer< String > m_values
Definition QCustomCombobox.h:260
void setup(const TranslatedString &title, const Buffer< std::pair< TranslatedString, t_object > > &items)
Definition QCustomCombobox.h:59
bool m_using_custom
Definition QCustomCombobox.h:253
const TranslatedString & suffix() const
Definition QCustomCombobox.h:226
t_type getAs(uint04 index) const
Definition QCustomCombobox.h:198
String m_current_custom
Definition QCustomCombobox.h:262
TranslatedString m_suffix
Definition QCustomCombobox.h:263
void setValue(const TranslatedString &t_value)
Definition QCustomCombobox.h:207
std::enable_if< ObjectInfo< t_enum >::Enum >::type set(t_enum value)
Definition QCustomCombobox.h:186
void setAutoFormat(bool auto_format)
Definition QCustomCombobox.h:184
uint04 m_last_index
Definition QCustomCombobox.h:259
void setValue(const t_type &t_value)
Definition QCustomCombobox.h:203
Dictionary< uint04, uint04 > enum_to_index
Definition QCustomCombobox.h:265
bool m_auto_format
Definition QCustomCombobox.h:254
bool isUsingCustom() const
Definition QCustomCombobox.h:56
void remove(const t_type &value, bool refresh_widget=false)
Definition QCustomCombobox.h:145
const Buffer< String > & values() const
Definition QCustomCombobox.h:231
void refresh()
Definition QCustomCombobox.h:156
std::enable_if< ObjectInfo< t_object >::Number >::type setup(const TranslatedString &title, const Buffer< t_object > &items)
Definition QCustomCombobox.h:83
std::enable_if<!ObjectInfo< t_object >::Enum &&!ObjectInfo< t_object >::Number >::type setup(const TranslatedString &title, const Buffer< t_object > &items)
Definition QCustomCombobox.h:111
void setSuffix(const TranslatedString &suffix)
Definition QCustomCombobox.h:225
void setAllowCustom(bool allow_custom)
Definition QCustomCombobox.h:224
std::enable_if< ObjectInfo< t_enum >::Enum >::type setup(const TranslatedString &title, uint04 size)
Definition QCustomCombobox.h:96
Buffer< TranslatedString > m_display_values
Definition QCustomCombobox.h:261
void add(const t_type &value, const TranslatedString &display_value, bool refresh_widget=false)
Definition QCustomCombobox.h:137
bool m_allow_custom
Definition QCustomCombobox.h:252
QTResourceListener * m_resource_changed_listener
Definition QCustomCombobox.h:267
t_type getAs() const
Definition QCustomCombobox.h:191
const Buffer< TranslatedString > & displayValues() const
Definition QCustomCombobox.h:232
std::enable_if< ObjectInfo< t_enum >::Enum >::type setup(const TranslatedString &title, t_enum first, t_enum last)
Definition QCustomCombobox.h:123
Dictionary< uint04, uint04 > index_to_enum
Definition QCustomCombobox.h:266
QCustomLineEdit * m_line_edit
Definition QCustomCombobox.h:264
std::enable_if< ObjectInfo< t_object >::Enum >::type setup(const TranslatedString &title, const Buffer< t_object > &items)
Definition QCustomCombobox.h:71
uint04 m_custom_index
Definition QCustomCombobox.h:257
void setupResource(const TranslatedString &title, Resource< t_type > &resource)
Definition QCustomCombobox.h:162
Definition QCustomLineEdit.h:118
Definition QCustomValidator.h:43
ResourceListener * addListener(ResourceListener *listener) const
Definition ResourceListener.cpp:37
A core part of the engine, stores variables that can be listened to with ResourceListener.
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
Definition QCustomLineEdit.h:49
The core String class for the software.
Definition String.h:47
Any text displayed to the user should be defined as a TranslatedString which allows the.
Definition TranslatedString.h:13
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:93
UnitCategory
A category of unit describing what it relates to. Any category can have some number of units.
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:115
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:195
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:176
Definition BaseValues.hpp:267
Information about the object.
Definition ObjectInfo.h:51