1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | #include "Layout.h"
|
---|
6 | #include "TabWidget.h"
|
---|
7 | #include "GroupBox.h"
|
---|
8 | #include "GridLayout.h"
|
---|
9 | #include "SpinBox.h"
|
---|
10 | #include "DoubleSpinBox.h"
|
---|
11 | #include "Vector3DSpinBox.h"
|
---|
12 | #include "CheckBox.h"
|
---|
13 | #include "ComboBox.h"
|
---|
14 | #include "PushButton.h"
|
---|
15 | #include "TextEdit.h"
|
---|
16 | #include "Label.h"
|
---|
17 | #include "DataPlot1D.h"
|
---|
18 | #include "DataPlot2D.h"
|
---|
19 | #include "RangeFinderPlot.h"
|
---|
20 | #include "UsSensorPlot.h"
|
---|
21 | #include "Picture.h"
|
---|
22 | #include "Map.h"
|
---|
23 | #include <QGeoCoordinate>
|
---|
24 | #include <QGridLayout>
|
---|
25 | #include "ListWidget.h"
|
---|
26 | #include <QStringList>
|
---|
27 |
|
---|
28 | Layout::Layout(QWidget *parent, XmlWidget *xml, QString name, QString type)
|
---|
29 | : XmlWidget(name, type, xml) {
|
---|
30 | qgridlayout = new QGridLayout(parent);
|
---|
31 | Constructor(name);
|
---|
32 | }
|
---|
33 |
|
---|
34 | Layout::Layout(Layout *parent, QString name, QString type)
|
---|
35 | : XmlWidget(name, type, parent) {
|
---|
36 | qgridlayout = new QGridLayout(new QWidget());
|
---|
37 | Constructor(name);
|
---|
38 | }
|
---|
39 |
|
---|
40 | void Layout::Constructor(QString name) {
|
---|
41 | visible_widget = qgridlayout->parentWidget();
|
---|
42 | // if(visible_widget==NULL) fprintf(stderr,"null\n");
|
---|
43 | qgridlayout->setObjectName(name);
|
---|
44 | // fprintf(stderr,"layout\n%s\n",XmlDoc().toString().toLocal8Bit().constData());
|
---|
45 | SetIsContainer(true);
|
---|
46 | SetIsExpandable(true);
|
---|
47 |
|
---|
48 | qgridlayout->setHorizontalSpacing(2);
|
---|
49 | qgridlayout->setVerticalSpacing(2);
|
---|
50 | qgridlayout->setContentsMargins(2, 2, 2, 2);
|
---|
51 |
|
---|
52 | // splitter = new QSplitter();
|
---|
53 | // addWidget(splitter);
|
---|
54 | /*
|
---|
55 | QWidget *widget = new QWidget();
|
---|
56 | //QHBoxLayout *parentLayout = new QHBoxLayout();
|
---|
57 | widget->setLayout(this);
|
---|
58 | parent->addWidget(widget);
|
---|
59 | //QTabWidget *tabWidget = new QTabWidget();
|
---|
60 | //parentLayout->addWidget(tabWidget);*/
|
---|
61 | }
|
---|
62 |
|
---|
63 | Layout::~Layout() { delete qgridlayout; }
|
---|
64 |
|
---|
65 | void Layout::addWidget(QWidget *widget, int row, int column) {
|
---|
66 | qgridlayout->addWidget(widget, row, column);
|
---|
67 | }
|
---|
68 |
|
---|
69 | QGridLayout *Layout::getQGridLayout() { return qgridlayout; }
|
---|
70 |
|
---|
71 | void Layout::XmlEvent(QDomElement *dom) {
|
---|
72 | XmlWidget *widget = NULL;
|
---|
73 | QString type = dom->tagName();
|
---|
74 | QString name = dom->attribute("name");
|
---|
75 | QString old_name = dom->attribute("old_name");
|
---|
76 | int row = dom->attribute("row").toInt();
|
---|
77 | int col = dom->attribute("col").toInt();
|
---|
78 |
|
---|
79 | // initially rowCount()=1 and columnCount()=1 but count()=0 !
|
---|
80 | // new row
|
---|
81 | if (row == -1 && col == -1) {
|
---|
82 | row = qgridlayout->rowCount();
|
---|
83 | if (qgridlayout->count() == 0)
|
---|
84 | row = 0;
|
---|
85 | col = 0;
|
---|
86 | }
|
---|
87 | // last row last col
|
---|
88 | if (row == -1 && col == 0) {
|
---|
89 | row = qgridlayout->rowCount() - 1;
|
---|
90 | int i;
|
---|
91 | for (i = 0; i <= qgridlayout->columnCount(); i++) {
|
---|
92 | if (qgridlayout->itemAtPosition(row, i) == NULL)
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | col = i;
|
---|
96 | }
|
---|
97 | // if an item already exists at this position, put it on a new row
|
---|
98 | if (qgridlayout->itemAtPosition(row, col) != NULL) {
|
---|
99 | fprintf(stderr,"widget %s: (%i,%i) already exists\n", name.toLocal8Bit().constData(),row, col);
|
---|
100 | row = qgridlayout->rowCount();
|
---|
101 | fprintf(stderr,"using (%i,%i) for %s\n", row, col,name.toLocal8Bit().constData());
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (type == "TabWidget") {
|
---|
105 | int position = dom->attribute("position").toInt();
|
---|
106 | widget =
|
---|
107 | new TabWidget(this, row, col, name, (QTabWidget::TabPosition)position);
|
---|
108 | }
|
---|
109 | if (type == "GroupBox") {
|
---|
110 | widget = new GroupBox(this, row, col, name);
|
---|
111 | }
|
---|
112 | if (type == "GridLayout") {
|
---|
113 | widget = new GridLayout(this, row, col, name);
|
---|
114 | }
|
---|
115 | if (type == "SpinBox") {
|
---|
116 | int value = dom->attribute("value").toInt();
|
---|
117 | QString suffix = dom->attribute("suffix");
|
---|
118 | int min = dom->attribute("min").toInt();
|
---|
119 | int max = dom->attribute("max").toInt();
|
---|
120 | int step = dom->attribute("step").toInt();
|
---|
121 | widget = new SpinBox(this, row, col, name, suffix, value, min, max, step);
|
---|
122 | }
|
---|
123 | if (type == "DoubleSpinBox") {
|
---|
124 | QString value = dom->attribute("value");
|
---|
125 | QString suffix = dom->attribute("suffix");
|
---|
126 | double min = dom->attribute("min").toDouble();
|
---|
127 | double max = dom->attribute("max").toDouble();
|
---|
128 | double step = dom->attribute("step").toDouble();
|
---|
129 | uint16_t decimals = dom->attribute("decimals").toUShort();
|
---|
130 | widget = new DoubleSpinBox(this, row, col, name, suffix, value, min, max,
|
---|
131 | step, decimals);
|
---|
132 | }
|
---|
133 | if (type == "Vector3DSpinBox") {
|
---|
134 | QString value[3];
|
---|
135 | value[0] = dom->attribute("value_x");
|
---|
136 | value[1] = dom->attribute("value_y");
|
---|
137 | value[2] = dom->attribute("value_z");
|
---|
138 | double min = dom->attribute("min").toDouble();
|
---|
139 | double max = dom->attribute("max").toDouble();
|
---|
140 | double step = dom->attribute("step").toDouble();
|
---|
141 | uint16_t decimals = dom->attribute("decimals").toUShort();
|
---|
142 | widget = new Vector3DSpinBox(this, row, col, name, value, min, max, step,
|
---|
143 | decimals);
|
---|
144 | }
|
---|
145 | if (type == "CheckBox") {
|
---|
146 | int value = dom->attribute("value").toInt();
|
---|
147 | widget = new CheckBox(this, row, col, name, value);
|
---|
148 | }
|
---|
149 | if (type == "ComboBox") {
|
---|
150 | uint16_t value = dom->attribute("value").toUShort();
|
---|
151 | widget = new ComboBox(this, row, col, name, value);
|
---|
152 | }
|
---|
153 | if (type == "PushButton") {
|
---|
154 | widget = new PushButton(this, row, col, name);
|
---|
155 | }
|
---|
156 | if (type == "DataPlot1D") {
|
---|
157 | float ymin = dom->attribute("min").toFloat();
|
---|
158 | float ymax = dom->attribute("max").toFloat();
|
---|
159 | int enabled = dom->attribute("enabled").toInt();
|
---|
160 | uint16_t period = dom->attribute("period").toUShort();
|
---|
161 | uint16_t nb_buffering = dom->attribute("nb_buf").toUShort();
|
---|
162 | if (enabled == 1) {
|
---|
163 | widget = new DataPlot1D(this, row, col, name, ymin, ymax, true, period,nb_buffering);
|
---|
164 | } else {
|
---|
165 | widget = new DataPlot1D(this, row, col, name, ymin, ymax, false, 100,nb_buffering);
|
---|
166 | }
|
---|
167 | }
|
---|
168 | if (type == "DataPlot2D") {
|
---|
169 | float xmin = dom->attribute("xmin").toFloat();
|
---|
170 | float xmax = dom->attribute("xmax").toFloat();
|
---|
171 | float ymin = dom->attribute("ymin").toFloat();
|
---|
172 | float ymax = dom->attribute("ymax").toFloat();
|
---|
173 | QString x_name = dom->attribute("x_name");
|
---|
174 | QString y_name = dom->attribute("y_name");
|
---|
175 | int enabled = dom->attribute("enabled").toInt();
|
---|
176 | uint16_t period = dom->attribute("period").toUShort();
|
---|
177 | uint16_t nb_buffering = dom->attribute("nb_buf").toUShort();
|
---|
178 | if (enabled == 1) {
|
---|
179 | widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
180 | ymin, ymax, true, period,nb_buffering);
|
---|
181 | } else {
|
---|
182 | widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
183 | ymin, ymax, false, 100,nb_buffering);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | if (type == "UsSensorPlot") {
|
---|
187 | float ymin = dom->attribute("ymin").toFloat();
|
---|
188 | float ymax = dom->attribute("ymax").toFloat();
|
---|
189 | QString y_name = dom->attribute("y_name");
|
---|
190 | int enabled = dom->attribute("enabled").toInt();
|
---|
191 | uint16_t period = dom->attribute("period").toUShort();
|
---|
192 | QString type = dom->attribute("type");
|
---|
193 | int samples = dom->attribute("samples").toInt();
|
---|
194 | if (enabled == 1) {
|
---|
195 | widget = new UsSensorPlot(this, row, col, name, y_name,
|
---|
196 | ymin, ymax, samples,type,true, period);
|
---|
197 | } else {
|
---|
198 | widget = new UsSensorPlot(this, row, col, name, y_name,
|
---|
199 | ymin, ymax, samples,type,false, 100);
|
---|
200 | }
|
---|
201 | }
|
---|
202 | if (type == "RangeFinderPlot") {
|
---|
203 | float xmin = dom->attribute("xmin").toFloat();
|
---|
204 | float xmax = dom->attribute("xmax").toFloat();
|
---|
205 | float ymin = dom->attribute("ymin").toFloat();
|
---|
206 | float ymax = dom->attribute("ymax").toFloat();
|
---|
207 | QString x_name = dom->attribute("x_name");
|
---|
208 | QString y_name = dom->attribute("y_name");
|
---|
209 | QString data_type = dom->attribute("type");
|
---|
210 | float start_angle = dom->attribute("start_angle").toFloat();
|
---|
211 | float end_angle = dom->attribute("end_angle").toFloat();
|
---|
212 | uint32_t nb_samples = dom->attribute("nb_samples").toUInt();
|
---|
213 | int enabled = dom->attribute("enabled").toInt();
|
---|
214 | uint16_t period = dom->attribute("period").toUShort();
|
---|
215 | int invert_axis = dom->attribute("invert_axis").toInt();
|
---|
216 | bool invert_axis_bool;
|
---|
217 | if (invert_axis == 0) {
|
---|
218 | invert_axis_bool = false;
|
---|
219 | } else {
|
---|
220 | invert_axis_bool = true;
|
---|
221 | }
|
---|
222 | if (enabled == 1) {
|
---|
223 | widget =
|
---|
224 | new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
225 | ymin, ymax, start_angle, end_angle, nb_samples,
|
---|
226 | data_type, invert_axis, true, period);
|
---|
227 | } else {
|
---|
228 | widget =
|
---|
229 | new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
230 | ymin, ymax, start_angle, end_angle, nb_samples,
|
---|
231 | data_type, invert_axis, false, 100);
|
---|
232 | }
|
---|
233 | }
|
---|
234 | if (type == "Picture") {
|
---|
235 | int width = dom->attribute("width").toInt();
|
---|
236 | int height = dom->attribute("height").toInt();
|
---|
237 | int enabled = dom->attribute("enabled").toInt();
|
---|
238 | uint16_t period = dom->attribute("period").toUShort();
|
---|
239 | if (enabled == 1) {
|
---|
240 | widget = new Picture(this, row, col, name, width, height, true, period);
|
---|
241 | } else {
|
---|
242 | widget = new Picture(this, row, col, name, width, height, false, period);
|
---|
243 | }
|
---|
244 | }
|
---|
245 | if (type == "Map") {
|
---|
246 | uint16_t period = dom->attribute("period").toUShort();
|
---|
247 | int enabled = dom->attribute("enabled").toInt();
|
---|
248 | int i = 0;
|
---|
249 | QList<QtMobility::QGeoCoordinate> coordinates;
|
---|
250 | while (dom->hasAttribute("lat" + QString::number(i))) {
|
---|
251 | double latitude = dom->attribute("lat" + QString::number(i)).toDouble();
|
---|
252 | double longitude = dom->attribute("long" + QString::number(i)).toDouble();
|
---|
253 | double alt = dom->attribute("alt" + QString::number(i)).toDouble();
|
---|
254 | QtMobility::QGeoCoordinate coordinate =
|
---|
255 | QtMobility::QGeoCoordinate(latitude, longitude, alt);
|
---|
256 | coordinates.append(coordinate);
|
---|
257 | i++;
|
---|
258 | }
|
---|
259 |
|
---|
260 | if (enabled == 1) {
|
---|
261 | widget = new Map(this, row, col, name, coordinates, true, period);
|
---|
262 | } else {
|
---|
263 | widget = new Map(this, row, col, name, coordinates, false, period);
|
---|
264 | }
|
---|
265 | }
|
---|
266 | if (type == "TextEdit") {
|
---|
267 | widget = new TextEdit(this, row, col, name);
|
---|
268 | }
|
---|
269 | if (type == "Label") {
|
---|
270 | widget = new Label(this, row, col, name);
|
---|
271 | }
|
---|
272 | if (type == "ListWidget") {
|
---|
273 | // Parse the item list
|
---|
274 | QStringList items;
|
---|
275 | int count = 0;
|
---|
276 | while (dom->hasAttribute("item" + QString::number(count))) {
|
---|
277 | QString item = dom->attribute("item" + QString::number(count));
|
---|
278 | items.append(item);
|
---|
279 | count++;
|
---|
280 | }
|
---|
281 | widget = new ListWidget(this, row, col, name, items);
|
---|
282 | }
|
---|
283 |
|
---|
284 | if (widget != NULL) {
|
---|
285 | if (old_name != "") {
|
---|
286 | widget->RenamedFrom(old_name);
|
---|
287 | }
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | bool Layout::IsUptodate(void) {
|
---|
292 | for (int i = 0; i < childs->count(); i++) {
|
---|
293 | if (childs->at(i)->IsUptodate() == false)
|
---|
294 | return false;
|
---|
295 | }
|
---|
296 | return true;
|
---|
297 | }
|
---|