QGCPendingParamWidget.cc 4.86 KB
Newer Older
1 2
#include "QGCPendingParamWidget.h"

3 4 5
#include <QGridLayout>
#include <QPushButton>

6 7 8 9 10
#include "UASManager.h"
#include "UASParameterCommsMgr.h"


QGCPendingParamWidget::QGCPendingParamWidget(QObject *parent) :
11
    QGCParamWidget((QWidget*)parent)
12 13 14 15
{
}


16
void QGCPendingParamWidget::connectToParamManager()
17
{
18
    paramMgr = mav->getParamManager();
19

20
    // Listen to updated param signals from the data model
21
    connect(paramMgr, SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
22
            this, SLOT(handlePendingParamUpdate(int , const QString& ,  QVariant, bool )));
23

24 25 26
    // Listen to communications status messages so we can display them
    connect(paramMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
            this, SLOT(handleParamStatusMsgUpdate(QString , int )));
27 28
}

29 30

void QGCPendingParamWidget::disconnectFromParamManager()
31
{
32
    // Listen to updated param signals from the data model
33
    disconnect(paramMgr, SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
34 35 36
            this, SLOT(handlePendingParamUpdate(int , const QString& ,  QVariant, bool )));

    // Listen to communications status messages so we can display them
37
    disconnect(paramMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
38
            this, SLOT(handleParamStatusMsgUpdate(QString , int )));
39 40

    paramMgr = NULL;
41 42
}

43 44 45 46 47 48 49 50 51 52 53 54

void QGCPendingParamWidget::disconnectViewSignalsAndSlots()
{
    //we ignore edits from the tree view
}


void QGCPendingParamWidget::connectViewSignalsAndSlots()
{
    //we ignore edits from the tree view
}

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
void QGCPendingParamWidget::handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending)
{
   // qDebug() << "handlePendingParamUpdate:" << paramName << "with updatingParamNameLock:" << updatingParamNameLock;

    if (updatingParamNameLock == paramName) {
        //qDebug() << "ignoring bounce from " << paramName;
        return;
    }
    else {
        updatingParamNameLock = paramName;
    }

    QTreeWidgetItem* paramItem = updateParameterDisplay(compId,paramName,value);

    if (isPending) {
        QTreeWidgetItem* paramItem = updateParameterDisplay(compId,paramName,value);
        paramItem->setFlags(paramItem->flags() & ~Qt::ItemIsEditable); //disallow editing
        paramItem->setBackground(0, QBrush(QColor(QGC::colorOrange)));
        paramItem->setBackground(1, QBrush(QColor(QGC::colorOrange)));
        tree->expandAll();
    }
    else {
        //we don't display non-pending items
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        QTreeWidgetItem* groupItem = paramItem->parent();
        if (NULL != groupItem) {
            tree->setUpdatesEnabled(false);
            QTreeWidgetItem* componentItem = NULL;
            if (1 == groupItem->childCount()) {
                componentItem = groupItem->parent();
            }

            //always remove the actual paramItem from its parent
            groupItem->removeChild(paramItem);

            //now we may need to remove the groupItem if it has no more children
            if (NULL != componentItem) {
                //remove the group from our internal data structures
                QMap<QString, QTreeWidgetItem*>* compParamGroups = paramGroups.value(compId);
                QString groupStr = paramName.section("_", 0, 0, QString::SectionSkipEmpty);
                compParamGroups->remove(groupStr);
                //remove the group item from componentItems
                componentItems->value(compId)->removeChild(groupItem);
                // remove the group item from the tree widget itself
                componentItem->removeChild(groupItem);

                if (0 == componentItem->childCount()) {
                    //the component itself no longer has any pending changes: remove it
                    paramGroups.remove(compId);
                    componentItems->remove(compId);
                    QTreeWidgetItem* compTop = tree->takeTopLevelItem(tree->indexOfTopLevelItem(componentItem));
                    delete compTop; //we own it after take
                }
            }
            tree->setUpdatesEnabled(true);
            tree->update();
110 111

        }
112 113 114 115 116
    }

    updatingParamNameLock.clear();

}
117

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
void QGCPendingParamWidget::addActionButtonsToLayout(QGridLayout* layout)
{

    QPushButton* setButton = new QPushButton(tr("Set"));
    setButton->setToolTip(tr("Send pending parameters to volatile onboard memory"));
    setButton->setWhatsThis(tr("Send pending parameters to volatile onboard memory"));
    connect(setButton, SIGNAL(clicked()),
            paramMgr, SLOT(sendPendingParameters()));
    layout->addWidget(setButton, 2, 0);

    QPushButton* clearButton = new QPushButton(tr("Clear"));
    clearButton->setToolTip(tr("Clear pending parameters without sending"));
    clearButton->setWhatsThis(tr("Clear pending parameters without sending"));
    connect(clearButton, SIGNAL(clicked()),
            paramMgr, SLOT(clearAllPendingParams()));
    layout->addWidget(clearButton, 2, 1);


}