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

Last change on this file since 10 was 10, checked in by Sanahuja Guillaume, 6 years ago

lic

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