mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
UI
optimize by passing by reference optimize by using std::move
This commit is contained in:
+2
-2
@@ -16,7 +16,7 @@ void UI_combobox::set_selected(size_t selected)
|
|||||||
{
|
{
|
||||||
if (selected == m_selected)
|
if (selected == m_selected)
|
||||||
return;
|
return;
|
||||||
m_selected = selected;
|
m_selected = std::move(selected);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
emit changed(selected_text());
|
emit changed(selected_text());
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ size_t UI_combobox::selected() const
|
|||||||
return m_selected;
|
return m_selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_combobox::selected_text() const
|
std::string UI_combobox::selected_text() const &
|
||||||
{
|
{
|
||||||
return m_options[m_selected];
|
return m_options[m_selected];
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ class UI_combobox : public UI_item
|
|||||||
*
|
*
|
||||||
* @return std::string The text of the selected option
|
* @return std::string The text of the selected option
|
||||||
*/
|
*/
|
||||||
std::string selected_text() const;
|
std::string selected_text() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deserialize the combobox from JSON
|
* @brief Deserialize the combobox from JSON
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ double UI_dial::max() const
|
|||||||
return m_max;
|
return m_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_dial::unit() const
|
std::string UI_dial::unit() const &
|
||||||
{
|
{
|
||||||
return m_unit;
|
return m_unit;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -96,7 +96,7 @@ class UI_dial : public UI_item
|
|||||||
*
|
*
|
||||||
* @return std::string The unit of the dial
|
* @return std::string The unit of the dial
|
||||||
*/
|
*/
|
||||||
std::string unit() const;
|
std::string unit() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deserialize the dial from JSON
|
* @brief Deserialize the dial from JSON
|
||||||
|
|||||||
+9
-9
@@ -12,7 +12,7 @@ UI_item::UI_item(std::string type, QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_item::type() const
|
std::string UI_item::type() const &
|
||||||
{
|
{
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ void UI_item::set_text(std::string text)
|
|||||||
{
|
{
|
||||||
if (this->m_text != text)
|
if (this->m_text != text)
|
||||||
{
|
{
|
||||||
this->m_text = text;
|
this->m_text = std::move(text);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ void UI_item::append_text(std::string text)
|
|||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_item::text() const
|
std::string UI_item::text() const &
|
||||||
{
|
{
|
||||||
return m_text;
|
return m_text;
|
||||||
}
|
}
|
||||||
@@ -50,12 +50,12 @@ void UI_item::set_fg_color(Color fg_color)
|
|||||||
{
|
{
|
||||||
if (this->m_fg_color != fg_color)
|
if (this->m_fg_color != fg_color)
|
||||||
{
|
{
|
||||||
this->m_fg_color = fg_color;
|
this->m_fg_color = std::move(fg_color);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Color UI_item::fg_color() const
|
Color UI_item::fg_color() const &
|
||||||
{
|
{
|
||||||
return m_fg_color;
|
return m_fg_color;
|
||||||
}
|
}
|
||||||
@@ -64,12 +64,12 @@ void UI_item::set_bg_color(Color bg_color)
|
|||||||
{
|
{
|
||||||
if (this->m_bg_color != bg_color)
|
if (this->m_bg_color != bg_color)
|
||||||
{
|
{
|
||||||
this->m_bg_color = bg_color;
|
this->m_bg_color = std::move(bg_color);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Color UI_item::bg_color() const
|
Color UI_item::bg_color() const &
|
||||||
{
|
{
|
||||||
return m_bg_color;
|
return m_bg_color;
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ void UI_item::set_enabled(bool enabled)
|
|||||||
{
|
{
|
||||||
if (this->m_enabled != enabled)
|
if (this->m_enabled != enabled)
|
||||||
{
|
{
|
||||||
this->m_enabled = enabled;
|
this->m_enabled = std::move(enabled);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ void UI_item::set_visible(bool visible)
|
|||||||
{
|
{
|
||||||
if (this->m_visible != visible)
|
if (this->m_visible != visible)
|
||||||
{
|
{
|
||||||
this->m_visible = visible;
|
this->m_visible = std::move(visible);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -41,7 +41,7 @@ class UI_item : public QObject
|
|||||||
*
|
*
|
||||||
* @return std::string The type of the UI item
|
* @return std::string The type of the UI item
|
||||||
*/
|
*/
|
||||||
std::string type() const;
|
std::string type() const &;
|
||||||
/**
|
/**
|
||||||
* @brief Check if the JSON object is of the correct type
|
* @brief Check if the JSON object is of the correct type
|
||||||
*
|
*
|
||||||
@@ -68,7 +68,7 @@ class UI_item : public QObject
|
|||||||
*
|
*
|
||||||
* @return std::string The text of the UI item
|
* @return std::string The text of the UI item
|
||||||
*/
|
*/
|
||||||
std::string text() const;
|
std::string text() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the foreground color of the UI item
|
* @brief Set the foreground color of the UI item
|
||||||
@@ -81,7 +81,7 @@ class UI_item : public QObject
|
|||||||
*
|
*
|
||||||
* @return Color The foreground color of the UI item
|
* @return Color The foreground color of the UI item
|
||||||
*/
|
*/
|
||||||
Color fg_color() const;
|
Color fg_color() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the background color of the UI item
|
* @brief Set the background color of the UI item
|
||||||
@@ -94,7 +94,7 @@ class UI_item : public QObject
|
|||||||
*
|
*
|
||||||
* @return Color The background color of the UI item
|
* @return Color The background color of the UI item
|
||||||
*/
|
*/
|
||||||
Color bg_color() const;
|
Color bg_color() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable or disable the UI item
|
* @brief Enable or disable the UI item
|
||||||
|
|||||||
+6
-6
@@ -12,24 +12,24 @@ UI_plot::UI_plot(std::string text, std::string x_label, std::string y_label, QOb
|
|||||||
|
|
||||||
void UI_plot::set_x_label(std::string name)
|
void UI_plot::set_x_label(std::string name)
|
||||||
{
|
{
|
||||||
m_x_label = name;
|
m_x_label = std::move(name);
|
||||||
|
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_plot::x_label() const
|
std::string UI_plot::x_label() const &
|
||||||
{
|
{
|
||||||
return m_x_label;
|
return m_x_label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI_plot::set_y_label(std::string name)
|
void UI_plot::set_y_label(std::string name)
|
||||||
{
|
{
|
||||||
m_y_label = name;
|
m_y_label = std::move(name);
|
||||||
|
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_plot::y_label() const
|
std::string UI_plot::y_label() const &
|
||||||
{
|
{
|
||||||
return m_y_label;
|
return m_y_label;
|
||||||
}
|
}
|
||||||
@@ -50,12 +50,12 @@ void UI_plot::add_value(double x, double y)
|
|||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double> &UI_plot::x_vals() const
|
const std::vector<double> &UI_plot::x_vals() const &
|
||||||
{
|
{
|
||||||
return m_x_vals;
|
return m_x_vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<double> &UI_plot::y_vals() const
|
const std::vector<double> &UI_plot::y_vals() const &
|
||||||
{
|
{
|
||||||
return m_y_vals;
|
return m_y_vals;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -37,7 +37,7 @@ class UI_plot : public UI_item
|
|||||||
*
|
*
|
||||||
* @return std::string The x-axis label
|
* @return std::string The x-axis label
|
||||||
*/
|
*/
|
||||||
std::string x_label() const;
|
std::string x_label() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the label for the y-axis
|
* @brief Set the label for the y-axis
|
||||||
@@ -50,7 +50,7 @@ class UI_plot : public UI_item
|
|||||||
*
|
*
|
||||||
* @return std::string The y-axis label
|
* @return std::string The y-axis label
|
||||||
*/
|
*/
|
||||||
std::string y_label() const;
|
std::string y_label() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add a value to the plot
|
* @brief Add a value to the plot
|
||||||
@@ -71,14 +71,14 @@ class UI_plot : public UI_item
|
|||||||
*
|
*
|
||||||
* @return a list of x values and a list of y values
|
* @return a list of x values and a list of y values
|
||||||
*/
|
*/
|
||||||
const std::vector<double> &x_vals() const;
|
const std::vector<double> &x_vals() const &;
|
||||||
/**
|
/**
|
||||||
* @brief Get the y values of the plot
|
* @brief Get the y values of the plot
|
||||||
* This is only for testing purposes
|
* This is only for testing purposes
|
||||||
*
|
*
|
||||||
* @return a list of y values
|
* @return a list of y values
|
||||||
*/
|
*/
|
||||||
const std::vector<double> &y_vals() const;
|
const std::vector<double> &y_vals() const &;
|
||||||
/**
|
/**
|
||||||
* @brief Clear all values from the plot
|
* @brief Clear all values from the plot
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,19 +7,19 @@ UI_status_bar::UI_status_bar(QObject *parent) : UI_item(UI_STATUS_BAR_TYPE, pare
|
|||||||
|
|
||||||
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_STATUS_BAR_TYPE, parent), m_timeout(0)
|
||||||
{
|
{
|
||||||
m_text = message;
|
m_text = std::move(message);
|
||||||
setup_item(true, false, false);
|
setup_item(true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI_status_bar::show_message(std::string message, size_t timeout)
|
void UI_status_bar::show_message(std::string message, size_t timeout)
|
||||||
{
|
{
|
||||||
// This should work because the message gets only send once when it changes
|
// This should work because the message gets only send once when it changes
|
||||||
m_text = message;
|
m_text = std::move(message);
|
||||||
m_timeout = timeout;
|
m_timeout = timeout;
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_status_bar::message() const
|
std::string UI_status_bar::message() const &
|
||||||
{
|
{
|
||||||
return m_text;
|
return m_text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class UI_status_bar : public UI_item
|
|||||||
*
|
*
|
||||||
* @return std::string The current message
|
* @return std::string The current message
|
||||||
*/
|
*/
|
||||||
std::string message() const;
|
std::string message() const &;
|
||||||
/**
|
/**
|
||||||
* @brief Get the timeout for the current message
|
* @brief Get the timeout for the current message
|
||||||
*
|
*
|
||||||
|
|||||||
+3
-3
@@ -90,7 +90,7 @@ void UI_table::set_column_label(size_t index, std::string label)
|
|||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_table::column_label(size_t index) const
|
std::string UI_table::column_label(size_t index) const &
|
||||||
{
|
{
|
||||||
if (m_column_count <= index)
|
if (m_column_count <= index)
|
||||||
{
|
{
|
||||||
@@ -113,12 +113,12 @@ void UI_table::insert_item(size_t row, size_t column, std::string text)
|
|||||||
|
|
||||||
size_t index = row * m_column_count + column;
|
size_t index = row * m_column_count + column;
|
||||||
|
|
||||||
m_table.at(index) = text;
|
m_table.at(index) = std::move(text);
|
||||||
|
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_table::item(size_t row, size_t column) const
|
std::string UI_table::item(size_t row, size_t column) const &
|
||||||
{
|
{
|
||||||
if (m_column_count <= column || m_row_count <= row)
|
if (m_column_count <= column || m_row_count <= row)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -90,7 +90,7 @@ class UI_table : public UI_item
|
|||||||
* @param index The index of the column
|
* @param index The index of the column
|
||||||
* @return std::string The label of the column
|
* @return std::string The label of the column
|
||||||
*/
|
*/
|
||||||
std::string column_label(size_t index) const;
|
std::string column_label(size_t index) const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Insert an item into the table at the specified row and column
|
* @brief Insert an item into the table at the specified row and column
|
||||||
@@ -107,7 +107,7 @@ class UI_table : public UI_item
|
|||||||
* @param column The column of the item
|
* @param column The column of the item
|
||||||
* @return std::string The text of the item
|
* @return std::string The text of the item
|
||||||
*/
|
*/
|
||||||
std::string item(size_t row, size_t column) const;
|
std::string item(size_t row, size_t column) const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief empty_item This function clears the item
|
* @brief empty_item This function clears the item
|
||||||
|
|||||||
+3
-3
@@ -13,18 +13,18 @@ void UI_textbox::set_text(std::string text)
|
|||||||
{
|
{
|
||||||
if (text == m_text)
|
if (text == m_text)
|
||||||
return;
|
return;
|
||||||
m_text = text;
|
m_text = std::move(text);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
emit changed(m_text);
|
emit changed(m_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI_textbox::set_hint(std::string hint)
|
void UI_textbox::set_hint(std::string hint)
|
||||||
{
|
{
|
||||||
m_hint = hint;
|
m_hint = std::move(hint);
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UI_textbox::hint() const
|
std::string UI_textbox::hint() const &
|
||||||
{
|
{
|
||||||
return m_hint;
|
return m_hint;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ class UI_textbox : public UI_item
|
|||||||
*
|
*
|
||||||
* @return std::string The hint text
|
* @return std::string The hint text
|
||||||
*/
|
*/
|
||||||
std::string hint() const;
|
std::string hint() const &;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deserialize the textbox from JSON
|
* @brief Deserialize the textbox from JSON
|
||||||
|
|||||||
Reference in New Issue
Block a user