diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-26 16:03:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-26 17:00:40 +0200 |
commit | 695b283b8c606a0df434ea5cd8e65a1804b24e7d (patch) | |
tree | 7e6757d40f6dc7507550852714355681517ddf62 | |
parent | 447b65bf7ba035d7c321d1046c6a42b97dd71fbb (diff) | |
download | serenity-695b283b8c606a0df434ea5cd8e65a1804b24e7d.zip |
Spreadsheet: Get rid of the "row numbers" column
Let's use TableView's row headers for this instead. :^)
-rw-r--r-- | Applications/Spreadsheet/SpreadsheetModel.cpp | 24 | ||||
-rw-r--r-- | Applications/Spreadsheet/SpreadsheetModel.h | 2 | ||||
-rw-r--r-- | Applications/Spreadsheet/SpreadsheetView.cpp | 10 |
3 files changed, 10 insertions, 26 deletions
diff --git a/Applications/Spreadsheet/SpreadsheetModel.cpp b/Applications/Spreadsheet/SpreadsheetModel.cpp index 0f66eac289..b6addb0c27 100644 --- a/Applications/Spreadsheet/SpreadsheetModel.cpp +++ b/Applications/Spreadsheet/SpreadsheetModel.cpp @@ -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(); } diff --git a/Applications/Spreadsheet/SpreadsheetModel.h b/Applications/Spreadsheet/SpreadsheetModel.h index b098b8cc8e..4ef028c417 100644 --- a/Applications/Spreadsheet/SpreadsheetModel.h +++ b/Applications/Spreadsheet/SpreadsheetModel.h @@ -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; diff --git a/Applications/Spreadsheet/SpreadsheetView.cpp b/Applications/Spreadsheet/SpreadsheetView.cpp index bb400567ca..8a2778d6e4 100644 --- a/Applications/Spreadsheet/SpreadsheetView.cpp +++ b/Applications/Spreadsheet/SpreadsheetView.cpp @@ -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); |