Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in ctkDateRangeWidget #1086

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Libs/Widgets/Testing/Cpp/ctkDateRangeWidgetTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ int ctkDateRangeWidgetTest1(int argc, char * argv [] )
{
QApplication app(argc, argv);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QDateTime today = QDate::currentDate().startOfDay();
#else
QDateTime today = QDateTime(QDate::currentDate());
#endif
QDateTime tomorrow = today.addDays(1);
QDateTime yesterday = today.addDays(-1);
QDateTime lastWeek = today.addDays(-7);
Expand Down Expand Up @@ -112,8 +116,13 @@ int ctkDateRangeWidgetTest1(int argc, char * argv [] )
return EXIT_FAILURE;
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
dateRange.setDateTimeRange(QDate(-2, -9,12345678).startOfDay(),
QDate(2010, 15, 32).startOfDay());
#else
dateRange.setDateTimeRange(QDateTime(QDate(-2, -9,12345678)),
QDateTime(QDate(2010, 15, 32)));
#endif
if (!dateRange.isAnyDate() ||
dateRange.startDateTime() == lastMonth ||
dateRange.endDateTime() == today)
Expand Down
22 changes: 8 additions & 14 deletions Libs/Widgets/ctkDateRangeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
// CTK includes
#include "ctkDateRangeWidget.h"
#include "ui_ctkDateRangeWidget.h"
#include "ctkLogger.h"

static ctkLogger logger("org.commontk.libs.widgets.ctkDateRangeWidget");

//-----------------------------------------------------------------------------
class ctkDateRangeWidgetPrivate: public Ui_ctkDateRangeWidget
Expand Down Expand Up @@ -65,13 +62,6 @@ void ctkDateRangeWidgetPrivate::autoselectRadioButton()
Q_Q(ctkDateRangeWidget);
QDate startDate = q->startDateTime().date();
QDate endDate = q->endDateTime().date();
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QDateTime startOfDay = q->startDateTime().date().startOfDay();
QDateTime endOfDay = q->startDateTime().date().endOfDay();
#else
QDateTime startOfDay = QDateTime(q->startDateTime().date());
QDateTime endOfDay = QDateTime(q->endDateTime().date());
#endif
if (this->ForceSelectRange)
{
this->SelectRangeRadioButton->setChecked(true);
Expand All @@ -80,8 +70,13 @@ void ctkDateRangeWidgetPrivate::autoselectRadioButton()
{
this->AnyDateRadioButton->setChecked(true);
}
else if (q->startDateTime() != startOfDay ||
q->endDateTime() != endOfDay)
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
else if (q->startDateTime() != q->startDateTime().date().startOfDay() ||
q->endDateTime() != q->endDateTime().date().startOfDay())
#else
else if (q->startDateTime() != QDateTime(q->startDateTime().date()) ||
q->endDateTime() != QDateTime(q->endDateTime().date()))
#endif
{
this->SelectRangeRadioButton->setChecked(true);
}
Expand Down Expand Up @@ -200,7 +195,7 @@ void ctkDateRangeWidget::setDateTimeRange(QDateTime startDateTime, QDateTime end
void ctkDateRangeWidget::setDateRange(QDate startDate, QDate endDate)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
this->setDateTimeRange(startDate.startOfDay(), endDate.endOfDay());
this->setDateTimeRange(startDate.startOfDay(), endDate.startOfDay());
#else
this->setDateTimeRange(QDateTime(startDate), QDateTime(endDate));
#endif
Expand Down Expand Up @@ -286,7 +281,6 @@ void ctkDateRangeWidget::setDisplayTime(bool displayTime)
// -------------------------------------------------------------------------
bool ctkDateRangeWidget::displayTime()const
{
logger.error("including time in the date range is not supported now");
Q_D(const ctkDateRangeWidget);
return d->DisplayTime;
}
Expand Down