QGCToolWidget.cc 19.2 KB
Newer Older
1 2 3 4 5 6 7 8
#include "QGCToolWidget.h"
#include "ui_QGCToolWidget.h"

#include <QMenu>
#include <QList>
#include <QInputDialog>
#include <QDockWidget>
#include <QContextMenuEvent>
lm's avatar
lm committed
9
#include <QSettings>
10 11
#include <QFileDialog>
#include <QDesktopServices>
lm's avatar
lm committed
12

13
#include "QGCParamSlider.h"
14
#include "QGCComboBox.h"
lm's avatar
lm committed
15
#include "QGCCommandButton.h"
16 17
#include "UASManager.h"

18
QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* settings) :
19 20 21
        QWidget(parent),
        mav(NULL),
        mainMenuAction(NULL),
22
        widgetTitle(title),
23
        ui(new Ui::QGCToolWidget)
24
{
25 26 27
    ui->setupUi(this);
    if (settings) loadSettings(*settings);

28 29 30 31
    if (title == "Unnamed Tool")
    {
        widgetTitle = QString("%1 %2").arg(title).arg(QGCToolWidget::instances()->count());
    }
Lorenz Meier's avatar
Lorenz Meier committed
32
    //qDebug() << "WidgetTitle" << widgetTitle;
33 34

    setObjectName(widgetTitle);
35
    createActions();
lm's avatar
lm committed
36
    toolLayout = ui->toolLayout;
37
    toolLayout->setAlignment(Qt::AlignTop);
38
    toolLayout->setSpacing(8);
39

lm's avatar
lm committed
40
    QDockWidget* dock = dynamic_cast<QDockWidget*>(this->parentWidget());
41
    if (dock) {
42 43
        dock->setWindowTitle(widgetTitle);
        dock->setObjectName(widgetTitle+"DOCK");
lm's avatar
lm committed
44
    }
45 46

    // Try with parent
47
    dock = dynamic_cast<QDockWidget*>(parent);
48
    if (dock) {
49 50
        dock->setWindowTitle(widgetTitle);
        dock->setObjectName(widgetTitle+"DOCK");
51 52
    }

53
    this->setWindowTitle(widgetTitle);
54
    QList<UASInterface*> systems = UASManager::instance()->getUASList();
55 56
    foreach (UASInterface* uas, systems)
    {
57
        UAS* newMav = dynamic_cast<UAS*>(uas);
58 59
        if (newMav)
        {
60 61 62 63
            addUAS(uas);
        }
    }
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)));
64 65 66 67
    if (!instances()->contains(widgetTitle)) instances()->insert(widgetTitle, this);

    // Enforce storage if this not loaded from settings
    // is MUST NOT BE SAVED if it was loaded from settings!
68
    //if (!settings) storeWidgetsToSettings();
69 70 71 72
}

QGCToolWidget::~QGCToolWidget()
{
73 74
    if (mainMenuAction) mainMenuAction->deleteLater();
    if (QGCToolWidget::instances()) QGCToolWidget::instances()->remove(widgetTitle);
75 76 77
    delete ui;
}

78 79 80 81 82 83 84 85 86 87 88 89
void QGCToolWidget::setParent(QWidget *parent)
{
    QWidget::setParent(parent);
    // Try with parent
    QDockWidget* dock = dynamic_cast<QDockWidget*>(parent);
    if (dock)
    {
        dock->setWindowTitle(getTitle());
        dock->setObjectName(getTitle()+"DOCK");
    }
}

lm's avatar
lm committed
90 91 92 93
/**
 * @param parent Object later holding these widgets, usually the main window
 * @return List of all widgets
 */
