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