source: flair-src/trunk/tools/FlairGCS/src/Layout.cpp@ 440

Last change on this file since 440 was 437, checked in by Sanahuja Guillaume, 3 years ago

prepare for graphs buffering

File size: 10.4 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]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"
[221]20#include "UsSensorPlot.h"
[9]21#include "Picture.h"
22#include "Map.h"
23#include <QGeoCoordinate>
24#include <QGridLayout>
[88]25#include "ListWidget.h"
26#include <QStringList>
[9]27
[15]28Layout::Layout(QWidget *parent, XmlWidget *xml, QString name, QString type)
29 : XmlWidget(name, type, xml) {
30 qgridlayout = new QGridLayout(parent);
31 Constructor(name);
[9]32}
33
[15]34Layout::Layout(Layout *parent, QString name, QString type)
35 : XmlWidget(name, type, parent) {
36 qgridlayout = new QGridLayout(new QWidget());
37 Constructor(name);
[9]38}
39
40void Layout::Constructor(QString name) {
[15]41 visible_widget = qgridlayout->parentWidget();
[244]42 // if(visible_widget==NULL) fprintf(stderr,"null\n");
[15]43 qgridlayout->setObjectName(name);
[244]44 // fprintf(stderr,"layout\n%s\n",XmlDoc().toString().toLocal8Bit().constData());
[15]45 SetIsContainer(true);
46 SetIsExpandable(true);
[9]47
[15]48 qgridlayout->setHorizontalSpacing(2);
49 qgridlayout->setVerticalSpacing(2);
50 qgridlayout->setContentsMargins(2, 2, 2, 2);
[9]51
[15]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);*/
[9]61}
62
[15]63Layout::~Layout() { delete qgridlayout; }
[9]64
65void Layout::addWidget(QWidget *widget, int row, int column) {
[15]66 qgridlayout->addWidget(widget, row, column);
[9]67}
68
[15]69QGridLayout *Layout::getQGridLayout() { return qgridlayout; }
[9]70
[269]71void Layout::XmlEvent(QDomElement *dom) {
[15]72 XmlWidget *widget = NULL;
[269]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();
[9]78
[15]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;
[9]94 }
[15]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) {
[244]99 fprintf(stderr,"widget %s: (%i,%i) already exists\n", name.toLocal8Bit().constData(),row, col);
[15]100 row = qgridlayout->rowCount();
[244]101 fprintf(stderr,"using (%i,%i) for %s\n", row, col,name.toLocal8Bit().constData());
[15]102 }
[9]103
[15]104 if (type == "TabWidget") {
[269]105 int position = dom->attribute("position").toInt();
[15]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") {
[269]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();
[15]121 widget = new SpinBox(this, row, col, name, suffix, value, min, max, step);
122 }
123 if (type == "DoubleSpinBox") {
[269]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();
[437]129 uint16_t decimals = dom->attribute("decimals").toUShort();
[15]130 widget = new DoubleSpinBox(this, row, col, name, suffix, value, min, max,
131 step, decimals);
132 }
133 if (type == "Vector3DSpinBox") {
134 QString value[3];
[269]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();
[437]141 uint16_t decimals = dom->attribute("decimals").toUShort();
[15]142 widget = new Vector3DSpinBox(this, row, col, name, value, min, max, step,
143 decimals);
144 }
145 if (type == "CheckBox") {
[269]146 int value = dom->attribute("value").toInt();
[15]147 widget = new CheckBox(this, row, col, name, value);
148 }
149 if (type == "ComboBox") {
[437]150 uint16_t value = dom->attribute("value").toUShort();
[15]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") {
[269]157 float ymin = dom->attribute("min").toFloat();
158 float ymax = dom->attribute("max").toFloat();
159 int enabled = dom->attribute("enabled").toInt();
[437]160 uint16_t period = dom->attribute("period").toUShort();
161 uint16_t nb_buffering = dom->attribute("nb_buf").toUShort();
[15]162 if (enabled == 1) {
[437]163 widget = new DataPlot1D(this, row, col, name, ymin, ymax, true, period,nb_buffering);
[15]164 } else {
[437]165 widget = new DataPlot1D(this, row, col, name, ymin, ymax, false, 100,nb_buffering);
[9]166 }
[15]167 }
168 if (type == "DataPlot2D") {
[269]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();
[437]176 uint16_t period = dom->attribute("period").toUShort();
177 uint16_t nb_buffering = dom->attribute("nb_buf").toUShort();
[15]178 if (enabled == 1) {
179 widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
[437]180 ymin, ymax, true, period,nb_buffering);
[15]181 } else {
182 widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
[437]183 ymin, ymax, false, 100,nb_buffering);
[9]184 }
[15]185 }
[221]186 if (type == "UsSensorPlot") {
[269]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();
[437]191 uint16_t period = dom->attribute("period").toUShort();
[269]192 QString type = dom->attribute("type");
193 int samples = dom->attribute("samples").toInt();
[221]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 }
[15]202 if (type == "RangeFinderPlot") {
[269]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();
[437]214 uint16_t period = dom->attribute("period").toUShort();
[269]215 int invert_axis = dom->attribute("invert_axis").toInt();
[15]216 bool invert_axis_bool;
217 if (invert_axis == 0) {
218 invert_axis_bool = false;
219 } else {
220 invert_axis_bool = true;
[9]221 }
[15]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);
[9]232 }
[15]233 }
234 if (type == "Picture") {
[269]235 int width = dom->attribute("width").toInt();
236 int height = dom->attribute("height").toInt();
237 int enabled = dom->attribute("enabled").toInt();
[437]238 uint16_t period = dom->attribute("period").toUShort();
[15]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);
[9]243 }
[15]244 }
245 if (type == "Map") {
[437]246 uint16_t period = dom->attribute("period").toUShort();
[269]247 int enabled = dom->attribute("enabled").toInt();
[15]248 int i = 0;
249 QList<QtMobility::QGeoCoordinate> coordinates;
[269]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();
[15]254 QtMobility::QGeoCoordinate coordinate =
255 QtMobility::QGeoCoordinate(latitude, longitude, alt);
256 coordinates.append(coordinate);
257 i++;
[9]258 }
259
[15]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);
[9]264 }
[15]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 }
[88]272 if (type == "ListWidget") {
273 // Parse the item list
274 QStringList items;
275 int count = 0;
[269]276 while (dom->hasAttribute("item" + QString::number(count))) {
277 QString item = dom->attribute("item" + QString::number(count));
[88]278 items.append(item);
279 count++;
280 }
281 widget = new ListWidget(this, row, col, name, items);
282 }
[9]283
[15]284 if (widget != NULL) {
285 if (old_name != "") {
286 widget->RenamedFrom(old_name);
[9]287 }
[15]288 }
[9]289}
290
291bool Layout::IsUptodate(void) {
[15]292 for (int i = 0; i < childs->count(); i++) {
293 if (childs->at(i)->IsUptodate() == false)
294 return false;
295 }
296 return true;
[9]297}
Note: See TracBrowser for help on using the repository browser.