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 |
|
---|
23 | using std::string;
|
---|
24 |
|
---|
25 | namespace flair {
|
---|
26 | namespace gui {
|
---|
27 |
|
---|
28 | ListWidget::ListWidget(const LayoutPosition *position, string name)
|
---|
29 | : Widget(position->getLayout(), name, string("ListWidget")),
|
---|
30 | selectedItemRow(-1), selectedItemChanged(false) {
|
---|
31 | // load the items in the xml file and send them to the ground station
|
---|
32 | size_t count = 0;
|
---|
33 | while (1) {
|
---|
34 | string item;
|
---|
35 | std::ostringstream item_prop;
|
---|
36 | item_prop << "item" << count;
|
---|
37 | if (GetPersistentXmlProp(item_prop.str(), item)) {
|
---|
38 | SetVolatileXmlProp(item_prop.str(), item);
|
---|
39 | items.push_back(item);
|
---|
40 | } else {
|
---|
41 | break;
|
---|
42 | }
|
---|
43 | count++;
|
---|
44 | }
|
---|
45 | SetVolatileXmlProp("row", position->Row());
|
---|
46 | SetVolatileXmlProp("col", position->Col());
|
---|
47 | delete position;
|
---|
48 | SendXml();
|
---|
49 | }
|
---|
50 |
|
---|
51 | ListWidget::~ListWidget() { core::Object::ObjectName(); }
|
---|
52 |
|
---|
53 | void ListWidget::AddItem(string name) {
|
---|
54 | items.push_back(name);
|
---|
55 | SetVolatileXmlProp("item", name);
|
---|
56 | SendXml();
|
---|
57 | }
|
---|
58 |
|
---|
59 | void ListWidget::RemoveItem(void) {
|
---|
60 | if (selectedItemChanged) {
|
---|
61 | // Delete the the last item, the xml file will automatically be updated by the GUI
|
---|
62 | // TODO diff when the apply all xml file is received to avoid clear here
|
---|
63 | std::ostringstream item_prop;
|
---|
64 | item_prop << "item" << (items.size() - 1);
|
---|
65 | UnsetPersistentXmlProp(item_prop.str());
|
---|
66 | // Delete the item from the internal list and ask the GUI to delete it
|
---|
67 | selectedItemChanged = false;
|
---|
68 | items.erase(items.cbegin() + selectedItemRow);
|
---|
69 | SetVolatileXmlProp("delete", selectedItemRow);
|
---|
70 | SendXml();
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | void ListWidget::XmlEvent(void) {
|
---|
75 | if (GetPersistentXmlProp("value", selectedItemRow)) {
|
---|
76 | selectedItemChanged = true;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | const std::vector<std::string> &ListWidget::GetItemList() const {
|
---|
81 | return items;
|
---|
82 | }
|
---|
83 |
|
---|
84 | } // end namespace gui
|
---|
85 | } // end namespace flair
|
---|