source: flair-src/branches/mavlink/tools/FlairGCS/src/Layout.cpp@ 48

Last change on this file since 48 was 48, checked in by Thomas Fuhrmann, 8 years ago

Add ListWidget

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