#include "DateReplaceEditor.h" #include "ui_DateReplaceEditor.h" #include #include #include #include extern unsigned char vartypeR; extern QMap> replaceValueMap; DateReplaceEditor::DateReplaceEditor(QWidget *parent) : QWidget(parent), ui(new Ui::DateReplaceEditor) { ui->setupUi(this); init(); initReplaceValue(); applyStyleSheet(); } DateReplaceEditor::~DateReplaceEditor() { delete ui; } DateItemModel DateReplaceEditor::dateModel() { DateItemModel model; model.dataMap = dataList; model.weeksMap = weekList; model.hoursMap = hourList; model.monthsMap = monthList; model.daysMap = dayList; for (int i = 0; i < yearInitList.size() && i < yearList.size(); ++i) { model.yearsMap[yearInitList[i]] = yearList[i]; } return model; } void DateReplaceEditor::setDateModel(const DateItemModel &model) { dataList = model.dataMap; weekList = model.weeksMap; hourList = model.hoursMap; monthList = model.monthsMap; dayList = model.daysMap; yearInitList = model.yearsMap.keys(); yearList = model.yearsMap.values(); switch (ui->cb_replaceType->currentIndex()) { case 0: loadDataShow(); break; case 1: loadWeekShow(); break; case 2: loadMonthShow(); break; case 3: loadYearShow(); break; case 4: loadDayShow(); break; case 5: loadHourShow(); break; default: loadMonthShow(); break; } } void DateReplaceEditor::applyStyleSheet() { QString styleSheet = R"( QPushButton#closeBtn, QPushButton#checkBtn{ background-color: #E6F7FF; border: 1px solid #87CEEB; border-radius: 4px; font-size: 24px; color: #228B22; } QPushButton#closeBtn:hover,QPushButton#checkBtn:hover{ background-color: #D1E9FF; } QPushButton#closeBtn:pressed,QPushButton#checkBtn:pressed{ background-color: #BAE7FF; } QPushButton { background-color: #5396C1; color: #ffffff; border: 1px solid #000000; border-radius: 3px; font-size: 18px; font-weight:500; width: 180px; height: 90px; } QPushButton:hover { background-color: #5396C1; } QPushButton:disabled { background-color: #7C828E; color: #606060; border-color: #808080; } QComboBox { border: 1px solid #000000; border-radius: 3px; font-size: 14px; width: 180px; height: 90px; padding-left: 10px; /* 文字左边距,避免紧贴边缘 */ } /* 下拉箭头区域 */ QComboBox::drop-down { border: 1px solid #333333; border-radius: 3px; width: 30px; /* 箭头区域宽度 */ background-color: #5396C1; } /* 下拉箭头图标 */ QComboBox::down-arrow { image: url(:/image/down_white.png); width: 16px; /* 图标显示宽度 */ height: 16px; /* 图标显示高度 */ } /* 悬停状态 */ QComboBox:hover { background-color: #efefef; } // 下拉框 QComboBox QAbstractItemView { border: 1px solid #000000; border-radius: 3px; font-size: 14px; selection-background-color: #5396C1; /* 选中项背景色(稍深) */ selection-color: #ffffff; } )"; setStyleSheet(styleSheet); } void DateReplaceEditor::init() { connect(ui->lineEdit_Replace1, &QLineEdit::textChanged, std::bind(&DateReplaceEditor::onLineEditReplaceChanged, this, 0, std::placeholders::_1)); connect(ui->lineEdit_Replace2, &QLineEdit::textChanged, std::bind(&DateReplaceEditor::onLineEditReplaceChanged, this, 1, std::placeholders::_1)); connect(ui->lineEdit_Replace3, &QLineEdit::textChanged, std::bind(&DateReplaceEditor::onLineEditReplaceChanged, this, 2, std::placeholders::_1)); connect(ui->lineEdit_Replace4, &QLineEdit::textChanged, std::bind(&DateReplaceEditor::onLineEditReplaceChanged, this, 3, std::placeholders::_1)); } void DateReplaceEditor::initReplaceValue() { monthList.clear(); for (int i = 1; i <= 12; ++i) { monthList.append(QString("%1").arg(i, 2, 10, QChar('0'))); } dataList.clear(); dataList << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "A" << "B" << "C" << "D" << "E" << "F"; weekList.clear(); weekList << "MON" << "TUE" << "WED" << "THU" << "FRI" << "SAT" << "SUN"; yearList.clear(); yearInitList.clear(); int startYear = QDate::currentDate().year(); for (int i = 0; i < 16; ++i) { yearList << QString::number(startYear + i); yearInitList << startYear + i; } dayList.clear(); for (int i = 1; i <= 31; ++i) { dayList.append(QString("%1").arg(i, 2, 10, QChar('0'))); } hourList.clear(); for (int i = 0; i <= 23; ++i) { hourList.append(QString("%1").arg(i, 2, 10, QChar('0'))); } currPage = 0; if(ui->cb_replaceType->currentIndex() == 2) loadMonthShow(); else if(ui->cb_replaceType->currentIndex() == 0) loadDataShow(); else if(ui->cb_replaceType->currentIndex() == 1) loadWeekShow(); else if(ui->cb_replaceType->currentIndex() == 3) loadYearShow(); else if(ui->cb_replaceType->currentIndex() == 4) loadDayShow(); else if(ui->cb_replaceType->currentIndex() == 5) loadHourShow(); } void DateReplaceEditor::on_cb_replaceType_currentIndexChanged(int index) { currPage = 0; initShowLineEdit(); if(index == 0){ loadDataShow(); }else if(index == 1){ loadWeekShow(); }else if(index == 2){ loadMonthShow(); }else if(index == 3){ loadYearShow(); }else if(index == 4){ loadDayShow(); }else if(index == 5){ loadHourShow(); } } void DateReplaceEditor::loadMonthShow() { initShowLineEdit(); if(currPage > 2) currPage = 2; int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject); if(lineEdit) lineEdit->setText(QString::number(i+1)); QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(monthList.at(i)); lineEdit2->blockSignals(b); } objectIndex++; } } void DateReplaceEditor::loadDataShow() { initShowLineEdit(); if(currPage > 3) currPage = 3; int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject); if(lineEdit) lineEdit->setText(QString::number(i)); QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(dataList.at(i)); lineEdit2->blockSignals(b); } objectIndex++; } } void DateReplaceEditor::loadWeekShow() { initShowLineEdit(); if(currPage > 1) currPage = 1; int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject); if(lineEdit) lineEdit->setText(QString::number(i+1)); QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(weekList.at(i)); lineEdit2->blockSignals(b); } objectIndex++; } } void DateReplaceEditor::loadYearShow() { initShowLineEdit(); if(currPage > 3) currPage = 3; int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject); if(lineEdit && isetText(QString::number(yearInitList.at(i))); QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(yearList.at(i)); lineEdit2->blockSignals(b); } objectIndex++; } } void DateReplaceEditor::loadDayShow() { initShowLineEdit(); if(currPage > 7) currPage = 7; int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject); if(lineEdit) lineEdit->setText(QString::number(i+1)); QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(dayList.at(i)); lineEdit2->blockSignals(b); } objectIndex++; } } void DateReplaceEditor::loadHourShow() { initShowLineEdit(); if(currPage > 5) currPage = 5; int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject); if(lineEdit) lineEdit->setText(QString::number(i)); QString strObject2 = QString("lineEdit_Replace") + QString::number(objectIndex); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(hourList.at(i)); lineEdit2->blockSignals(b); } objectIndex++; } } void DateReplaceEditor::getMonthValue() { int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject2); if(lineEdit2) monthList[i] = lineEdit2->text(); objectIndex++; } } void DateReplaceEditor::getYearValue() { int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject2); if(lineEdit2) yearList[i] = lineEdit2->text(); objectIndex++; } } void DateReplaceEditor::getDayValue() { int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject2); if(lineEdit2) dayList[i] = lineEdit2->text(); objectIndex++; } } void DateReplaceEditor::getHourValue() { int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject2); if(lineEdit2) hourList[i] = lineEdit2->text(); objectIndex++; } } void DateReplaceEditor::getWeekValue() { int objectIndex = 1; for(int i=currPage*4;(i<(currPage+1)*4)&&(ifindChild(strObject2); if(lineEdit2) weekList[i] = lineEdit2->text(); objectIndex++; } } void DateReplaceEditor::on_btnUP_clicked() { if(currPage < 1) return; currPage = currPage - 1; if(ui->cb_replaceType->currentIndex() == 2){ loadMonthShow(); }else if(ui->cb_replaceType->currentIndex() == 0){ loadDataShow(); }else if(ui->cb_replaceType->currentIndex() == 1){ loadWeekShow(); }else if(ui->cb_replaceType->currentIndex() == 3){ loadYearShow(); }else if(ui->cb_replaceType->currentIndex() == 4){ loadDayShow(); }else if(ui->cb_replaceType->currentIndex() == 5){ loadHourShow(); } } void DateReplaceEditor::on_btnDown_clicked() { initShowLineEdit(); int currentIndex = ui->cb_replaceType->currentIndex(); if (currentIndex == 2) { if (currPage < 2) { currPage++; } loadMonthShow(); return; } if (currentIndex == 0) { if (currPage < 3) { currPage++; } loadDataShow(); return; } if(currentIndex == 1){ if(currPage < 1){ currPage++; } loadWeekShow(); return; } if(currentIndex == 3){ if(currPage < 3){ currPage++; } loadYearShow(); return; } if(currentIndex == 4){ if(currPage < 7){ currPage++; } loadDayShow(); return; } if(currentIndex == 5){ if(currPage < 5){ currPage++; } loadHourShow(); return; } } void DateReplaceEditor::initShowLineEdit() { for(int i=1;i<=4;i++){ QString strObject = QString("lineEditName") + QString::number(i); QLineEdit *lineEdit = this->findChild(strObject); if(lineEdit) lineEdit->setText(""); QString strObject2 = QString("lineEdit_Replace") + QString::number(i); QLineEdit *lineEdit2 = this->findChild(strObject2); if(lineEdit2) { auto b = lineEdit2->blockSignals(true); lineEdit2->setText(""); lineEdit2->blockSignals(b); } } } void DateReplaceEditor::on_btnPreSetValue_clicked() { if(ui->cb_replaceType->currentIndex() == 2){ getMonthValue(); vartypeR = vartypeR | 1<<2; QMap monthMap; for(int i=0;icb_replaceType->currentIndex() == 3){ getYearValue(); vartypeR = vartypeR | 1<<3; QMap yearMap; for(int i=0;icb_replaceType->currentIndex() == 4){ getDayValue(); vartypeR = vartypeR | 1<<4; QMap dayMap; for(int i=0;icb_replaceType->currentIndex() == 5){ getHourValue(); vartypeR = vartypeR | 1<<5; QMap hourMap; for(int i=0;icb_replaceType->currentIndex() == 1){ getWeekValue(); vartypeR = vartypeR | 1<<1; QMap weekMap; for(int i=0;icb_replaceType->currentIndex()) { case 0: if (mapIdx < dataList.size()) dataList[mapIdx] = txt; break; case 1: if (mapIdx < weekList.size()) weekList[mapIdx] = txt; break; case 2: if (mapIdx < monthList.size()) monthList[mapIdx] = txt; break; case 3: if (mapIdx < yearList.size()) yearList[mapIdx] = txt; break; case 4: if (mapIdx < dayList.size()) dayList[mapIdx] = txt; break; case 5: if (mapIdx < hourList.size()) hourList[mapIdx] = txt; break; default: break; } }