94
QList<QGCToolWidget*> QGCToolWidget::createWidgetsFromSettings(QWidget* parent, QString settingsFile)
lm's avatar
lm committed
95
{
96 97 98 99 100 101 102
    // Load widgets from application settings
    QSettings* settings;

    // Or load them from a settings file
    if (!settingsFile.isEmpty())
    {
        settings = new QSettings(settingsFile, QSettings::IniFormat);
Lorenz Meier's avatar
Lorenz Meier committed
103
       //qDebug() << "LOADING SETTINGS FROM" << settingsFile;
104 105 106 107
    }
    else
    {
        settings = new QSettings();
Lorenz Meier's avatar
Lorenz Meier committed
108
        //qDebug() << "LOADING SETTINGS FROM DEFAULT" << settings->fileName();
109 110
    }

lm's avatar
lm committed
111
    QList<QGCToolWidget*> newWidgets;
112
    int size = settings->beginReadArray("QGC_TOOL_WIDGET_NAMES");
113 114
    for (int i = 0; i < size; i++)
    {
115
        settings->setArrayIndex(i);
116
        QString name = settings->value("TITLE", "").toString();
lm's avatar
lm committed
117

118
        if (!instances()->contains(name) && name.length() != 0)
119
        {
Lorenz Meier's avatar
Lorenz Meier committed
120
            //qDebug() << "CREATED WIDGET:" << name;
121
            QGCToolWidget* tool = new QGCToolWidget(name, parent, settings);
lm's avatar
lm committed
122 123
            newWidgets.append(tool);
        }
124 125 126 127 128
        else if (name.length() == 0)
        {
            // Silently catch empty widget name - sanity check
            // to survive broken settings (e.g. from user manipulation)
        }
129 130
        else
        {
Lorenz Meier's avatar
Lorenz Meier committed
131
            //qDebug() << "WIDGET" << name << "DID ALREADY EXIST, REJECTING";
132
        }
lm's avatar
lm committed
133
    }
134
    settings->endArray();
lm's avatar
lm committed
135

Lorenz Meier's avatar
Lorenz Meier committed
136
    //qDebug() << "NEW WIDGETS: " << newWidgets.size();
lm's avatar
lm committed
137 138

    // Load individual widget items
139 140
    for (int i = 0; i < newWidgets.size(); i++)
    {
141
        newWidgets.at(i)->loadSettings(*settings);
lm's avatar
lm committed
142
    }
143
    delete settings;
lm's avatar
lm committed
144 145 146 147

    return instances()->values();
}

LM's avatar
LM committed
148 149 150 151
/**
 * @param singleinstance If this is set to true, the widget settings will only be loaded if not another widget with the same title exists
 */
bool QGCToolWidget::loadSettings(const QString& settings, bool singleinstance)
152
{
153 154
    QSettings set(settings, QSettings::IniFormat);
    QStringList groups = set.childGroups();
155 156 157
    if (groups.length() > 0)
    {
        QString widgetName = groups.first();
158
	this->setObjectName(widgetName);
159
        if (singleinstance && QGCToolWidget::instances()->keys().contains(widgetName)) return false;
160 161 162
        // Do not use setTitle() here,
        // interferes with loading settings
        widgetTitle = widgetName;
Lorenz Meier's avatar
Lorenz Meier committed
163
        //qDebug() << "WIDGET TITLE LOADED: " << widgetName;
164 165 166 167 168 169 170
        loadSettings(set);
        return true;
    }
    else
    {
        return false;
    }
171
}
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
void QGCToolWidget::setSettings(QVariantMap& settings)
{
    settingsMap = settings;
    QString widgetName = getTitle();
    int size = settingsMap["count"].toInt();
    for (int j = 0; j < size; j++)
    {
        QString type = settings.value(widgetName + "\\" + QString::number(j) + "\\" + "TYPE", "UNKNOWN").toString();
        if (type == "SLIDER")
        {
            QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_SLIDER_PARAMID").toString();
            paramList.append(checkparam);
        }
        else if (type == "COMBO")
        {
            QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_COMBOBOX_PARAMID").toString();
            paramList.append(checkparam);
        }
    }
}
QList<QString> QGCToolWidget::getParamList()
{
    return paramList;
}
void QGCToolWidget::setParameterValue(int uas, int component, QString parameterName, const QVariant value)
{
//settings.setValue("QGC_PARAM_SLIDER_PARAMID", parameterName);
//settings.setValue("QGC_PARAM_COMBOBOX_PARAMID", parameterName);
    QString widgetName = getTitle();
    //settings.beginGroup(widgetName);
    //qDebug() << "LOADING FOR" << widgetName;
    //int size = settings.beginReadArray("QGC_TOOL_WIDGET_ITEMS");
    int size = settingsMap["count"].toInt();
    //qDebug() << "CHILDREN SIZE:" << size;

    for (int j = 0; j < size; j++)
    {
        QString type = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "TYPE", "UNKNOWN").toString();
        QGCToolWidgetItem* item = NULL;
        if (type == "COMMANDBUTTON")
        {
            return;
            //item = new QGCCommandButton(this);
            //qDebug() << "CREATED COMMANDBUTTON";
        }
        else if (type == "SLIDER")
        {
            QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_SLIDER_PARAMID").toString();
            if (checkparam == parameterName)
            {
                item = new QGCParamSlider(this);
                addToolWidget(item);
                item->readSettings(widgetName + "\\" + QString::number(j) + "\\",settingsMap);

                return;
            }

            //qDebug() << "CREATED PARAM SLIDER";
        }
        else if (type == "COMBO")
        {
            QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_COMBOBOX_PARAMID").toString();
            if (checkparam == parameterName)
            {
                item = new QGCComboBox(this);
                addToolWidget(item);
                item->readSettings(widgetName + "\\" + QString::number(j) + "\\",settingsMap);
                return;
            }

            //qDebug() << "CREATED PARAM COMBOBOX";
        }
    }
}

