Qt writes a visual large-screen electronic kanban system 28-module 6 is qualified for inspection

I. Introduction

The pass rate module for inspection includes four sub-modules: steel pass rate, motor pass rate, today’s pass rate, and mold parts pass rate. Among them, the pass rate of steel parts and the pass rate of electrodes are displayed in graphs, and the qualified rate within 15 days is counted. The positioning line is placed at the value of 90, which is equivalent to a 90% pass rate. This control is different from the previous line chart, which is displayed in a smooth curve. Of course, the packaged curve control can be used anywhere. Features: The pass rate of the custom control used for the day's pass rate is displayed on the pass rate dashboard, and the corresponding pass rate text is displayed in the middle of the dashboard; the pass rate of mold parts uses a bar chart to display the pass rate of different mold parts categories, and the value corresponding to the pass rate is displayed On the top of the histogram, in order to make this value fully displayed in the graph, the maximum value should be calculated when the Y-axis range is initially displayed, and then a little larger than the maximum value to leave room to draw the corresponding value.

Submodule table name corresponding table:

submodule title submodule table name
Steel qualification rate t_6_1_wp_qual_rate
Electrode pass rate t_6_2_ele_qual_rate
Pass rate of the day t_6_3_qual_rate_today
Mold Parts Qualification Rate t_6_4_mold_qual_rate

1 Qualification rate of steel parts

Table name: t_6_1_wp_qual_rate

field name Chinese name Types of length illustrate
internal_id serial number INTEGER 11 Primary key auto increment
date_1 Day 1 pass rate INTEGER 3
date_* Day * Pass Rate INTEGER 3
date_15 Day 15 Pass Rate INTEGER 3

Default data:
1, 100, 99, 89, 95, 95, 92, 98, 100, 96, 97, 98, 99, 90, 85, 84

2 Electrode qualification rate

表名:t_6_2_ele_qual_rate

field name Chinese name Types of length illustrate
internal_id serial number INTEGER 11 Primary key auto increment
date_1 Day 1 pass rate INTEGER 3
date_* Day * Pass Rate INTEGER 3
date_15 Day 15 Pass Rate INTEGER 3

Default data:
1, 100, 99, 89, 95, 95, 92, 98, 100, 96, 97, 98, 99, 90, 85, 84

3 day pass rate

表名:t_6_3_qual_rate_today

field name Chinese name Types of length illustrate
internal_id serial number INTEGER 11 Primary key auto increment
what_rate Pass rate INTEGER 3

Default data: 90

4 Qualification rate of mold parts

Table name: t_6_4_mold_qual_rate

field name Chinese name Types of length illustrate
internal_id serial number INTEGER 11 Primary key auto increment
mold_name module name VARCHAR 255
what_rate Pass rate INTEGER 3

Default data:

internal_id mold_name what_rate
1 IK19001 95
2 IK19002 88
3 IK19003 94
4 IK19004 75
5 IK19005 94
6 IK19006 89

