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 | // created: 2016/07/26
|
---|
6 | // filename: ListWidget.cpp
|
---|
7 | //
|
---|
8 | // author: Thomas Fuhrmann
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class displaying a QListWidget on the ground station
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 | #include "ListWidget.h"
|
---|
18 | #include "Layout.h"
|
---|
19 | #include "LayoutPosition.h"
|
---|
20 |
|
---|
21 | #include <sstream>
|
---|
22 | #include <iostream>
|
---|
23 |
|
---|
24 | using std::string;
|
---|
25 | using std::ostringstream;
|
---|
26 |
|
---|
27 | namespace flair {
|
---|
28 | namespace gui {
|
---|
29 |
|
---|
30 | ListWidget::ListWidget(const LayoutPosition *position, string name)
|
---|
31 | : Widget(position->getLayout(), name, string("ListWidget")) {
|
---|
32 |
|
---|
33 | selected_item_row = -1;
|
---|
34 | selected_item_changed = false;
|
---|
35 |
|
---|
36 | size_t count = 0;
|
---|
37 | while (1) {
|
---|
38 | string item;
|
---|
39 | ostringstream item_prop;
|
---|
40 | item_prop << "item" << count;
|
---|
41 | if(GetPersistentXmlProp(item_prop.str(), item)) {
|
---|
42 | SetVolatileXmlProp(item_prop.str(), item);
|
---|
43 | items.push_back(item);
|
---|
44 | } else {
|
---|
45 | break;
|
---|
46 | }
|
---|
47 | count++;
|
---|
48 | }
|
---|
49 |
|
---|
50 | SetVolatileXmlProp("row", position->Row());
|
---|
51 | SetVolatileXmlProp("col", position->Col());
|
---|
52 | delete position;
|
---|
53 | SendXml();
|
---|
54 | }
|
---|
55 |
|
---|
56 | ListWidget::~ListWidget() { core::Object::ObjectName(); }
|
---|
57 |
|
---|
58 | void ListWidget::AddItem(string name) {
|
---|
59 | items.push_back(name);
|
---|
60 | SetVolatileXmlProp("item", name);
|
---|
61 | SendXml();
|
---|
62 | }
|
---|
63 |
|
---|
64 | void ListWidget::RemoveItem(void) {
|
---|
65 | if (selected_item_changed) {
|
---|
66 | selected_item_changed = false;
|
---|
67 | SetVolatileXmlProp("delete", selected_item_row);
|
---|
68 | SendXml();
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | void ListWidget::XmlEvent(void) {
|
---|
73 | if (GetPersistentXmlProp("value", selected_item_row)) {
|
---|
74 | selected_item_changed = true;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | } // end namespace gui
|
---|
79 | } // end namespace flair
|
---|