Qt writing visual large-screen electronic Kanban system 29-module 7 quality management

I. Introduction

The quality management module is based on the addition of statistics to the inspection pass module. It includes three sub-modules in total: quality ratio, team qualification rate, and daily pass rate statistics. The quality ratio sub-module is displayed by a pie chart control. The corresponding percentage, the color of different percentages is different. This pie chart control is drawn with a custom control painter. The pie chart built in qchart is used at the beginning, which is easy to use, but does not support Qt4. Simply draw a simple pie chart control directly with the painter. The core is the drawpie function; the class pass rate is displayed by a bar chart; the daily pass rate statistics are displayed by a smooth curve graph.

Submodule table name corresponding table:

submodule title submodule table name
Quality ratio t_7_1_qual_percent
class pass rate t_7_2_group_qual_rate
Daily pass rate statistics t_7_3_qual_rate_daily

1 Quality ratio

Table name: t_7_1_qual_percent

field name Chinese name Types of length illustrate
internal_id serial number INTEGER 11 Primary key auto increment
green green percentage INTEGER 3
blue blue percentage INTEGER 3
yellow yellow percentage INTEGER 3
red red percentage INTEGER 3

Default data:
1 45 30 15 10

Class 2 pass rate

Table name: t_7_2_group_qual_rate

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

Default data:

internal_id group_name what_rate
1 CNC 90
2 EDM 85
3 WEDM 92
4 grinder 94
5 milling machine 93
6 Outsourcing 92

3 Daily pass rate statistics

Table name: t_7_3_qual_rate_daily

field name Chinese name Types of length illustrate
internal_id serial number INTEGER 11 Primary key auto increment
group_name Group Name VARCHAR 255
day_1 Day 1 INTEGER 3
day_* day * INTEGER 3
day_31 Day 31 INTEGER 3

Default data:
1, 'all', 90, 90, 97, 91, 92, 88, 89, 90, 78, 87, 86, 90, 80, 97, 87, 87, 88, 89, 90, 90, 89 , 86, 90, 80, 97, 87, 87, 89, 89, 89, 90

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 "frmmodule7.h"
#include "ui_frmmodule7.h"
#include "quihelper.h"

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

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

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

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

#ifdef qchart
    pie = new CustomChart;
#else
    pie = new CustomPie;
#endif

    pie->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
    ui->widgetSub1->layout()->addWidget(pie);

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

    //绑定信号槽处理接收的数据+发送执查询语句
    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 frmModule7::receiveData(const QString &tag, const QStringList &data, int mesc)
{
    int count = data.count();
    if (tag == "t_7_1_qual_percent") {
        if (count == 4) {
            int value1 = data.at(0).toDouble();
            int value2 = data.at(1).toDouble();
            int value3 = data.at(2).toDouble();
            int value4 = data.at(3).toDouble();
            loadPie(value1, value2, value3, value4);
        }
    } else if (tag == "t_7_2_group_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();
            }

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

            loadPlot2(lab, key, lvdouble() << value1);
        }
    }
}

void frmModule7::initPie()
{
    lcolor colors;
    colors << QColor(0, 176, 80) << QColor(65, 176, 255) << QColor(255, 192, 0) << QColor(255, 0, 0);

    pie->setColors(colors);
    pie->setDefaultColor(false);
    pie->initPie();
}

void frmModule7::loadPie()
{
    QString tableName = "t_7_1_qual_percent";
    QString columnName = "green,blue,yellow,red";

    if (AppConfig::WorkMode == "timer") {
        int value1 = QUIHelper::getRandValue(10, 30);
        int value2 = QUIHelper::getRandValue(10, 30);
        int value3 = QUIHelper::getRandValue(10, 30);
        int value4 = QUIHelper::getRandValue(10, 30);
        loadPie(value1, value2, value3, value4);
    } else if (AppConfig::WorkMode == "db") {
        DbData::DbLocal->select(tableName, columnName, true);
    } else if (AppConfig::WorkMode == "http") {
        DbData::DbHttp->select(tableName, columnName, true);
    }
}

void frmModule7::loadPie(int value1, int value2, int value3, int value4)
{
    pie->clearPie();
    pie->appendPie("", value1);
    pie->appendPie("", value2);
    pie->appendPie("", value3);
    pie->appendPie("", value4);
    pie->loadPercent();
}

void frmModule7::initPlot1()
{
    rowNames << "CNC" << "EDM" << "线割" << "磨床" << "铣床" << "外协";
    columnNames << "系列1";
}

void frmModule7::loadPlot1()
{
    QString tableName = "t_7_2_group_qual_rate";
    QString columnName = "group_name,qual_rate";

    if (AppConfig::WorkMode == "timer") {
        vdouble value1;
        for (int i = 0; i < rowNames.count(); ++i) {
            value1 << QUIHelper::getRandValue(10 + (i * 10), 100);
        }
        loadPlot1(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 frmModule7::loadPlot1(const lvdouble &values)
{
    ui->customPlot1->clear();
    double maxY = CustomPlotHelper::getMaxValue(values) * 1.2;
    ui->customPlot1->setRangeX(0.5, rowNames.count() + 0.5);
    ui->customPlot1->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->customPlot1->setDataBarv(data);
    ui->customPlot1->replot();
}

void frmModule7::initPlot2()
{
    lineNames << "数据1" << "数据2";
    ui->customPlot2->addGraph(2);
}

void frmModule7::loadPlot2()
{
    QStringList list;
    list << "group_name";
    for (int i = 1; i <= 31; i++) {
        list << QString("day_%1").arg(i);
    }

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

    if (AppConfig::WorkMode == "timer") {
        vstring lab;
        vdouble key, value1;
        int dataCount = 31;
        if (QUIHelper::deskWidth() <= 1440) {
            dataCount = 20;
        }

        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 frmModule7::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 = lineNames.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->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 frmModule7::start(int interval)
{
    this->loadPie();
    this->loadPlot1();
    this->loadPlot2();

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

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

Guess you like

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