WaypointEditableView.cc 21.5 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
/*===================================================================
pixhawk's avatar
pixhawk committed
2 3 4 5 6 7 8 9
======================================================================*/

/**
 * @file
 *   @brief Displays one waypoint
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *   @author Benjamin Knecht <mavteam@student.ethz.ch>
10
 *   @author Petri Tanskanen <mavteam@student.ethz.ch>
pixhawk's avatar
pixhawk committed
11 12 13 14 15 16
 *
 */

#include <QDoubleSpinBox>
#include <QDebug>

17 18
#include <cmath>
#include <qmath.h>
pixhawk's avatar
pixhawk committed
19

20 21
#include "WaypointEditableView.h"
#include "ui_WaypointEditableView.h"
22

23
#include "MainWindow.h"
24 25 26 27 28 29 30 31 32 33 34 35 36
#include "mission/QGCMissionNavWaypoint.h"
#include "mission/QGCMissionNavLoiterUnlim.h"
#include "mission/QGCMissionNavLoiterTurns.h"
#include "mission/QGCMissionNavLoiterTime.h"
#include "mission/QGCMissionNavReturnToLaunch.h"
#include "mission/QGCMissionNavLand.h"
#include "mission/QGCMissionNavTakeoff.h"
#include "mission/QGCMissionNavSweep.h"
#include "mission/QGCMissionConditionDelay.h"
#include "mission/QGCMissionDoJump.h"
#include "mission/QGCMissionDoStartSearch.h"
#include "mission/QGCMissionDoFinishSearch.h"
#include "mission/QGCMissionOther.h"
pixhawk's avatar
pixhawk committed
37

pixhawk's avatar
pixhawk committed
38

39
WaypointEditableView::WaypointEditableView(Waypoint* wp, QWidget* parent) :
40
    QWidget(parent),
41
    viewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DEFAULT),
42
    m_ui(new Ui::WaypointEditableView)
pixhawk's avatar
pixhawk committed
43 44 45 46
{
    m_ui->setupUi(this);

    this->wp = wp;
pixhawk's avatar
pixhawk committed
47
    connect(wp, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*)));
48

49
    // CUSTOM COMMAND WIDGET
pixhawk's avatar
pixhawk committed
50
    QHBoxLayout *layout = new QHBoxLayout;
51
    layout->setSpacing(2);
52
    layout->setContentsMargins(4, 0 ,4 ,0);
53
    m_ui->customActionWidget->setLayout(layout);
pixhawk's avatar
pixhawk committed
54

55
    MissionNavWaypointWidget = NULL;
56 57 58
    MissionNavLoiterUnlimWidget = NULL;
    MissionNavLoiterTurnsWidget = NULL;
    MissionNavLoiterTimeWidget = NULL;
59 60 61
    MissionNavReturnToLaunchWidget = NULL;
    MissionNavLandWidget = NULL;
    MissionNavTakeoffWidget = NULL;
62
    MissionNavSweepWidget = NULL;
63
    MissionConditionDelayWidget = NULL;
64 65 66
    MissionDoJumpWidget = NULL;    
    MissionDoStartSearchWidget = NULL;
    MissionDoFinishSearchWidget = NULL;
67
    MissionOtherWidget = NULL;
68 69


70
    // add actions
71 72 73 74 75 76 77
    m_ui->comboBox_action->addItem(tr("NAV: Waypoint"),MAV_CMD_NAV_WAYPOINT);
    m_ui->comboBox_action->addItem(tr("NAV: TakeOff"),MAV_CMD_NAV_TAKEOFF);
    m_ui->comboBox_action->addItem(tr("NAV: Loiter Unlim."),MAV_CMD_NAV_LOITER_UNLIM);
    m_ui->comboBox_action->addItem(tr("NAV: Loiter Time"),MAV_CMD_NAV_LOITER_TIME);
    m_ui->comboBox_action->addItem(tr("NAV: Loiter Turns"),MAV_CMD_NAV_LOITER_TURNS);
    m_ui->comboBox_action->addItem(tr("NAV: Ret. to Launch"),MAV_CMD_NAV_RETURN_TO_LAUNCH);
    m_ui->comboBox_action->addItem(tr("NAV: Land"),MAV_CMD_NAV_LAND);
