QCustomPlot 共用X轴多Y轴绘制多条曲线

文章描述了一个使用Qt库进行数据库操作(SQLite)的AttitudeWidget类,包括数据导入、清除、刷新、搜索和姿态数据的绘制。展示了如何使用QComboBox、QTableView、线程以及QCustomPlot进行界面交互和数据处理。

这个参照了一个大佬的代码,时间太久,不记得出处了。

#include "AttitudeWidget.h"
#include "ui_AttitudeWidget.h"

#include "AttitudeWorker.h"

#include <QFileDialog>

#include <QThreadPool>

#include "QCustomPlot/XxwCustomPlot.h"

AttitudeWidget::AttitudeWidget(QSettings* poSet, QWidget* parent) :
    QWidget(parent),
    ui(new Ui::AttitudeWidget), poSet(poSet)
{
    ui->setupUi(this);

    db = QSqlDatabase::addDatabase("QSQLITE", "Main");
    db.setDatabaseName("SIG.db"); //设置数据库名称

    if(!db.isOpen())
    {
        if(!db.open())
        {
            qDebugV0() << "open error:" << db.lastError().text();
            this->recvMsg(db.lastError().text());
            return;
        }
        else
        {
            qDebugV0() << "database connect OK!";
        }
    }
    QSqlQuery query(db);
    query.exec("CREATE TABLE IF NOT EXISTS Attitude(DevId TEXT, "
               "TaskName TEXT, CreateTime TEXT, Timestamp TEXT, "
               "pitch REAL, roll REAL, yaw REAL)");

    this->refresh();

    ui->splitterH->setStretchFactor(0, 2);
    ui->splitterH->setStretchFactor(1, 1);

    ui->splitterV->setStretchFactor(0, 4);
    ui->splitterV->setStretchFactor(1, 1);

    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
}

AttitudeWidget::~AttitudeWidget()
{
    delete ui;

    db.close();
}

void AttitudeWidget::on_pushButtonImport_clicked()
{
    QString oStrPath = poSet->value("PATH_OPEN").toString();

    if(oStrPath.isEmpty())
    {
        oStrPath = QCoreApplication::applicationDirPath();
    }

    QStringList aoStrFileName = QFileDialog::getOpenFileNames(this, tr("打开姿态文件"),
                                oStrPath,
                                tr("Raw(*_atti*.dat)"));

    foreach(QString oStrFileName, aoStrFileName)
    {

        AttitudeWorker* poWorker = new AttitudeWorker(oStrFileName);
        poWorker->setParent(nullptr);

        connect(poWorker, &AttitudeWorker::sigMsg, this, &AttitudeWidget::recvMsg);

        QThreadPool::globalInstance()->start(poWorker);
    }

    if(!aoStrFileName.isEmpty())
    {
        QFileInfo oFileInfo( aoStrFileName.first() );

        if(! oFileInfo.absolutePath().isEmpty())
        {
            poSet->setValue("PATH_OPEN",  oFileInfo.absolutePath());
        }
    }
}

void AttitudeWidget::on_pushButtonClear_clicked()
{
    QMessageBox::StandardButton standarButton = QMessageBox::question(this,
        "警告",
        "谨慎操作!",
        QMessageBox::Ok | QMessageBox::Cancel,
        QMessageBox::Cancel);
    switch (standarButton)
    {
        case QMessageBox::Ok:
            if(poModel != nullptr)
            {
                poModel->setQuery("delete from Attitude");

                poModel->submit();
            }
            break;
        case QMessageBox::Cancel:

            break;
        default:
            break;
    }
}

void AttitudeWidget::on_pushButtonRefresh_clicked()
{
    this->refresh();
}

void AttitudeWidget::recvMsg(QString oStrMsg)
{
    ui->textBrowser->append(oStrMsg);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值