2. Features

  1. The layered design is adopted, and the whole is divided into three levels of interfaces. The first level interface is the overall layout, the second level interface is a single function module, and the third level interface is a single control.
  2. Sub-controls include pie chart, doughnut chart, curve chart, column chart, column group chart, horizontal column chart, horizontal column group chart, pass rate control, percentage control, progress control, equipment status panel, table data, map control , video controls, etc.
  3. The secondary interface can be freely dragged and suspended, and supports minimizing and hiding, maximizing and closing, and responding to double-clicks to customize the title bar.
  4. The data source supports analog data (default), database acquisition, serial communication (to be customized), network communication (to be customized), network request, etc. The acquisition interval of each sub-interface, that is, the data refresh frequency, can be freely set.
  5. Written in pure QWidget, test any version from Qt4.6 to Qt6.2, and theoretically support other subsequent Qt versions.
  6. Super cross-platform, pro-test windows, linux, mac, domestic uos, domestic Galaxy Kirin kylin and other systems, the effect is perfect, and also supports embedded linux such as raspberry pie, orange pie, allwinner, imx6, etc.
  7. At the same time, it integrates functions such as custom controls, qchart pie charts, and echart maps.
  8. Built-in multiple sets of color matching styles (purple, blue, dark blue, black), the default purple, adaptive to any resolution.
  9. You can set the system title, target resolution, layout scheme, and start the application immediately.
  10. Various colors such as main background color, panel color, crosshair cursor color, etc. can be set.
  11. Multiple curves with different colors can be set, and multiple sets of exquisite colors can be randomly applied if no color is set.
  12. You can set the background color and text color of the title bar.
  13. You can set the background color, text color, and grid color of the curve chart.
  14. Normal color, warning color, alarm color, disabled color, and percentage progress color can be set.
  15. Various font sizes can be set separately, such as global font, software name, title bar, sub-title bar, bold labels, etc.
  16. The title bar height, header height, and row height can be set.
  17. Curves support cursors, positioning lines, hover to highlight data points, hover to display values.
  18. The histogram supports the top (top, top, middle, bottom can be set) to display data, and all adaptive calculation positions.
  19. Supports smooth curves, built-in multiple smooth curve algorithms, and also supports area graph smoothing.
  20. The area chart fill color can be selected from a variety of rules, such as single-color transparency fill, transparency gradient fill, etc.
  21. The database supports sqlite, mysql, postgresql, oracle, domestic NPC Jincang and other databases.
  22. Right-click on the main interface to switch the layout, color scheme, and close or open a secondary form.
  23. Automatically memorize the size and position of all sub-windows, and apply it immediately the next time you start it.
  24. Dynamically load the layout scheme menu, you can dynamically create new layouts, restore layouts, save layouts, save layouts, etc., users can create any layout.
  25. The secondary form, double-click to separate from the main form and float, can be freely resized. Double-click the title bar again to maximize, double-click again to restore.
  26. The sub-module can also be displayed in full screen as a large screen, so that one large screen can be extended to multiple sub-large screens, and the data details of the sub-module can be enlarged and viewed, which is suitable for multi-screen display.
  27. Each module can customize the collection speed. If it is database collection, it will be automatically queued for processing. Later, you can expand the database collection of each sub-module independently.
  28. Provides a system setting module for overall configuration parameter settings, and the effect is applied immediately.
  29. Provide beautiful and cool large-screen map modules, including static pictures, flickering effects, migration effects, world maps, regional maps, etc., you can specify the latitude and longitude coordinates of points, identify click responses, and do map jumps, etc. Each point is Can have different colors and prompt messages.
  30. In addition to providing a large-screen system, each module has an independent module example interface, each module can be learned and used independently, and the controls used in it have also been separately made a control example interface, which is convenient for learning how to use each control. .
  31. Very detailed development and use manual, including database description, module comparison diagram, control comparison diagram, project structure, code description (accurate to each class), demonstration demo, usage method, etc.

3. Experience address

  1. Experience address: https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g Extraction code: 01jf File name: bin_bigscreen.zip.
  2. Domestic site: https://gitee.com/feiyangqingyun
  3. International site: https://github.com/feiyangqingyun
  4. Personal homepage: https://blog.csdn.net/feiyangqingyun
  5. Know the homepage: https://www.zhihu.com/people/feiyangqingyun/
  6. Online documentation: https://feiyangqingyun.gitee.io/qwidgetdemo/bigscreen/

Fourth, the effect map

insert image description here

Five, the core code

#include "frmmodule6.h"
#include "ui_frmmodule6.h"
#include "quihelper.h"

frmModule6::frmModule6(QWidget *parent) : QWidget(parent), ui(new Ui::frmModule6)
{
    ui->setupUi(this);
    this->initForm();
    this->initPercent();
    this->initPlot1();
    this->initPlot2();
    this->initPlot3();
}

frmModule6::~frmModule6()
{
    delete ui;
}

void frmModule6::initForm()
{
    //设置对应的属性应用特定样式
    ui->labTitle1->setProperty("flag", "title");
    ui->labTitle2->setProperty("flag", "title");
    ui->labTitle3->setProperty("flag", "title");
    ui->labTitle4->setProperty("flag", "title");

    ui->widgetSub1->setProperty("flag", "sub");
    ui->widgetSub2->setProperty("flag", "sub");
    ui->widgetSub3->setProperty("flag", "sub");
    ui->widgetSub4->setProperty("flag", "sub");

    //定时器模拟数据
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(loadPercent()));
    connect(timer, SIGNAL(timeout()), this, SLOT(loadPlot1()));
    connect(timer, SIGNAL(timeout()), this, SLOT(loadPlot2()));
    connect(timer, SIGNAL(timeout()), this, SLOT(loadPlot3()));

    //绑定信号槽处理接收的数据+发送执查询语句
    connect(DbData::DbLocal, SIGNAL(receiveData(QString, QStringList, int)),
            this, SLOT(receiveData(QString, QStringList, int)));
    connect(DbData::DbHttp, SIGNAL(receiveData(QString, QStringList, int)),
            this, SLOT(receiveData(QString, QStringList, int)));

    //绑定样式改变信号重新加载数据
    connect(AppEvent::Instance(), SIGNAL(changeStyle()), this, SLOT(start()));
}

