[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();
|
---|
| 42 | // if(visible_widget==NULL) printf("null\n");
|
---|
| 43 | qgridlayout->setObjectName(name);
|
---|
| 44 | // printf("layout\n%s\n",XmlDoc().toString().toLocal8Bit().constData());
|
---|
| 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 |
|
---|
| 71 | void Layout::XmlEvent(QDomElement dom) {
|
---|
[15] | 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();
|
---|
[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) {
|
---|
| 99 | printf("existe %s\n", name.toLocal8Bit().constData());
|
---|
| 100 | row = qgridlayout->rowCount();
|
---|
| 101 | }
|
---|
[9] | 102 |
|
---|
[15] | 103 | if (type == "TabWidget") {
|
---|
| 104 | int position = dom.attribute("position").toInt();
|
---|
| 105 | widget =
|
---|
| 106 | new TabWidget(this, row, col, name, (QTabWidget::TabPosition)position);
|
---|
| 107 | }
|
---|
| 108 | if (type == "GroupBox") {
|
---|
| 109 | widget = new GroupBox(this, row, col, name);
|
---|
| 110 | }
|
---|
| 111 | if (type == "GridLayout") {
|
---|
| 112 | widget = new GridLayout(this, row, col, name);
|
---|
| 113 | }
|
---|
| 114 | if (type == "SpinBox") {
|
---|
| 115 | int value = dom.attribute("value").toInt();
|
---|
| 116 | QString suffix = dom.attribute("suffix");
|
---|
| 117 | int min = dom.attribute("min").toInt();
|
---|
| 118 | int max = dom.attribute("max").toInt();
|
---|
| 119 | int step = dom.attribute("step").toInt();
|
---|
| 120 | widget = new SpinBox(this, row, col, name, suffix, value, min, max, step);
|
---|
| 121 | }
|
---|
| 122 | if (type == "DoubleSpinBox") {
|
---|
| 123 | QString value = dom.attribute("value");
|
---|
| 124 | QString suffix = dom.attribute("suffix");
|
---|
| 125 | double min = dom.attribute("min").toDouble();
|
---|
| 126 | double max = dom.attribute("max").toDouble();
|
---|
| 127 | double step = dom.attribute("step").toDouble();
|
---|
| 128 | int decimals = dom.attribute("decimals").toInt();
|
---|
| 129 | widget = new DoubleSpinBox(this, row, col, name, suffix, value, min, max,
|
---|
| 130 | step, decimals);
|
---|
| 131 | }
|
---|
| 132 | if (type == "Vector3DSpinBox") {
|
---|
| 133 | QString value[3];
|
---|
| 134 | value[0] = dom.attribute("value_x");
|
---|
| 135 | value[1] = dom.attribute("value_y");
|
---|
| 136 | value[2] = dom.attribute("value_z");
|
---|
| 137 | double min = dom.attribute("min").toDouble();
|
---|
| 138 | double max = dom.attribute("max").toDouble();
|
---|
| 139 | double step = dom.attribute("step").toDouble();
|
---|
| 140 | int decimals = dom.attribute("decimals").toInt();
|
---|
| 141 | widget = new Vector3DSpinBox(this, row, col, name, value, min, max, step,
|
---|
| 142 | decimals);
|
---|
| 143 | }
|
---|
| 144 | if (type == "CheckBox") {
|
---|
| 145 | int value = dom.attribute("value").toInt();
|
---|
| 146 | widget = new CheckBox(this, row, col, name, value);
|
---|
| 147 | }
|
---|
| 148 | if (type == "ComboBox") {
|
---|
| 149 | int value = dom.attribute("value").toInt();
|
---|
| 150 | widget = new ComboBox(this, row, col, name, value);
|
---|
| 151 | }
|
---|
| 152 | if (type == "PushButton") {
|
---|
| 153 | widget = new PushButton(this, row, col, name);
|
---|
| 154 | }
|
---|
| 155 | if (type == "DataPlot1D") {
|
---|
| 156 | float ymin = dom.attribute("min").toFloat();
|
---|
| 157 | float ymax = dom.attribute("max").toFloat();
|
---|
| 158 | int enabled = dom.attribute("enabled").toInt();
|
---|
| 159 | int period = dom.attribute("period").toInt();
|
---|
| 160 | if (enabled == 1) {
|
---|
| 161 | widget = new DataPlot1D(this, row, col, name, ymin, ymax, true, period);
|
---|
| 162 | } else {
|
---|
| 163 | widget = new DataPlot1D(this, row, col, name, ymin, ymax, false, 100);
|
---|
[9] | 164 | }
|
---|
[15] | 165 | }
|
---|
| 166 | if (type == "DataPlot2D") {
|
---|
| 167 | float xmin = dom.attribute("xmin").toFloat();
|
---|
| 168 | float xmax = dom.attribute("xmax").toFloat();
|
---|
| 169 | float ymin = dom.attribute("ymin").toFloat();
|
---|
| 170 | float ymax = dom.attribute("ymax").toFloat();
|
---|
| 171 | QString x_name = dom.attribute("x_name");
|
---|
| 172 | QString y_name = dom.attribute("y_name");
|
---|
| 173 | int enabled = dom.attribute("enabled").toInt();
|
---|
| 174 | int period = dom.attribute("period").toInt();
|
---|
| 175 | if (enabled == 1) {
|
---|
| 176 | widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
| 177 | ymin, ymax, true, period);
|
---|
| 178 | } else {
|
---|
| 179 | widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
| 180 | ymin, ymax, false, 100);
|
---|
[9] | 181 | }
|
---|
[15] | 182 | }
|
---|
[221] | 183 | if (type == "UsSensorPlot") {
|
---|
| 184 | float ymin = dom.attribute("ymin").toFloat();
|
---|
| 185 | float ymax = dom.attribute("ymax").toFloat();
|
---|
| 186 | QString y_name = dom.attribute("y_name");
|
---|
| 187 | int enabled = dom.attribute("enabled").toInt();
|
---|
| 188 | int period = dom.attribute("period").toInt();
|
---|
| 189 | QString type = dom.attribute("type");
|
---|
| 190 | int samples = dom.attribute("samples").toInt();
|
---|
| 191 | if (enabled == 1) {
|
---|
| 192 | widget = new UsSensorPlot(this, row, col, name, y_name,
|
---|
| 193 | ymin, ymax, samples,type,true, period);
|
---|
| 194 | } else {
|
---|
| 195 | widget = new UsSensorPlot(this, row, col, name, y_name,
|
---|
| 196 | ymin, ymax, samples,type,false, 100);
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
[15] | 199 | if (type == "RangeFinderPlot") {
|
---|
| 200 | float xmin = dom.attribute("xmin").toFloat();
|
---|
| 201 | float xmax = dom.attribute("xmax").toFloat();
|
---|
| 202 | float ymin = dom.attribute("ymin").toFloat();
|
---|
| 203 | float ymax = dom.attribute("ymax").toFloat();
|
---|
| 204 | QString x_name = dom.attribute("x_name");
|
---|
| 205 | QString y_name = dom.attribute("y_name");
|
---|
| 206 | QString data_type = dom.attribute("type");
|
---|
| 207 | float start_angle = dom.attribute("start_angle").toFloat();
|
---|
| 208 | float end_angle = dom.attribute("end_angle").toFloat();
|
---|
| 209 | uint32_t nb_samples = dom.attribute("nb_samples").toUInt();
|
---|
| 210 | int enabled = dom.attribute("enabled").toInt();
|
---|
| 211 | int period = dom.attribute("period").toInt();
|
---|
| 212 | int invert_axis = dom.attribute("invert_axis").toInt();
|
---|
| 213 | bool invert_axis_bool;
|
---|
| 214 | if (invert_axis == 0) {
|
---|
| 215 | invert_axis_bool = false;
|
---|
| 216 | } else {
|
---|
| 217 | invert_axis_bool = true;
|
---|
[9] | 218 | }
|
---|
[15] | 219 | if (enabled == 1) {
|
---|
| 220 | widget =
|
---|
| 221 | new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
| 222 | ymin, ymax, start_angle, end_angle, nb_samples,
|
---|
| 223 | data_type, invert_axis, true, period);
|
---|
| 224 | } else {
|
---|
| 225 | widget =
|
---|
| 226 | new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax,
|
---|
| 227 | ymin, ymax, start_angle, end_angle, nb_samples,
|
---|
| 228 | data_type, invert_axis, false, 100);
|
---|
[9] | 229 | }
|
---|
[15] | 230 | }
|
---|
| 231 | if (type == "Picture") {
|
---|
| 232 | int width = dom.attribute("width").toInt();
|
---|
| 233 | int height = dom.attribute("height").toInt();
|
---|
| 234 | int enabled = dom.attribute("enabled").toInt();
|
---|
| 235 | int period = dom.attribute("period").toInt();
|
---|
| 236 | if (enabled == 1) {
|
---|
| 237 | widget = new Picture(this, row, col, name, width, height, true, period);
|
---|
| 238 | } else {
|
---|
| 239 | widget = new Picture(this, row, col, name, width, height, false, period);
|
---|
[9] | 240 | }
|
---|
[15] | 241 | }
|
---|
| 242 | if (type == "Map") {
|
---|
| 243 | int period = dom.attribute("period").toInt();
|
---|
| 244 | int enabled = dom.attribute("enabled").toInt();
|
---|
| 245 | int i = 0;
|
---|
| 246 | QList<QtMobility::QGeoCoordinate> coordinates;
|
---|
| 247 | while (dom.hasAttribute("lat" + QString::number(i))) {
|
---|
| 248 | double latitude = dom.attribute("lat" + QString::number(i)).toDouble();
|
---|
| 249 | double longitude = dom.attribute("long" + QString::number(i)).toDouble();
|
---|
| 250 | double alt = dom.attribute("alt" + QString::number(i)).toDouble();
|
---|
| 251 | QtMobility::QGeoCoordinate coordinate =
|
---|
| 252 | QtMobility::QGeoCoordinate(latitude, longitude, alt);
|
---|
| 253 | coordinates.append(coordinate);
|
---|
| 254 | i++;
|
---|
[9] | 255 | }
|
---|
| 256 |
|
---|
[15] | 257 | if (enabled == 1) {
|
---|
| 258 | widget = new Map(this, row, col, name, coordinates, true, period);
|
---|
| 259 | } else {
|
---|
| 260 | widget = new Map(this, row, col, name, coordinates, false, period);
|
---|
[9] | 261 | }
|
---|
[15] | 262 | }
|
---|
| 263 | if (type == "TextEdit") {
|
---|
| 264 | widget = new TextEdit(this, row, col, name);
|
---|
| 265 | }
|
---|
| 266 | if (type == "Label") {
|
---|
| 267 | widget = new Label(this, row, col, name);
|
---|
| 268 | }
|
---|
[88] | 269 | if (type == "ListWidget") {
|
---|
| 270 | // Parse the item list
|
---|
| 271 | QStringList items;
|
---|
| 272 | int count = 0;
|
---|
| 273 | while (dom.hasAttribute("item" + QString::number(count))) {
|
---|
| 274 | QString item = dom.attribute("item" + QString::number(count));
|
---|
| 275 | items.append(item);
|
---|
| 276 | count++;
|
---|
| 277 | }
|
---|
| 278 | widget = new ListWidget(this, row, col, name, items);
|
---|
| 279 | }
|
---|
[9] | 280 |
|
---|
[15] | 281 | if (widget != NULL) {
|
---|
| 282 | if (old_name != "") {
|
---|
| 283 | widget->RenamedFrom(old_name);
|
---|
[9] | 284 | }
|
---|
[15] | 285 | }
|
---|
[9] | 286 | }
|
---|
| 287 |
|
---|
| 288 | bool Layout::IsUptodate(void) {
|
---|
[15] | 289 | for (int i = 0; i < childs->count(); i++) {
|
---|
| 290 | if (childs->at(i)->IsUptodate() == false)
|
---|
| 291 | return false;
|
---|
| 292 | }
|
---|
| 293 | return true;
|
---|
[9] | 294 | }
|
---|