添加状态生成

This commit is contained in:
hm
2021-03-05 15:32:31 +08:00
parent 23b6706dcf
commit 011f759aa9
4 changed files with 48 additions and 11 deletions
+6 -3
View File
@@ -1,6 +1,6 @@
#include "StateWidget.h" #include "StateWidget.h"
StateWidget::StateWidget(int flag,QWidget *parent) : QWidget(parent) StateWidget::StateWidget(int flag,int index,QWidget *parent) : QWidget(parent)
{ {
int w = 150; int w = 150;
int h = 20; int h = 20;
@@ -21,7 +21,7 @@ StateWidget::StateWidget(int flag,QWidget *parent) : QWidget(parent)
label = new QLabel("0"); label = new QLabel("0");
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
label->setFixedSize(w,h); label->setFixedSize(w,h);
setColor(label,state::inital); setColor(label,state::gray);
gridlayout->addWidget(label,0,1); gridlayout->addWidget(label,0,1);
} }
else else
@@ -35,8 +35,11 @@ StateWidget::StateWidget(int flag,QWidget *parent) : QWidget(parent)
} }
} }
StateWidget::StateWidget(int flag, QString t,QVariant v,state s, QWidget *parent) : QWidget(parent) StateWidget::StateWidget(int flag, QString t,QVariant v,state s,int index, QWidget *parent) : QWidget(parent)
{ {
id = index;
int w = 150; int w = 150;
int h = 20; int h = 20;
+24 -6
View File
@@ -24,19 +24,33 @@ class StateWidget :public QWidget
public: public:
enum state{ enum state{
success = 0, green = 0,
failure = 1, rad = 1,
warning = 2, orange = 2,
inital = 3, gray = 3,
}; };
explicit StateWidget(int flag, QWidget *parent = nullptr); explicit StateWidget(int flag, int index = 0,QWidget *parent = nullptr);
explicit StateWidget(int flag, QString t, QVariant v = 0, state s = state::inital, QWidget *parent = nullptr); explicit StateWidget(int flag, QString t, QVariant v = 0, state s = state::gray, int index = 0, QWidget *parent = nullptr);
~StateWidget(); ~StateWidget();
int id;
void setMax(double v)
{
max = v;
}
void setMin(double v)
{
min = v;
}
signals: signals:
@@ -54,6 +68,10 @@ private slots:
private: private:
double max = 99999999999999999;
double min = -99999999999999999;
QGridLayout *gridlayout; QGridLayout *gridlayout;
QLabel *title = nullptr; QLabel *title = nullptr;
QLabel *label = nullptr; QLabel *label = nullptr;
+12
View File
@@ -38,6 +38,18 @@ void StatusUI::setValue(QLabel *w,QString s)
w->setText(s); w->setText(s);
} }
void StatusUI::install(int flag, QString t,QVariant v,StateWidget::state s,int index)
{
StateWidget *w = new StateWidget(flag,t,v,s,index);
StateList.insert(index,w);
}
void StatusUI::setMode(uint32_t pos,QVariant value1,QVariant value2) void StatusUI::setMode(uint32_t pos,QVariant value1,QVariant value2)
{ {
switch (pos) { switch (pos) {
+6 -2
View File
@@ -28,8 +28,7 @@ public:
~StatusUI(); ~StatusUI();
void install(int flag, QString t,QVariant v,StateWidget::state s,int index);
QMap<int,QMap<int,QLabel *>> StateList;
public slots: public slots:
@@ -53,6 +52,11 @@ private slots:
private: private:
Ui::StatusUI *ui; Ui::StatusUI *ui;
QMap<int,StateWidget *> StateList;
}; };
#endif // STATUSUI_H #endif // STATUSUI_H