Changeset 59 in flair-src


Ignore:
Timestamp:
Jul 29, 2016, 3:02:35 PM (8 years ago)
Author:
Thomas Fuhrmann
Message:

Improve ListWidget + code cleanup + doxygen comments

Location:
branches/mavlink/lib/FlairCore/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/mavlink/lib/FlairCore/src/ListWidget.cpp

    r57 r59  
    2020
    2121#include <sstream>
    22 #include <iostream>
    2322
    2423using std::string;
    25 using std::ostringstream;
    2624
    2725namespace flair {
     
    2927
    3028ListWidget::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 
     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
    3632  size_t count = 0;
    3733  while (1) {
    3834    string item;
    39     ostringstream item_prop;
     35    std::ostringstream item_prop;
    4036    item_prop << "item" << count;
    41     if(GetPersistentXmlProp(item_prop.str(), item)) {
     37    if (GetPersistentXmlProp(item_prop.str(), item)) {
    4238      SetVolatileXmlProp(item_prop.str(), item);
    4339      items.push_back(item);
     
    4743    count++;
    4844  }
    49 
    5045  SetVolatileXmlProp("row", position->Row());
    5146  SetVolatileXmlProp("col", position->Col());
     
    6358
    6459void ListWidget::RemoveItem(void) {
    65   if (selected_item_changed) {
    66     selected_item_changed = false;
    67     SetVolatileXmlProp("delete", selected_item_row);
     60  if (selectedItemChanged) {
     61    selectedItemChanged = false;
     62    items.erase(items.cbegin() + selectedItemRow);
     63    SetVolatileXmlProp("delete", selectedItemRow);
    6864    SendXml();
    6965  }
     
    7167
    7268void ListWidget::XmlEvent(void) {
    73   if (GetPersistentXmlProp("value", selected_item_row)) {
    74     selected_item_changed = true;
     69  if (GetPersistentXmlProp("value", selectedItemRow)) {
     70    selectedItemChanged = true;
    7571  }
    7672}
  • branches/mavlink/lib/FlairCore/src/ListWidget.h

    r57 r59  
    2222
    2323/*! \class ListWidget
    24 *
    25 * \brief Class displaying a QListWidget on the ground station
    26 *
    27 */
     24 *
     25 * \brief Class displaying a QListWidget on the ground station
     26 * 
     27 *  The internal list (called items) contains the same elements
     28 *  as the list of the QListWidget on the ground station.
     29 *  To do that, each action done on the ground station has to
     30 *  applied thanks to a click on the "apply" button.
     31 *
     32 */
    2833class ListWidget : public Widget {
    2934public:
     
    6974  void XmlEvent(void);
    7075
    71   //store the items
     76  /**
     77   * List of items displayed in the ground station.
     78   */
    7279  std::vector<std::string> items;
    73   //selected item row, starting from 0
    74   uint16_t selected_item_row;
    75   bool selected_item_changed;
     80  /**
     81   * Row of the item currently selected in the list.
     82   */
     83  uint16_t selectedItemRow;
     84  /**
     85   * Flag to know if the selected item has changed.
     86   */
     87  bool selectedItemChanged;
    7688};
    7789
  • branches/mavlink/lib/FlairCore/src/Widget.cpp

    r53 r59  
    1919#include "Widget_impl.h"
    2020
    21 //to delete, for test purpose
    22 #include <iostream>
    23 
    2421using std::string;
    2522
     
    9693  result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
    9794  if (result != NULL) {
    98     value = std::string((char*)result);
     95    value = std::string((char *)result);
    9996    xmlFree(result);
    10097    return true;
Note: See TracChangeset for help on using the changeset viewer.