void frmModule6::receiveData(const QString &tag, const QStringList &data, int mesc)
{
    int count = data.count();
    if (tag == "t_6_3_qual_rate_today") {
        if (count == 1) {
            int value = data.at(0).toDouble();
            loadPercent(value);
        }
    } else if (tag == "t_6_1_wp_qual_rate") {
        if (count == 15) {
            vstring lab;
            vdouble key, value1;
            for (int i = 0; i < count; i++) {
                lab << QString("%1").arg(i + 1);
                key << i;
                value1 << data.at(i).toDouble();
            }

            loadPlot1(lab, key, lvdouble() << value1);
        }
    } else if (tag == "t_6_2_ele_qual_rate") {
        if (count == 15) {
            vstring lab;
            vdouble key, value1;
            for (int i = 0; i < count; i++) {
                lab << QString("%1").arg(i + 1);
                key << i;
                value1 << data.at(i).toDouble();
            }

            loadPlot2(lab, key, lvdouble() << value1);
        }
    } else if (tag == "t_6_4_mold_qual_rate") {
        if (count % 2 == 0) {
            rowNames.clear();
            vdouble value1;
            for (int i = 0; i < count; i = i + 2) {
                rowNames << data.at(i);
                value1 << data.at(i + 1).toDouble();
            }

            loadPlot3(lvdouble() << value1);
        }
    }
}

void frmModule6::initPercent()
{
    ui->gaugePercent->setTitle("合格率");
}

void frmModule6::loadPercent()
{
    QString tableName = "t_6_3_qual_rate_today";
    QString columnName = "qual_rate";

    if (AppConfig::WorkMode == "timer") {
        loadPercent(QUIHelper::getRandValue(10, 100));
    } else if (AppConfig::WorkMode == "db") {
        DbData::DbLocal->select(tableName, columnName, true);
    } else if (AppConfig::WorkMode == "http") {
        DbData::DbHttp->select(tableName, columnName, true);
    }
}

void frmModule6::loadPercent(int value)
{
    ui->gaugePercent->setValue(value);
}

void frmModule6::initPlot1()
{
    lineNames1 << "钢件合格率";
    ui->customPlot1->addGraph(1);
    ui->customPlot1->setOffsetX(0);
}

void frmModule6::loadPlot1()
{
    QStringList list;
    for (int i = 1; i <= 15; i++) {
        list << QString("date_%1").arg(i);
    }

    QString tableName = "t_6_1_wp_qual_rate";
    QString columnName = list.join(",");

    if (AppConfig::WorkMode == "timer") {
        vstring lab;
        vdouble key, value1;
        int dataCount = 10;
        for (int i = 0; i < dataCount; i++) {
            lab << QString("%1").arg(i + 1);
            key << i;
            value1 << QUIHelper::getRandValue(30, 100);
        }

        loadPlot1(lab, key, lvdouble() << value1);
    } else if (AppConfig::WorkMode == "db") {
        DbData::DbLocal->select(tableName, columnName, true);
    } else if (AppConfig::WorkMode == "http") {
        DbData::DbHttp->select(tableName, columnName, true);
    }
}

void frmModule6::loadPlot1(const vstring &lab, const vdouble &key, const lvdouble &values)
{
    //清空数据
    ui->customPlot1->clear();
    ui->customPlot1->replot();

    //绘制定位线
    if (AppConfig::StaticLine) {
        ui->customPlot1->drawStaticLineh(-0.5, 90, AppConfig::ColorLine);
    }

    LineData data;
    data.index = 0;
    data.name = lineNames1.at(0);
    data.key = key;
    data.value = values.at(0);
    data.lineColor = AppConfig::ColorLine1;
    data.fillColor = AppConfig::FillColor;
    data.smoothType = AppConfig::PlotStyle - 1;

    //绘制对应的数值
    //data.drawValue = true;

    //不同的曲线类型
    if (AppConfig::PlotStyle == 0) {
        ui->customPlot1->addDataLine(data);
    } else {
        vpoint points;
        int count = key.count();
        for (int i = 0; i < count; ++i) {
            points << QPointF(data.key.at(i), data.value.at(i));
        }
        data.points = points;
        data.dataWidth = 3;
        ui->customPlot1->addSmoothLine(data);
    }

    //设置坐标轴范围值+X坐标对应显示文字
    ui->customPlot1->setLabX(key, lab);
    ui->customPlot1->setRangeX(-0.5, key.count() - 0.5);
    ui->customPlot1->setRangeY(0, 120, AppConfig::StepY, AppConfig::ShowPercent);

    //初始化指示器数据高亮及悬停提示等
    ui->customPlot1->initItem();
    //重新刷新显示
    ui->customPlot1->replot();
}

void frmModule6::initPlot2()
{
    lineNames2 << "电极合格率";
    ui->customPlot2->addGraph(1);
    ui->customPlot2->setOffsetX(0);
}

