Qt
、 Qml
、 Data
、 play back
、 数据
欢迎来到我们的 QML & C++ 项目!这个项目结合了 QML(Qt Meta-Object Language)和 C++ 的强大功能,旨在开发出色的用户界面和高性能的后端逻辑。
在项目中,我们利用 QML 的声明式语法和可视化设计能力创建出现代化的用户界面。通过直观的编码和可重用的组件,我们能够迅速开发出丰富多样的界面效果和动画效果。同时,我们利用 QML 强大的集成能力,轻松将 C++ 的底层逻辑和数据模型集成到前端界面中。
在后端方面,我们使用 C++ 编写高性能的算法、数据处理和计算逻辑。C++ 是一种强大的编程语言,能够提供卓越的性能和可扩展性。我们的团队致力于优化代码,减少资源消耗,以确保我们的项目在各种平台和设备上都能够高效运行。
无论您是对 QML 和 C++ 开发感兴趣,还是需要我们为您构建复杂的用户界面和后端逻辑,我们都随时准备为您提供支持。请随时联系我们,让我们一同打造现代化、高性能的 QML & C++ 项目!
重要说明☝
☀该专栏在第三代软开发更新完将涨价
额,今天看代码才发现,这部分代码还是Demo阶段,只能看部分了
#include "XXX_dataplayback.h"
#include "ui_XXX_dataplayback.h"
XXX_dataPlayBack::XXX_dataPlayBack(QWidget *parent,QString strDBPath) :
QWidget(parent),
ui(new Ui::XXX_dataPlayBack),
m_strDBPath(strDBPath)
{
ui->setupUi(this);
initUI();
getListDBName();
}
XXX_dataPlayBack::~XXX_dataPlayBack()
{
deleteDBThread();
delete ui;
}
void XXX_dataPlayBack::slotTimerMove()
{
//qDebug() << "slotTimerMove";
QTime timer;
timer.start();
int iIndex = ui->hSlider_move->value();
ui->hSlider_move->setValue(iIndex+8*m_iFrequency);
int iSKye = XXX_BaseDB::instance()->g_vectorKey.at(0);
int iLeft = m_pDraw1->gCustomplot->xAxis->range().lower+8*m_iFrequency;
int iDff = iLeft - iSKye;
if(iDff > 0)
{
XXX_BaseDB::instance()->m_mutexThread.lock();
if(iDff >= XXX_BaseDB::instance()->g_vectorKey.count())
{
XXX_BaseDB::instance()->g_vectorKey.clear();
XXX_BaseDB::instance()->g_vectorTime.clear();
XXX_BaseDB::instance()->g_mapTime.clear();
XXX_BaseDB::instance()->g_vectorData1.clear();
XXX_BaseDB::instance()->g_vectorData2.clear();
}
else
{
XXX_BaseDB::instance()->g_vectorKey.remove(0,iDff);
XXX_BaseDB::instance()->g_vectorTime.remove(0,iDff);
XXX_BaseDB::instance()->g_vectorData1.remove(0,iDff);
XXX_BaseDB::instance()->g_vectorData2.remove(0,iDff);
}
XXX_BaseDB::instance()->m_mutexThread.unlock();
}
ui->label_RunTime->setText(XXX_BaseDB::instance()->g_mapTime.value(m_pDraw1->gCustomplot->xAxis->range().upper));
qDebug() << "XXX_BaseDB::instance()->g_vectorKey" << XXX_BaseDB::instance()->g_vectorKey.count();
int iMaxY = quiteMaxData();
m_pDraw1->setYHeiget(iMaxY);
m_pDraw2->setYHeiget(iMaxY);
m_pDraw1->setDataPad(XXX_BaseDB::instance()->g_vectorKey,XXX_BaseDB::instance()->g_vectorData1);
m_pDraw2->setDataPad(XXX_BaseDB::instance()->g_vectorKey,XXX_BaseDB::instance()->g_vectorData2);
m_pDraw1->slotMovePad(ui->hSlider_move->value(),m_iPlayX);
m_pDraw2->slotMovePad(ui->hSlider_move->value(),m_iPlayX);
}
void XXX_dataPlayBack::slotSliderPressed()
{
if(m_timerMove == nullptr)
return;
m_timerMove->stop();
XXX_BaseDB::instance()->stopDBThread(true);
XXX_BaseDB::instance()->exitDBThread(false);
}
void XXX_dataPlayBack::slotSliderReleased()
{
if(m_bRunTimer)
{
if(m_timerMove == nullptr)
return;
if(ui->hSlider_move->value() < m_iPlayX)
XXX_BaseDB::instance()->setStartGetID(0,m_iPlayX);
else
XXX_BaseDB::instance()->setStartGetID(ui->hSlider_move->value()-m_iPlayX,m_iPlayX);
XXX_BaseDB::instance()->exitDBThread(true);
XXX_BaseDB::instance()->stopDBThread(false);
QThread::msleep(100);
m_timerMove->start(m_iFrequency);
}
else
{
if(m_timerMove == nullptr)
return;
if(ui->hSlider_move->value() < m_iPlayX)
XXX_BaseDB::instance()->setStartGetID(0,m_iPlayX);
else
XXX_BaseDB::instance()->setStartGetID(ui->hSlider_move->value()-m_iPlayX,m_iPlayX);
XXX_BaseDB::instance()->exitDBThread(true);
XXX_BaseDB::instance()->stopDBThread(false);
}
}
void XXX_dataPlayBack::slotSliderMoved()
{
qDebug() << "ui->hSlider_move->value()" << ui->hSlider_move->value();
QString strRunTime;
XXX_BaseDB::instance()->getFirstTime(ui->hSlider_move->value(),strRunTime);
ui->label_RunTime->setText(strRunTime);
if(m_timerMove == nullptr)
return;
QTime timer;
timer.start();
int iIndex = ui->hSlider_move->value();
if(iIndex < m_iPlayX)
{
XXX_BaseDB::instance()->getDataBase(iIndex,iIndex);
}
else
{
XXX_BaseDB::instance()->getDataBase(iIndex,m_iPlayX);
}
int iMaxY = quiteMaxData();
m_pDraw1->setYHeiget(iMaxY);
m_pDraw1->setDataPad(XXX_BaseDB::instance()->g_vectorOneKey,XXX_BaseDB::instance()->g_vectorOneData1);
m_pDraw1->slotMovePad(iIndex,m_iPlayX);
m_pDraw2->setYHeiget(iMaxY);
m_pDraw2->setDataPad(XXX_BaseDB::instance()->g_vectorOneKey,XXX_BaseDB::instance()->g_vectorOneData2);
m_pDraw2->slotMovePad(iIndex,m_iPlayX);
qDebug() << "Time elapsed: " << timer.elapsed() << "ms";
}
void XXX_dataPlayBack::slotZoomIn()
{
ui->pushButton_zoom_out->setVisible(true);
if(m_iPlayX>1*8000)
{
m_iPlayX-=8000;
}
else if(m_iPlayX>1000)
{
m_iPlayX-=1000;
}
else if(m_iPlayX>100)
{
m_iPlayX-=100;
}
else
{
m_iPlayX = 100;
}
zoomUpdate();
}
void XXX_dataPlayBack::slotZoomOut()
{
ui->pushButton_zoom_in->setVisible(true);
if(m_iPlayX>=20*8000)
{
m_iPlayX = 20*8000;
}
else if(m_iPlayX>1*8000)
{
m_iPlayX += 1*8000;
}
else if(m_iPlayX>=1000)
{
m_iPlayX += 1000;
}
else if(m_iPlayX>=100)
{
m_iPlayX += 100;
}
else
{
m_iPlayX = 100;
}
zoomUpdate();
}
void XXX_dataPlayBack::zoomUpdate()
{
int iIndex = ui->hSlider_move->value();
if(iIndex < m_iPlayX)
{
XXX_BaseDB::instance()->getDataBase(iIndex,iIndex);
}
else
{
XXX_BaseDB::instance()->getDataBase(iIndex,m_iPlayX);
}
int iMaxY = quiteMaxData();
m_pDraw1->setYHeiget(iMaxY);
m_pDraw2->setYHeiget(iMaxY);
m_pDraw1->setDataPad(XXX_BaseDB::instance()->g_vectorOneKey,XXX_BaseDB::instance()->g_vectorOneData1);
// m_pDraw1->slotMovePad(iIndex,m_iPlayX);
m_pDraw2->setDataPad(XXX_BaseDB::instance()->g_vectorOneKey,XXX_BaseDB::instance()->g_vectorOneData2);
// m_pDraw2->slotMovePad(iIndex,m_iPlayX);
m_pDraw1->slotMovePad(ui->hSlider_move->value(),m_iPlayX);
m_pDraw2->slotMovePad(ui->hSlider_move->value(),m_iPlayX);
}
void XXX_dataPlayBack::initUI()
{
QColor color1(255,0,0);
QColor color2(0,255,0);
m_pDraw1 = new XXX_DrawCurve(color1,this);
m_pDraw2 = new XXX_DrawCurve(color2,this);
QHBoxLayout *hBox1 = new QHBoxLayout(ui->widge_dataPlay_1);
QHBoxLayout *hBox2 = new QHBoxLayout(ui->widge_dataPlay_2);
hBox1->addWidget(m_pDraw1);
hBox2->addWidget(m_pDraw2);
//启用长按
ui->pushButton_zoom_in->setAutoRepeat(true);
//触发长按的时间
ui->pushButton_zoom_in->setAutoRepeatDelay(400);
//长按时click信号间隔
ui->pushButton_zoom_in->setAutoRepeatInterval(50);
ui->pushButton_zoom_out->setAutoRepeat(true);
ui->pushButton_zoom_out->setAutoRepeatDelay(400);
ui->pushButton_zoom_out->setAutoRepeatInterval(50);
connect(ui->pushButton_zoom_in,&QPushButton::clicked,this,&XXX_dataPlayBack::slotZoomIn);
connect(ui->pushButton_zoom_out,&QPushButton::clicked,this,&XXX_dataPlayBack::slotZoomOut);
ui->pushButton_zoom_in->setVisible(false);
ui->pushButton_zoom_out->setVisible(false);
ui->hSlider_move->setRange(0,m_iPlayX);
m_timerMove = new QTimer;
m_timerMove->setTimerType(Qt::PreciseTimer);
connect(m_timerMove, &QTimer::timeout, this, &XXX_dataPlayBack::slotTimerMove);
//
connect(ui->hSlider_move, &QSlider::sliderPressed, this, &XXX_dataPlayBack::slotSliderPressed);
connect(ui->hSlider_move, &QSlider::sliderReleased, this, &XXX_dataPlayBack::slotSliderReleased);
connect(ui->hSlider_move, &QSlider::sliderMoved, this, &XXX_dataPlayBack::slotSliderMoved);
}
void XXX_dataPlayBack::getListDBName()
{
if(m_strDBPath.isEmpty())
{
return;
}
QDirIterator it(m_strDBPath, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDirIterator::Subdirectories);
while(it.hasNext())
{
it.next();
if(it.fileInfo().suffix() == "db")
{
QString strDBName = it.fileName().split(".").at(0);
m_listDBName.append(strDBName);
}
}
ui->comboBox_DB->addItems(m_listDBName);
}
int XXX_dataPlayBack::quiteMaxData()
{
int iSurplus = XXX_BaseDB::instance()->g_vectorData1.count() - ui->hSlider_move->value();
if(iSurplus < 0)
iSurplus = 0;
int iFontSurplus = XXX_BaseDB::instance()->g_vectorData1.count() - m_iPlayX - iSurplus;
if(iFontSurplus< 0)
iFontSurplus = 0;
double dMaxID1 = *std::max_element(std::begin(XXX_BaseDB::instance()->g_vectorData1) + iFontSurplus,std::end(XXX_BaseDB::instance()->g_vectorData1)-iSurplus);
double dMaxID2 = *std::min_element(std::begin(XXX_BaseDB::instance()->g_vectorData2),std::end(XXX_BaseDB::instance()->g_vectorData2));
// double dMinID1 = *std::min_element(std::begin(XXX_BaseDB::instance()->g_vectorData1),std::end(XXX_BaseDB::instance()->g_vectorData1));
// double dMinID2 = *std::min_element(std::begin(XXX_BaseDB::instance()->g_vectorData2),std::end(XXX_BaseDB::instance()->g_vectorData2));
if(dMaxID2>dMaxID1)
{
dMaxID1 = dMaxID2;
}
int iMaxY = (int(dMaxID1)/10+1)*10;
return iMaxY;
}
void XXX_dataPlayBack::deleteDBThread()
{
XXX_BaseDB::instance()->closeDBThread(false);
XXX_BaseDB::instance()->stopDBThread(true);
XXX_BaseDB::instance()->exitDBThread(false);
if(m_threadDBBase->isRunning())
{
m_threadDBBase->quit();
m_threadDBBase->wait();
}
// m_threadDBBase = nullptr;
// delete m_threadDBBase;
// XXX_BaseDB::instance() = nullptr;
// delete XXX_BaseDB::instance();
}
void XXX_dataPlayBack::on_comboBox_Table_currentTextChanged(const QString &arg1)
{
m_strTableName = arg1;
//XXX_BaseDB::instance()->setOpenTableName(m_strTableName);
int iMaxID;
XXX_BaseDB::instance()->setOpenTableName(arg1);
XXX_BaseDB::instance()->getMaxID(iMaxID);
ui->hSlider_move->setRange(1,iMaxID);
QString strMaxTime;
XXX_BaseDB::instance()->getFirstTime(iMaxID,strMaxTime);
ui->label_LastTime->setText(strMaxTime);
m_threadDBBase->start();
XXX_BaseDB::instance()->exitDBThread(true);
XXX_BaseDB::instance()->closeDBThread(true);
XXX_BaseDB::instance()->stopDBThread(false);
XXX_BaseDB::instance()->setStartGetID(0,m_iPlayX);
emit signalDBThread();
QThread::msleep(100);
m_timerMove->start(m_iFrequency);
}
void XXX_dataPlayBack::on_comboBox_DB_currentIndexChanged(int index)
{
ui->comboBox_Table->clear();
QString strOpenDBPath = m_strDBPath + m_listDBName.at(index) + ".db";
//XXX_BaseDB::instance() = new XXX_BaseDB;
m_threadDBBase = new QThread(this);
XXX_BaseDB::instance()->moveToThread(m_threadDBBase);
connect(this,&XXX_dataPlayBack::signalDBThread,XXX_BaseDB::instance(),&XXX_BaseDB::backDataBaseThread);
QStringList listTableName;
bool bRet = XXX_BaseDB::instance()->getDBTableName(strOpenDBPath,listTableName);
if(!bRet)
{
return;
}
for (int var = 0; var < listTableName.count(); ++var) {
if(!listTableName.at(var).contains("Default"))
{
listTableName.removeAt(var);
}
}
ui->comboBox_Table->addItems(listTableName);
}
void XXX_dataPlayBack::on_pushButton_start_clicked(bool checked)
{
//m_bRunTimer = checked;
m_pDraw1->setLabelView(m_bRunTimer);
m_pDraw2->setLabelView(m_bRunTimer);
m_bRunTimer = !m_bRunTimer;
if(m_bRunTimer)
{
if(m_timerMove == nullptr)
return;
if(ui->hSlider_move->value() < m_iPlayX)
XXX_BaseDB::instance()->setStartGetID(0,m_iPlayX);
else
XXX_BaseDB::instance()->setStartGetID(ui->hSlider_move->value()-m_iPlayX,m_iPlayX);
XXX_BaseDB::instance()->exitDBThread(true);
XXX_BaseDB::instance()->stopDBThread(false);
m_timerMove->start(m_iFrequency);
ui->pushButton_zoom_in->setVisible(false);
ui->pushButton_zoom_out->setVisible(false);
ui->pushButton_start->setText("暂停");
}
else
{
if(m_timerMove == nullptr)
return;
m_timerMove->stop();
XXX_BaseDB::instance()->stopDBThread(true);
XXX_BaseDB::instance()->exitDBThread(false);
ui->pushButton_zoom_in->setVisible(true);
ui->pushButton_zoom_out->setVisible(true);
ui->pushButton_start->setText("播放");
}
}