Add date onlyBackward limit.

This commit is contained in:
Krad
2022-05-09 15:30:36 +08:00
parent b1eca40565
commit 99f19e8b5b
2 changed files with 21 additions and 0 deletions

View File

@@ -4,6 +4,8 @@
#include "DateSelectDialog.h" #include "DateSelectDialog.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel>
#include <QDate>
#include "components/DateSlidePickerBox.h" #include "components/DateSlidePickerBox.h"
DateSelectDialog::DateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { DateSelectDialog::DateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
this->setFixedSize(460, 380); this->setFixedSize(460, 380);
@@ -11,7 +13,12 @@ DateSelectDialog::DateSelectDialog(QWidget *parent, Qt::WindowFlags f) : GUIForm
box = new DateSlidePickerBox(formWidget); box = new DateSlidePickerBox(formWidget);
box->setObjectName("slider_one"); box->setObjectName("slider_one");
box->setSelectedValue("1990-01-01"); box->setSelectedValue("1990-01-01");
lbl_error = new QLabel(this);
lbl_error->setObjectName("warn");
lbl_error->setVisible(false);
lbl_error->setText(tr("Date exceeded!"));
layout->addWidget(box); layout->addWidget(box);
layout->addWidget(lbl_error);
} }
DateSelectDialog::~DateSelectDialog() { DateSelectDialog::~DateSelectDialog() {
@@ -19,6 +26,7 @@ DateSelectDialog::~DateSelectDialog() {
} }
QString DateSelectDialog::getSelectedValue() { QString DateSelectDialog::getSelectedValue() {
return box->getSelectedValue(); return box->getSelectedValue();
} }
@@ -28,6 +36,13 @@ void DateSelectDialog::setSelectedValue(const QString &val) {
} }
bool DateSelectDialog::updateReferenceData() { bool DateSelectDialog::updateReferenceData() {
if (onlyBackward){
QDate v = QDate::fromString(box->getSelectedValue(),"yyyy-MM-dd");
bool flag = QDate::currentDate()>=v;
this->setFixedHeight(flag? 380:410);
lbl_error->setVisible(!flag);
return flag;
}
return true; return true;
} }

View File

@@ -7,6 +7,7 @@
#include "dialogs/GUIFormBaseDialog.h" #include "dialogs/GUIFormBaseDialog.h"
class DateSlidePickerBox; class DateSlidePickerBox;
class QLabel;
class DateSelectDialog:public GUIFormBaseDialog{ class DateSelectDialog:public GUIFormBaseDialog{
Q_OBJECT Q_OBJECT
public: public:
@@ -15,9 +16,14 @@ public:
QString getSelectedValue(); QString getSelectedValue();
void setSelectedValue(const QString& val); void setSelectedValue(const QString& val);
void showEvent(QShowEvent *) override; void showEvent(QShowEvent *) override;
void setOnlyBackward(bool val){
onlyBackward = val;
}
protected: protected:
bool updateReferenceData() override; bool updateReferenceData() override;
DateSlidePickerBox* box; DateSlidePickerBox* box;
QLabel* lbl_error = nullptr;
bool onlyBackward = true;
}; };