mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Turn the time selector in the Profile Editor into a tabbed window (#3562)
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
#include <openspace/scene/profile.h>
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QDateTimeEdit;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QTabWidget;
|
||||
|
||||
class TimeDialog final : public QDialog {
|
||||
Q_OBJECT
|
||||
@@ -48,18 +48,15 @@ public:
|
||||
TimeDialog(QWidget* parent, std::optional<openspace::Profile::Time>* time);
|
||||
|
||||
private slots:
|
||||
void enableAccordingToType(int);
|
||||
void approved();
|
||||
|
||||
private:
|
||||
void createWidgets();
|
||||
void enableFormatForAbsolute(bool enableAbs);
|
||||
|
||||
std::optional<openspace::Profile::Time>* _time = nullptr;
|
||||
openspace::Profile::Time _timeData;
|
||||
bool _initializedAsAbsolute = true;
|
||||
|
||||
QComboBox* _typeCombo = nullptr;
|
||||
QTabWidget* _tabWidget = nullptr;
|
||||
QLabel* _absoluteLabel = nullptr;
|
||||
QDateTimeEdit* _absoluteEdit = nullptr;
|
||||
QLabel* _relativeLabel = nullptr;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QTabWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <format>
|
||||
#include <algorithm>
|
||||
@@ -45,8 +46,6 @@ TimeDialog::TimeDialog(QWidget* parent, std::optional<openspace::Profile::Time>*
|
||||
setWindowTitle("Time");
|
||||
createWidgets();
|
||||
|
||||
const QStringList types = { "Absolute", "Relative" };
|
||||
_typeCombo->addItems(types);
|
||||
if (_time->has_value()) {
|
||||
_timeData = **_time;
|
||||
if (_timeData.type == Profile::Time::Type::Relative) {
|
||||
@@ -66,44 +65,75 @@ TimeDialog::TimeDialog(QWidget* parent, std::optional<openspace::Profile::Time>*
|
||||
}
|
||||
_startPaused->setChecked(_timeData.startPaused);
|
||||
|
||||
_initializedAsAbsolute = (_timeData.type == Profile::Time::Type::Absolute);
|
||||
enableAccordingToType(static_cast<int>(_timeData.type));
|
||||
if (_timeData.type == Profile::Time::Type::Relative) {
|
||||
_relativeEdit->setText(QString::fromStdString(_timeData.value));
|
||||
_relativeEdit->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
else {
|
||||
const size_t tIdx = _timeData.value.find_first_of('T', 0);
|
||||
const QString importDate = QString::fromStdString(
|
||||
_timeData.value.substr(0, tIdx)
|
||||
);
|
||||
const QString importTime = QString::fromStdString(
|
||||
_timeData.value.substr(tIdx + 1)
|
||||
);
|
||||
_absoluteEdit->setDate(QDate::fromString(importDate, Qt::DateFormat::ISODate));
|
||||
_absoluteEdit->setTime(QTime::fromString(importTime));
|
||||
_relativeEdit->clear();
|
||||
_absoluteEdit->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
|
||||
_tabWidget->setCurrentIndex(static_cast<int>(_timeData.type));
|
||||
}
|
||||
|
||||
void TimeDialog::createWidgets() {
|
||||
QBoxLayout* layout = new QVBoxLayout(this);
|
||||
|
||||
_tabWidget = new QTabWidget;
|
||||
|
||||
{
|
||||
layout->addWidget(new QLabel("Time Type"));
|
||||
_typeCombo = new QComboBox;
|
||||
_typeCombo->setAccessibleName("Time type");
|
||||
_typeCombo->setToolTip("Types: Absolute defined time or Relative to actual time");
|
||||
connect(
|
||||
_typeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &TimeDialog::enableAccordingToType
|
||||
);
|
||||
layout->addWidget(_typeCombo);
|
||||
}
|
||||
{
|
||||
QWidget* container = new QWidget;
|
||||
QBoxLayout* l = new QVBoxLayout(container);
|
||||
_absoluteLabel = new QLabel("Absolute UTC:");
|
||||
layout->addWidget(_absoluteLabel);
|
||||
l->addWidget(_absoluteLabel);
|
||||
|
||||
_absoluteEdit = new QDateTimeEdit;
|
||||
_absoluteEdit->setDisplayFormat("yyyy-MM-dd T hh:mm:ss");
|
||||
_absoluteEdit->setDateTime(QDateTime::currentDateTime());
|
||||
_absoluteEdit->setAccessibleName("Set absolute time");
|
||||
layout->addWidget(_absoluteEdit);
|
||||
l->addWidget(_absoluteEdit);
|
||||
|
||||
l->addStretch();
|
||||
|
||||
_tabWidget->addTab(container, "Absolute");
|
||||
}
|
||||
{
|
||||
QWidget* container = new QWidget;
|
||||
QBoxLayout* l = new QVBoxLayout(container);
|
||||
_relativeLabel = new QLabel("Relative Time:");
|
||||
layout->addWidget(_relativeLabel);
|
||||
l->addWidget(_relativeLabel);
|
||||
|
||||
_relativeEdit = new QLineEdit;
|
||||
_relativeEdit->setAccessibleName("Set relative time");
|
||||
_relativeEdit->setToolTip(
|
||||
"String for relative time to actual (e.g. \"-1d\" for back 1 day)"
|
||||
);
|
||||
layout->addWidget(_relativeEdit);
|
||||
l->addWidget(_relativeEdit);
|
||||
|
||||
QLabel* desc = new QLabel(
|
||||
"This field modifies the default start time. It has to be of the form "
|
||||
"[-]XX(s,m,h,d,M,y). For example '-1d' will cause the profile to start at "
|
||||
"yesterday's date."
|
||||
);
|
||||
desc->setObjectName("information");
|
||||
desc->setWordWrap(true);
|
||||
l->addWidget(desc);
|
||||
|
||||
_tabWidget->addTab(container, "Relative");
|
||||
}
|
||||
|
||||
layout->addWidget(_tabWidget);
|
||||
|
||||
{
|
||||
_startPaused = new QCheckBox("Start with time paused");
|
||||
_startPaused->setChecked(false);
|
||||
@@ -123,47 +153,9 @@ void TimeDialog::createWidgets() {
|
||||
}
|
||||
}
|
||||
|
||||
void TimeDialog::enableAccordingToType(int idx) {
|
||||
const Profile::Time::Type comboIdx = static_cast<Profile::Time::Type>(idx);
|
||||
const bool setFormatForAbsolute = (comboIdx == Profile::Time::Type::Absolute);
|
||||
enableFormatForAbsolute(setFormatForAbsolute);
|
||||
_typeCombo->setCurrentIndex(idx);
|
||||
if (comboIdx == Profile::Time::Type::Relative) {
|
||||
_relativeEdit->setText("<font color='black'>Relative Time:</font>");
|
||||
if (_initializedAsAbsolute) {
|
||||
_relativeEdit->setText("0d");
|
||||
}
|
||||
else {
|
||||
_relativeEdit->setText(QString::fromStdString(_timeData.value));
|
||||
}
|
||||
_relativeEdit->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
else {
|
||||
_relativeEdit->setText("<font color='gray'>Relative Time:</font>");
|
||||
const size_t tIdx = _timeData.value.find_first_of('T', 0);
|
||||
const QString importDate = QString::fromStdString(
|
||||
_timeData.value.substr(0, tIdx)
|
||||
);
|
||||
const QString importTime = QString::fromStdString(
|
||||
_timeData.value.substr(tIdx + 1)
|
||||
);
|
||||
_absoluteEdit->setDate(QDate::fromString(importDate, Qt::DateFormat::ISODate));
|
||||
_absoluteEdit->setTime(QTime::fromString(importTime));
|
||||
_relativeEdit->clear();
|
||||
_absoluteEdit->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
}
|
||||
|
||||
void TimeDialog::enableFormatForAbsolute(bool enableAbs) {
|
||||
_absoluteLabel->setEnabled(enableAbs);
|
||||
_absoluteEdit->setEnabled(enableAbs);
|
||||
_relativeLabel->setEnabled(!enableAbs);
|
||||
_relativeEdit->setEnabled(!enableAbs);
|
||||
}
|
||||
|
||||
void TimeDialog::approved() {
|
||||
constexpr int Relative = static_cast<int>(Profile::Time::Type::Relative);
|
||||
if (_typeCombo->currentIndex() == Relative) {
|
||||
if (_tabWidget->currentIndex() == Relative) {
|
||||
if (_relativeEdit->text().isEmpty()) {
|
||||
*_time = std::nullopt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user