123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- #include "oneitem.h"
- #include "ui_oneitem.h"
- #include <QFile>
- #include "LHQLogAPI.h"
- OneItem::OneItem(QWidget *parent, bool isSpecial) :
- QWidget(parent), m_isSpecial(isSpecial),
- ui(new Ui::OneItem)
- {
- ui->setupUi(this);
- /* 加载QSS */
- QFile file(":/QSS/QSS/OneItem_dark.qss");
- if(file.open(QIODevice::ReadOnly))
- {
- QString stylesheet = file.readAll();
- this->setStyleSheet(stylesheet);
- file.close();
- } else
- {
- LH_WRITE_ERROR(QString("打开文件失败:%1").arg(file.fileName()));
- }
- /* 设置定时器 */
- m_warnTimer.setTimerType(Qt::PreciseTimer);
- m_warnTimer.setSingleShot(true);
- connect(&m_warnTimer,&QTimer::timeout,this,[this](){
- ui->label_warnning->hide();
- });
- /* 根据是否是特殊日移动位置 */
- layoutInit();
- /* 注册事件过滤器 */
- ui->comboBox_devName->installEventFilter(this);
- ui->comboBox_action->installEventFilter(this);
- /* 连接信号和槽 */
- connect(ui->comboBox_devName,QOverload<const QString&>::of(&QComboBox::currentTextChanged),this,&OneItem::do_devChanged);
- connect(ui->comboBox_action,QOverload<const QString&>::of(&QComboBox::currentTextChanged),this,&OneItem::do_actionChanged);
- connect(ui->pBtn_execTime,&QPushButton::clicked,this,&OneItem::do_pBtn_execTime_clicked);
- connect(ui->pBtn_execDate,&QPushButton::clicked,this,&OneItem::do_pBtn_execDate_clicked);
- }
- OneItem::~OneItem()
- {
- delete ui;
- }
- /* 设置序号 */
- void OneItem::setNum(int num)
- {
- ui->label_num->setText(QString::number(num));
- }
- /* 获取序号 */
- int OneItem::getNum()
- {
- return ui->label_num->text().toInt();
- }
- /* 设置日期 */
- void OneItem::setDate(const QDate& date)
- {
- ui->pBtn_execDate->setText(date.toString("yyyy-MM-dd"));
- }
- /* 获取日期 */
- QDate OneItem::getDate()
- {
- return QDate::fromString(ui->pBtn_execDate->text(),"yyyy-MM-dd");
- }
- /* 设置执行时间 */
- void OneItem::setExecTime(const QTime& time)
- {
- ui->pBtn_execTime->setText(time.toString("hh:mm:ss"));
- }
- /* 获取执行时间 */
- QTime OneItem::getExecTime()
- {
- return QTime::fromString(ui->pBtn_execTime->text(),"hh:mm:ss");
- }
- /* 设置设备名称 */
- void OneItem::setDevName(const QString& dev)
- {
- ui->comboBox_devName->setCurrentText(dev);
- }
- /* 获取设备名称 */
- QString OneItem::getDevName()
- {
- return ui->comboBox_devName->currentText();
- }
- /* 通过动作名称设置动作 */
- void OneItem::setActionName(const QString &action)
- {
- ui->comboBox_action->setCurrentText(action);
- }
- /* 获取动作名称 */
- QString OneItem::getActionName()
- {
- return ui->comboBox_action->currentText();
- }
- /* 获取动作类型 */
- int OneItem::getActionNum()
- {
- return ui->comboBox_action->currentIndex();
- }
- /* 添加设备 */
- void OneItem::addDevice(const QMap<QString, DeviceInfo>& mapDev)
- {
- ui->comboBox_devName->clear();
- for(const auto& it : mapDev)
- {
- ui->comboBox_devName->addItem(it.devName);
- }
- /* 设置显示第一个设备,并设置可选的动作 */
- ui->comboBox_devName->setCurrentIndex(0);
- setActionName(ui->comboBox_devName->currentText());
- }
- /* 获取日期类型 */
- bool OneItem::getDateType()
- {
- return m_isSpecial;
- }
- /* 设置警告 */
- void OneItem::setWarningText(QString str, int ms)
- {
- ui->label_warnning->setText(str);
- ui->label_warnning->show();
- if(ms > 0)
- {
- m_warnTimer.start(ms);
- }
- }
- /* 隐藏警告 */
- void OneItem::hideWarn()
- {
- ui->label_warnning->hide();
- }
- /* 设备改变了 */
- void OneItem::do_devChanged(QString devName)
- {
- /* 根据选择的设备,设置该设备的动作 */
- ui->comboBox_action->clear();
- auto it = DeviceContainer.getDevice(devName);
- if(it.PTTypeCode > 0)
- {
- m_devInfo = it;
- for(auto it1 = m_devInfo.DevType.devAction.begin();it1 != m_devInfo.DevType.devAction.end();it1++)
- {
- ui->comboBox_action->addItem(it1.value(), it1.key());
- }
- }else
- {
- LH_WRITE_ERROR(QString("没有这个设备:%1").arg(devName));
- return;
- }
- emit signal_devChanged();
- }
- /* 动作改变了 */
- void OneItem::do_actionChanged(QString action)
- {
- }
- /* 执行时间被点击了 */
- void OneItem::do_pBtn_execTime_clicked()
- {
- emit signal_execTimeClicked(getExecTime());
- }
- /* 执行日期被点击了 */
- void OneItem::do_pBtn_execDate_clicked()
- {
- emit signal_dateClicked(getDate());
- }
- /* 根据日期类型布局 */
- void OneItem::layoutInit()
- {
- /* 正常日,日期隐藏 */
- if(!m_isSpecial)
- {
- ui->pBtn_execDate->hide();
- ui->pBtn_iconDate->hide();
- /* 序号 */
- ui->label_num->move(18, 0);
- /* 设备名称 */
- ui->comboBox_devName->move(114, 0);
- /* 执行时间 */
- ui->pBtn_execTime->move(390, 40);
- /* 执行时间图标 */
- ui->pBtn_iconTime->move(498, 8);
- /* 动作 */
- ui->comboBox_action->move(538, 0);
- /* 关闭 */
- ui->pBtn_close->move(814, 0);
- }else
- {
- ui->pBtn_execDate->show();
- ui->pBtn_iconDate->show();
- /* 序号 */
- ui->label_num->move(18, 0);
- /* 设备名称 */
- ui->comboBox_devName->move(114, 0);
- /* 执行日期 */
- ui->pBtn_execDate->move(390, 0);
- /* 执行日期图标 */
- ui->pBtn_iconDate->move(498, 8);
- /* 执行时间 */
- ui->pBtn_execTime->move(539, 40);
- /* 执行时间图标 */
- ui->pBtn_iconTime->move(646, 8);
- /* 动作 */
- ui->comboBox_action->move(686, 0);
- /* 关闭 */
- ui->pBtn_close->move(962, 0);
- }
- }
- /* 事件过滤器 */
- bool OneItem::eventFilter(QObject *watched, QEvent *event)
- {
- if(watched == ui->comboBox_action)
- {
- if(event->type() == QEvent::Wheel)
- {
- return true;
- }
- }
- else if(watched == ui->comboBox_devName)
- {
- if(event->type() == QEvent::Wheel)
- {
- return true;
- }
- }
- return QWidget::eventFilter(watched,event);
- }
|