summaryrefslogtreecommitdiff
path: root/LibGUI/GModelIndex.h
blob: 6817270a663a9a80a970c556963c6ae52bd63cdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

class GModel;

class GModelIndex {
    friend class GModel;

public:
    GModelIndex() {}

    bool is_valid() const { return m_row != -1 && m_column != -1; }
    int row() const { return m_row; }
    int column() const { return m_column; }

    void* internal_data() const { return m_internal_data; }

    GModelIndex parent() const;

    bool operator==(const GModelIndex& other) const
    {
        return m_model == other.m_model && m_row == other.m_row && m_column == other.m_column && m_internal_data == other.m_internal_data;
    }

    bool operator!=(const GModelIndex& other) const
    {
        return !(*this == other);
    }

private:
    GModelIndex(const GModel& model, int row, int column, void* internal_data)
        : m_model(&model)
        , m_row(row)
        , m_column(column)
        , m_internal_data(internal_data)
    {
    }

    const GModel* m_model { nullptr };
    int m_row { -1 };
    int m_column { -1 };
    void* m_internal_data { nullptr };
};