78
    //m_ui->comboBox_action->addItem(tr("NAV: Target"),MAV_CMD_NAV_TARGET);
pixhawk's avatar
pixhawk committed
79
    m_ui->comboBox_action->addItem(tr("IF: Delay over"),MAV_CMD_CONDITION_DELAY);
lm's avatar
lm committed
80
    //m_ui->comboBox_action->addItem(tr("IF: Yaw angle is"),MAV_CMD_CONDITION_YAW);
81 82 83
    m_ui->comboBox_action->addItem(tr("DO: Jump to Index"),MAV_CMD_DO_JUMP);    
#ifdef MAVLINK_ENABLED_PIXHAWK
    m_ui->comboBox_action->addItem(tr("NAV: Sweep"),MAV_CMD_NAV_SWEEP);
84 85
    m_ui->comboBox_action->addItem(tr("Do: Start Search"),MAV_CMD_DO_START_SEARCH);
    m_ui->comboBox_action->addItem(tr("Do: Finish Search"),MAV_CMD_DO_FINISH_SEARCH);
86
#endif
87
    m_ui->comboBox_action->addItem(tr("Other"), MAV_CMD_ENUM_END);
88

89
    // add frames
90 91 92
    m_ui->comboBox_frame->addItem("Global/Abs. Alt",MAV_FRAME_GLOBAL);
    m_ui->comboBox_frame->addItem("Global/Rel. Alt", MAV_FRAME_GLOBAL_RELATIVE_ALT);
    m_ui->comboBox_frame->addItem("Local(NED)",MAV_FRAME_LOCAL_NED);
93 94 95
    m_ui->comboBox_frame->addItem("Mission",MAV_FRAME_MISSION);

    // Initialize view correctly
96 97
    int actionID = wp->getAction();
    initializeActionView(actionID);
98
    updateValues();
99
    updateActionView(actionID);
pixhawk's avatar
pixhawk committed
100

101
    // Check for mission frame
102 103
    if (wp->getFrame() == MAV_FRAME_MISSION)
    {
104 105 106
        m_ui->comboBox_action->setCurrentIndex(m_ui->comboBox_action->count()-1);
    }

pixhawk's avatar
pixhawk committed
107 108 109 110
    connect(m_ui->upButton, SIGNAL(clicked()), this, SLOT(moveUp()));
    connect(m_ui->downButton, SIGNAL(clicked()), this, SLOT(moveDown()));
    connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(remove()));

pixhawk's avatar
pixhawk committed
111 112
    connect(m_ui->autoContinue, SIGNAL(stateChanged(int)), this, SLOT(changedAutoContinue(int)));
    connect(m_ui->selectedBox, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
113 114
    connect(m_ui->comboBox_action, SIGNAL(activated(int)), this, SLOT(changedAction(int)));
    connect(m_ui->comboBox_frame, SIGNAL(activated(int)), this, SLOT(changedFrame(int)));
pixhawk's avatar
pixhawk committed
115

pixhawk's avatar
pixhawk committed
116 117
}

118
void WaypointEditableView::moveUp()
pixhawk's avatar
pixhawk committed
119 120 121 122
{
    emit moveUpWaypoint(wp);
}

123
void WaypointEditableView::moveDown()
pixhawk's avatar
pixhawk committed
124 125 126 127
{
    emit moveDownWaypoint(wp);
}

Alejandro's avatar
Alejandro committed
128

129
void WaypointEditableView::remove()
pixhawk's avatar
pixhawk committed
130 131
{
    emit removeWaypoint(wp);
132
    deleteLater();
pixhawk's avatar
pixhawk committed
133 134
}

135
void WaypointEditableView::changedAutoContinue(int state)
pixhawk's avatar
pixhawk committed
136 137
{
    if (state == 0)
138
        wp->setAutocontinue(false);
pixhawk's avatar
pixhawk committed
139
    else
140
        wp->setAutocontinue(true);
pixhawk's avatar
pixhawk committed
141 142
}

