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

Last change on this file since 265 was 244, checked in by Sanahuja Guillaume, 7 years ago

modifs segfault when closing connection

File size: 10.1 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
71void Layout::XmlEvent(QDomElement dom) {
[15]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();
[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") {
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 int decimals = dom.attribute("decimals").toInt();
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 int decimals = dom.attribute("decimals").toInt();
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 int value = dom.attribute("value").toInt();
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 int period = dom.attribute("period").toInt();
161 if (enabled == 1) {
162 widget = new DataPlot1D(this, row, col, name, ymin, ymax, true, period);
163 } else {
164 widget = new DataPlot1D(this, row, col, name, ymin, ymax, false, 100);
[9]165 }
[15]166 }
167 if (type == "DataPlot2D") {
168 float xmin = dom.attribute("xmin").toFloat();
169 float xmax = dom.attribute("xmax").toFloat();
170 float ymin = dom.attribute("ymin").toFloat();
171 float ymax = dom.attribute("ymax").toFloat();
172 QString x_name = dom.attribute("x_name");
173 QString y_name = dom.attribute("y_name");
174 int enabled = dom.attribute("enabled").toInt();
175 int period = dom.attribute("period").toInt();
176 if (enabled == 1) {
177 widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
178 ymin, ymax, true, period);
179 } else {
180 widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
181 ymin, ymax, false, 100);
[9]182 }
[15]183 }
[221]184 if (type == "UsSensorPlot") {
185 float ymin = dom.attribute("ymin").toFloat();
186 float ymax = dom.attribute("ymax").toFloat();
187 QString y_name = dom.attribute("y_name");
188 int enabled = dom.attribute("enabled").toInt();
189 int period = dom.attribute("period").toInt();
190 QString type = dom.attribute("type");
191 int samples = dom.attribute("samples").toInt();
192 if (enabled == 1) {
193 widget = new UsSensorPlot(this, row, col, name, y_name,
194 ymin, ymax, samples,type,true, period);
195 } else {
196 widget = new UsSensorPlot(this, row, col, name, y_name,
197 ymin, ymax, samples,type,false, 100);
198 }
199 }
[15]200 if (type == "RangeFinderPlot") {
201 float xmin = dom.attribute("xmin").toFloat();
202 float xmax = dom.attribute("xmax").toFloat();
203 float ymin = dom.attribute("ymin").toFloat();
204 float ymax = dom.attribute("ymax").toFloat();
205 QString x_name = dom.attribute("x_name");
206 QString y_name = dom.attribute("y_name");
207 QString data_type = dom.attribute("type");
208 float start_angle = dom.attribute("start_angle").toFloat();
209 float end_angle = dom.attribute("end_angle").toFloat();
210 uint32_t nb_samples = dom.attribute("nb_samples").toUInt();
211 int enabled = dom.attribute("enabled").toInt();
212 int period = dom.attribute("period").toInt();
213 int invert_axis = dom.attribute("invert_axis").toInt();
214 bool invert_axis_bool;
215 if (invert_axis == 0) {
216 invert_axis_bool = false;
217 } else {
218 invert_axis_bool = true;
[9]219 }
[15]220 if (enabled == 1) {
221 widget =
222 new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
223 ymin, ymax, start_angle, end_angle, nb_samples,
224 data_type, invert_axis, true, period);
225 } else {
226 widget =
227 new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
228 ymin, ymax, start_angle, end_angle, nb_samples,
229 data_type, invert_axis, false, 100);
[9]230 }
[15]231 }
232 if (type == "Picture") {
233 int width = dom.attribute("width").toInt();
234 int height = dom.attribute("height").toInt();
235 int enabled = dom.attribute("enabled").toInt();
236 int period = dom.attribute("period").toInt();
237 if (enabled == 1) {
238 widget = new Picture(this, row, col, name, width, height, true, period);
239 } else {
240 widget = new Picture(this, row, col, name, width, height, false, period);
[9]241 }
[15]242 }
243 if (type == "Map") {
244 int period = dom.attribute("period").toInt();
245 int enabled = dom.attribute("enabled").toInt();
246 int i = 0;
247 QList<QtMobility::QGeoCoordinate> coordinates;
248 while (dom.hasAttribute("lat" + QString::number(i))) {
249 double latitude = dom.attribute("lat" + QString::number(i)).toDouble();
250 double longitude = dom.attribute("long" + QString::number(i)).toDouble();
251 double alt = dom.attribute("alt" + QString::number(i)).toDouble();
252 QtMobility::QGeoCoordinate coordinate =
253 QtMobility::QGeoCoordinate(latitude, longitude, alt);
254 coordinates.append(coordinate);
255 i++;
[9]256 }
257
[15]258 if (enabled == 1) {
259 widget = new Map(this, row, col, name, coordinates, true, period);
260 } else {
261 widget = new Map(this, row, col, name, coordinates, false, period);
[9]262 }
[15]263 }
264 if (type == "TextEdit") {
265 widget = new TextEdit(this, row, col, name);
266 }
267 if (type == "Label") {
268 widget = new Label(this, row, col, name);
269 }
[88]270 if (type == "ListWidget") {
271 // Parse the item list
272 QStringList items;
273 int count = 0;
274 while (dom.hasAttribute("item" + QString::number(count))) {
275 QString item = dom.attribute("item" + QString::number(count));
276 items.append(item);
277 count++;
278 }
279 widget = new ListWidget(this, row, col, name, items);
280 }
[9]281
[15]282 if (widget != NULL) {
283 if (old_name != "") {
284 widget->RenamedFrom(old_name);
[9]285 }
[15]286 }
[9]287}
288
289bool Layout::IsUptodate(void) {
[15]290 for (int i = 0; i < childs->count(); i++) {
291 if (childs->at(i)->IsUptodate() == false)
292 return false;
293 }
294 return true;
[9]295}
Note: See TracBrowser for help on using the repository browser.