dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
telemetryschedulergadgetwidget.h
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 #ifndef TELEMETRYSCHEDULERGADGETWIDGET_H_
27 #define TELEMETRYSCHEDULERGADGETWIDGET_H_
28 
29 #include <QMap>
30 #include <QSpinBox>
31 #include <QTableView>
32 #include <QStandardItemModel>
33 #include <QItemDelegate>
34 #include <QLabel>
35 
38 #include "uavobjects/uavobject.h"
39 
40 class Ui_TelemetryScheduler;
41 class Ui_Metadata_Dialog;
43 class SchedulerModel;
44 
45 class TelemetrySchedulerGadgetWidget : public QWidget
46 {
47  Q_OBJECT
48 
49 public:
50  TelemetrySchedulerGadgetWidget(QWidget *parent = nullptr);
52 
53 signals:
54 
55 protected slots:
56 
57 private slots:
58  void saveTelemetryToFile();
59  void loadTelemetryFromFile();
60 
62  QList<UAVMetaObject *> applySchedule();
64  void saveSchedule();
65  void onSavedSchedule(bool);
66  void onCompletedMetadataWrite(bool);
67  void onCompletedMetadataSave(int, bool);
68  void updateCurrentColumn(UAVObject *);
69  void dataModel_itemChanged(int col);
70  void dataModel_itemChanged(QStandardItem *item);
71  void addTelemetryColumn();
72  void removeTelemetryColumn();
73  void changeVerticalHeader(int);
74  void changeHorizontalHeader(int);
75  void customMenuRequested(QPoint pos);
76  void uavoPresentOnHardwareChanged(UAVDataObject *);
77  void onHideNotPresent(bool);
78 
79 private:
80  int stripMs(QVariant rate_ms);
81  QList<UAVMetaObject *> metaObjectsToSave;
82  void importTelemetryConfiguration(const QString &fileName);
83  UAVObjectUtilManager *getObjectUtilManager();
84  UAVObjectManager *getObjectManager();
85 
86  Ui_TelemetryScheduler *m_telemetryeditor;
87 
88  UAVObjectManager *objManager;
89  QString filename;
90 
91  QMap<QString, UAVObject::Metadata> defaultMdata;
92  QMap<UAVDataObject *, int> uavoIndex;
93 
94  QStringList columnHeaders;
95 
96  SchedulerModel *schedulerModel;
97  QFrozenTableViewWithCopyPaste *telemetryScheduleView;
98  QStandardItemModel *frozenModel;
99 };
100 
105 class SchedulerModel : public QStandardItemModel
106 {
107 public:
108  SchedulerModel(int rows, int cols, QObject *parent = nullptr)
109  : QStandardItemModel(rows, cols, parent)
110  {
111  }
112 
114 
115  // The first two columns are not editable, but all other columns are
116  Qt::ItemFlags flags(const QModelIndex &index) const
117  {
118  if (index.column() == 0 || index.column() == 1)
119  return nullptr;
120  else
121  return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
122  }
123 };
124 
132 class QFrozenTableViewWithCopyPaste : public QTableView
133 {
134  Q_OBJECT
135 
136 public:
137  QFrozenTableViewWithCopyPaste(QAbstractItemModel *model);
139 
140  QStandardItemModel *getFrozenModel() { return frozenModel; }
141  QTableView *getFrozenTableView() { return frozenTableView; }
142  void setHorizontalHeaderItem(int column, QStandardItem *item);
143  bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
144 
145  void fixGeometry(int value);
146 
147 protected:
148  virtual void keyPressEvent(QKeyEvent *event);
149 
150  virtual void resizeEvent(QResizeEvent *event);
151  void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
152 
153 private slots:
154  void updateSectionWidth(int logicalIndex, int, int newSize);
155  void updateSectionHeight(int logicalIndex, int, int newSize);
156 
157 private:
158  void copy();
159  void paste();
160  void deleteCells();
161 
162  void updateFrozenTableGeometry(int verticalHeaderWidth);
163  void init();
164  QTableView *frozenTableView;
165  QStandardItemModel *frozenModel;
166 };
167 
168 class SpinBoxDelegate : public QItemDelegate
169 {
170  Q_OBJECT
171 
172 public:
173  SpinBoxDelegate(QObject *parent = nullptr);
174 
175  QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
176  const QModelIndex &index) const;
177 
178  void setEditorData(QWidget *editor, const QModelIndex &index) const;
179  void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
180 
181  void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
182  const QModelIndex &index) const;
183 };
184 
185 #endif /* TELEMETRYSCHEDULERGADGETWIDGET_H_ */
Qt::ItemFlags flags(const QModelIndex &index) const
virtual void keyPressEvent(QKeyEvent *event)
TelemetrySchedulerGadgetWidget(QWidget *parent=nullptr)
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
QFrozenTableViewWithCopyPaste::removeColumns Ensures that the frozen table geometry is updated when c...
virtual void resizeEvent(QResizeEvent *event)
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
QFrozenTableViewWithCopyPaste(QAbstractItemModel *model)
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
The QFrozenTableViewWithCopyPaste class QTableView with support for a frozen row as well as copy and ...
void fixGeometry(int value)
This class uses a tableview inside a table view to achieve the frozen row effect on the 1st row this ...
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)
The SchedulerModel class Subclasses QStandardItemModel in order to reimplement the editable flags...
SpinBoxDelegate(QObject *parent=nullptr)
void setHorizontalHeaderItem(int column, QStandardItem *item)
QFrozenTableViewWithCopyPaste::setHorizontalHeaderItem Ensures that the frozen table geometry is upda...
SchedulerModel(int rows, int cols, QObject *parent=nullptr)
void setEditorData(QWidget *editor, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const