2020-08-23 08:25:16 +04:30
|
|
|
/*
|
2022-02-10 12:28:48 -07:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2020-08-23 08:25:16 +04:30
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-23 08:25:16 +04:30
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Spreadsheet.h"
|
|
|
|
#include <LibGUI/Model.h>
|
|
|
|
|
|
|
|
namespace Spreadsheet {
|
|
|
|
|
|
|
|
class SheetModel final : public GUI::Model {
|
|
|
|
public:
|
2021-04-23 16:46:57 +02:00
|
|
|
static NonnullRefPtr<SheetModel> create(Sheet& sheet) { return adopt_ref(*new SheetModel(sheet)); }
|
2022-02-10 12:28:48 -07:00
|
|
|
virtual ~SheetModel() override = default;
|
2020-08-23 08:25:16 +04:30
|
|
|
|
|
|
|
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->row_count(); }
|
2020-08-26 16:03:45 +02:00
|
|
|
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->column_count(); }
|
2020-08-23 08:25:16 +04:30
|
|
|
virtual String column_name(int) const override;
|
|
|
|
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
2020-11-07 23:18:41 +03:30
|
|
|
virtual RefPtr<Core::MimeData> mime_data(const GUI::ModelSelection&) const override;
|
2020-08-23 08:25:16 +04:30
|
|
|
virtual bool is_editable(const GUI::ModelIndex&) const override;
|
|
|
|
virtual void set_data(const GUI::ModelIndex&, const GUI::Variant&) override;
|
2020-08-27 10:38:14 +02:00
|
|
|
virtual bool is_column_sortable(int) const override { return false; }
|
2020-11-02 20:21:07 +03:30
|
|
|
virtual StringView drag_data_type() const override { return "text/x-spreadsheet-data"; }
|
2020-12-22 12:52:59 +03:30
|
|
|
Sheet& sheet() { return *m_sheet; }
|
2020-08-23 08:25:16 +04:30
|
|
|
|
2021-05-25 14:13:19 +00:00
|
|
|
void update();
|
|
|
|
|
2022-02-19 14:03:50 -06:00
|
|
|
Function<void(Cell&, String&)> on_cell_data_change;
|
|
|
|
|
2020-08-23 08:25:16 +04:30
|
|
|
private:
|
|
|
|
explicit SheetModel(Sheet& sheet)
|
|
|
|
: m_sheet(sheet)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NonnullRefPtr<Sheet> m_sheet;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|