summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GModelSelection.cpp
blob: bf3a6fb37ec2e5affb93e7a87fae8c2655cabac4 (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
43
44
45
46
47
48
49
#include <LibGUI/GAbstractView.h>
#include <LibGUI/GModelSelection.h>

void GModelSelection::set(const GModelIndex& index)
{
    ASSERT(index.is_valid());
    if (m_indexes.size() == 1 && m_indexes.contains(index))
        return;
    m_indexes.clear();
    m_indexes.set(index);
    m_view.notify_selection_changed({});
}

void GModelSelection::add(const GModelIndex& index)
{
    ASSERT(index.is_valid());
    if (m_indexes.contains(index))
        return;
    m_indexes.set(index);
    m_view.notify_selection_changed({});
}

void GModelSelection::toggle(const GModelIndex& index)
{
    ASSERT(index.is_valid());
    if (m_indexes.contains(index))
        m_indexes.remove(index);
    else
        m_indexes.set(index);
    m_view.notify_selection_changed({});
}

bool GModelSelection::remove(const GModelIndex& index)
{
    ASSERT(index.is_valid());
    if (!m_indexes.contains(index))
        return false;
    m_indexes.remove(index);
    m_view.notify_selection_changed({});
    return true;
}

void GModelSelection::clear()
{
    if (m_indexes.is_empty())
        return;
    m_indexes.clear();
    m_view.notify_selection_changed({});
}