QGCUDPLinkConfiguration.cc 1.11 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 31 32 33 34 35 36 37
#include <QInputDialog>

#include "QGCUDPLinkConfiguration.h"
#include "ui_QGCUDPLinkConfiguration.h"

QGCUDPLinkConfiguration::QGCUDPLinkConfiguration(UDPLink* link, QWidget *parent) :
    QWidget(parent),
    link(link),
    ui(new Ui::QGCUDPLinkConfiguration)
{
    ui->setupUi(this);
    ui->portSpinBox->setValue(link->getPort());
    connect(ui->portSpinBox, SIGNAL(valueChanged(int)), link, SLOT(setPort(int)));
    connect(ui->addIPButton, SIGNAL(clicked()), this, SLOT(addHost()));
}

QGCUDPLinkConfiguration::~QGCUDPLinkConfiguration()
{
    delete ui;
}

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

void QGCUDPLinkConfiguration::addHost()
{
    bool ok;
    QString hostName = QInputDialog::getText(this, tr("Add a new IP address / hostname to MAVLink"),
38 39
                       tr("Host (hostname:port):"), QLineEdit::Normal,
                       "localhost:14555", &ok);
40
    if (ok && !hostName.isEmpty())
41
        link->addHost(hostName);
42
}