Qt实现天气预报与PM2.5监测系统(9)空气质量

Qt实现天气预报与PM2.5监测系统(9)空气质量

程序运行界面

Qt实现天气预报与PM2.5监测系统(9)空气质量_第1张图片

程序代码
头文件

#ifndef SHOWAQI_H
#define SHOWAQI_H
#include 
#include "showlabel.h"
class ShowAqi : public QWidget
{
    Q_OBJECT
public:
    ShowAqi(QWidget *parent=0);
    void updateVal(QString *daily);
    void setValue(QString value);
    int get_x_point(int val);
public slots:

private:
    int pm25_net;
    int pm25_local;
    int pm10;
    int aqi;
    ShowLabel *aqiInfo;
    ShowLabel *aqiItem;
    ShowLabel *aqiValue;
    ShowLabel *aqiValNet;
    ShowLabel *aqiValLocal;
    ShowLabel *net_falg;
    ShowLabel *local_falg;
    QLabel *aqiIndexNet;
    QLabel *aqiIndexLocal;
    QLabel *aqiPic;
};



#endif // SHOWAQI_H

实现文件


#include "showaqi.h"

ShowAqi::ShowAqi( QWidget *parent)
    : QWidget( parent)
{


    this->setMinimumSize(1024,600);
    this->setMaximumSize(1024,600);


    aqiInfo = new ShowLabel(this);
    aqiInfo->addFontSize(8);
    aqiInfo->setAlignment(Qt::AlignHCenter);
    aqiInfo->setGeometry(QRect(200,60,800,60));
    aqiInfo->setText(tr("细颗粒物指数 (PM 2.5)"));


    pm25_net = 75;

    int x;
    x = get_x_point(pm25_net);
    //net value
    aqiIndexNet = new QLabel(this);
    aqiIndexNet->setAlignment(Qt::AlignHCenter);
    aqiIndexNet->setGeometry(QRect(x, 150, 80, 80));
    aqiIndexNet->setPixmap(QPixmap(":/images/index_net.png"));

    aqiValNet = new ShowLabel(this);
    aqiValNet->addFontSize(0);
    aqiValNet->setAlignment(Qt::AlignHCenter);
    aqiValNet->setGeometry(QRect(x, 170, 80, 80));
    aqiValNet->setText(QString::number(pm25_net));

    net_falg = new ShowLabel(this);
    net_falg->setAlignment(Qt::AlignHCenter);
    net_falg->setGeometry(QRect(x, 120, 80, 80));
    net_falg->setText(tr("网络"));

    pm25_local = 256;
    x = get_x_point(pm25_local);
    //local value
    aqiIndexLocal = new QLabel(this);
    aqiIndexLocal->setAlignment(Qt::AlignHCenter);
    aqiIndexLocal->setGeometry(QRect(x, 290, 80, 80));
    aqiIndexLocal->setPixmap(QPixmap(":/images/index_local.png"));

    aqiValLocal = new ShowLabel(this);
    aqiValLocal->addFontSize(0);
    aqiValLocal->setAlignment(Qt::AlignHCenter);
    aqiValLocal->setGeometry(QRect(x, 320, 80, 80));
    aqiValLocal->setText(QString::number(pm25_local));

    local_falg = new ShowLabel(this);
    local_falg->setAlignment(Qt::AlignHCenter);
    local_falg->setGeometry(QRect(x, 365, 80, 80));
    local_falg->setText(tr("本地"));


    aqiPic = new QLabel(this);
    aqiPic->setAlignment(Qt::AlignHCenter);
    aqiPic->setGeometry(QRect(230, 230, 800, 100));
    aqiPic->setPixmap(QPixmap(":/images/aqi.png"));
   // aqiPic->setScaledContents(true);


    aqiValue = new ShowLabel(this);
    aqiValue->addFontSize(1);
    aqiValue->setAlignment(Qt::AlignHCenter);
    aqiValue->setGeometry(QRect(210, 460, 800, 60));
    aqiValue->setText(tr("武汉     AQI(空气质量指数)  94     PM2.5  45     PM10  56"));

}


int ShowAqi::get_x_point(int val)
{
    int base = 230+40;

    if(val>0){
        if(val>500) return base+600;
        if(val<0) return base;

        if(val>=0 && val<=200)
            return val*2 + base;

        if(val>200 && val<=300)
            return (val-200) + base + 400;

        if(val>300 && val<=500)
            return (val-300)/2 + base + 500;
    }else{
        return base;
    }

}

void ShowAqi::updateVal(QString *aqiArr)
{
    pm25_net = aqiArr[0].toInt();
    pm25_local = aqiArr[3].toInt();

    int x;
    x = get_x_point(pm25_net);
    //net value
    aqiIndexNet->setGeometry(QRect(x, 150, 80, 80));

    aqiValNet->setGeometry(QRect(x, 170, 80, 80));
    aqiValNet->setText(QString::number(pm25_net));

    net_falg->setGeometry(QRect(x, 120, 80, 80));


    x = get_x_point(pm25_local);
    //local value
    aqiIndexLocal->setGeometry(QRect(x, 290, 80, 80));

    aqiValLocal->setGeometry(QRect(x, 320, 80, 80));
    aqiValLocal->setText(QString::number(pm25_local));

    local_falg->setGeometry(QRect(x, 365, 80, 80));

    aqiValue->setText(aqiArr[4] + tr("    AQI(空气质量指数)  ") + aqiArr[2] + tr("    PM2.5  ") + aqiArr[0] + tr("     PM10  ") + aqiArr[1]);

}

你可能感兴趣的:(嵌入式项目,Linux应用)