algorithm.cpp
1.36 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
#include <QStringList>
#include <openbr/openbr.h>
#include "algorithm.h"
/**** ALGORITHM ****/
/*** PUBLIC ***/
br::Algorithm::Algorithm(QWidget *parent)
: QMenu(parent)
{
setTitle("Algorithm");
br_set_property("enrollAll", "true");
connect(this, SIGNAL(triggered(QAction*)), this, SLOT(setAlgorithm(QAction*)));
}
/*** PUBLIC SLOTS ***/
bool br::Algorithm::addAlgorithm(const QString &algorithm, const QString &displayName)
{
static QStringList availableAlgorithms;
if (availableAlgorithms.isEmpty())
availableAlgorithms = QString(br_objects("Abbreviation", ".*", false)).split("\n");
if (!availableAlgorithms.contains(algorithm))
return false;
QString name;
if (displayName.isEmpty()) {
name = algorithm;
} else {
displayNames.insert(displayName, algorithm);
name = displayName;
}
QAction *action = addAction(name);
action->setCheckable(true);
if (actions().size() == 1) action->trigger();
return true;
}
/*** PRIVATE SLOTS ***/
void br::Algorithm::setAlgorithm(QAction *action)
{
QString algorithm = action->text();
if (displayNames.contains(algorithm))
algorithm = displayNames[algorithm];
br_set_property("algorithm", qPrintable(algorithm));
emit newAlgorithm(algorithm);
}
#include "moc_algorithm.cpp"