summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-02-09 12:59:42 +0100
committerMitch Curtis <mitch.curtis@qt.io>2018-02-09 12:30:34 +0000
commit9dc39b7f0610990dabf9f8544ca64ff5175e7c77 (patch)
tree4a12bcd9e8c0a93b3f985f9f4ba941540d6aaaf3
parent48bfc02e82cb4b666fb832ef0ace59af8a0c7ef2 (diff)
downloadqtquickcontrols-9dc39b7f0610990dabf9f8544ca64ff5175e7c77.tar.gz
Calendar: make clicked(date) emit the correct date5.10
Calendar was implemented in such a way that pressing on a date selects that date, rather than releasing or clicking. With the current code, this presents issues when the month changes as a result of the press. For example, clicking on a date in an adjacent month will result in the clicked() signal passing the date under the mouse in the new month, instead of the originally pressed date. This patches fixes the issue by storing the pressed date and using it when emitting the released() and clicked() signals. Task-number: QTBUG-54129 Change-Id: I0c16293033b77f6ae783b5365d198b4a516af90b Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/controls/Styles/Base/CalendarStyle.qml8
-rw-r--r--tests/auto/controls/data/tst_calendar.qml10
2 files changed, 15 insertions, 3 deletions
diff --git a/src/controls/Styles/Base/CalendarStyle.qml b/src/controls/Styles/Base/CalendarStyle.qml
index d1b172e0..9da43ce5 100644
--- a/src/controls/Styles/Base/CalendarStyle.qml
+++ b/src/controls/Styles/Base/CalendarStyle.qml
@@ -369,6 +369,7 @@ Style {
property int hoveredCellIndex: -1
property int pressedCellIndex: -1
property int pressCellIndex: -1
+ property var pressDate: null
Rectangle {
anchors.fill: parent
@@ -581,9 +582,11 @@ Style {
onPressed: {
pressCellIndex = cellIndexAt(mouse.x, mouse.y);
+ pressDate = null;
if (pressCellIndex !== -1) {
var date = view.model.dateAt(pressCellIndex);
pressedCellIndex = pressCellIndex;
+ pressDate = date;
if (__isValidDate(date)) {
control.selectedDate = date;
control.pressed(date);
@@ -608,9 +611,8 @@ Style {
onClicked: {
var indexOfCell = cellIndexAt(mouse.x, mouse.y);
if (indexOfCell !== -1 && indexOfCell === pressCellIndex) {
- var date = view.model.dateAt(indexOfCell);
- if (__isValidDate(date))
- control.clicked(date);
+ if (__isValidDate(pressDate))
+ control.clicked(pressDate);
}
}
diff --git a/tests/auto/controls/data/tst_calendar.qml b/tests/auto/controls/data/tst_calendar.qml
index 55283b02..17b2b9b4 100644
--- a/tests/auto/controls/data/tst_calendar.qml
+++ b/tests/auto/controls/data/tst_calendar.qml
@@ -414,6 +414,9 @@ Item {
compare(calendar.selectedDate.getDate(), expectedDate.getDate());
compare(calendar.__panel.pressedCellIndex, cellIndex);
compare(pressedSignalSpy.count, 1);
+ compare(pressedSignalSpy.signalArguments[0][0].getFullYear(), expectedDate.getFullYear());
+ compare(pressedSignalSpy.signalArguments[0][0].getMonth(), expectedDate.getMonth());
+ compare(pressedSignalSpy.signalArguments[0][0].getDate(), expectedDate.getDate());
compare(releasedSignalSpy.count, 0);
compare(clickedSignalSpy.count, 0);
@@ -421,7 +424,14 @@ Item {
compare(calendar.__panel.pressedCellIndex, -1);
compare(pressedSignalSpy.count, 1);
compare(releasedSignalSpy.count, 1);
+ // Will fail
+// compare(releasedSignalSpy.signalArguments[0][0].getFullYear(), expectedDate.getFullYear());
+// compare(releasedSignalSpy.signalArguments[0][0].getMonth(), expectedDate.getMonth());
+// compare(releasedSignalSpy.signalArguments[0][0].getDate(), expectedDate.getDate());
compare(clickedSignalSpy.count, 1);
+ compare(clickedSignalSpy.signalArguments[0][0].getFullYear(), expectedDate.getFullYear());
+ compare(clickedSignalSpy.signalArguments[0][0].getMonth(), expectedDate.getMonth());
+ compare(clickedSignalSpy.signalArguments[0][0].getDate(), expectedDate.getDate());
pressedSignalSpy.clear();
releasedSignalSpy.clear();