void QGCToolWidget::loadSettings(QVariantMap& settings)
{

    QString widgetName = getTitle();
    //settings.beginGroup(widgetName);
    qDebug() << "LOADING FOR" << widgetName;
    //int size = settings.beginReadArray("QGC_TOOL_WIDGET_ITEMS");
    int size = settings["count"].toInt();
    qDebug() << "CHILDREN SIZE:" << size;
    for (int j = 0; j < size; j++)
    {
        QApplication::processEvents();
        //settings.setArrayIndex(j);
        QString type = settings.value(widgetName + "\\" + QString::number(j) + "\\" + "TYPE", "UNKNOWN").toString();
        if (type != "UNKNOWN")
        {
            QGCToolWidgetItem* item = NULL;
            if (type == "COMMANDBUTTON")
            {
                item = new QGCCommandButton(this);
                //qDebug() << "CREATED COMMANDBUTTON";
            }
            else if (type == "SLIDER")
            {
                item = new QGCParamSlider(this);
                //qDebug() << "CREATED PARAM SLIDER";
            }
            else if (type == "COMBO")
            {
                item = new QGCComboBox(this);
                //qDebug() << "CREATED PARAM COMBOBOX";
            }
            if (item)
            {
                // Configure and add to layout
                addToolWidget(item);
                item->readSettings(widgetName + "\\" + QString::number(j) + "\\",settings);

                //qDebug() << "Created tool widget";
            }
        }
        else
        {
            qDebug() << "UNKNOWN TOOL WIDGET TYPE" << type;
        }
    }
    //settings.endArray();
    //settings.endGroup();
}
296 297 298 299 300

void QGCToolWidget::loadSettings(QSettings& settings)
{
    QString widgetName = getTitle();
    settings.beginGroup(widgetName);
Lorenz Meier's avatar
Lorenz Meier committed
301
    //qDebug() << "LOADING FOR" << widgetName;
302
    int size = settings.beginReadArray("QGC_TOOL_WIDGET_ITEMS");
Lorenz Meier's avatar
Lorenz Meier committed
303
    //qDebug() << "CHILDREN SIZE:" << size;
304 305
    for (int j = 0; j < size; j++)
    {
306 307
        settings.setArrayIndex(j);
        QString type = settings.value("TYPE", "UNKNOWN").toString();
308 309
        if (type != "UNKNOWN")
        {
310
            QGCToolWidgetItem* item = NULL;
311 312
            if (type == "COMMANDBUTTON")
            {
313
                item = new QGCCommandButton(this);
Lorenz Meier's avatar
Lorenz Meier committed
314
                //qDebug() << "CREATED COMMANDBUTTON";
315 316 317
            }
            else if (type == "SLIDER")
            {
318
                item = new QGCParamSlider(this);
Lorenz Meier's avatar
Lorenz Meier committed
319
                //qDebug() << "CREATED PARAM SLIDER";
320
            }
321 322 323 324 325
            else if (type == "COMBO")
            {
                item = new QGCComboBox(this);
                qDebug() << "CREATED PARAM COMBOBOX";
            }
326

327 328
            if (item)
            {
329 330 331 332
                // Configure and add to layout
                addToolWidget(item);
                item->readSettings(settings);

Lorenz Meier's avatar
Lorenz Meier committed
333
                //qDebug() << "Created tool widget";
334
            }
335 336 337
        }
        else
        {
Lorenz Meier's avatar
Lorenz Meier committed
338
            //qDebug() << "UNKNOWN TOOL WIDGET TYPE";
339 340 341 342 343 344 345
        }
    }
    settings.endArray();
    settings.endGroup();
}

