move type names over to enum
This commit is contained in:
2026-04-06 18:55:43 +02:00
parent bc61f4990f
commit 514b3e402a
43 changed files with 113 additions and 103 deletions
+9
View File
@@ -34,6 +34,15 @@ target_link_libraries(UI
PUBLIC
Color
nlohmann_json::nlohmann_json
magic_enum::magic_enum
Qt::Core
Qt::SerialBus
UI_enum
)
add_library(UI_enum INTERFACE)
target_include_directories(UI_enum
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/enum
)
+25
View File
@@ -0,0 +1,25 @@
#pragma once
enum class UI_enum
{
ui_button,
ui_can,
ui_checkbox,
ui_combobox,
ui_dial,
ui_double_spinbox,
ui_hex_spinbox,
ui_label,
ui_led,
ui_plot,
ui_slider,
ui_spinbox,
ui_stacked_widget,
ui_status_bar,
ui_tab_widget,
ui_table,
ui_textbox,
ui_thermo,
end,
begin = 0
};
+3 -2
View File
@@ -1,11 +1,12 @@
#include "ui_button.hpp"
#include "ui_enum.hpp"
UI_button::UI_button(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_BUTTON_TYPE, text, fg_color, bg_color, parent)
: UI_item(UI_enum::ui_button, text, fg_color, bg_color, parent)
{
}
UI_button::UI_button(QObject *parent) : UI_item(UI_BUTTON_TYPE, parent)
UI_button::UI_button(QObject *parent) : UI_item(UI_enum::ui_button, parent)
{
}
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_BUTTON_TYPE std::string("ui_button")
/**
* @brief Class representing a UI button
*
+3 -2
View File
@@ -12,12 +12,13 @@ template <class T> T ByteArrayToStdArray(const QByteArray &byteArray)
return stdArray;
}
UI_can::UI_can(Color fg_color, Color bg_color, QObject *parent) : UI_item(UI_CAN_TYPE, "", fg_color, bg_color, parent)
UI_can::UI_can(Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_enum::ui_can, "", fg_color, bg_color, parent)
{
setup_item(false, true, true);
}
UI_can::UI_can(QObject *parent) : UI_item(UI_CAN_TYPE, parent)
UI_can::UI_can(QObject *parent) : UI_item(UI_enum::ui_can, parent)
{
setup_item(false, true, true);
}
-2
View File
@@ -2,8 +2,6 @@
#include "ui_item.hpp"
#include <QCanBusFrame>
#define UI_CAN_TYPE std::string("ui_can")
/**
* @brief Class representing a CAN UI item
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_checkbox.hpp"
UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m_checked()
UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_enum::ui_checkbox, parent), m_checked()
{
}
UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_CHECKBOX_TYPE, text, fg_color, bg_color, parent), m_checked(false)
: UI_item(UI_enum::ui_checkbox, text, fg_color, bg_color, parent), m_checked(false)
{
}
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_CHECKBOX_TYPE std::string("ui_checkbox")
/**
* @brief Class representing a UI checkbox
*
+2 -2
View File
@@ -1,13 +1,13 @@
#include "ui_combobox.hpp"
UI_combobox::UI_combobox(QObject *parent) : UI_item(UI_COMBOBOX_TYPE, parent), m_options()
UI_combobox::UI_combobox(QObject *parent) : UI_item(UI_enum::ui_combobox, parent), m_options()
{
setup_item(false, true, true);
}
UI_combobox::UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected,
QObject *parent)
: UI_item(UI_COMBOBOX_TYPE, "", fg_color, bg_color, parent), m_options(options), m_selected(selected)
: UI_item(UI_enum::ui_combobox, "", fg_color, bg_color, parent), m_options(options), m_selected(selected)
{
setup_item(false, true, true);
}
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_COMBOBOX_TYPE std::string("ui_combobox")
/**
* @brief Class representing a UI combobox
*
+2 -2
View File
@@ -2,7 +2,7 @@
UI_dial::UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parent)
: UI_item(UI_DIAL_TYPE, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
: UI_item(UI_enum::ui_dial, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
{
}
@@ -22,7 +22,7 @@ UI_dial::UI_dial(std::string text, double min, double max, double value, QObject
{
}
UI_dial::UI_dial(QObject *parent) : UI_item(UI_DIAL_TYPE, parent)
UI_dial::UI_dial(QObject *parent) : UI_item(UI_enum::ui_dial, parent)
{
}
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_DIAL_TYPE std::string("ui_dial")
/**
* @brief Class representing a UI dial
*
+2 -2
View File
@@ -1,12 +1,12 @@
#include "ui_double_spinbox.hpp"
UI_double_spinbox::UI_double_spinbox(QObject *parent) : UI_item(UI_DOUBLE_SPINBOX_TYPE, parent)
UI_double_spinbox::UI_double_spinbox(QObject *parent) : UI_item(UI_enum::ui_double_spinbox, parent)
{
setup_item(false, false, false);
}
UI_double_spinbox::UI_double_spinbox(double min, double max, double value, QObject *parent)
: UI_item(UI_DOUBLE_SPINBOX_TYPE, parent)
: UI_item(UI_enum::ui_double_spinbox, parent)
{
setup_item(false, false, false);
m_min = min;
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_DOUBLE_SPINBOX_TYPE std::string("ui_double_spinbox")
/**
* @brief Class representing a UI double spinbox
*
+2 -2
View File
@@ -1,12 +1,12 @@
#include "ui_hex_spinbox.hpp"
UI_hex_spinbox::UI_hex_spinbox(QObject *parent) : UI_item(UI_HEX_SPINBOX_TYPE, parent)
UI_hex_spinbox::UI_hex_spinbox(QObject *parent) : UI_item(UI_enum::ui_hex_spinbox, parent)
{
setup_item(false, false, false);
}
UI_hex_spinbox::UI_hex_spinbox(double min, double max, double value, QObject *parent)
: UI_item(UI_HEX_SPINBOX_TYPE, parent)
: UI_item(UI_enum::ui_hex_spinbox, parent)
{
setup_item(false, false, false);
m_min = min;
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_HEX_SPINBOX_TYPE std::string("ui_hex_spinbox")
/**
* @brief Class representing a UI hex spinbox
*
+7 -6
View File
@@ -1,20 +1,21 @@
#include "ui_item.hpp"
#include <magic_enum/magic_enum.hpp>
UI_item::UI_item(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent)
UI_item::UI_item(UI_enum type, std::string text, Color fg_color, Color bg_color, QObject *parent)
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(text), m_fg_color(fg_color), m_bg_color(bg_color),
m_enabled(true), m_visible(true)
{
}
UI_item::UI_item(std::string type, QObject *parent)
UI_item::UI_item(UI_enum type, QObject *parent)
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(""), m_fg_color(Color::Default),
m_bg_color(Color::Default), m_enabled(true), m_visible(true)
{
}
std::string UI_item::type() const &
std::string_view UI_item::type() const &
{
return m_type;
return magic_enum::enum_name(m_type);
}
bool UI_item::is_type(json j)
@@ -23,7 +24,7 @@ bool UI_item::is_type(json j)
{
return false;
}
return j.at("type") == m_type;
return magic_enum::enum_cast<UI_enum>(j.at("type")).value_or(UI_enum::end) == m_type;
}
void UI_item::set_text(std::string text)
@@ -129,7 +130,7 @@ json UI_item::to_json(size_t id) const
{
json j;
j["id"] = id;
j["type"] = m_type;
j["type"] = type();
if (m_text_enabled)
j["text"] = m_text;
if (m_fg_color_enabled)
+5 -4
View File
@@ -1,5 +1,6 @@
#pragma once
#include "color.hpp"
#include "ui_enum.hpp"
#include <cstdint>
#include <nlohmann/json.hpp>
#include <string>
@@ -24,7 +25,7 @@ class UI_item : public QObject
* @param type The type of the UI item
* @param parent The parent QObject
*/
explicit UI_item(std::string type, QObject *parent = nullptr);
explicit UI_item(UI_enum type, QObject *parent = nullptr);
/**
* @brief Construct a new UI item object
*
@@ -34,14 +35,14 @@ class UI_item : public QObject
* @param bg_color The background color of the UI item
* @param parent The parent QObject
*/
explicit UI_item(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
explicit UI_item(UI_enum type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
/**
* @brief Get the type of the UI item
*
* @return std::string The type of the UI item
*/
std::string type() const &;
std::string_view type() const &;
/**
* @brief Check if the JSON object is of the correct type
*
@@ -196,7 +197,7 @@ class UI_item : public QObject
* @brief The type of the UI item
*
*/
std::string m_type;
UI_enum m_type;
/**
* @brief The text of the UI item
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_label.hpp"
UI_label::UI_label(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_LABEL_TYPE, text, fg_color, bg_color, parent)
: UI_item(UI_enum::ui_label, text, fg_color, bg_color, parent)
{
}
UI_label::UI_label(QObject *parent) : UI_item(UI_LABEL_TYPE, parent)
UI_label::UI_label(QObject *parent) : UI_item(UI_enum::ui_label, parent)
{
}
-2
View File
@@ -2,8 +2,6 @@
#include "ui_item.hpp"
#include <string>
#define UI_LABEL_TYPE std::string("ui_label")
/**
* @brief Class representing a UI label
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_led.hpp"
UI_led::UI_led(QObject *parent) : UI_item(UI_LED_TYPE, "", Color::Default, Color::Default, parent)
UI_led::UI_led(QObject *parent) : UI_item(UI_enum::ui_led, "", Color::Default, Color::Default, parent)
{
}
UI_led::UI_led(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_LED_TYPE, text, fg_color, bg_color, parent)
: UI_item(UI_enum::ui_led, text, fg_color, bg_color, parent)
{
}
-2
View File
@@ -2,8 +2,6 @@
#include "ui_item.hpp"
#include <string>
#define UI_LED_TYPE std::string("ui_led")
/**
* @brief Class representing a UI led
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_plot.hpp"
UI_plot::UI_plot(QObject *parent) : UI_item{UI_PLOT_TYPE, parent}
UI_plot::UI_plot(QObject *parent) : UI_item{UI_enum::ui_plot, parent}
{
}
UI_plot::UI_plot(std::string text, std::string x_label, std::string y_label, QObject *parent)
: UI_item(UI_PLOT_TYPE, parent), m_x_label(x_label), m_y_label(y_label)
: UI_item(UI_enum::ui_plot, parent), m_x_label(x_label), m_y_label(y_label)
{
set_text(text);
}
-1
View File
@@ -1,6 +1,5 @@
#pragma once
#include "ui_item.hpp"
#define UI_PLOT_TYPE std::string("ui_plot")
/**
* @brief Class representing a UI plot
+3 -2
View File
@@ -2,7 +2,8 @@
UI_slider::UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parent)
: UI_item(UI_SLIDER_TYPE, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
: UI_item(UI_enum::ui_slider, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value),
m_unit(unit)
{
}
@@ -22,7 +23,7 @@ UI_slider::UI_slider(std::string text, double min, double max, double value, QOb
{
}
UI_slider::UI_slider(QObject *parent) : UI_item(UI_SLIDER_TYPE, parent)
UI_slider::UI_slider(QObject *parent) : UI_item(UI_enum::ui_slider, parent)
{
}
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_SLIDER_TYPE std::string("ui_slider")
/**
* @brief Class representing a UI slider
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_spinbox.hpp"
UI_spinbox::UI_spinbox(QObject *parent) : UI_item(UI_SPINBOX_TYPE, parent)
UI_spinbox::UI_spinbox(QObject *parent) : UI_item(UI_enum::ui_spinbox, parent)
{
setup_item(false, false, false);
}
UI_spinbox::UI_spinbox(double min, double max, double value, QObject *parent) : UI_item(UI_SPINBOX_TYPE, parent)
UI_spinbox::UI_spinbox(double min, double max, double value, QObject *parent) : UI_item(UI_enum::ui_spinbox, parent)
{
setup_item(false, false, false);
m_min = min;
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_SPINBOX_TYPE std::string("ui_spinbox")
/**
* @brief Class representing a UI spinbox
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_stacked_widget.hpp"
UI_stacked_widget::UI_stacked_widget(QObject *parent) : UI_item(UI_STACKED_WIDGET_TYPE, parent)
UI_stacked_widget::UI_stacked_widget(QObject *parent) : UI_item(UI_enum::ui_stacked_widget, parent)
{
}
UI_stacked_widget::UI_stacked_widget(size_t tab_count, size_t current_tab, QObject *parent)
: UI_item(UI_STACKED_WIDGET_TYPE, parent), m_tab_count(tab_count), m_current_tab(current_tab)
: UI_item(UI_enum::ui_stacked_widget, parent), m_tab_count(tab_count), m_current_tab(current_tab)
{
}
-1
View File
@@ -1,6 +1,5 @@
#pragma once
#include "ui_item.hpp"
#define UI_STACKED_WIDGET_TYPE std::string("ui_stacked_widget")
/**
* @brief Class representing a UI stacked widget
+3 -2
View File
@@ -1,11 +1,12 @@
#include "ui_status_bar.hpp"
UI_status_bar::UI_status_bar(QObject *parent) : UI_item(UI_STATUS_BAR_TYPE, parent), m_timeout(0)
UI_status_bar::UI_status_bar(QObject *parent) : UI_item(UI_enum::ui_status_bar, parent), m_timeout(0)
{
setup_item(true, false, false);
}
UI_status_bar::UI_status_bar(std::string message, QObject *parent) : UI_item(UI_STATUS_BAR_TYPE, parent), m_timeout(0)
UI_status_bar::UI_status_bar(std::string message, QObject *parent)
: UI_item(UI_enum::ui_status_bar, parent), m_timeout(0)
{
m_text = std::move(message);
setup_item(true, false, false);
-1
View File
@@ -1,6 +1,5 @@
#pragma once
#include "ui_item.hpp"
#define UI_STATUS_BAR_TYPE std::string("ui_status_bar")
/**
* @brief Class representing a UI status bar
+2 -2
View File
@@ -1,12 +1,12 @@
#include "ui_tab_widget.hpp"
UI_tab_widget::UI_tab_widget(QObject *parent) : UI_item(UI_TAB_WIDGET_TYPE, parent)
UI_tab_widget::UI_tab_widget(QObject *parent) : UI_item(UI_enum::ui_tab_widget, parent)
{
setup_item(false, false, false);
}
UI_tab_widget::UI_tab_widget(std::vector<std::string> tab_names, size_t selected, QObject *parent)
: UI_item(UI_TAB_WIDGET_TYPE, parent), m_selected_tab(selected), m_tab_names(tab_names)
: UI_item(UI_enum::ui_tab_widget, parent), m_selected_tab(selected), m_tab_names(tab_names)
{
setup_item(false, false, false);
m_tab_visible.resize(m_tab_names.size(), true);
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_TAB_WIDGET_TYPE std::string("ui_tab_widget")
/**
* @brief Class representing a UI tab widget
*
+3 -3
View File
@@ -1,14 +1,14 @@
#include "ui_table.hpp"
UI_table::UI_table(QObject *parent) : UI_item(UI_TABLE_TYPE, parent), m_row_count(0), m_column_count(0)
UI_table::UI_table(QObject *parent) : UI_item(UI_enum::ui_table, parent), m_row_count(0), m_column_count(0)
{
setup_item(false, false, false);
}
UI_table::UI_table(size_t row_count, size_t column_count, std::vector<std::string> row_labels,
std::vector<std::string> column_labels, QObject *parent)
: UI_item(UI_TABLE_TYPE, parent), m_row_count(row_count), m_column_count(column_count), m_row_labels(row_labels),
m_column_labels(column_labels), m_table()
: UI_item(UI_enum::ui_table, parent), m_row_count(row_count), m_column_count(column_count),
m_row_labels(row_labels), m_column_labels(column_labels), m_table()
{
setup_item(false, false, false);
m_row_labels.reserve(100);
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_TABLE_TYPE std::string("ui_table")
/**
* @brief Class representing a UI table
*
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_textbox.hpp"
UI_textbox::UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_TEXTBOX_TYPE, "", fg_color, bg_color, parent), m_hint(hint)
: UI_item(UI_enum::ui_textbox, "", fg_color, bg_color, parent), m_hint(hint)
{
}
UI_textbox::UI_textbox(QObject *parent) : UI_item(UI_TEXTBOX_TYPE, parent)
UI_textbox::UI_textbox(QObject *parent) : UI_item(UI_enum::ui_textbox, parent)
{
}
-2
View File
@@ -2,8 +2,6 @@
#include "ui_item.hpp"
#include <string>
#define UI_TEXTBOX_TYPE std::string("ui_textbox")
/**
* @brief Class representing a UI textbox
*
+3 -2
View File
@@ -2,7 +2,8 @@
UI_thermo::UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parent)
: UI_item(UI_THERMO_TYPE, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
: UI_item(UI_enum::ui_thermo, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value),
m_unit(unit)
{
}
@@ -22,7 +23,7 @@ UI_thermo::UI_thermo(std::string text, double min, double max, double value, QOb
{
}
UI_thermo::UI_thermo(QObject *parent) : UI_item(UI_THERMO_TYPE, parent)
UI_thermo::UI_thermo(QObject *parent) : UI_item(UI_enum::ui_thermo, parent)
{
}
-2
View File
@@ -1,8 +1,6 @@
#pragma once
#include "ui_item.hpp"
#define UI_THERMO_TYPE std::string("ui_thermo")
// TODO: Add color scale
/**
* @brief Class representing a UI thermometer
+1 -1
View File
@@ -62,7 +62,7 @@ target_compile_definitions(client_common PRIVATE
)
target_link_libraries(client_common
PUBLIC
qwt Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets magic_enum::magic_enum nlohmann_json::nlohmann_json
qwt Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets magic_enum::magic_enum nlohmann_json::nlohmann_json UI_enum
)
set_target_properties(
+22 -21
View File
@@ -20,7 +20,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
QPushButton *exit_app = m_error->addButton("Exit Application", QMessageBox::AcceptRole);
m_error->addButton("Close", QMessageBox::RejectRole);
connect(exit_app, &QPushButton::clicked, this, &QCoreApplication::quit, Qt::QueuedConnection);
m_process_lookup.insert("ui_label", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_label, [=, this](json &ui_item, QWidget *widget) {
auto label = qobject_cast<QLabel *>(widget);
if (label == nullptr)
{
@@ -48,7 +48,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
}
});
m_process_lookup.insert("ui_slider", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_slider, [=, this](json &ui_item, QWidget *widget) {
QLabel *label = id_to_label(id_to_ui(ui_item.at("id")));
// TODO: Find a cleaner fix
#ifdef __WIN32
@@ -93,7 +93,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
}
// TODO: Add color for scale
});
m_process_lookup.insert("ui_dial", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_dial, [=, this](json &ui_item, QWidget *widget) {
QLabel *label = id_to_label(id_to_ui(ui_item.at("id")));
// TODO: Find a cleaner fix
#ifdef __WIN32
@@ -131,7 +131,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
dial->setVisible(visible);
}
});
m_process_lookup.insert("ui_thermo", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_thermo, [=, this](json &ui_item, QWidget *widget) {
QLabel *label = id_to_label(id_to_ui(ui_item.at("id")));
// TODO: Find a cleaner fix
#ifdef __WIN32
@@ -169,7 +169,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
thermo->setVisible(visible);
}
});
m_process_lookup.insert("ui_textbox", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_textbox, [=, this](json &ui_item, QWidget *widget) {
auto line_edit = qobject_cast<QLineEdit *>(widget);
if (line_edit == nullptr)
{
@@ -200,7 +200,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
line_edit->setText(text);
}
});
m_process_lookup.insert("ui_combobox", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_combobox, [=, this](json &ui_item, QWidget *widget) {
auto combobox = qobject_cast<QComboBox *>(widget);
if (combobox == nullptr)
{
@@ -233,9 +233,9 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
combobox->setCurrentIndex(selected);
}
});
m_process_lookup.insert("ui_radiobutton",
[=, this](json &ui_item, QWidget *widget) { LOG_CRITICAL("Not implemented"); });
m_process_lookup.insert("ui_checkbox", [=, this](json &ui_item, QWidget *widget) {
// m_process_lookup.insert(UI_enum::ui_radiobutton,
// [=, this](json &ui_item, QWidget *widget) { LOG_CRITICAL("Not implemented"); });
m_process_lookup.insert(UI_enum::ui_checkbox, [=, this](json &ui_item, QWidget *widget) {
auto checkbox = qobject_cast<QCheckBox *>(widget);
if (checkbox == nullptr)
{
@@ -299,7 +299,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
set_widget_color(checkbox, fg_color, bg_color);
}
});
m_process_lookup.insert("ui_button", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_button, [=, this](json &ui_item, QWidget *widget) {
auto button = qobject_cast<QPushButton *>(widget);
if (button == nullptr)
{
@@ -357,7 +357,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
set_widget_color(button, fg_color, bg_color);
}
});
m_process_lookup.insert("ui_led", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_led, [=, this](json &ui_item, QWidget *widget) {
auto led = qobject_cast<Led *>(widget);
if (led == nullptr)
{
@@ -409,7 +409,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
set_widget_color(led, color, bg_color);
}
});
m_process_lookup.insert("ui_spinbox", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_spinbox, [=, this](json &ui_item, QWidget *widget) {
auto spinbox = qobject_cast<QSpinBox *>(widget);
if (spinbox == nullptr)
{
@@ -446,7 +446,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
spinbox->setValue((int)value);
}
});
m_process_lookup.insert("ui_double_spinbox", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_double_spinbox, [=, this](json &ui_item, QWidget *widget) {
auto spinbox = qobject_cast<QDoubleSpinBox *>(widget);
if (spinbox == nullptr)
{
@@ -483,7 +483,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
spinbox->setValue(value);
}
});
m_process_lookup.insert("ui_hex_spinbox", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_hex_spinbox, [=, this](json &ui_item, QWidget *widget) {
auto spinbox = qobject_cast<HexSpinBox *>(widget);
if (spinbox == nullptr)
{
@@ -520,7 +520,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
spinbox->setValue((int)value);
}
});
m_process_lookup.insert("ui_tab_widget", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_tab_widget, [=, this](json &ui_item, QWidget *widget) {
auto tab_widget = qobject_cast<QTabWidget *>(widget);
if (tab_widget == nullptr)
{
@@ -565,7 +565,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
tab_widget->setCurrentIndex(ui_item.at("selected"));
}
});
m_process_lookup.insert("ui_stacked_widget", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_stacked_widget, [=, this](json &ui_item, QWidget *widget) {
auto stacked_widget = qobject_cast<QStackedWidget *>(widget);
if (stacked_widget == nullptr)
{
@@ -597,7 +597,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
stacked_widget->setCurrentIndex(ui_item.at("current_tab"));
}
});
m_process_lookup.insert("ui_status_bar", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_status_bar, [=, this](json &ui_item, QWidget *widget) {
auto status_bar = qobject_cast<QStatusBar *>(widget);
if (status_bar == nullptr)
{
@@ -610,7 +610,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
status_bar->showMessage(QString::fromStdString(ui_item.at("text")), ui_item.at("timeout"));
}
});
m_process_lookup.insert("ui_plot", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_plot, [=, this](json &ui_item, QWidget *widget) {
auto plot = qobject_cast<Plot_wrapper *>(widget);
if (plot == nullptr)
{
@@ -670,7 +670,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
plot->setAxisScale(QwtAxis::XBottom, x_vals[0], x_vals[x_vals.size() - 1]);
plot->replot();
});
m_process_lookup.insert("ui_table", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_table, [=, this](json &ui_item, QWidget *widget) {
auto table = qobject_cast<QTableWidget *>(widget);
if (table == nullptr)
{
@@ -739,7 +739,7 @@ UI_base::UI_base(QString name, Web_socket_wrapper *web_socket, QWidget *parent)
}
table->resizeColumnsToContents();
});
m_process_lookup.insert("ui_can", [=, this](json &ui_item, QWidget *widget) {
m_process_lookup.insert(UI_enum::ui_can, [=, this](json &ui_item, QWidget *widget) {
auto can_ui = qobject_cast<Can_Transceive *>(widget);
if (can_ui == nullptr)
{
@@ -851,7 +851,8 @@ void UI_base::UI_item_parser(json &input)
return;
}
m_process_lookup[ui_item.at("type")](ui_item, widget);
m_process_lookup[magic_enum::enum_cast<UI_enum>((std::string)ui_item.at("type")).value_or(UI_enum::end)](
ui_item, widget);
}
}
+2 -1
View File
@@ -1,4 +1,5 @@
#pragma once
#include "ui_enum.hpp"
#include <QMainWindow>
#include <QWidget>
#include <functional>
@@ -222,5 +223,5 @@ class EXPORT UI_base : public QMainWindow
bool m_open = false;
bool m_first_load = true;
std::vector<QWidget *> m_ui_lookup;
QMap<std::string, std::function<void(json &, QWidget *)>> m_process_lookup;
QMap<UI_enum, std::function<void(json &, QWidget *)>> m_process_lookup;
};