From ff1d84f80be8704f9b677522c55da9c9b93b64ba Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Sat, 26 Sep 2020 10:59:12 -0600 Subject: [PATCH] Switch to combined date+time Qt widget for improved data entry --- apps/OpenSpace/ext/launcher/include/ostime.h | 1 - .../ext/launcher/include/ui_ostime.h | 23 ++++++------------- apps/OpenSpace/ext/launcher/src/ostime.cpp | 21 +++++------------ 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/include/ostime.h b/apps/OpenSpace/ext/launcher/include/ostime.h index 756cf819e2..dc619cb64a 100644 --- a/apps/OpenSpace/ext/launcher/include/ostime.h +++ b/apps/OpenSpace/ext/launcher/include/ostime.h @@ -19,7 +19,6 @@ public slots: void enableAccordingToType(int); void cancel(); void approved(); - void keyPressEvent(QKeyEvent *evt); public: explicit ostime(openspace::Profile* imported, QWidget *parent = nullptr); diff --git a/apps/OpenSpace/ext/launcher/include/ui_ostime.h b/apps/OpenSpace/ext/launcher/include/ui_ostime.h index 3c2400cd9c..928e311ee4 100644 --- a/apps/OpenSpace/ext/launcher/include/ui_ostime.h +++ b/apps/OpenSpace/ext/launcher/include/ui_ostime.h @@ -30,9 +30,8 @@ public: QLineEdit *line_relative; QComboBox *combo_type; QLabel *label_type; - QDateEdit *dateEdit; - QTimeEdit *timeEdit; QLabel *label_absolete; + QDateTimeEdit *dateTimeEdit; void setupUi(QDialog *time) { @@ -62,22 +61,15 @@ public: label_type->setObjectName(QString::fromUtf8("label_type")); label_type->setGeometry(QRect(20, 20, 91, 17)); label_type->setFont(font); - dateEdit = new QDateEdit(time); - dateEdit->setObjectName(QString::fromUtf8("dateEdit")); - dateEdit->setGeometry(QRect(140, 80, 131, 31)); - dateEdit->setFont(font); - timeEdit = new QTimeEdit(time); - timeEdit->setObjectName(QString::fromUtf8("timeEdit")); - timeEdit->setGeometry(QRect(290, 80, 131, 31)); - timeEdit->setFont(font); - timeEdit->setMaximumDate(QDate(2000, 1, 1)); - timeEdit->setMinimumDate(QDate(2000, 1, 1)); - timeEdit->setCurrentSection(QDateTimeEdit::HourSection); - timeEdit->setTimeSpec(Qt::UTC); label_absolete = new QLabel(time); label_absolete->setObjectName(QString::fromUtf8("label_absolete")); label_absolete->setGeometry(QRect(20, 88, 111, 17)); label_absolete->setFont(font); + dateTimeEdit = new QDateTimeEdit(time); + dateTimeEdit->setObjectName(QString::fromUtf8("dateTimeEdit")); + dateTimeEdit->setGeometry(QRect(140, 80, 201, 31)); + dateTimeEdit->setFont(font); + dateTimeEdit->setMinimumDate(QDate(100,1,1)); retranslateUi(time); //QObject::connect(buttonBox, SIGNAL(accepted()), time, SLOT(accept())); @@ -97,9 +89,8 @@ public: combo_type->setToolTip(QCoreApplication::translate("time", "

Types: Absolute defined time or Relative to actual time

", nullptr)); #endif // QT_CONFIG(tooltip) label_type->setText(QCoreApplication::translate("time", "Time Type", nullptr)); - dateEdit->setDisplayFormat(QCoreApplication::translate("time", "yyyy-MM-dd", nullptr)); - timeEdit->setDisplayFormat(QCoreApplication::translate("time", "hh:mm:ss", nullptr)); label_absolete->setText(QCoreApplication::translate("time", "Absolute UTC:", nullptr)); + dateTimeEdit->setDisplayFormat(QCoreApplication::translate("time", "yyyy-MM-dd T hh:mm:ss", nullptr)); } // retranslateUi }; diff --git a/apps/OpenSpace/ext/launcher/src/ostime.cpp b/apps/OpenSpace/ext/launcher/src/ostime.cpp index a024932b00..a06a20e828 100644 --- a/apps/OpenSpace/ext/launcher/src/ostime.cpp +++ b/apps/OpenSpace/ext/launcher/src/ostime.cpp @@ -22,7 +22,7 @@ ostime::ostime(openspace::Profile* imported, QWidget *parent) ui->line_relative->setSelection(0, ui->line_relative->text().length()); } else { - ui->dateEdit->setSelectedSection(QDateTimeEdit::YearSection); + ui->dateTimeEdit->setSelectedSection(QDateTimeEdit::YearSection); } } else { @@ -58,17 +58,16 @@ void ostime::enableAccordingToType(int idx) { size_t tIdx = _data.time.find_first_of('T', 0); QString importDate = QString(_data.time.substr(0, tIdx).c_str()); QString importTime = QString(_data.time.substr(tIdx + 1).c_str()); - ui->dateEdit->setDate(QDate::fromString(importDate, Qt::DateFormat::ISODate)); - ui->timeEdit->setTime(QTime::fromString(importTime)); + ui->dateTimeEdit->setDate(QDate::fromString(importDate, Qt::DateFormat::ISODate)); + ui->dateTimeEdit->setTime(QTime::fromString(importTime)); ui->line_relative->setText(""); - ui->dateEdit->setFocus(Qt::OtherFocusReason); + ui->dateTimeEdit->setFocus(Qt::OtherFocusReason); } } void ostime::enableFormatForAbsolute(bool enableAbs) { ui->label_absolete->setEnabled(enableAbs); - ui->dateEdit->setEnabled(enableAbs); - ui->timeEdit->setEnabled(enableAbs); + ui->dateTimeEdit->setEnabled(enableAbs); ui->label_relative->setEnabled(!enableAbs); ui->line_relative->setEnabled(!enableAbs); } @@ -98,17 +97,9 @@ void ostime::approved() { else { openspace::Profile::Time t; t.type = openspace::Profile::Time::Type::Absolute; - QString res = ui->dateEdit->date().toString("yyyy-MM-dd") + "T" + ui->timeEdit->time().toString(); + QString res = ui->dateTimeEdit->date().toString("yyyy-MM-dd") + "T" + ui->dateTimeEdit->time().toString(); t.time = res.toUtf8().constData(); _imported->setTime(t); } accept(); } - -void ostime::keyPressEvent(QKeyEvent *evt) -{ - if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) - return; - QDialog::keyPressEvent(evt); -} -