143
void WaypointEditableView::updateActionView(int action)
144
{    
145 146
    //Hide all
    if(MissionNavWaypointWidget) MissionNavWaypointWidget->hide();
147 148 149
    if(MissionNavLoiterUnlimWidget) MissionNavLoiterUnlimWidget->hide();
    if(MissionNavLoiterTurnsWidget) MissionNavLoiterTurnsWidget->hide();
    if(MissionNavLoiterTimeWidget) MissionNavLoiterTimeWidget->hide();
150 151 152
    if(MissionNavReturnToLaunchWidget) MissionNavReturnToLaunchWidget->hide();
    if(MissionNavLandWidget) MissionNavLandWidget->hide();
    if(MissionNavTakeoffWidget) MissionNavTakeoffWidget->hide();
153
    if(MissionNavSweepWidget) MissionNavSweepWidget->hide();
154 155
    if(MissionConditionDelayWidget) MissionConditionDelayWidget->hide();
    if(MissionDoJumpWidget) MissionDoJumpWidget->hide();
156 157
    if(MissionDoStartSearchWidget) MissionDoStartSearchWidget->hide();
    if(MissionDoFinishSearchWidget) MissionDoFinishSearchWidget->hide();
158
    if(MissionOtherWidget) MissionOtherWidget->hide();
159 160 161 162 163

    //Show only the correct one
    if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
    {
        switch(action) {
164 165 166
        case MAV_CMD_NAV_WAYPOINT:
            if(MissionNavWaypointWidget) MissionNavWaypointWidget->show();
            break;
167
        case MAV_CMD_NAV_LOITER_UNLIM:
168 169
            if(MissionNavLoiterUnlimWidget) MissionNavLoiterUnlimWidget->show();
            break;
170
        case MAV_CMD_NAV_LOITER_TURNS:
171 172
            if(MissionNavLoiterTurnsWidget) MissionNavLoiterTurnsWidget->show();
            break;
173
        case MAV_CMD_NAV_LOITER_TIME:
174
            if(MissionNavLoiterTimeWidget) MissionNavLoiterTimeWidget->show();
175
            break;
176
        case MAV_CMD_NAV_RETURN_TO_LAUNCH:
177 178
            if(MissionNavReturnToLaunchWidget) MissionNavReturnToLaunchWidget->show();
            break;
179
        case MAV_CMD_NAV_LAND:
180 181
            if(MissionNavLandWidget) MissionNavLandWidget->show();
            break;
182
        case MAV_CMD_NAV_TAKEOFF:
183 184
            if(MissionNavTakeoffWidget) MissionNavTakeoffWidget->show();
            break;
185 186
        case MAV_CMD_CONDITION_DELAY:
            if(MissionConditionDelayWidget) MissionConditionDelayWidget->show();
187 188 189 190
            break;
        case MAV_CMD_DO_JUMP:
            if(MissionDoJumpWidget) MissionDoJumpWidget->show();
            break;
191 192 193 194
        #ifdef MAVLINK_ENABLED_PIXHAWK
        case MAV_CMD_NAV_SWEEP:
            if(MissionNavSweepWidget) MissionNavSweepWidget->show();
            break;
195 196 197 198 199 200
        case MAV_CMD_DO_START_SEARCH:
            if(MissionDoStartSearchWidget) MissionDoStartSearchWidget->show();
            break;
        case MAV_CMD_DO_FINISH_SEARCH:
            if(MissionDoFinishSearchWidget) MissionDoFinishSearchWidget->show();
            break;
201 202
        #endif

203 204
        default:
            if(MissionOtherWidget) MissionOtherWidget->show();
205
            viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING;
206 207 208 209 210 211
            break;
        }
    }
    else
    {
        if(MissionOtherWidget) MissionOtherWidget->show();
212 213 214
    }
}

215 216 217
/**
 * @param index The index of the combo box of the action entry, NOT the action ID
 */
218
void WaypointEditableView::changedAction(int index)
219 220
{
    // set waypoint action
221 222 223 224 225 226 227 228 229
    int actionID = m_ui->comboBox_action->itemData(index).toUInt();
    if (actionID == QVariant::Invalid || actionID == MAV_CMD_ENUM_END)
    {
        viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING;
    }
    else //(actionID < MAV_CMD_ENUM_END && actionID >= 0)
    {
        viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DEFAULT;
        MAV_CMD action = (MAV_CMD) actionID;
230 231
        wp->setAction(action);
    }
232 233 234 235 236
    // change the view
    initializeActionView(actionID);
    updateValues();
    updateActionView(actionID);
}
237