void QGCToolWidget::storeWidgetsToSettings(QString settingsFile)
lm's avatar
lm committed
346 347
{
    // Store list of widgets
348 349 350 351
    QSettings* settings;
    if (!settingsFile.isEmpty())
    {
        settings = new QSettings(settingsFile, QSettings::IniFormat);
Lorenz Meier's avatar
Lorenz Meier committed
352
        //qDebug() << "STORING SETTINGS TO" << settings->fileName();
353 354 355 356
    }
    else
    {
        settings = new QSettings();
Lorenz Meier's avatar
Lorenz Meier committed
357
        //qDebug() << "STORING SETTINGS TO DEFAULT" << settings->fileName();
358 359
    }

360 361 362
    int preArraySize = settings->beginReadArray("QGC_TOOL_WIDGET_NAMES");
    settings->endArray();

363
    settings->beginWriteArray("QGC_TOOL_WIDGET_NAMES");
364
    for (int i = 0; i < qMax(preArraySize, instances()->size()); ++i)
365
    {
366
        settings->setArrayIndex(i);
367 368 369 370
        if (i < instances()->size())
        {
            // Updating value
            settings->setValue("TITLE", instances()->values().at(i)->getTitle());
Lorenz Meier's avatar
Lorenz Meier committed
371
            //qDebug() << "WRITING TITLE" << instances()->values().at(i)->getTitle();
372 373 374 375 376 377
        }
        else
        {
            // Deleting old value
            settings->remove("TITLE");
        }
lm's avatar
lm committed
378
    }
379
    settings->endArray();
lm's avatar
lm committed
380 381

    // Store individual widget items
382 383
    for (int i = 0; i < instances()->size(); ++i)
    {
384 385 386 387 388
        instances()->values().at(i)->storeSettings(*settings);
    }
    delete settings;
}

389 390 391 392 393 394
void QGCToolWidget::storeSettings()
{
    QSettings settings;
    storeSettings(settings);
}

395 396 397 398 399 400 401 402
void QGCToolWidget::storeSettings(const QString& settingsFile)
{
    QSettings settings(settingsFile, QSettings::IniFormat);
    storeSettings(settings);
}

void QGCToolWidget::storeSettings(QSettings& settings)
{
Lorenz Meier's avatar
Lorenz Meier committed
403
    //qDebug() << "WRITING WIDGET" << widgetTitle << "TO SETTINGS";
404
    settings.beginGroup(widgetTitle);
405 406
    settings.beginWriteArray("QGC_TOOL_WIDGET_ITEMS");
    int k = 0; // QGCToolItem counter
407 408
    for (int j = 0; j  < children().size(); ++j)
    {
409 410
        // Store only QGCToolWidgetItems
        QGCToolWidgetItem* item = dynamic_cast<QGCToolWidgetItem*>(children().at(j));
411 412
        if (item)
        {
413
            // Only count actual tool widget item children
414 415 416
            settings.setArrayIndex(k++);
            // Store the ToolWidgetItem
            item->writeSettings(settings);
lm's avatar
lm committed
417 418
        }
    }
Lorenz Meier's avatar
Lorenz Meier committed
419
    //qDebug() << "WROTE" << k << "SUB-WIDGETS TO SETTINGS";
420 421
    settings.endArray();
    settings.endGroup();
lm's avatar
lm committed
422 423
}

424 425 426
void QGCToolWidget::addUAS(UASInterface* uas)
{
    UAS* newMav = dynamic_cast<UAS*>(uas);
427 428
    if (newMav)
    {
429 430 431 432 433 434 435 436
        // FIXME Convert to list
        if (mav == NULL) mav = newMav;
    }
}

void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event)
{
    QMenu menu(this);
437
    menu.addAction(addParamAction);
lm's avatar
lm committed
438
    menu.addAction(addCommandAction);
439
    menu.addSeparator();
440
    menu.addAction(setTitleAction);
441
    menu.addAction(exportAction);
442
    menu.addAction(importAction);
lm's avatar
lm committed
443
    menu.addAction(deleteAction);
444 445 446
    menu.exec(event->globalPos());
}

447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
void QGCToolWidget::hideEvent(QHideEvent* event)
{
    // Store settings
    QWidget::hideEvent(event);
}

/**
 * The widgets current view and the applied dock widget area.
 * Both values are only stored internally and allow an external
 * widget to configure it accordingly
 */
void QGCToolWidget::setViewVisibilityAndDockWidgetArea(int view, bool visible, Qt::DockWidgetArea area)
{
    viewVisible.insert(view, visible);
    dockWidgetArea.insert(view, area);
}

464 465 466 467 468 469
void QGCToolWidget::createActions()
{
    addParamAction = new QAction(tr("New &Parameter Slider"), this);
    addParamAction->setStatusTip(tr("Add a parameter setting slider widget to the tool"));
    connect(addParamAction, SIGNAL(triggered()), this, SLOT(addParam()));

lm's avatar
lm committed
470 471 472
    addCommandAction = new QAction(tr("New MAV &Command Button"), this);
    addCommandAction->setStatusTip(tr("Add a new action button to the tool"));
    connect(addCommandAction, SIGNAL(triggered()), this, SLOT(addCommand()));
473 474 475 476

    setTitleAction = new QAction(tr("Set Widget Title"), this);
    setTitleAction->setStatusTip(tr("Set the title caption of this tool widget"));
    connect(setTitleAction, SIGNAL(triggered()), this, SLOT(setTitle()));
lm's avatar
lm committed
477 478 479 480

    deleteAction = new QAction(tr("Delete this widget"), this);
    deleteAction->setStatusTip(tr("Delete this widget permanently"));
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteWidget()));
481 482 483 484 485 486 487

    exportAction = new QAction(tr("Export this widget"), this);
    exportAction->setStatusTip(tr("Export this widget to be reused by others"));
    connect(exportAction, SIGNAL(triggered()), this, SLOT(exportWidget()));

    importAction = new QAction(tr("Import widget"), this);
    importAction->setStatusTip(tr("Import this widget from a file (current content will be removed)"));
488
    connect(importAction, SIGNAL(triggered()), this, SLOT(importWidget()));
lm's avatar
lm committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502
}

QMap<QString, QGCToolWidget*>* QGCToolWidget::instances()
{
    static QMap<QString, QGCToolWidget*>* instances;
    if (!instances) instances = new QMap<QString, QGCToolWidget*>();
    return instances;
}

QList<QGCToolWidgetItem*>* QGCToolWidget::itemList()
{
    static QList<QGCToolWidgetItem*>* instances;
    if (!instances) instances = new QList<QGCToolWidgetItem*>();
    return instances;
503 504 505 506 507
}

void QGCToolWidget::addParam()
{
    QGCParamSlider* slider = new QGCParamSlider(this);
508
    connect(slider, SIGNAL(destroyed()), this, SLOT(storeSettings()));
509 510
    if (ui->hintLabel)
    {
lm's avatar
lm committed
511
        ui->hintLabel->deleteLater();
512
        ui->hintLabel = NULL;
lm's avatar
lm committed
513
    }
514 515 516 517
    toolLayout->addWidget(slider);
    slider->startEditMode();
}

lm's avatar
lm committed
518 519 520
void QGCToolWidget::addCommand()
{
    QGCCommandButton* button = new QGCCommandButton(this);
521
    connect(button, SIGNAL(destroyed()), this, SLOT(storeSettings()));
522 523
    if (ui->hintLabel)
    {
lm's avatar
lm committed
524 525 526 527 528 529 530
        ui->hintLabel->deleteLater();
        ui->hintLabel = NULL;
    }
    toolLayout->addWidget(button);
    button->startEditMode();
}

lm's avatar
lm committed
531 532
void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget)
{
533 534
    if (ui->hintLabel)
    {
lm's avatar
lm committed
535
        ui->hintLabel->deleteLater();
536
        ui->hintLabel = NULL;
lm's avatar
lm committed
537
    }
538
    connect(widget, SIGNAL(destroyed()), this, SLOT(storeSettings()));
lm's avatar
lm committed
539 540 541
    toolLayout->addWidget(widget);
}

542 543
void QGCToolWidget::exportWidget()
{
544 545 546 547 548 549 550
    const QString widgetFileExtension(".qgw");
    QString fileName = QFileDialog::getSaveFileName(this, tr("Specify File Name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("QGroundControl Widget (*%1);;").arg(widgetFileExtension));
    if (!fileName.endsWith(widgetFileExtension))
    {
        fileName = fileName.append(widgetFileExtension);
    }
    storeSettings(fileName);
551 552
}

553
void QGCToolWidget::importWidget()
554
{
555 556 557
    const QString widgetFileExtension(".qgw");
    QString fileName = QFileDialog::getOpenFileName(this, tr("Specify File Name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("QGroundControl Widget (*%1);;").arg(widgetFileExtension));
    loadSettings(fileName);
558 559
}

lm's avatar
lm committed
560 561
const QString QGCToolWidget::getTitle()
{
562
    return widgetTitle;
lm's avatar
lm committed
563 564
}

565 566 567
void QGCToolWidget::setTitle()
{
    QDockWidget* parent = dynamic_cast<QDockWidget*>(this->parentWidget());
568 569
    if (parent)
    {
lm's avatar
lm committed
570
        bool ok;
571
        QString text = QInputDialog::getText(this, tr("Enter Widget Title"),
572 573
                                             tr("Widget title:"), QLineEdit::Normal,
                                             parent->windowTitle(), &ok);
574 575 576
        if (ok && !text.isEmpty())
        {
            setTitle(text);
lm's avatar
lm committed
577
        }
578 579
    }
}
lm's avatar
lm committed
580

581 582 583
void QGCToolWidget::setWindowTitle(const QString& title)
{
    // Sets title and calls setWindowTitle on QWidget
584 585
    widgetTitle = title;
    QWidget::setWindowTitle(title);
586 587
}

588 589
void QGCToolWidget::setTitle(QString title)
{
590
    // Remove references to old title
591 592 593 594 595 596
    QSettings settings;
    settings.beginGroup(widgetTitle);
    settings.remove("");
    settings.endGroup();
    settings.sync();

597 598 599 600 601 602 603
    if (instances()->contains(widgetTitle)) instances()->remove(widgetTitle);

    // Switch to new title
    widgetTitle = title;

    if (!instances()->contains(title)) instances()->insert(title, this);
    QWidget::setWindowTitle(title);
604
    QDockWidget* parent = dynamic_cast<QDockWidget*>(this->parentWidget());
605
    if (parent) parent->setWindowTitle(title);
606
    // Store all widgets
607
    //storeWidgetsToSettings();
608 609 610 611 612

    emit titleChanged(title);
    if (mainMenuAction) mainMenuAction->setText(title);
}

lm's avatar
lm committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
void QGCToolWidget::setMainMenuAction(QAction* action)
{
    this->mainMenuAction = action;
}

void QGCToolWidget::deleteWidget()
{
    // Remove from settings

    // Hide
    this->hide();
    instances()->remove(getTitle());
    QSettings settings;
    settings.beginGroup(getTitle());
    settings.remove("");
    settings.endGroup();
    storeWidgetsToSettings();

    // Delete
    this->deleteLater();
}