-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeviceList.cpp
61 lines (49 loc) · 1.76 KB
/
DeviceList.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
//
// Created by Kamil Rojewski on 15.07.2021.
//
#include <algorithm>
#include <QHBoxLayout>
#include <QListWidget>
#include <ResourceManager.h>
#include "Settings.h"
#include "DeviceList.h"
DeviceList::DeviceList(ResourceManager *resourceManager, Settings &settings, QWidget *parent)
: QWidget{parent}
, resourceManager{resourceManager}
, settings{settings}
{
const auto layout = new QHBoxLayout{this};
deviceList = new QListWidget{};
connect(deviceList, &QListWidget::itemChanged, this, &DeviceList::saveCheckState);
connect(deviceList, &QListWidget::currentItemChanged, this, [=](auto current, auto previous) {
if (current != nullptr)
emit controllerSelected(current->data(Qt::UserRole).toString());
});
layout->addWidget(deviceList);
}
void DeviceList::fillControllerList()
{
deviceList->clear();
const auto &controllers = resourceManager->GetRGBControllers();
for (const auto controller : controllers)
{
if (std::none_of(std::begin(controller->modes), std::end(controller->modes), [](const auto &mode) {
return mode.name == "Direct";
}))
{
continue;
}
const auto item = new QListWidgetItem{QString::fromStdString(controller->name)};
item->setCheckState(settings.isControllerSelected(controller->location) ? Qt::Checked : Qt::Unchecked);
item->setData(Qt::UserRole, QString::fromStdString(controller->location));
deviceList->addItem(item);
}
}
void DeviceList::saveCheckState(QListWidgetItem *item)
{
const auto location = item->data(Qt::UserRole).toString().toStdString();
if (item->checkState() == Qt::Checked)
settings.selectController(location);
else
settings.unselectController(location);
}