ParameterInterface.cc 3.45 KB
Newer Older
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
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Definition of class ParameterInterface
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

31 32
#include <QTreeWidget>

pixhawk's avatar
pixhawk committed
33 34 35
#include "ParameterInterface.h"
#include "UASManager.h"
#include "ui_ParameterInterface.h"
lm's avatar
lm committed
36
#include "QGCSensorSettingsWidget.h"
pixhawk's avatar
pixhawk committed
37

38
#include <QDebug>
39
#include <QSettings>
40

pixhawk's avatar
pixhawk committed
41
ParameterInterface::ParameterInterface(QWidget *parent) :
42 43 44 45
    QWidget(parent),
    paramWidgets(new QMap<int, QGCParamWidget*>()),
    curr(-1),
    m_ui(new Ui::parameterWidget)
pixhawk's avatar
pixhawk committed
46 47
{
    m_ui->setupUi(this);
48

49 50
    QSettings settings;

lm's avatar
lm committed
51 52 53 54
    // Get current MAV list
    QList<UASInterface*> systems = UASManager::instance()->getUASList();

    // Add each of them
55
    foreach (UASInterface* sys, systems) {
lm's avatar
lm committed
56 57 58
        addUAS(sys);
    }

pixhawk's avatar
pixhawk committed
59 60
    // Setup MAV connections
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)));
61
    connect(UASManager::instance(), SIGNAL(activeUASSetListIndex(int)), this, SLOT(selectUAS(int)));
62
    this->setVisible(false);
pixhawk's avatar
pixhawk committed
63 64 65 66
}

ParameterInterface::~ParameterInterface()
{
67
    delete paramWidgets;
pixhawk's avatar
pixhawk committed
68 69 70
    delete m_ui;
}

pixhawk's avatar
pixhawk committed
71 72
void ParameterInterface::selectUAS(int index)
{
73
    m_ui->stackedWidget->setCurrentIndex(index);
74
    m_ui->sensorSettings->setCurrentIndex(index);
pixhawk's avatar
pixhawk committed
75 76 77
    curr = index;
}

pixhawk's avatar
pixhawk committed
78 79 80 81 82 83
/**
 *
 * @param uas System to add to list
 */
void ParameterInterface::addUAS(UASInterface* uas)
{
84
    int uasId = uas->getUASID();
tstellanova's avatar
tstellanova committed
85 86
    qDebug() << "ParameterInterface::addUAS : " << uasId ;

87 88 89 90
    if (paramWidgets->contains(uasId) ) {
        return;
    }

91 92 93
    QGCParamWidget* paramWidget = new QGCParamWidget(this);
    paramWidget = (QGCParamWidget*)paramWidget->initWithUAS(uas);

94
    QString ptrStr;
95
    ptrStr.sprintf("QGCParamWidget %8p (parent %8p)", paramWidget,this);
96
    qDebug() << "Created " << ptrStr << " for UAS id: " << uasId << " count: " << paramWidgets->count();
97

98 99
    paramWidgets->insert(uasId, paramWidget);
    m_ui->stackedWidget->addWidget(paramWidget);
lm's avatar
lm committed
100

101
    QGCSensorSettingsWidget* sensor = NULL;
lm's avatar
lm committed
102

103 104
        sensor = new QGCSensorSettingsWidget(uas, this);
        m_ui->sensorSettings->addWidget(sensor);
lm's avatar
lm committed
105 106

    // Set widgets as default
107
    if (curr == -1) {
108
        // Clear
109 110
        if (m_ui->sensorSettings && sensor)
            m_ui->sensorSettings->setCurrentWidget(sensor);
111
        m_ui->stackedWidget->setCurrentWidget(paramWidget);
112
        curr = 0;
pixhawk's avatar
pixhawk committed
113
    }
pixhawk's avatar
pixhawk committed
114 115 116 117 118 119 120 121 122 123 124 125
}

void ParameterInterface::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}