source: flair-src/branches/mavlink/lib/FlairCore/src/ListWidget.cpp@ 59

Last change on this file since 59 was 59, checked in by Thomas Fuhrmann, 5 years ago

Improve ListWidget + code cleanup + doxygen comments

File size: 1.8 KB
RevLine 
[49]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
[53]21#include <sstream>
22
[49]23using std::string;
24
25namespace flair {
26namespace gui {
27
28ListWidget::ListWidget(const LayoutPosition *position, string name)
[59]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
[53]32 size_t count = 0;
33 while (1) {
34 string item;
[59]35 std::ostringstream item_prop;
[53]36 item_prop << "item" << count;
[59]37 if (GetPersistentXmlProp(item_prop.str(), item)) {
[53]38 SetVolatileXmlProp(item_prop.str(), item);
39 items.push_back(item);
40 } else {
41 break;
42 }
43 count++;
44 }
[49]45 SetVolatileXmlProp("row", position->Row());
46 SetVolatileXmlProp("col", position->Col());
47 delete position;
48 SendXml();
49}
50
51ListWidget::~ListWidget() { core::Object::ObjectName(); }
52
53void ListWidget::AddItem(string name) {
[57]54 items.push_back(name);
[49]55 SetVolatileXmlProp("item", name);
56 SendXml();
57}
58
59void ListWidget::RemoveItem(void) {
[59]60 if (selectedItemChanged) {
61 selectedItemChanged = false;
62 items.erase(items.cbegin() + selectedItemRow);
63 SetVolatileXmlProp("delete", selectedItemRow);
[57]64 SendXml();
65 }
[49]66}
67
68void ListWidget::XmlEvent(void) {
[59]69 if (GetPersistentXmlProp("value", selectedItemRow)) {
70 selectedItemChanged = true;
[57]71 }
[49]72}
73
74} // end namespace gui
75} // end namespace flair
Note: See TracBrowser for help on using the repository browser.