238 239 240 241
void WaypointEditableView::initializeActionView(int actionID)
{
    //initialize a new action-widget, if needed.
    switch(actionID) {
242 243 244 245 246
    case MAV_CMD_NAV_WAYPOINT:
        if (!MissionNavWaypointWidget)
        {
            MissionNavWaypointWidget = new QGCMissionNavWaypoint(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavWaypointWidget);
247
        }
248
        break;
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
    case MAV_CMD_NAV_LOITER_UNLIM:
        if (!MissionNavLoiterUnlimWidget)
        {
            MissionNavLoiterUnlimWidget = new QGCMissionNavLoiterUnlim(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavLoiterUnlimWidget);
        }
        break;
    case MAV_CMD_NAV_LOITER_TURNS:
        if (!MissionNavLoiterTurnsWidget)
        {
            MissionNavLoiterTurnsWidget = new QGCMissionNavLoiterTurns(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavLoiterTurnsWidget);
        }
        break;
    case MAV_CMD_NAV_LOITER_TIME:
        if (!MissionNavLoiterTimeWidget)
        {
            MissionNavLoiterTimeWidget = new QGCMissionNavLoiterTime(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavLoiterTimeWidget);
        }
        break;
    case MAV_CMD_NAV_RETURN_TO_LAUNCH:
271 272 273 274 275 276
        if (!MissionNavReturnToLaunchWidget)
        {
            MissionNavReturnToLaunchWidget = new QGCMissionNavReturnToLaunch(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavReturnToLaunchWidget);
        }
        break;
277
    case MAV_CMD_NAV_LAND:
278 279 280 281 282 283
        if (!MissionNavLandWidget)
        {
            MissionNavLandWidget = new QGCMissionNavLand(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavLandWidget);
        }
        break;
284
    case MAV_CMD_NAV_TAKEOFF:
285 286 287 288 289 290
        if (!MissionNavTakeoffWidget)
        {
            MissionNavTakeoffWidget = new QGCMissionNavTakeoff(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavTakeoffWidget);
        }
        break;
291 292 293 294 295 296 297 298
    case MAV_CMD_CONDITION_DELAY:
        if (!MissionConditionDelayWidget)
        {
            MissionConditionDelayWidget = new QGCMissionConditionDelay(this);
            m_ui->customActionWidget->layout()->addWidget(MissionConditionDelayWidget);
        }
        break;
    case MAV_CMD_DO_JUMP:
299
        if (!MissionDoJumpWidget)
300
        {
301
            MissionDoJumpWidget = new QGCMissionDoJump(this);
302
            m_ui->customActionWidget->layout()->addWidget(MissionDoJumpWidget);
303
        }
304
        break;
305 306 307 308 309 310 311 312
 #ifdef MAVLINK_ENABLED_PIXHAWK
    case MAV_CMD_NAV_SWEEP:
        if (!MissionNavSweepWidget)
        {
            MissionNavSweepWidget = new QGCMissionNavSweep(this);
            m_ui->customActionWidget->layout()->addWidget(MissionNavSweepWidget);
        }
        break;
313 314 315 316 317 318 319 320 321 322 323 324 325 326
    case MAV_CMD_DO_START_SEARCH:
        if (!MissionDoStartSearchWidget)
        {
            MissionDoStartSearchWidget = new QGCMissionDoStartSearch(this);
            m_ui->customActionWidget->layout()->addWidget(MissionDoStartSearchWidget);
        }
        break;
    case MAV_CMD_DO_FINISH_SEARCH:
        if (!MissionDoFinishSearchWidget)
        {
            MissionDoFinishSearchWidget = new QGCMissionDoFinishSearch(this);
            m_ui->customActionWidget->layout()->addWidget(MissionDoFinishSearchWidget);
        }
        break;
327
#endif
328 329 330
    case MAV_CMD_ENUM_END:
    default:
        if (!MissionOtherWidget)
331
        {
332 333
            MissionOtherWidget = new QGCMissionOther(this);
            m_ui->customActionWidget->layout()->addWidget(MissionOtherWidget);
334
        }
335
        break;
336 337 338
    }
}

339
void WaypointEditableView::deleted(QObject* waypoint)
pixhawk's avatar
pixhawk committed
340
{
341
    Q_UNUSED(waypoint);
pixhawk's avatar
pixhawk committed
342 343
}

