mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +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 {};
|
return {};
|
||||||
|
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
if (index.column() == 0)
|
const auto* value = m_sheet->at({ m_sheet->column(index.column()), (size_t)index.row() });
|
||||||
return String::number(index.row());
|
|
||||||
|
|
||||||
const auto* value = m_sheet->at({ m_sheet->column(index.column() - 1), (size_t)index.row() });
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return String::empty();
|
return String::empty();
|
||||||
|
|
||||||
|
@ -51,12 +48,8 @@ GUI::Variant SheetModel::data(const GUI::ModelIndex& index, GUI::ModelRole role)
|
||||||
return value->data;
|
return value->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == GUI::ModelRole::TextAlignment) {
|
if (role == GUI::ModelRole::TextAlignment)
|
||||||
if (index.column() == 0)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -66,10 +59,7 @@ String SheetModel::column_name(int index) const
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (index == 0)
|
return m_sheet->column(index);
|
||||||
return "";
|
|
||||||
|
|
||||||
return m_sheet->column(index - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SheetModel::is_editable(const GUI::ModelIndex& index) const
|
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())
|
if (!index.is_valid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (index.column() == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,10 +75,7 @@ void SheetModel::set_data(const GUI::ModelIndex& index, const GUI::Variant& valu
|
||||||
if (!index.is_valid())
|
if (!index.is_valid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (index.column() == 0)
|
auto& cell = m_sheet->ensure({ m_sheet->column(index.column()), (size_t)index.row() });
|
||||||
return;
|
|
||||||
|
|
||||||
auto& cell = m_sheet->ensure({ m_sheet->column(index.column() - 1), (size_t)index.row() });
|
|
||||||
cell.set_data(value.to_string());
|
cell.set_data(value.to_string());
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
virtual ~SheetModel() override;
|
virtual ~SheetModel() override;
|
||||||
|
|
||||||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->row_count(); }
|
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 String column_name(int) const override;
|
||||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||||
virtual bool is_editable(const GUI::ModelIndex&) 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);
|
return StringModelEditingDelegate::set_value(value);
|
||||||
|
|
||||||
m_has_set_initial_value = true;
|
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)
|
if (option)
|
||||||
return StringModelEditingDelegate::set_value(option->source());
|
return StringModelEditingDelegate::set_value(option->source());
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||||
|
|
||||||
// FIXME: This is dumb.
|
// FIXME: This is dumb.
|
||||||
for (size_t i = 0; i < m_sheet->column_count(); ++i) {
|
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_painting_delegate(i, make<TableCellPainter>(*m_table_view));
|
||||||
m_table_view->set_column_width(i + 1, 50);
|
m_table_view->set_column_width(i, 50);
|
||||||
m_table_view->set_column_header_alignment(i + 1, Gfx::TextAlignment::Center);
|
m_table_view->set_column_header_alignment(i, Gfx::TextAlignment::Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_table_view->set_alternating_row_colors(false);
|
m_table_view->set_alternating_row_colors(false);
|
||||||
|
@ -83,7 +83,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||||
if (selection.column() == 0)
|
if (selection.column() == 0)
|
||||||
return;
|
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);
|
auto& cell = m_sheet->ensure(position);
|
||||||
if (on_selection_changed)
|
if (on_selection_changed)
|
||||||
on_selection_changed(position, cell);
|
on_selection_changed(position, cell);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue