item delegates: fix clicking on tristate checkboxes.
QCheckBox cycles through the 3 states, but item delegates didn't do that. Change-Id: Iad1e464341033ca357925fe8064f53bb584459f4 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
0a3eb0fe44
commit
8f4b6f1cd1
@ -1295,8 +1295,11 @@ bool QItemDelegate::editorEvent(QEvent *event,
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
||||
? Qt::Unchecked : Qt::Checked);
|
||||
Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
|
||||
if (flags & Qt::ItemIsTristate)
|
||||
state = ((Qt::CheckState)((state + 1) % 3));
|
||||
else
|
||||
state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
|
||||
return model->setData(index, state, Qt::CheckStateRole);
|
||||
}
|
||||
|
||||
|
@ -764,8 +764,11 @@ bool QStyledItemDelegate::editorEvent(QEvent *event,
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
||||
? Qt::Unchecked : Qt::Checked);
|
||||
Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
|
||||
if (flags & Qt::ItemIsTristate)
|
||||
state = ((Qt::CheckState)((state + 1) % 3));
|
||||
else
|
||||
state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
|
||||
return model->setData(index, state, Qt::CheckStateRole);
|
||||
}
|
||||
|
||||
|
@ -1198,6 +1198,57 @@ void tst_QItemDelegate::editorEvent_data()
|
||||
<< (int)(Qt::LeftButton)
|
||||
<< true
|
||||
<< (int)(Qt::Unchecked);
|
||||
|
||||
QTest::newRow("unchecked, tristate, release")
|
||||
<< QRect(0, 0, 20, 20)
|
||||
<< QString("foo")
|
||||
<< (int)(Qt::Unchecked)
|
||||
<< (int)(Qt::ItemIsEditable
|
||||
|Qt::ItemIsSelectable
|
||||
|Qt::ItemIsUserCheckable
|
||||
|Qt::ItemIsTristate
|
||||
|Qt::ItemIsEnabled
|
||||
|Qt::ItemIsDragEnabled
|
||||
|Qt::ItemIsDropEnabled)
|
||||
<< true
|
||||
<< (int)(QEvent::MouseButtonRelease)
|
||||
<< (int)(Qt::LeftButton)
|
||||
<< true
|
||||
<< (int)(Qt::PartiallyChecked);
|
||||
|
||||
QTest::newRow("partially checked, tristate, release")
|
||||
<< QRect(0, 0, 20, 20)
|
||||
<< QString("foo")
|
||||
<< (int)(Qt::PartiallyChecked)
|
||||
<< (int)(Qt::ItemIsEditable
|
||||
|Qt::ItemIsSelectable
|
||||
|Qt::ItemIsUserCheckable
|
||||
|Qt::ItemIsTristate
|
||||
|Qt::ItemIsEnabled
|
||||
|Qt::ItemIsDragEnabled
|
||||
|Qt::ItemIsDropEnabled)
|
||||
<< true
|
||||
<< (int)(QEvent::MouseButtonRelease)
|
||||
<< (int)(Qt::LeftButton)
|
||||
<< true
|
||||
<< (int)(Qt::Checked);
|
||||
|
||||
QTest::newRow("checked, tristate, release")
|
||||
<< QRect(0, 0, 20, 20)
|
||||
<< QString("foo")
|
||||
<< (int)(Qt::Checked)
|
||||
<< (int)(Qt::ItemIsEditable
|
||||
|Qt::ItemIsSelectable
|
||||
|Qt::ItemIsUserCheckable
|
||||
|Qt::ItemIsTristate
|
||||
|Qt::ItemIsEnabled
|
||||
|Qt::ItemIsDragEnabled
|
||||
|Qt::ItemIsDropEnabled)
|
||||
<< true
|
||||
<< (int)(QEvent::MouseButtonRelease)
|
||||
<< (int)(Qt::LeftButton)
|
||||
<< true
|
||||
<< (int)(Qt::Unchecked);
|
||||
}
|
||||
|
||||
void tst_QItemDelegate::editorEvent()
|
||||
|
Loading…
Reference in New Issue
Block a user