1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +00:00

LibGUI: Make GTableModel a retainable object.

It became clear that this class needs to support multiple owners.
This commit is contained in:
Andreas Kling 2019-03-20 03:27:07 +01:00
parent 41c744b3c8
commit f47945759b
22 changed files with 44 additions and 34 deletions

View file

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <stdio.h>
GSortingProxyTableModel::GSortingProxyTableModel(OwnPtr<GTableModel>&& target)
GSortingProxyTableModel::GSortingProxyTableModel(Retained<GTableModel>&& target)
: m_target(move(target))
, m_key_column(-1)
{

View file

@ -4,7 +4,7 @@
class GSortingProxyTableModel final : public GTableModel {
public:
explicit GSortingProxyTableModel(OwnPtr<GTableModel>&&);
static Retained<GSortingProxyTableModel> create(Retained<GTableModel>&& model) { return adopt(*new GSortingProxyTableModel(move(model))); }
virtual ~GSortingProxyTableModel() override;
virtual int row_count() const override;
@ -23,12 +23,14 @@ public:
GModelIndex map_to_target(const GModelIndex&) const;
private:
explicit GSortingProxyTableModel(Retained<GTableModel>&&);
GTableModel& target() { return *m_target; }
const GTableModel& target() const { return *m_target; }
void resort();
OwnPtr<GTableModel> m_target;
Retained<GTableModel> m_target;
Vector<int> m_row_mappings;
int m_key_column { -1 };
GSortOrder m_sort_order { GSortOrder::Ascending };

View file

@ -34,7 +34,7 @@ private:
GModelIndex m_index;
};
class GTableModel {
class GTableModel : public Retainable<GTableModel> {
public:
struct ColumnMetadata {
int preferred_width { 0 };

View file

@ -13,7 +13,7 @@ GTableView::~GTableView()
{
}
void GTableView::set_model(OwnPtr<GTableModel>&& model)
void GTableView::set_model(RetainPtr<GTableModel>&& model)
{
if (model.ptr() == m_model.ptr())
return;

View file

@ -16,7 +16,7 @@ public:
int header_height() const { return m_headers_visible ? 16 : 0; }
int item_height() const { return 16; }
void set_model(OwnPtr<GTableModel>&&);
void set_model(RetainPtr<GTableModel>&&);
GTableModel* model() { return m_model.ptr(); }
const GTableModel* model() const { return m_model.ptr(); }
@ -49,7 +49,7 @@ private:
int column_width(int) const;
void update_content_size();
OwnPtr<GTableModel> m_model;
RetainPtr<GTableModel> m_model;
int m_horizontal_padding { 5 };
bool m_headers_visible { true };
bool m_alternating_row_colors { true };