[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] | 28 | Layout::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] | 34 | Layout::Layout(Layout *parent, QString name, QString type)
|
---|
| 35 | : XmlWidget(name, type, parent) {
|
---|
| 36 | qgridlayout = new QGridLayout(new QWidget());
|
---|
| 37 | Constructor(name);
|
---|
[9] | 38 | }
|
---|
| 39 |
|
---|
| 40 | void 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] | 63 | Layout::~Layout() { delete qgridlayout; }
|
---|
[9] | 64 |
|
---|
| 65 | void Layout::addWidget(QWidget *widget, int row, int column) {
|
---|
[15] | 66 | qgridlayout->addWidget(widget, row, column);
|
---|
[9] | 67 | }
|
---|
| 68 |
|
---|
[15] | 69 | QGridLayout *Layout::getQGridLayout() { return qgridlayout; }
|
---|
[9] | 70 |
|
---|
[269] | 71 | void Layout::XmlEvent(QDomElement *dom) {
|
---|
[15] | 72 | XmlWidget *widget = NULL;
|
---|
[269] | 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") {
|
---|
[269] | 105 | int position = dom->attribute("position").toInt();
|
---|
[15] | 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") {
|
---|
[269] | 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();
|
---|
[15] | 121 | widget = new SpinBox(this, row, col, name, suffix, value, min, max, step);
|
---|
| 122 | }
|
---|
| 123 | if (type == "DoubleSpinBox") {
|
---|
[269] | 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();
|
---|
[437] | 129 | uint16_t decimals = dom->attribute("decimals").toUShort();
|
---|
[15] | 130 | widget = new DoubleSpinBox(this, row, col, name, suffix, value, min, max,
|
---|
| 131 | step, decimals);
|
---|
| 132 | }
|
---|
| 133 | if (type == "Vector3DSpinBox") {
|
---|
| 134 | QString value[3];
|
---|
[269] | 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();
|
---|
[437] | 141 | uint16_t decimals = dom->attribute("decimals").toUShort();
|
---|
[15] | 142 | widget = new Vector3DSpinBox(this, row, col, name, value, min, max, step,
|
---|
| 143 | decimals);
|
---|
| 144 | }
|
---|
| 145 | if (type == "CheckBox") {
|
---|
[269] | 146 | int value = dom->attribute("value").toInt();
|
---|
[15] | 147 | widget = new CheckBox(this, row, col, name, value);
|
---|
| 148 | }
|
---|
| 149 | if (type == "ComboBox") {
|
---|
[437] | 150 | uint16_t value = dom->attribute("value").toUShort();
|
---|
[15] | 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") {
|
---|
[269] | 157 | float ymin = dom->attribute("min").toFloat();
|
---|
| 158 | float ymax = dom->attribute("max").toFloat();
|
---|
| 159 | int enabled = dom->attribute("enabled").toInt();
|
---|
[437] | 160 | uint16_t period = dom->attribute("period").toUShort();
|
---|
| 161 | uint16_t nb_buffering = dom->attribute("nb_buf").toUShort();
|
---|
[455] | 162 | if(period==0) period=100;
|
---|
[15] | 163 | if (enabled == 1) {
|
---|
[437] | 164 | widget = new DataPlot1D(this, row, col, name, ymin, ymax, true, period,nb_buffering);
|
---|
[15] | 165 | } else {
|
---|
[455] | 166 | widget = new DataPlot1D(this, row, col, name, ymin, ymax, false, period,nb_buffering);
|
---|
[9] | 167 | }
|
---|
[15] | 168 | }
|
---|
| 169 | if (type == "DataPlot2D") {
|
---|
[269] | 170 | float xmin = dom->attribute("xmin").toFloat();
|
---|
| 171 | float xmax = dom->attribute("xmax").toFloat();
|
---|
| 172 | float ymin = dom->attribute("ymin").toFloat();
|
---|
| 173 | float ymax = dom->attribute("ymax").toFloat();
|
---|
| 174 | QString x_name = dom->attribute("x_name");
|
---|
| 175 | QString y_name = dom->attribute("y_name");
|
---|
| 176 | int enabled = dom->attribute("enabled").toInt();
|
---|
[437] | 177 | uint16_t period = dom->attribute("period").toUShort();
|
---|
| 178 | uint16_t nb_buffering = dom->attribute("nb_buf").toUShort();
|
---|
[455] | 179 | if(period==0) period=100;
|
---|
[15] | 180 | if (enabled == 1) {
|
---|
| 181 | widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
[437] | 182 | ymin, ymax, true, period,nb_buffering);
|
---|
[15] | 183 | } else {
|
---|
| 184 | widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
[455] | 185 | ymin, ymax, false, period,nb_buffering);
|
---|
[9] | 186 | }
|
---|
[15] | 187 | }
|
---|
[221] | 188 | if (type == "UsSensorPlot") {
|
---|
[269] | 189 | float ymin = dom->attribute("ymin").toFloat();
|
---|
| 190 | float ymax = dom->attribute("ymax").toFloat();
|
---|
| 191 | QString y_name = dom->attribute("y_name");
|
---|
| 192 | int enabled = dom->attribute("enabled").toInt();
|
---|
[437] | 193 | uint16_t period = dom->attribute("period").toUShort();
|
---|
[269] | 194 | QString type = dom->attribute("type");
|
---|
| 195 | int samples = dom->attribute("samples").toInt();
|
---|
[455] | 196 | if(period==0) period=100;
|
---|
[221] | 197 | if (enabled == 1) {
|
---|
| 198 | widget = new UsSensorPlot(this, row, col, name, y_name,
|
---|
| 199 | ymin, ymax, samples,type,true, period);
|
---|
| 200 | } else {
|
---|
| 201 | widget = new UsSensorPlot(this, row, col, name, y_name,
|
---|
[455] | 202 | ymin, ymax, samples,type,false, period);
|
---|
[221] | 203 | }
|
---|
| 204 | }
|
---|
[15] | 205 | if (type == "RangeFinderPlot") {
|
---|
[269] | 206 | float xmin = dom->attribute("xmin").toFloat();
|
---|
| 207 | float xmax = dom->attribute("xmax").toFloat();
|
---|
| 208 | float ymin = dom->attribute("ymin").toFloat();
|
---|
| 209 | float ymax = dom->attribute("ymax").toFloat();
|
---|
| 210 | QString x_name = dom->attribute("x_name");
|
---|
| 211 | QString y_name = dom->attribute("y_name");
|
---|
| 212 | QString data_type = dom->attribute("type");
|
---|
| 213 | float start_angle = dom->attribute("start_angle").toFloat();
|
---|
| 214 | float end_angle = dom->attribute("end_angle").toFloat();
|
---|
| 215 | uint32_t nb_samples = dom->attribute("nb_samples").toUInt();
|
---|
| 216 | int enabled = dom->attribute("enabled").toInt();
|
---|
[437] | 217 | uint16_t period = dom->attribute("period").toUShort();
|
---|
[269] | 218 | int invert_axis = dom->attribute("invert_axis").toInt();
|
---|
[15] | 219 | bool invert_axis_bool;
|
---|
| 220 | if (invert_axis == 0) {
|
---|
| 221 | invert_axis_bool = false;
|
---|
| 222 | } else {
|
---|
| 223 | invert_axis_bool = true;
|
---|
[9] | 224 | }
|
---|
[455] | 225 | if(period==0) period=100;
|
---|
[15] | 226 | if (enabled == 1) {
|
---|
| 227 | widget =
|
---|
| 228 | new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
| 229 | ymin, ymax, start_angle, end_angle, nb_samples,
|
---|
| 230 | data_type, invert_axis, true, period);
|
---|
| 231 | } else {
|
---|
| 232 | widget =
|
---|
| 233 | new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
| 234 | ymin, ymax, start_angle, end_angle, nb_samples,
|
---|
[455] | 235 | data_type, invert_axis, false, period);
|
---|
[9] | 236 | }
|
---|
[15] | 237 | }
|
---|
| 238 | if (type == "Picture") {
|
---|
[269] | 239 | int width = dom->attribute("width").toInt();
|
---|
| 240 | int height = dom->attribute("height").toInt();
|
---|
| 241 | int enabled = dom->attribute("enabled").toInt();
|
---|
[437] | 242 | uint16_t period = dom->attribute("period").toUShort();
|
---|
[455] | 243 | if(period==0) period=100;
|
---|
[15] | 244 | if (enabled == 1) {
|
---|
| 245 | widget = new Picture(this, row, col, name, width, height, true, period);
|
---|
| 246 | } else {
|
---|
| 247 | widget = new Picture(this, row, col, name, width, height, false, period);
|
---|
[9] | 248 | }
|
---|
[15] | 249 | }
|
---|
| 250 | if (type == "Map") {
|
---|
[437] | 251 | uint16_t period = dom->attribute("period").toUShort();
|
---|
[269] | 252 | int enabled = dom->attribute("enabled").toInt();
|
---|
[15] | 253 | int i = 0;
|
---|
| 254 | QList<QtMobility::QGeoCoordinate> coordinates;
|
---|
[269] | 255 | while (dom->hasAttribute("lat" + QString::number(i))) {
|
---|
| 256 | double latitude = dom->attribute("lat" + QString::number(i)).toDouble();
|
---|
| 257 | double longitude = dom->attribute("long" + QString::number(i)).toDouble();
|
---|
| 258 | double alt = dom->attribute("alt" + QString::number(i)).toDouble();
|
---|
[15] | 259 | QtMobility::QGeoCoordinate coordinate =
|
---|
| 260 | QtMobility::QGeoCoordinate(latitude, longitude, alt);
|
---|
| 261 | coordinates.append(coordinate);
|
---|
| 262 | i++;
|
---|
[9] | 263 | }
|
---|
[455] | 264 | if(period==0) period=100;
|
---|
[15] | 265 | if (enabled == 1) {
|
---|
| 266 | widget = new Map(this, row, col, name, coordinates, true, period);
|
---|
| 267 | } else {
|
---|
| 268 | widget = new Map(this, row, col, name, coordinates, false, period);
|
---|
[9] | 269 | }
|
---|
[15] | 270 | }
|
---|
| 271 | if (type == "TextEdit") {
|
---|
| 272 | widget = new TextEdit(this, row, col, name);
|
---|
| 273 | }
|
---|
| 274 | if (type == "Label") {
|
---|
| 275 | widget = new Label(this, row, col, name);
|
---|
| 276 | }
|
---|
[88] | 277 | if (type == "ListWidget") {
|
---|
| 278 | // Parse the item list
|
---|
| 279 | QStringList items;
|
---|
| 280 | int count = 0;
|
---|
[269] | 281 | while (dom->hasAttribute("item" + QString::number(count))) {
|
---|
| 282 | QString item = dom->attribute("item" + QString::number(count));
|
---|
[88] | 283 | items.append(item);
|
---|
| 284 | count++;
|
---|
| 285 | }
|
---|
| 286 | widget = new ListWidget(this, row, col, name, items);
|
---|
| 287 | }
|
---|
[9] | 288 |
|
---|
[15] | 289 | if (widget != NULL) {
|
---|
| 290 | if (old_name != "") {
|
---|
| 291 | widget->RenamedFrom(old_name);
|
---|
[9] | 292 | }
|
---|
[15] | 293 | }
|
---|
[9] | 294 | }
|
---|
| 295 |
|
---|
| 296 | bool Layout::IsUptodate(void) {
|
---|
[15] | 297 | for (int i = 0; i < childs->count(); i++) {
|
---|
| 298 | if (childs->at(i)->IsUptodate() == false)
|
---|
| 299 | return false;
|
---|
| 300 | }
|
---|
| 301 | return true;
|
---|
[9] | 302 | }
|
---|