Improve checks for dates range in wxQt wxCalendarCtrl
Account for the minimum and maximum dates supported by QDatePicker, both in the code and in the test suite, which shouldn't rely on not having any range restrictions in wxQt. Closes https://github.com/wxWidgets/wxWidgets/pull/1088
This commit is contained in:
@@ -136,6 +136,10 @@ bool wxCalendarCtrl::SetDate(const wxDateTime& date)
|
|||||||
if ( !m_qtCalendar )
|
if ( !m_qtCalendar )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if ( wxQtConvertDate( date ) > m_qtCalendar->maximumDate() ||
|
||||||
|
wxQtConvertDate( date ) < m_qtCalendar->minimumDate() )
|
||||||
|
return false;
|
||||||
|
|
||||||
m_qtCalendar->blockSignals(true);
|
m_qtCalendar->blockSignals(true);
|
||||||
m_qtCalendar->setSelectedDate(wxQtConvertDate(date));
|
m_qtCalendar->setSelectedDate(wxQtConvertDate(date));
|
||||||
m_qtCalendar->blockSignals(false);
|
m_qtCalendar->blockSignals(false);
|
||||||
@@ -171,12 +175,21 @@ bool wxCalendarCtrl::GetDateRange(wxDateTime *lowerdate,
|
|||||||
if ( !m_qtCalendar )
|
if ( !m_qtCalendar )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (lowerdate)
|
bool status = false;
|
||||||
*lowerdate = wxQtConvertDate(m_qtCalendar->minimumDate());
|
|
||||||
if (upperdate)
|
|
||||||
*upperdate = wxQtConvertDate(m_qtCalendar->maximumDate());
|
|
||||||
|
|
||||||
return true;
|
if ( lowerdate )
|
||||||
|
{
|
||||||
|
*lowerdate = wxQtConvertDate(m_qtCalendar->minimumDate());
|
||||||
|
status = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( upperdate )
|
||||||
|
{
|
||||||
|
*upperdate = wxQtConvertDate(m_qtCalendar->maximumDate());
|
||||||
|
status = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from wxMSW
|
// Copied from wxMSW
|
||||||
|
@@ -85,8 +85,13 @@ void DatePickerCtrlTestCase::Range()
|
|||||||
// minimum as it doesn't support dates before 1601-01-01, hence don't rely
|
// minimum as it doesn't support dates before 1601-01-01, hence don't rely
|
||||||
// on GetRange() returning false.
|
// on GetRange() returning false.
|
||||||
wxDateTime dtRangeStart, dtRangeEnd;
|
wxDateTime dtRangeStart, dtRangeEnd;
|
||||||
|
|
||||||
|
// Default end date for QT is 31/12/7999 which is considered valid,
|
||||||
|
// therefore we should omit this assertion for QT
|
||||||
|
#ifndef __WXQT__
|
||||||
m_datepicker->GetRange(&dtRangeStart, &dtRangeEnd);
|
m_datepicker->GetRange(&dtRangeStart, &dtRangeEnd);
|
||||||
CPPUNIT_ASSERT( !dtRangeEnd.IsValid() );
|
CPPUNIT_ASSERT( !dtRangeEnd.IsValid() );
|
||||||
|
#endif
|
||||||
|
|
||||||
// After we set it we should be able to get it back.
|
// After we set it we should be able to get it back.
|
||||||
const wxDateTime
|
const wxDateTime
|
||||||
|
Reference in New Issue
Block a user