mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
Spreadsheet: Get rid of the "row numbers" column
Let's use TableView's row headers for this instead. :^)
This commit is contained in:
parent
447b65bf7b
commit
695b283b8c
3 changed files with 10 additions and 26 deletions
|
@ -38,10 +38,7 @@ GUI::Variant SheetModel::data(const GUI::ModelIndex& index, GUI::ModelRole role)
|
|||
return {};
|
||||
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
if (index.column() == 0)
|
||||
return String::number(index.row());
|
||||
|
||||
const auto* value = m_sheet->at({ m_sheet->column(index.column() - 1), (size_t)index.row() });
|
||||
const auto* value = m_sheet->at({ m_sheet->column(index.column()), (size_t)index.row() });
|
||||
if (!value)
|
||||
return String::empty();
|
||||
|
||||
|
@ -51,12 +48,8 @@ GUI::Variant SheetModel::data(const GUI::ModelIndex& index, GUI::ModelRole role)
|
|||
return value->data;
|
||||
}
|
||||
|
||||
if (role == GUI::ModelRole::TextAlignment) {
|
||||
if (index.column() == 0)
|
||||
return {};
|
||||
|
||||
if (role == GUI::ModelRole::TextAlignment)
|
||||
return {};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -66,10 +59,7 @@ String SheetModel::column_name(int index) const
|
|||
if (index < 0)
|
||||
return {};
|
||||
|
||||
if (index == 0)
|
||||
return "";
|
||||
|
||||
return m_sheet->column(index - 1);
|
||||
return m_sheet->column(index);
|
||||
}
|
||||
|
||||
bool SheetModel::is_editable(const GUI::ModelIndex& index) const
|
||||
|
@ -77,9 +67,6 @@ bool SheetModel::is_editable(const GUI::ModelIndex& index) const
|
|||
if (!index.is_valid())
|
||||
return false;
|
||||
|
||||
if (index.column() == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -88,10 +75,7 @@ void SheetModel::set_data(const GUI::ModelIndex& index, const GUI::Variant& valu
|
|||
if (!index.is_valid())
|
||||
return;
|
||||
|
||||
if (index.column() == 0)
|
||||
return;
|
||||
|
||||
auto& cell = m_sheet->ensure({ m_sheet->column(index.column() - 1), (size_t)index.row() });
|
||||
auto& cell = m_sheet->ensure({ m_sheet->column(index.column()), (size_t)index.row() });
|
||||
cell.set_data(value.to_string());
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual ~SheetModel() override;
|
||||
|
||||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->row_count(); }
|
||||
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->column_count() + 1; }
|
||||
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->column_count(); }
|
||||
virtual String column_name(int) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
virtual bool is_editable(const GUI::ModelIndex&) const override;
|
||||
|
|
|
@ -44,7 +44,7 @@ void SpreadsheetView::EditingDelegate::set_value(const GUI::Variant& value)
|
|||
return StringModelEditingDelegate::set_value(value);
|
||||
|
||||
m_has_set_initial_value = true;
|
||||
const auto option = m_sheet.at({ m_sheet.column(index().column() - 1), (size_t)index().row() });
|
||||
const auto option = m_sheet.at({ m_sheet.column(index().column()), (size_t)index().row() });
|
||||
if (option)
|
||||
return StringModelEditingDelegate::set_value(option->source());
|
||||
|
||||
|
@ -62,9 +62,9 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
|||
|
||||
// FIXME: This is dumb.
|
||||
for (size_t i = 0; i < m_sheet->column_count(); ++i) {
|
||||
m_table_view->set_column_painting_delegate(i + 1, make<TableCellPainter>(*m_table_view));
|
||||
m_table_view->set_column_width(i + 1, 50);
|
||||
m_table_view->set_column_header_alignment(i + 1, Gfx::TextAlignment::Center);
|
||||
m_table_view->set_column_painting_delegate(i, make<TableCellPainter>(*m_table_view));
|
||||
m_table_view->set_column_width(i, 50);
|
||||
m_table_view->set_column_header_alignment(i, Gfx::TextAlignment::Center);
|
||||
}
|
||||
|
||||
m_table_view->set_alternating_row_colors(false);
|
||||
|
@ -83,7 +83,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
|||
if (selection.column() == 0)
|
||||
return;
|
||||
|
||||
Position position { m_sheet->column(selection.column() - 1), (size_t)selection.row() };
|
||||
Position position { m_sheet->column(selection.column()), (size_t)selection.row() };
|
||||
auto& cell = m_sheet->ensure(position);
|
||||
if (on_selection_changed)
|
||||
on_selection_changed(position, cell);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue