-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAlgorithmSelectionWidget.cpp
More file actions
82 lines (68 loc) · 2.97 KB
/
Copy pathAlgorithmSelectionWidget.cpp
File metadata and controls
82 lines (68 loc) · 2.97 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "../AlgorithmSelectionWidget.h"
#include <QString>
#include <QComboBox>
#include "biotracker/Registry.h"
namespace BioTracker {
namespace Gui {
AlgorithmSelectionWidget::AlgorithmSelectionWidget(QWidget *parent,
Core::BioTrackerApp &facade)
: QWidget(parent)
, m_ui(parent)
, m_biotracker(facade) {
initConnects();
initAlgorithmList();
m_ui.cb_algorithms->setInsertPolicy(
QComboBox::InsertPolicy::InsertAlphabetically);
}
void AlgorithmSelectionWidget::addTrackingAlgorithm(const Core::TrackerType type) {
const QString trackerName = QString::fromStdString(
m_biotracker.getRegistry().getStringByType().at(type));
m_ui.cb_algorithms->addItem(trackerName);
const int index = m_ui.cb_algorithms->findText(trackerName);
m_ui.cb_algorithms->setCurrentIndex(index);
}
void AlgorithmSelectionWidget::initAlgorithmList() {
// add NoTracker first
m_ui.cb_algorithms->addItem(QString::fromStdString(
m_biotracker.getRegistry().getStringByType().at(Core::NoTracking)));
// add Trackers
for (auto &algByStr : m_biotracker.getRegistry().getTypeByString()) {
if (algByStr.second != Core::NoTracking) {
m_ui.cb_algorithms->addItem(QString::fromStdString(algByStr.first));
}
}
}
void AlgorithmSelectionWidget::initConnects() {
QObject::connect(&m_biotracker.getRegistry(), &Core::Registry::newTracker,
this, &AlgorithmSelectionWidget::addTrackingAlgorithm);
QObject::connect(m_ui.cb_algorithms, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &AlgorithmSelectionWidget::trackingAlgorithmSelected);
QObject::connect(m_ui.chk_enableTracking, &QCheckBox::toggled,
this, &AlgorithmSelectionWidget::enableDisableTracking);
const QString shortcutTrackingKey = QString::fromStdString(
m_biotracker.getSettings().getValueOrDefault<std::string>
(GuiParam::SHORTCUT_TRACKING, "T"));
auto *shortcutTracking = new QShortcut(QKeySequence(shortcutTrackingKey), this);
QObject::connect(shortcutTracking, &QShortcut::activated, m_ui.chk_enableTracking,
&QCheckBox::click);
}
void AlgorithmSelectionWidget::trackingAlgorithmSelected(const QString &name) {
m_biotracker.setTrackingAlgorithm(name.toStdString());
// check if we have "any" tracking or not
auto noTrackingStr = QString::fromStdString(m_biotracker.getRegistry().getStringByType().at(Core::NoTracking));
if (name.compare(noTrackingStr) == 0) {
m_ui.chk_enableTracking->setChecked(true);
m_ui.chk_enableTracking->setEnabled(false);
} else {
m_ui.chk_enableTracking->setEnabled(true);
}
}
void AlgorithmSelectionWidget::enableDisableTracking(bool checked) {
if (checked) {
m_biotracker.enableTracking();
} else {
m_biotracker.disableTracking();
}
}
}
}