aboutsummaryrefslogtreecommitdiff
path: root/selectionhandler.cpp
blob: 190040d711176ece885795c27dbe16561453acf6 (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
#include "selectionhandler.h"

#include <QDebug>

SelectionHandler::SelectionHandler(int numItems)
    : m_selection(numItems, false)
{
}

void SelectionHandler::setSelection(const std::vector<bool> &selection)
{
    if (m_selection.size() != selection.size()) {
        return;
    }

    m_selection = selection;
    emit selectionChanged(m_selection);
}

void SelectionHandler::setSelected(int item, bool selected)
{
    m_selection[item] = selected;
    emit selectionChanged(m_selection);
}

void SelectionHandler::setSelected(const std::set<int> &items, bool selected)
{
    for (auto it = items.cbegin(); it != items.cend(); it++) {
        m_selection[*it] = selected;
    }

    emit selectionChanged(m_selection);
}