WSL/SLF GitLab Repository

Commit beaf2d2d authored by Michael Reisecker's avatar Michael Reisecker
Browse files

Un-hide Datepicker on key presses

If a user starts just entering stuff then we show the value, even if it
may not be valid yet.
parent 73742131
......@@ -24,6 +24,36 @@
#include <iostream>
#endif //def DEBUG
* @class DateKeyPressFilter
* @brief Key press event listener for the Datepicker panel.
* @details We can not override 'event' in the panel itself because we want to
* listen to the events of a child widget.
* @param[in] object Object the event stems from (the QDateTimeEdit).
* @param[in] event The type of event.
* @return True if the event was accepted.
bool DateKeyPressFilter::eventFilter(QObject *object, QEvent *event)
if (event->type() == QEvent::KeyPress) {
const QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
if (key_event->key() != Qt::Key_Tab) {
if (object->property("empty").toBool()) {
* A Datepicker panel's value may be hidden to mark the panel as not set.
* If a user starts entering something we reveal the value as the current date.
object->setProperty("empty", "false");
auto *panel = qobject_cast<QDateTimeEdit*>(object);
panel->parent()->setProperty("ini_value", QDateTime::currentDateTime().toString());
} //endif property
} //endif key_event
return QObject::eventFilter(object, event); //pass to actual event of the object
* @class Datepicker
* @brief Default constructor for a Datepicker.
......@@ -45,6 +75,9 @@ Datepicker::Datepicker(const QString &section, const QString &key, const QDomNod
QTimer::singleShot(1, this, [=]{ setEmpty(true); });
connect(datepicker_, &QDateTimeEdit::dateTimeChanged, this, &Datepicker::checkValue);
key_filter_ = new DateKeyPressFilter;
auto *datepicker_layout( new QHBoxLayout );
datepicker_layout->addWidget(key_label, 0, Qt::AlignLeft);
......@@ -56,6 +89,14 @@ Datepicker::Datepicker(const QString &section, const QString &key, const QDomNod
* @brief The destructor with minimal cleanup.
delete key_filter_;
* @brief Parse options for a Datepicker from XML.
* @param[in] options XML node holding the Datepicker.
......@@ -32,12 +32,18 @@
#include <QWidget>
#include <QtXml>
class DateKeyPressFilter : public QObject { //detect key press events in the datepicker_
bool eventFilter(QObject *object, QEvent *event) override;
class Datepicker : public Atomic {
explicit Datepicker(const QString &section, const QString &key, const QDomNode &options,
const bool &no_spacers, QWidget *parent = nullptr);
~Datepicker() override;
void setOptions(const QDomNode &options);
......@@ -45,6 +51,7 @@ class Datepicker : public Atomic {
QDateTimeEdit *datepicker_ = nullptr;
QString date_format_ = "yyyy-MM-ddThh:mm:ss"; //ISO date format is default
DateKeyPressFilter *key_filter_ = nullptr;
private slots:
void onPropertySet() override;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment