QGCToolWidget.h 4.24 KB
Newer Older
1 2 3 4 5
#ifndef QGCTOOLWIDGET_H
#define QGCTOOLWIDGET_H

#include <QWidget>
#include <QAction>
lm's avatar
lm committed
6
#include <QMap>
7
#include <QVBoxLayout>
lm's avatar
lm committed
8
#include "QGCToolWidgetItem.h"
9 10 11

#include "UAS.h"

12 13 14
namespace Ui
{
class QGCToolWidget;
15 16 17 18 19 20 21
}

class QGCToolWidget : public QWidget
{
    Q_OBJECT

public:
22
    explicit QGCToolWidget(const QString& objectName, const QString& title, QWidget *parent = 0, QSettings* settings = 0);
23 24
    ~QGCToolWidget();

lm's avatar
lm committed
25
    /** @brief Factory method to instantiate all tool widgets */
26
    static QList<QGCToolWidget*> createWidgetsFromSettings(QWidget* parent, QString settingsFile=QString());
lm's avatar
lm committed
27 28 29 30
    /** @Give the tool widget a reference to its action in the main menu */
    void setMainMenuAction(QAction* action);
    /** @brief All instances of this class */
    static QMap<QString, QGCToolWidget*>* instances();
31
    /** @brief Get title of widget */
32
    QString getTitle() const;
lm's avatar
lm committed
33

34
    int isVisible(int view) const { return viewVisible.value(view, false); }
35
    Qt::DockWidgetArea getDockWidgetArea(int view) { return dockWidgetArea.value(view, Qt::BottomDockWidgetArea); }
36
    void setParent(QWidget *parent);
37

38 39 40
    /** @brief Store all widgets of this type to QSettings */
    static void storeWidgetsToSettings(QSettings &settingsFile);

41 42
public slots:
    void addUAS(UASInterface* uas);
lm's avatar
lm committed
43 44
    /** @brief Delete this widget */
    void deleteWidget();
45 46 47
    /** @brief Export this widget to a file */
    void exportWidget();
    /** @brief Import settings for this widget from a file */
48
    void importWidget();
lm's avatar
lm committed
49
    /** @brief Store all widgets of this type to QSettings */
50
    void storeWidgetsToSettings() { QSettings settings; QGCToolWidget::storeWidgetsToSettings(settings); }
Don Gagne's avatar
Don Gagne committed
51
    void showLabel(QString name,int num);
52 53

public:
54
    void loadSettings(QVariantMap& settings);
55 56 57
    /** @brief Load this widget from a QSettings object */
    void loadSettings(QSettings& settings);
    /** @brief Load this widget from a settings file */
LM's avatar
LM committed
58
    bool loadSettings(const QString& settings, bool singleinstance=false);
59 60
    /** @brief Store the view id and dock widget area */
    void setViewVisibilityAndDockWidgetArea(int view, bool visible, Qt::DockWidgetArea area);
61 62 63
    void setSettings(QVariantMap& settings);
    QList<QString> getParamList();
    void setParameterValue(int uas, int component, QString parameterName, const QVariant value);
64
    bool fromMetaData() const { return isFromMetaData; }
65

lm's avatar
lm committed
66
signals:
67
    void titleChanged(const QString &title);
68 69

protected:
70
    bool isFromMetaData;
71
    QMap<QString,QGCToolWidgetItem*> paramToItemMap;
72
    QList<QGCToolWidgetItem*> toolItemList;
73 74
    QList<QString> paramList;
    QVariantMap settingsMap;
75
    QAction* addParamAction;
lm's avatar
lm committed
76
    QAction* addCommandAction;
John Tapsell's avatar
John Tapsell committed
77
    QAction* addPlotAction;
78
    QAction* addLabelAction;
79
    QAction* setTitleAction;
lm's avatar
lm committed
80
    QAction* deleteAction;
81 82
    QAction* exportAction;
    QAction* importAction;
83 84
    QVBoxLayout* toolLayout;
    UAS* mav;
85 86 87
    QAction* mainMenuAction;             ///< Main menu action
    QMap<int, Qt::DockWidgetArea> dockWidgetArea;   ///< Dock widget area desired by this widget
    QMap<int, bool> viewVisible;  ///< Visibility in one view
88
    QString widgetTitle;
89 90 91

    void contextMenuEvent(QContextMenuEvent* event);
    void createActions();
lm's avatar
lm committed
92 93
    /** @brief Add an existing tool widget */
    void addToolWidget(QGCToolWidgetItem* widget);
John Tapsell's avatar
John Tapsell committed
94 95
    /** @brief Add an existing tool widget and set it to edit mode */
    void addToolWidgetAndEdit(QGCToolWidgetItem* widget);
96

97
    void hideEvent(QHideEvent* event);
98
public slots:
99
    void setTitle(const QString &title);
100
    void addParam(int uas,int component,QString paramname,QVariant value);
101 102
protected slots:
    void addParam();
lm's avatar
lm committed
103
    void addCommand();
John Tapsell's avatar
John Tapsell committed
104
    void addPlot();
105
    void addLabel();
106
    void setTitle();
107
    void widgetRemoved();
108

109
private:
110 111 112 113 114 115
    /** Do not use this from outside the class to set the object name,
     * because we cannot track changes to the object name, and the
     * QObject::setObjectName() function is not virtual. Instead only
     * pass in the object name to the constructor, or use the , then
     * never change it again. */
    void setObjectName(const QString &name) { QWidget::setObjectName(name); }
116 117 118
    /** Helper for storeWidgetsToSettings() */
    void storeSettings(QSettings& settings);

119 120 121 122
    Ui::QGCToolWidget *ui;
};

#endif // QGCTOOLWIDGET_H