mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
tab widget
started working on implementation
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "ui_slider.hpp"
|
#include "ui_slider.hpp"
|
||||||
#include "ui_spinbox.hpp"
|
#include "ui_spinbox.hpp"
|
||||||
#include "ui_table.hpp"
|
#include "ui_table.hpp"
|
||||||
|
#include "ui_tab_widget.hpp"
|
||||||
#include "ui_textbox.hpp"
|
#include "ui_textbox.hpp"
|
||||||
#include "ui_thermo.hpp"
|
#include "ui_thermo.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#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(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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI_tab_widget::set_selected(size_t selected)
|
||||||
|
{
|
||||||
|
m_selected_tab = selected;
|
||||||
|
emit ui_changed();
|
||||||
|
emit this->selected(m_selected_tab);
|
||||||
|
}
|
||||||
|
size_t UI_tab_widget::selected() const
|
||||||
|
{
|
||||||
|
return m_selected_tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI_tab_widget::set_visible(size_t index, bool visible)
|
||||||
|
{
|
||||||
|
if (index >= m_tab_visible.size()) {
|
||||||
|
m_tab_visible.resize(index + 1);
|
||||||
|
}
|
||||||
|
m_tab_visible.at(index) = visible;
|
||||||
|
emit ui_changed();
|
||||||
|
}
|
||||||
|
bool UI_tab_widget::visible(size_t index) const
|
||||||
|
{
|
||||||
|
return m_tab_visible.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI_tab_widget::set_tab_name(size_t index, std::string name)
|
||||||
|
{
|
||||||
|
if (index >= m_tab_names.size()) {
|
||||||
|
m_tab_names.resize(index + 1);
|
||||||
|
}
|
||||||
|
m_tab_names.at(index) = name;
|
||||||
|
emit ui_changed();
|
||||||
|
}
|
||||||
|
std::string UI_tab_widget::tab_name(size_t index) const
|
||||||
|
{
|
||||||
|
return m_tab_names.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UI_tab_widget::from_json(const json &j)
|
||||||
|
{
|
||||||
|
UI_item::from_json(j);
|
||||||
|
if (j.contains("tab_names"))
|
||||||
|
{
|
||||||
|
this->m_tab_names.clear();
|
||||||
|
for (auto option : j["tab_names"])
|
||||||
|
{
|
||||||
|
this->m_tab_names.push_back(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j.contains("tab_visible"))
|
||||||
|
{
|
||||||
|
this->m_tab_visible.clear();
|
||||||
|
for (auto option : j["tab_visible"])
|
||||||
|
{
|
||||||
|
this->m_tab_visible.push_back(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_selected_tab = j.at("selected");
|
||||||
|
}
|
||||||
|
json UI_tab_widget::to_json(size_t id) const
|
||||||
|
{
|
||||||
|
json j = UI_item::to_json(id);
|
||||||
|
j["tab_names"] = m_tab_names;
|
||||||
|
j["tab_visible"] = m_tab_visible;
|
||||||
|
j["selected"] = m_selected_tab;
|
||||||
|
return j;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef UI_TAB_WIDGET_HPP
|
||||||
|
#define UI_TAB_WIDGET_HPP
|
||||||
|
|
||||||
|
#include "ui_item.hpp"
|
||||||
|
|
||||||
|
#define UI_TAB_WIDGET_TYPE std::string("ui_tab_widget")
|
||||||
|
|
||||||
|
class UI_tab_widget : public UI_item
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit UI_tab_widget(QObject *parent = nullptr);
|
||||||
|
UI_tab_widget(std::vector<std::string> tab_names, size_t selected = 0,
|
||||||
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
|
void set_selected(size_t selected) override;
|
||||||
|
size_t selected() const;
|
||||||
|
|
||||||
|
void set_visible(size_t index, bool visible);
|
||||||
|
bool visible(size_t index) const;
|
||||||
|
|
||||||
|
void set_tab_name(size_t index, std::string name);
|
||||||
|
std::string tab_name(size_t index) const;
|
||||||
|
|
||||||
|
void from_json(const json &j) override;
|
||||||
|
json to_json(size_t id) const override;
|
||||||
|
signals:
|
||||||
|
void selected(size_t index);
|
||||||
|
private:
|
||||||
|
size_t m_selected_tab;
|
||||||
|
std::vector<std::string> m_tab_names;
|
||||||
|
std::vector<bool> m_tab_visible;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UI_TAB_WIDGET_HPP
|
||||||
@@ -606,6 +606,18 @@ void Simulator_base::process_ui_hex_spinbox(json &ui_item, QWidget *widget)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Simulator_base::process_ui_tab_widget(json &ui_item, QWidget *widget)
|
||||||
|
{
|
||||||
|
auto tab_widget = qobject_cast<QTabWidget *>(widget);
|
||||||
|
if (tab_widget == nullptr)
|
||||||
|
{
|
||||||
|
SPDLOG_WARN("widget is not of type QTabWidget");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Simulator_base::process_ui_plot(json &ui_item, QWidget *widget)
|
void Simulator_base::process_ui_plot(json &ui_item, QWidget *widget)
|
||||||
{
|
{
|
||||||
auto plot = qobject_cast<Plot_wrapper *>(widget);
|
auto plot = qobject_cast<Plot_wrapper *>(widget);
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class Simulator_base : public QMainWindow
|
|||||||
virtual void process_ui_spinbox(json &ui_item, QWidget *widget);
|
virtual void process_ui_spinbox(json &ui_item, QWidget *widget);
|
||||||
virtual void process_ui_double_spinbox(json &ui_item, QWidget *widget);
|
virtual void process_ui_double_spinbox(json &ui_item, QWidget *widget);
|
||||||
virtual void process_ui_hex_spinbox(json &ui_item, QWidget *widget);
|
virtual void process_ui_hex_spinbox(json &ui_item, QWidget *widget);
|
||||||
|
virtual void process_ui_tab_widget(json &ui_item, QWidget *widget);
|
||||||
virtual void process_ui_plot(json &ui_item, QWidget *widget);
|
virtual void process_ui_plot(json &ui_item, QWidget *widget);
|
||||||
virtual void process_ui_table(json &ui_item, QWidget *widget);
|
virtual void process_ui_table(json &ui_item, QWidget *widget);
|
||||||
virtual void process_ui_can(json &ui_item, QWidget *widget);
|
virtual void process_ui_can(json &ui_item, QWidget *widget);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ Test_Sim::Test_Sim(Web_socket_wrapper *web_socket, QWidget *parent)
|
|||||||
PUSH_UI_ITEM(spinBox);
|
PUSH_UI_ITEM(spinBox);
|
||||||
PUSH_UI_ITEM(doubleSpinBox);
|
PUSH_UI_ITEM(doubleSpinBox);
|
||||||
PUSH_UI_ITEM(hexSpinBox);
|
PUSH_UI_ITEM(hexSpinBox);
|
||||||
|
PUSH_UI_ITEM(tabWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test_Sim::~Test_Sim()
|
Test_Sim::~Test_Sim()
|
||||||
|
|||||||
@@ -123,6 +123,28 @@
|
|||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="HexSpinBox" name="hexSpinBox"/>
|
<widget class="HexSpinBox" name="hexSpinBox"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Tab 1</string>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_2">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Tab 2</string>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Tab 3</string>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
@@ -131,7 +153,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>23</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
Reference in New Issue
Block a user