dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobjectbrowserwidget.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef UAVOBJECTBROWSERWIDGET_H_
29 #define UAVOBJECTBROWSERWIDGET_H_
30 
31 #include <QModelIndex>
32 #include <QWidget>
33 #include <QKeyEvent>
34 #include <QTreeView>
35 #include <QSortFilterProxyModel>
36 #include "objectpersistence.h"
37 #include "uavobjecttreemodel.h"
38 
39 class QPushButton;
40 class ObjectTreeItem;
41 class Ui_UAVObjectBrowser;
42 class Ui_viewoptions;
43 
44 class TreeSortFilterProxyModel : public QSortFilterProxyModel
45 {
46 public:
47  TreeSortFilterProxyModel(QObject *parent);
48 
49 protected:
50  bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
51  bool filterAcceptsRowItself(int source_row, const QModelIndex &source_parent) const;
52  bool hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const;
53 };
54 
55 class UAVOBrowserTreeView : public QTreeView
56 {
57  Q_OBJECT
58 public:
60  void updateView(const QModelIndex &topLeft, const QModelIndex &bottomRight);
61  void updateTimerPeriod(unsigned int val);
62 
63  virtual void setModel(QAbstractItemModel *model)
64  {
65  QTreeView::setModel(model);
66  proxyModel = static_cast<TreeSortFilterProxyModel *>(model);
67  }
68 
75  virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
76  const QVector<int> &roles = QVector<int>());
77 
78 private slots:
79  void onTimeout_updateView();
80 
81 private:
82  bool m_updateTreeViewFlag;
83  TreeSortFilterProxyModel *proxyModel;
84 
85  QTimer m_updateViewTimer;
86 };
87 
88 class UAVObjectBrowserWidget : public QWidget
89 {
90  Q_OBJECT
91 
92 public:
93  UAVObjectBrowserWidget(QWidget *parent = nullptr);
95  void setRecentlyUpdatedColor(QColor color)
96  {
97  m_recentlyUpdatedColor = color;
98  m_model->setRecentlyUpdatedColor(color);
99  }
100  void setManuallyChangedColor(QColor color)
101  {
102  m_manuallyChangedColor = color;
103  m_model->setManuallyChangedColor(color);
104  }
105  void setNotPresentOnHwColor(QColor color)
106  {
107  m_notPresentOnHwColor = color;
108  m_model->setNotPresentOnHwColor(color);
109  }
110  void setOnlyHighlightChangedValues(bool highlight)
111  {
112  m_onlyHighlightChangedValues = highlight;
113  m_model->setOnlyHighlightChangedValues(highlight);
114  }
115  void setViewOptions(bool scientific, bool metadata, bool hideNotPresent);
116  void initialize();
117  void refreshHiddenObjects();
118 public slots:
119  void showMetaData(bool show);
120  void showNotPresent(bool show);
121  void doRefreshHiddenObjects();
122 private slots:
123  void sendUpdate();
124  void requestUpdate();
125  void saveObject();
126  void loadObject();
127  void eraseObject();
128  void toggleUAVOButtons(const QModelIndex &current, const QModelIndex &previous);
129  void viewSlot();
130  void viewOptionsChangedSlot();
131 
132  void onTreeItemCollapsed(QModelIndex);
133  void onTreeItemExpanded(QModelIndex);
134 
135  void searchTextChanged(QString searchText);
136  void searchTextCleared();
137 
138 signals:
139  void viewOptionsChanged(bool scientific, bool metadata, bool hideNotPresent);
140 
141 private:
142  QPushButton *m_requestUpdate;
143  QPushButton *m_sendUpdate;
144  Ui_UAVObjectBrowser *m_browser;
145  Ui_viewoptions *m_viewoptions;
146  QDialog *m_viewoptionsDialog;
147  UAVObjectTreeModel *m_model;
148  TreeSortFilterProxyModel *proxyModel;
149 
150  int m_recentlyUpdatedTimeout;
151  QColor m_recentlyUpdatedColor;
152  QColor m_manuallyChangedColor;
153  QColor m_notPresentOnHwColor;
154  bool m_onlyHighlightChangedValues;
155 
156  void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
157  void enableUAVOBrowserButtons(bool enableState);
158  ObjectTreeItem *findCurrentObjectTreeItem();
159  void updateThrottlePeriod(UAVObject *);
160  void keyPressEvent(QKeyEvent *e);
161  void keyReleaseEvent(QKeyEvent *e);
162 
163  UAVOBrowserTreeView *treeView;
164 
165  QMap<QString, unsigned int> expandedUavoItems;
166 
167  unsigned int updatePeriod;
168  void refreshViewOptions();
169 };
170 
171 #endif /* UAVOBJECTBROWSERWIDGET_H_ */
bool hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const
void setRecentlyUpdatedColor(QColor color)
void setManuallyChangedColor(QColor color)
void setViewOptions(bool scientific, bool metadata, bool hideNotPresent)
UAVObjectBrowserWidget::setViewOptions Sets the viewing options.
UAVObjectBrowserWidget(QWidget *parent=nullptr)
void setNotPresentOnHwColor(QColor color)
void initialize()
Initializes the model and makes the necessary signal/slot connections.
void updateView(const QModelIndex &topLeft, const QModelIndex &bottomRight)
UAVOBrowserTreeView::updateView Determines if a view updates lies outside the range of updates queued...
void setOnlyHighlightChangedValues(bool highlight)
void setNotPresentOnHwColor(QColor color)
void showNotPresent(bool show)
UAVObjectBrowserWidget::showNotPresent Shows or hides object not present on the hardware.
void setOnlyHighlightChangedValues(bool highlight)
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
TreeSortFilterProxyModel::filterAcceptsRow Taken from http://qt-project.org/forums/viewthread/7782. This proxy model will accept rows:
bool filterAcceptsRowItself(int source_row, const QModelIndex &source_parent) const
virtual void setModel(QAbstractItemModel *model)
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
dataChanged Reimplements QTreeView::dataChanged signal
void showMetaData(bool show)
UAVObjectBrowserWidget::showMetaData Shows UAVO metadata.
void refreshHiddenObjects()
Refreshes the hidden object display.
UAVOBrowserTreeView(unsigned int updateTimerPeriod)
UAVOBrowserTreeView::UAVOBrowserTreeView Constructor for reimplementation of QTreeView.
void setManuallyChangedColor(QColor color)
void setRecentlyUpdatedColor(QColor color)
void viewOptionsChanged(bool scientific, bool metadata, bool hideNotPresent)
void updateTimerPeriod(unsigned int val)
e
Definition: OPPlots.m:99