344
void WaypointEditableView::changedFrame(int index)
345 346 347 348 349 350
{
    // set waypoint action
    MAV_FRAME frame = (MAV_FRAME)m_ui->comboBox_frame->itemData(index).toUInt();
    wp->setFrame(frame);
}

351
void WaypointEditableView::changedCurrent(int state)
352
{    
353 354 355
    if (state == 0)
    {
        if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current
356
        {            
357 358 359 360
            m_ui->selectedBox->setChecked(true);
            m_ui->selectedBox->setCheckState(Qt::Checked);
        }
        else
361
        {            
362
            m_ui->selectedBox->setChecked(false);
363
            m_ui->selectedBox->setCheckState(Qt::Unchecked);            
364 365 366
        }
    }
    else
367
    {       
pixhawk's avatar
pixhawk committed
368
        wp->setCurrent(true);
369
        emit changeCurrentWaypoint(wp->getId());   //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
370
    }    
pixhawk's avatar
pixhawk committed
371 372
}

373
void WaypointEditableView::updateValues()
374
{
pixhawk's avatar
pixhawk committed
375 376
    // Check if we just lost the wp, delete the widget
    // accordingly
377
    if (!wp) {
pixhawk's avatar
pixhawk committed
378 379 380
        deleteLater();
        return;
    }
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422

    //wp->blockSignals(true);

    // Deactivate all QDoubleSpinBox signals due to
    // unwanted rounding effects
    for (int j = 0; j  < children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(children().at(j));
        if (spin)
        {
            //qDebug() << "DEACTIVATED SPINBOX #" << j;
            spin->blockSignals(true);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QWidget* item = dynamic_cast<QWidget*>(children().at(j));
            if (item)
            {
                //qDebug() << "FOUND WIDGET BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                        //qDebug() << "DEACTIVATED SPINBOX #" << k;
                        spin->blockSignals(true);
                    }
                }
            }
        }
    }

    // Block all custom action widget actions
    for (int j = 0; j  < m_ui->customActionWidget->children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(m_ui->customActionWidget->children().at(j));
        if (spin)
        {
423
            //qDebug() << "DEACTIVATED SPINBOX #" << j;
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
            spin->blockSignals(true);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QWidget* item = dynamic_cast<QWidget*>(m_ui->customActionWidget->children().at(j));
            if (item)
            {
                //qDebug() << "CUSTOM ACTIONS FOUND WIDGET BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                        //qDebug() << "DEACTIVATED SPINBOX #" << k;
                        spin->blockSignals(true);
                    }
                }
            }
        }
    }


448 449
    // update frame
    MAV_FRAME frame = wp->getFrame();
450
    int frame_index = m_ui->comboBox_frame->findData(frame);
451
    if (m_ui->comboBox_frame->currentIndex() != frame_index) {
452
        m_ui->comboBox_frame->setCurrentIndex(frame_index);        
453 454
    }

455
    // Update action
456
    MAV_CMD action = wp->getAction();
457
    int action_index = m_ui->comboBox_action->findData(action);
458 459
    if (m_ui->comboBox_action->currentIndex() != action_index)
    {
460
        if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
461
        {
462 463
            // Set to "Other" action if it was -1
            if (action_index == -1)
464
            {
465 466
                action_index = m_ui->comboBox_action->findData(MAV_CMD_ENUM_END);
                viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING;
lm's avatar
lm committed
467
            }
468
            m_ui->comboBox_action->setCurrentIndex(action_index);
469
        }
pixhawk's avatar
pixhawk committed
470
    }
471

472 473 474 475 476 477 478 479 480 481 482
    emit commandBroadcast(wp->getAction());
    emit frameBroadcast(wp->getFrame());
    emit param1Broadcast(wp->getParam1());
    emit param2Broadcast(wp->getParam2());
    emit param3Broadcast(wp->getParam3());
    emit param4Broadcast(wp->getParam4());
    emit param5Broadcast(wp->getParam5());
    emit param6Broadcast(wp->getParam6());
    emit param7Broadcast(wp->getParam7());


483 484
    if (m_ui->selectedBox->isChecked() != wp->getCurrent())
    {
pixhawk's avatar
pixhawk committed
485 486
        m_ui->selectedBox->setChecked(wp->getCurrent());
    }
