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

Last change on this file since 204 was 88, checked in by Sanahuja Guillaume, 8 years ago

m

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