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