acmd.cpp 1.96 KB
Newer Older
Giacomo Strangolino's avatar
Giacomo Strangolino committed
1
2
3
4
5
#include "acmd.h"
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QMultiMap>
#include <AlarmTreeWidget.h>
Giacomo Strangolino's avatar
Giacomo Strangolino committed
6
#include <AlarmTreeWidgetItem.h>
Giacomo Strangolino's avatar
Giacomo Strangolino committed
7
8
9
10
11
12
13
14
15
16
17
18
#include <quwriter.h>

Acmd::Acmd() {

}

void Acmd::ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool& fpoo) {
    QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
    foreach(const QString& dev, map.uniqueKeys()) {
        QuWriter *w = new QuWriter(nullptr, cup, fpoo);
        const QStringList &alarms = map.values(dev);
        w->setAutoDestroy(true);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
19
        w->setTarget(QString("%1->Ack").arg(dev));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
20
        printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
21
        w->execute(alarms);
Giacomo Strangolino's avatar
Giacomo Strangolino committed
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

        /* stop new */
        QuWriter *stopNewWriter = new QuWriter(nullptr, cup, fpoo);
        stopNewWriter->setAutoDestroy(true);
        stopNewWriter->setTarget(dev + "->StopNew");
        stopNewWriter->execute();
    }
}

void Acmd::silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) {
    QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
    foreach(const QString& dev, map.uniqueKeys()) {
        QuWriter *w = new QuWriter(nullptr, cup, fpoo);
        const QStringList &alarms = map.values(dev);
        w->setAutoDestroy(true);
        w->setTarget(dev + "->Silence");
        printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
        w->execute(alarms);
    }
}

QMultiMap<QString, QString> Acmd::m_getDevAlarmMap(const QTreeWidget *tw, bool all) const {
    QMultiMap<QString, QString> map;
    QList<QTreeWidgetItem *> selected;
    for(int i = 0; all && i < tw->topLevelItemCount(); i++)
        selected << tw->topLevelItem(i);
    if(!all)
        selected = tw->selectedItems();
    foreach(QTreeWidgetItem *si, selected)
Giacomo Strangolino's avatar
Giacomo Strangolino committed
51
        map.insert(si->data(AlarmTreeWidgetItem::Device, Qt::UserRole).toString(), si->text(AlarmTreeWidget::ALARM));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
52
53
    return map;
}