void frmModule6::loadPlot2()
{
    QStringList list;
    for (int i = 1; i <= 15; i++) {
        list << QString("date_%1").arg(i);
    }

    QString tableName = "t_6_2_ele_qual_rate";
    QString columnName = list.join(",");

    if (AppConfig::WorkMode == "timer") {
        vstring lab;
        vdouble key, value1;
        int dataCount = 10;
        for (int i = 0; i < dataCount; i++) {
            lab << QString("%1").arg(i + 1);
            key << i;
            value1 << QUIHelper::getRandValue(30, 100);
        }

        loadPlot2(lab, key, lvdouble() << value1);
    } else if (AppConfig::WorkMode == "db") {
        DbData::DbLocal->select(tableName, columnName, true);
    } else if (AppConfig::WorkMode == "http") {
        DbData::DbHttp->select(tableName, columnName, true);
    }
}

void frmModule6::loadPlot2(const vstring &lab, const vdouble &key, const lvdouble &values)
{
    //清空数据
    ui->customPlot2->clear();
    ui->customPlot2->replot();

    //绘制定位线
    if (AppConfig::StaticLine) {
        ui->customPlot2->drawStaticLineh(-0.5, 90, AppConfig::ColorLine);
    }

    LineData data;
    data.index = 0;
    data.name = lineNames2.at(0);
    data.key = key;
    data.value = values.at(0);
    data.lineColor = AppConfig::ColorLine2;
    data.fillColor = AppConfig::FillColor;
    data.smoothType = AppConfig::PlotStyle - 1;

    //绘制对应的数值
    //data.drawValue = true;

    //不同的曲线类型
    if (AppConfig::PlotStyle == 0) {
        ui->customPlot2->addDataLine(data);
    } else {
        vpoint points;
        int count = key.count();
        for (int i = 0; i < count; ++i) {
            points << QPointF(data.key.at(i), data.value.at(i));
        }
        data.points = points;
        data.dataWidth = 3;
        ui->customPlot2->addSmoothLine(data);
    }

    //设置坐标轴范围值+X坐标对应显示文字
    ui->customPlot2->setLabX(key, lab);
    ui->customPlot2->setRangeX(-0.5, key.count() - 0.5);
    ui->customPlot2->setRangeY(0, 120, AppConfig::StepY, AppConfig::ShowPercent);

    //初始化指示器数据高亮及悬停提示等
    ui->customPlot2->initItem();
    //重新刷新显示
    ui->customPlot2->replot();
}

void frmModule6::initPlot3()
{
    rowNames << "CNC粗" << "CNC精" << "EDM" << "WEDM" << "铣床" << "磨床";
    columnNames << "系列1";
}

void frmModule6::loadPlot3()
{
    QString tableName = "t_6_4_mold_qual_rate";
    QString columnName = "mold_name,qual_rate";

    if (AppConfig::WorkMode == "timer") {
        vdouble value1;
        for (int i = 0; i < rowNames.count(); ++i) {
            value1 << QUIHelper::getRandValue(10 + (i * 10), 100);
        }
        loadPlot3(lvdouble() << value1);
    } else if (AppConfig::WorkMode == "db") {
        DbData::DbLocal->select(tableName, columnName, true);
    } else if (AppConfig::WorkMode == "http") {
        DbData::DbHttp->select(tableName, columnName, true);
    }
}

void frmModule6::loadPlot3(const lvdouble &values)
{
    ui->customPlot3->clear();
    double maxY = CustomPlotHelper::getMaxValue(values) * 1.2;
    ui->customPlot3->setRangeX(0.5, rowNames.count() + 0.5);
    ui->customPlot3->setRangeY(0, maxY, AppConfig::StepY, AppConfig::ShowPercent);

    //设置柱状数据结构体
    BarData data;
    data.rowNames = rowNames;
    data.columnNames = columnNames;
    data.values = values;
    data.borderColor = AppConfig::ColorChartText;
    data.valuePosition = 1;
    data.valuePrecision = 0;
    data.valueColor = AppConfig::ColorChartText;
    data.checkData = true;
    ui->customPlot3->setDataBarv(data);
    ui->customPlot3->replot();
}

void frmModule6::start(int interval)
{
    this->loadPercent();
    this->loadPlot1();
    this->loadPlot2();
    this->loadPlot3();

    //如果间隔太短表示不需要刷新,执行一次即可
    if (interval > 2000) {
        timer->start(interval);
    }
}

void frmModule6::stop()
{
    if (timer->isActive()) {
        timer->stop();
    }
}

Guess you like

Origin blog.csdn.net/feiyangqingyun/article/details/123727749