mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
b server ui table
fix crashing by resizing the table
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
#include "UI_led.hpp"
|
#include "UI_led.hpp"
|
||||||
#include "UI_plot.hpp"
|
#include "UI_plot.hpp"
|
||||||
#include "UI_slider.hpp"
|
#include "UI_slider.hpp"
|
||||||
#include "ui_table.hpp"
|
#include "UI_table.hpp"
|
||||||
#include "UI_textbox.hpp"
|
#include "UI_textbox.hpp"
|
||||||
#include "UI_thermo.hpp"
|
#include "UI_thermo.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
#include "ui_table.hpp"
|
#include "UI_table.hpp"
|
||||||
|
|
||||||
UI_table::UI_table(QObject* parent)
|
UI_table::UI_table(QObject *parent) : UI_item(UI_TABLE_TYPE, parent), m_row_count(0), m_column_count(0)
|
||||||
: UI_item(UI_TABLE_TYPE, parent), m_row_count(0), m_column_count(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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_table::UI_table(size_t row_count, size_t column_count, std::vector<std::string> row_labels,
|
||||||
: 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)
|
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_valid(), m_table()
|
||||||
{
|
{
|
||||||
|
m_table.resize(m_column_count * m_row_count);
|
||||||
|
m_valid.resize(m_column_count * m_row_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI_table::set_row_count(size_t count)
|
void UI_table::set_row_count(size_t count)
|
||||||
{
|
{
|
||||||
m_row_count = count;
|
m_row_count = count;
|
||||||
|
if (m_row_count != 0 || m_column_count != 0)
|
||||||
|
{
|
||||||
|
m_table.resize(m_column_count * m_row_count);
|
||||||
|
m_valid.resize(m_column_count * m_row_count);
|
||||||
|
}
|
||||||
|
|
||||||
emit value_changed();
|
emit value_changed();
|
||||||
}
|
}
|
||||||
@@ -25,6 +33,11 @@ size_t UI_table::row_count() const
|
|||||||
void UI_table::set_column_count(size_t count)
|
void UI_table::set_column_count(size_t count)
|
||||||
{
|
{
|
||||||
m_column_count = count;
|
m_column_count = count;
|
||||||
|
if (m_row_count != 0 || m_column_count != 0)
|
||||||
|
{
|
||||||
|
m_table.resize(m_column_count * m_row_count);
|
||||||
|
m_valid.resize(m_column_count * m_row_count);
|
||||||
|
}
|
||||||
|
|
||||||
emit value_changed();
|
emit value_changed();
|
||||||
}
|
}
|
||||||
@@ -34,6 +47,11 @@ size_t UI_table::column_count() const
|
|||||||
return m_column_count;
|
return m_column_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t UI_table::capacity() const
|
||||||
|
{
|
||||||
|
return m_row_count * m_column_count;
|
||||||
|
}
|
||||||
|
|
||||||
void UI_table::set_row_label(size_t index, std::string label)
|
void UI_table::set_row_label(size_t index, std::string label)
|
||||||
{
|
{
|
||||||
if (m_row_count <= index)
|
if (m_row_count <= index)
|
||||||
@@ -84,10 +102,18 @@ void UI_table::insert_item(size_t row, size_t column, std::string text)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (capacity() > m_table.capacity())
|
||||||
|
{
|
||||||
|
m_table.resize(capacity());
|
||||||
|
}
|
||||||
|
if (capacity() > m_valid.capacity())
|
||||||
|
{
|
||||||
|
m_valid.resize(capacity());
|
||||||
|
}
|
||||||
size_t index = row * m_column_count + column;
|
size_t index = row * m_column_count + column;
|
||||||
|
|
||||||
m_table[index] = text;
|
m_table.at(index) = text;
|
||||||
m_valid[index] = true;
|
m_valid.at(index) = true;
|
||||||
|
|
||||||
emit value_changed();
|
emit value_changed();
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,19 @@
|
|||||||
|
|
||||||
#define UI_TABLE_TYPE std::string("UI_table")
|
#define UI_TABLE_TYPE std::string("UI_table")
|
||||||
|
|
||||||
class UI_table : public UI_item {
|
class UI_table : public UI_item
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit UI_table(QObject* parent = nullptr);
|
explicit UI_table(QObject *parent = nullptr);
|
||||||
explicit UI_table(size_t row_count, size_t column_count, std::vector<std::string> row_labels, std::vector<std::string> column_labels, QObject* parent = nullptr);
|
explicit UI_table(size_t row_count, size_t column_count, std::vector<std::string> row_labels,
|
||||||
|
std::vector<std::string> column_labels, QObject *parent = nullptr);
|
||||||
|
|
||||||
void set_row_count(size_t count);
|
void set_row_count(size_t count);
|
||||||
size_t row_count() const;
|
size_t row_count() const;
|
||||||
void set_column_count(size_t count);
|
void set_column_count(size_t count);
|
||||||
size_t column_count() const;
|
size_t column_count() const;
|
||||||
|
size_t capacity() const;
|
||||||
void set_row_label(size_t index, std::string label);
|
void set_row_label(size_t index, std::string label);
|
||||||
std::string row_label(size_t index) const;
|
std::string row_label(size_t index) const;
|
||||||
void set_column_label(size_t index, std::string label);
|
void set_column_label(size_t index, std::string label);
|
||||||
Reference in New Issue
Block a user