487 488
    if (m_ui->autoContinue->isChecked() != wp->getAutoContinue())
    {
pixhawk's avatar
pixhawk committed
489 490
        m_ui->autoContinue->setChecked(wp->getAutoContinue());
    }
491

492
    m_ui->idLabel->setText(QString::number(wp->getId()));
493

494 495
    // Style alternating rows of Missions as lighter/darker.
    QString backGroundColor;
496 497 498 499 500 501
    static int lastId = -1;
    int currId = wp->getId() % 2;
    if (currId != lastId)
    {
        if (currId == 1)
        {
502 503 504 505 506 507 508 509
            if (MainWindow::instance()->getStyle() == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT)
            {
                backGroundColor = "#999";
            }
            else
            {
                backGroundColor = "#333";
            }
510 511 512
        }
        else
        {
513 514 515 516 517 518 519 520
            if (MainWindow::instance()->getStyle() == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT)
            {
                backGroundColor = "#CCC";
            }
            else
            {
                backGroundColor = "#555";
            }
521
        }
522 523 524 525

        QString newStyle = QString("WaypointEditableView {background-color: %1}").arg(backGroundColor);

        this->setStyleSheet(newStyle);
526 527
        lastId = currId;
    }
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592

    // Activate all QDoubleSpinBox signals due to
    // unwanted rounding effects
    for (int j = 0; j  < children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(children().at(j));
        if (spin)
        {
            //qDebug() << "ACTIVATED SPINBOX #" << j;
            spin->blockSignals(false);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QGroupBox* item = dynamic_cast<QGroupBox*>(children().at(j));
            if (item)
            {
                //qDebug() << "FOUND GROUP BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                        //qDebug() << "ACTIVATED SPINBOX #" << k;
                        spin->blockSignals(false);
                    }
                }
            }
        }
    }

    // Unblock all custom action widget actions
    for (int j = 0; j  < m_ui->customActionWidget->children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(m_ui->customActionWidget->children().at(j));
        if (spin)
        {
            //qDebug() << "ACTIVATED SPINBOX #" << j;
            spin->blockSignals(false);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QWidget* item = dynamic_cast<QWidget*>(m_ui->customActionWidget->children().at(j));
            if (item)
            {
                //qDebug() << "FOUND WIDGET BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                       //qDebug() << "ACTIVATED SPINBOX #" << k;
                        spin->blockSignals(false);
                    }
                }
            }
        }
    }

//    wp->blockSignals(false);
593 594
}

595
void WaypointEditableView::setCurrent(bool state)
pixhawk's avatar
pixhawk committed
596
{
597
    m_ui->selectedBox->blockSignals(true);
598
    m_ui->selectedBox->setChecked(state);
599
    m_ui->selectedBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
600 601
}

602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638

void WaypointEditableView::changedCommand(int mav_cmd_id)
{
    if (mav_cmd_id<MAV_CMD_ENUM_END)
    {
        wp->setAction(mav_cmd_id);
    }
}
void WaypointEditableView::changedParam1(double value)
{
    wp->setParam1(value);
}
void WaypointEditableView::changedParam2(double value)
{
    wp->setParam2(value);
}
void WaypointEditableView::changedParam3(double value)
{
    wp->setParam3(value);
}
void WaypointEditableView::changedParam4(double value)
{
    wp->setParam4(value);
}
void WaypointEditableView::changedParam5(double value)
{
    wp->setParam5(value);
}
void WaypointEditableView::changedParam6(double value)
{
    wp->setParam6(value);
}
void WaypointEditableView::changedParam7(double value)
{
    wp->setParam7(value);
}

639
WaypointEditableView::~WaypointEditableView()
pixhawk's avatar
pixhawk committed
640 641 642 643
{
    delete m_ui;
}

644
void WaypointEditableView::changeEvent(QEvent *e)
pixhawk's avatar
pixhawk committed
645 646 647 648 649 650 651 652 653
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
654

655 656 657
/**
 * Implement paintEvent() so that stylesheets work for our custom widget.
 */
658 659 660 661 662 663 664
void WaypointEditableView::paintEvent(QPaintEvent *)
 {
     QStyleOption opt;
     opt.init(this);
     QPainter p(this);
     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
 }