GTableView: Handle not having a model a bit more gracefully.

This commit is contained in:
Andreas Kling 2019-04-11 17:26:30 +02:00
parent f52e66ceda
commit ef23ed7ef1
Notes: sideshowbarker 2024-07-19 14:45:13 +09:00

View File

@ -65,6 +65,9 @@ Rect GTableView::header_rect(int column_index) const
void GTableView::mousedown_event(GMouseEvent& event)
{
if (!model())
return;
if (event.y() < header_height()) {
auto adjusted_position = event.position().translated(horizontal_scrollbar().value(), 0);
for (int i = 0; i < model()->column_count(); ++i) {
@ -100,6 +103,9 @@ void GTableView::paint_event(GPaintEvent& event)
{
GFrame::paint_event(event);
if (!model())
return;
GPainter painter(*this);
painter.add_clip_rect(frame_inner_rect());
painter.add_clip_rect(event.rect());
@ -213,6 +219,8 @@ void GTableView::paint_headers(Painter& painter)
int GTableView::item_count() const
{
if (!model())
return 0;
return model()->row_count();
}