2024-10-10 16:59:51 +08:00
|
|
|
#include "dateTimeWidget.h"
|
|
|
|
|
#include "./ui_dateTimeWidget.h"
|
|
|
|
|
#include "dateTimeSelectionPanel.h"
|
|
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
DateTimeWidget::DateTimeWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, ui(new Ui::dateTimeWidget)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DateTimeWidget::~DateTimeWidget()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
|
|
|
|
|
if(m_pTimer_Range->isActive())
|
|
|
|
|
m_pTimer_Range->stop();
|
|
|
|
|
|
2024-12-13 16:41:08 +08:00
|
|
|
// if(m_pTimer_RealTime->isActive())
|
|
|
|
|
// m_pTimer_RealTime->stop();
|
2024-10-10 16:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DateTimeWidget::eventFilter(QObject* obj, QEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QPushButton *pButton = qobject_cast<QPushButton*>(obj);
|
|
|
|
|
if(pButton)
|
|
|
|
|
{
|
|
|
|
|
QString strName = pButton->property("name").toString();
|
|
|
|
|
if(strName == "historicalDataBtn")
|
|
|
|
|
{
|
|
|
|
|
if(event->type() == QEvent::Enter)
|
|
|
|
|
{
|
|
|
|
|
pButton->setText(QString::fromWCharArray(L"实时数据"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(event->type() == QEvent::Leave)
|
|
|
|
|
{
|
|
|
|
|
pButton->setText(QString::fromWCharArray(L"历史数据"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::initialize()
|
|
|
|
|
{
|
|
|
|
|
ui->btnHistoricalData->setProperty("name", "historicalDataBtn");
|
|
|
|
|
ui->btnHistoricalData->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
connect(ui->btnDate, SIGNAL(clicked()), this, SLOT(onBtnClicked_date()));
|
|
|
|
|
connect(ui->btnHistoricalData, SIGNAL(clicked()), this, SLOT(onBtnClicked_historicalData()));
|
|
|
|
|
|
2024-12-17 16:48:46 +08:00
|
|
|
//int nMinUnit = 60 * 1000; //以毫秒为最小单位
|
|
|
|
|
//ui->btnRange_1m->setProperty("range", 1*nMinUnit);
|
|
|
|
|
ui->btnRange_1m->setProperty("timeUnit", TU_Minute_1);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_1m, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_3m->setProperty("range", 3*nMinUnit);
|
|
|
|
|
ui->btnRange_3m->setProperty("timeUnit", TU_Minute_3);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_3m, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_5m->setProperty("range", 5*nMinUnit);
|
|
|
|
|
ui->btnRange_5m->setProperty("timeUnit", TU_Minute_5);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_5m, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_10m->setProperty("range", 10*nMinUnit);
|
|
|
|
|
ui->btnRange_10m->setProperty("timeUnit", TU_Minute_10);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_10m, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_30m->setProperty("range", 30*nMinUnit);
|
|
|
|
|
ui->btnRange_30m->setProperty("timeUnit", TU_Minute_30);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_30m, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_1h->setProperty("range", 1*60*nMinUnit);
|
|
|
|
|
ui->btnRange_1h->setProperty("timeUnit", TU_Hour);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_1h, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_1d->setProperty("range", 24*60*nMinUnit);
|
|
|
|
|
ui->btnRange_1d->setProperty("timeUnit", TU_Day);
|
2024-10-10 16:59:51 +08:00
|
|
|
connect(ui->btnRange_1d, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-12-17 16:48:46 +08:00
|
|
|
//ui->btnRange_30d->setProperty("range", 30*24*60*nMinUnit);
|
|
|
|
|
ui->btnRange_30d->setProperty("timeUnit", TU_Month);
|
|
|
|
|
connect(ui->btnRange_30d, SIGNAL(clicked()), this, SLOT(onBtnClicked_range()));
|
2024-10-10 16:59:51 +08:00
|
|
|
|
|
|
|
|
connect(ui->btnRangeSelect1, SIGNAL(clicked()), this, SLOT(onBtnClicked_rangeSelect()));
|
|
|
|
|
connect(ui->btnRangeSelect2, SIGNAL(clicked()), this, SLOT(onBtnClicked_rangeSelect()));
|
|
|
|
|
|
|
|
|
|
QString strCurrentDate = QDate::currentDate().toString("yyyy/MM/dd");
|
|
|
|
|
ui->btnDate->setText(strCurrentDate);
|
|
|
|
|
QString strCurrentTime = QTime::currentTime().toString("HH:mm:ss");
|
|
|
|
|
ui->label_time->setText(strCurrentTime);
|
|
|
|
|
|
|
|
|
|
m_pTimer_Range = new QTimer(this);
|
|
|
|
|
connect(m_pTimer_Range, SIGNAL(timeout()), this, SLOT(onTimeout_rangeSelect()));
|
2024-12-13 16:41:08 +08:00
|
|
|
// m_pTimer_RealTime = new QTimer(this);
|
|
|
|
|
// connect(m_pTimer_RealTime, SIGNAL(timeout()), this, SLOT(onTimeout_realTime()));
|
|
|
|
|
// m_pTimer_RealTime->start(1000);
|
2024-10-10 16:59:51 +08:00
|
|
|
|
|
|
|
|
m_pSelectionPanel = new DateTimeSelectionPanel(this);
|
|
|
|
|
connect(m_pSelectionPanel, SIGNAL(selectResults(QDateTime)), this, SLOT(onDateTimeSelectResults(QDateTime)));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 16:48:46 +08:00
|
|
|
void DateTimeWidget::setRange(TimeUnit unit)
|
|
|
|
|
{
|
|
|
|
|
QString strName = g_timeUnit.value(unit);
|
|
|
|
|
ui->btnRangeSelect1->setText(strName);
|
|
|
|
|
QChar c = strName.back();
|
|
|
|
|
if(c == 'm')
|
|
|
|
|
ui->btnRangeSelect2->setText("Minute Chart Range");
|
|
|
|
|
else if(c == 'h')
|
|
|
|
|
ui->btnRangeSelect2->setText("Hour Chart Range");
|
|
|
|
|
else if(c == 'd')
|
|
|
|
|
ui->btnRangeSelect2->setText("Day Chart Range");
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 16:41:08 +08:00
|
|
|
void DateTimeWidget::setState(DateTimeWidgetState state)
|
|
|
|
|
{
|
|
|
|
|
if(state == realTime)
|
|
|
|
|
{
|
|
|
|
|
//m_pTimer_RealTime->start(1000);
|
|
|
|
|
ui->stacked_time->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
else if(state == historical)
|
|
|
|
|
{
|
|
|
|
|
//m_pTimer_RealTime->stop();
|
|
|
|
|
ui->btnHistoricalData->setText(QString::fromWCharArray(L"历史数据"));
|
|
|
|
|
ui->stacked_time->setCurrentIndex(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::setDateTime(QDateTime dateTime)
|
|
|
|
|
{
|
|
|
|
|
QString strTime = dateTime.time().toString("HH:mm:ss");
|
|
|
|
|
ui->label_time->setText(strTime);
|
2024-12-17 16:48:46 +08:00
|
|
|
//if(dateTime.time() == QTime(0,0,0))
|
2024-12-13 16:41:08 +08:00
|
|
|
{
|
|
|
|
|
QString strDate = dateTime.date().toString("yyyy/MM/dd");
|
|
|
|
|
ui->btnDate->setText(strDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:59:51 +08:00
|
|
|
void DateTimeWidget::onBtnClicked_historicalData()
|
|
|
|
|
{
|
2024-12-13 16:41:08 +08:00
|
|
|
setState(realTime);
|
2024-12-17 16:48:46 +08:00
|
|
|
emit viewRealTimeData();
|
2024-10-10 16:59:51 +08:00
|
|
|
}
|
|
|
|
|
void DateTimeWidget::onBtnClicked_realTimeData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::onBtnClicked_date()
|
|
|
|
|
{
|
|
|
|
|
emit showMask();
|
|
|
|
|
|
|
|
|
|
QPoint originPoint = ui->btnDate->mapToGlobal(QPoint(0, 0));
|
|
|
|
|
int nX = originPoint.x() + (ui->btnDate->width() - m_pSelectionPanel->width());
|
|
|
|
|
int nY = originPoint.y() + ui->btnDate->height();
|
|
|
|
|
m_pSelectionPanel->move(nX, nY);
|
|
|
|
|
m_pSelectionPanel->show_();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::onBtnClicked_rangeSelect()
|
|
|
|
|
{
|
|
|
|
|
ui->stacked_range->setCurrentIndex(1);
|
|
|
|
|
m_pTimer_Range->start(5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::onBtnClicked_range()
|
|
|
|
|
{
|
|
|
|
|
QPushButton* pBtn = qobject_cast<QPushButton*>(sender());
|
|
|
|
|
if(!pBtn)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-12-17 16:48:46 +08:00
|
|
|
TimeUnit unit = (TimeUnit)pBtn->property("timeUnit").toInt();
|
|
|
|
|
setRange(unit);
|
|
|
|
|
emit timeRangeChanged(unit);
|
2024-10-10 16:59:51 +08:00
|
|
|
|
|
|
|
|
ui->stacked_range->setCurrentIndex(0);
|
|
|
|
|
if(m_pTimer_Range->isActive())
|
|
|
|
|
m_pTimer_Range->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::onTimeout_rangeSelect()
|
|
|
|
|
{
|
|
|
|
|
ui->stacked_range->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::onTimeout_realTime()
|
|
|
|
|
{
|
|
|
|
|
QString strCurrentTime = QTime::currentTime().toString("HH:mm:ss");
|
|
|
|
|
ui->label_time->setText(strCurrentTime);
|
|
|
|
|
if(QTime::currentTime() == QTime(0,0,0))
|
|
|
|
|
{
|
2024-12-13 16:41:08 +08:00
|
|
|
QString strCurrentDate = QDate::currentDate().toString("yyyy/MM/dd");
|
|
|
|
|
ui->btnDate->setText(strCurrentDate);
|
2024-10-10 16:59:51 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DateTimeWidget::onDateTimeSelectResults(QDateTime dateTime)
|
|
|
|
|
{
|
2024-12-17 16:48:46 +08:00
|
|
|
if(dateTime.date() == QDate::currentDate() && ui->stacked_time->currentIndex() == 0)
|
2024-10-10 16:59:51 +08:00
|
|
|
{
|
|
|
|
|
emit hideMask();
|
2024-12-17 16:48:46 +08:00
|
|
|
return;
|
2024-10-10 16:59:51 +08:00
|
|
|
}
|
2024-12-17 16:48:46 +08:00
|
|
|
|
|
|
|
|
setState(historical);
|
|
|
|
|
dateTime.setTime(QTime::currentTime());
|
|
|
|
|
emit viewHistoricalData(dateTime);
|
2024-10-10 16:59:51 +08:00
|
|
|
}
|