diff --git a/patches/kwidgetsaddons/ignore-invalid-dates-in-picker.patch b/patches/kwidgetsaddons/ignore-invalid-dates-in-picker.patch new file mode 100755 index 00000000..776cd6db --- /dev/null +++ b/patches/kwidgetsaddons/ignore-invalid-dates-in-picker.patch @@ -0,0 +1,174 @@ +#! /bin/sh +patch -p1 -l -f $* < $0 +exit $? + +From bb5a1f1b35f6efe34c0cda33d469aa5739151534 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= +Date: Wed, 23 Jun 2021 16:00:08 +0200 +Subject: [PATCH] KDateComboBox: Ignore invalid dates entered in date picker + +This fixes the problem that potentially invalid dates emitted by +the date picker with the KDatePicker::dateEntered() signal were taken +over by the date combobox without validation. Using the same signal +handler (renamed to datePicked) as for the KDatePicker::tableClicked() +signal fixes this. + +This commit also adds a small test app for KDateComboBox. +--- + autotests/kdatecomboboxtest.cpp | 27 +++++++++++++++++++++++++++ + autotests/kdatecomboboxtest.h | 1 + + src/kdatecombobox.cpp | 10 +++++----- + tests/CMakeLists.txt | 1 + + tests/kdatecomboboxtestapp.cpp | 32 ++++++++++++++++++++++++++++++++ + 5 files changed, 66 insertions(+), 5 deletions(-) + create mode 100644 tests/kdatecomboboxtestapp.cpp + +diff --git a/autotests/kdatecomboboxtest.cpp b/autotests/kdatecomboboxtest.cpp +index 80694af7..1ffa4dd0 100644 +--- a/autotests/kdatecomboboxtest.cpp ++++ b/autotests/kdatecomboboxtest.cpp +@@ -1,5 +1,7 @@ + /* + SPDX-FileCopyrightText: 2011 John Layt ++ SPDX-FileCopyrightText: 2021 g10 Code GmbH ++ SPDX-FileContributor: Ingo Klöcker + + SPDX-License-Identifier: LGPL-2.0-or-later + */ +@@ -9,6 +11,8 @@ + #include + + #include "kdatecombobox.h" ++#include "kdatepicker.h" ++ + #include + #include + #include +@@ -221,3 +225,26 @@ void KDateComboBoxTest::testSignals() + QCOMPARE(spyDateChanged.count(), 1); + clearSpies(); + } ++ ++void KDateComboBoxTest::testDatePickerIntegration() ++{ ++ // GIVEN ++ QScopedPointer combo{new KDateComboBox}; ++ combo->setDateRange(QDate{2001, 1, 1}, QDate{2106, 1, 1}); ++ combo->setDate(QDate{2021, 6, 23}); ++ ++ // WHEN the date picker emits tableClicked signal with an invalid date ++ auto datePicker = combo->findChild(); ++ QVERIFY(datePicker); ++ datePicker->setDate(QDate{1921, 6, 23}); ++ Q_EMIT datePicker->tableClicked(); ++ ++ // THEN ++ QCOMPARE(combo->date(), QDate(2021, 6, 23)); ++ ++ // WHEN the date picker emits dateEntered signal with an invalid date ++ Q_EMIT datePicker->dateEntered(QDate{1921, 6, 23}); ++ ++ // THEN ++ QCOMPARE(combo->date(), QDate(2021, 6, 23)); ++} +diff --git a/autotests/kdatecomboboxtest.h b/autotests/kdatecomboboxtest.h +index 883980c0..8f5fd187 100644 +--- a/autotests/kdatecomboboxtest.h ++++ b/autotests/kdatecomboboxtest.h +@@ -23,6 +23,7 @@ private Q_SLOTS: + void testOptions(); + void testDisplayFormat(); + void testSignals(); ++ void testDatePickerIntegration(); + }; + + #endif // KDATECOMBOBOXTEST_H +diff --git a/src/kdatecombobox.cpp b/src/kdatecombobox.cpp +index 9e5a589d..d120038b 100644 +--- a/src/kdatecombobox.cpp ++++ b/src/kdatecombobox.cpp +@@ -41,7 +41,7 @@ public: + void setDateRange(const QDate &minDate, const QDate &maxDate, const QString &minWarnMsg, const QString &maxWarnMsg); + bool isInDateRange(const QDate &date) const; + +- void clickDate(); ++ void datePicked(); + void selectDate(QAction *action); + void editDate(const QString &text); + void enterDate(const QDate &date); +@@ -244,7 +244,7 @@ void KDateComboBoxPrivate::selectDate(QAction *action) + } + } + +-void KDateComboBoxPrivate::clickDate() ++void KDateComboBoxPrivate::datePicked() + { + QDate date = m_datePicker->date(); + if (isInDateRange(date)) { +@@ -334,11 +334,11 @@ KDateComboBox::KDateComboBox(QWidget *parent) + } + }); + +- connect(d->m_datePicker, &KDatePicker::dateEntered, this, [this](const QDate &date) { +- d->enterDate(date); ++ connect(d->m_datePicker, &KDatePicker::dateEntered, this, [this]() { ++ d->datePicked(); + }); + connect(d->m_datePicker, &KDatePicker::tableClicked, this, [this]() { +- d->clickDate(); ++ d->datePicked(); + }); + } + +diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt +index dee4a0dc..e8ac0eed 100644 +--- a/tests/CMakeLists.txt ++++ b/tests/CMakeLists.txt +@@ -16,6 +16,7 @@ kwidgetsaddons_executable_tests( + kbusyindicatorwidgettest + kcharselecttest + kcollapsiblegroupboxtest ++ kdatecomboboxtestapp + kdatepicktest + kdatetimeedittestapp + kledtest +diff --git a/tests/kdatecomboboxtestapp.cpp b/tests/kdatecomboboxtestapp.cpp +new file mode 100644 +index 00000000..87e6669f +--- /dev/null ++++ b/tests/kdatecomboboxtestapp.cpp +@@ -0,0 +1,32 @@ ++/* ++ SPDX-FileCopyrightText: 2021 g10 Code GmbH ++ SPDX-FileContributor: Ingo Klöcker ++ ++ SPDX-License-Identifier: GPL-2.0-or-later ++*/ ++ ++#include "kdatecombobox.h" ++#include ++#include ++#include ++ ++int main(int argc, char **argv) ++{ ++ QApplication::setApplicationName(QStringLiteral("test")); ++ QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); ++ QApplication app{argc, argv}; ++ KDateComboBox dateComboBox; ++ dateComboBox.setOptions(KDateComboBox::EditDate ++ | KDateComboBox::SelectDate ++ | KDateComboBox::DatePicker ++ | KDateComboBox::DateKeywords ++ | KDateComboBox::WarnOnInvalid); ++ dateComboBox.setDateRange(QDate{2021, 1, 1}, QDate{2106, 2, 6}); ++ QObject::connect(&dateComboBox, &KDateComboBox::dateEntered, [](const QDate &d) { qDebug() << "dateEntered" << d; }); ++ QObject::connect(&dateComboBox, &KDateComboBox::dateChanged, [](const QDate &d) { qDebug() << "dateChanged" << d; }); ++ QObject::connect(&dateComboBox, &KDateComboBox::dateEdited, [](const QDate &d) { qDebug() << "dateEdited" << d; }); ++ dateComboBox.resize(200, dateComboBox.sizeHint().height()); ++ dateComboBox.show(); ++ // dateComboBox.setEnabled(false); ++ return app.exec(); ++} +-- +GitLab