Changeset 56 in flair-src


Ignore:
Timestamp:
Jul 28, 2016, 6:04:21 PM (8 years ago)
Author:
Thomas Fuhrmann
Message:

Management of lists using red/black colors

Location:
branches/mavlink/tools/FlairGCS/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/mavlink/tools/FlairGCS/src/ListWidget.cpp

    r54 r56  
    88#include <QFormLayout>
    99#include <QLabel>
     10#include <QListWidgetItem>
     11#include <QPalette>
    1012
    1113#include <iostream>
     14#include <sstream>
    1215
    1316ListWidget::ListWidget(Layout *parent, int row, int col, QString name)
     
    1619  object_layout->addRow(new QLabel(name));
    1720  object_layout->addRow(listwidget);
     21
     22  list_red_pal.setColor(QPalette::HighlightedText, QColor(255, 0, 0));
     23  list_black_pal.setColor(QPalette::HighlightedText, QColor(255, 255, 255));
     24
     25  current_item_row = -1;
     26  is_up_to_date = true;
     27
     28  connect(listwidget, SIGNAL(currentRowChanged(int)), this,
     29          SLOT(SelectedItemChanged(int)));
     30
    1831  // to avoid duplicates when adding items
    1932  SetIsExpandable(true);
     
    2942ListWidget::~ListWidget() { delete listwidget; }
    3043
     44//received from the UAV / FlairCore
    3145void ListWidget::XmlEvent(QDomElement dom) {
     46  is_up_to_date = false;
     47  // if (dom.attribute("value") != "") {
     48  //   int new_row = dom.attribute("value");
     49  //   listwidget->setCurrentRow(new_row);
     50  // }
    3251  if (dom.attribute("item") != "") {
    3352    QString item = dom.attribute("item");
    34     listwidget->addItem(item);
     53    QListWidgetItem* widget_item = new QListWidgetItem(item);
     54    widget_item->setForeground(Qt::red);
     55    listwidget->addItem(widget_item);
    3556  }
    3657  if (dom.attribute("delete") != "") {
    37     QListWidgetItem* current_item = listwidget->currentItem();
    38     listwidget->removeItemWidget(current_item);
    39     if (current_item) {
    40       delete current_item;
     58    int row_to_del = dom.attribute("delete").toInt();
     59    QListWidgetItem* item_to_del = listwidget->takeItem(row_to_del);
     60    if (item_to_del) {
     61      delete item_to_del;
    4162    }
    4263  }
     
    4465
    4566void ListWidget::SetUptodate(void) {
    46   // ui_to_var();
    47   // ui_to_xml();
    48   std::cout << "SetUptodate" << std::endl;
    49   visible_widget->setPalette(black_pal);
     67  ui_to_var();
     68  ui_to_xml();
     69  listwidget->setPalette(list_black_pal);
     70  is_up_to_date = true;
    5071}
    5172
    52 // void ListWidget::ui_to_var(void) { combobox_value = listwidget->currentIndex(); }
     73void ListWidget::ui_to_var(void) { current_item_row = listwidget->currentRow(); }
    5374
    54 // void ListWidget::ui_to_xml(void) {
    55 //   SetValue(QString::number(listwidget->currentIndex()));
    56 // }
     75void ListWidget::ui_to_xml(void) {
     76  SetValue(QString::number(listwidget->currentRow()));
     77  //add the list of items
     78  for(int count = 0; count < listwidget->count(); count++) {
     79    std::string item;
     80    std::ostringstream item_prop;
     81    item_prop << "item" << count;
     82    SetAttribute(QString::fromStdString(item_prop.str()), listwidget->item(count)->text());
     83    listwidget->item(count)->setForeground(Qt::black);
     84  }
     85}
    5786
    58 void ListWidget::Reset(void) {
    59   // listwidget->setCurrentIndex(combobox_value);
     87void ListWidget::Reset(void) {
     88  if (current_item_row != -1) {
     89    listwidget->setCurrentRow(current_item_row);
     90  }
    6091}
    6192
     
    6394  std::cout << "In LoadEvent" << std::endl;
    6495  // Parse the item list   
    65   QStringList items;
    66   int count = 0;
    67   while (dom.hasAttribute("item" + QString::number(count))) {
    68     QString item = dom.attribute("item" + QString::number(count));
    69     std::cout << "Item" << count << " : " << item.toStdString() << std::endl;
    70     items.append(item);
    71     count++;
    72   }
     96  // QStringList items;
     97  // int count = 0;
     98  // while (dom.hasAttribute("item" + QString::number(count))) {
     99  //   QString item = dom.attribute("item" + QString::number(count));
     100  //   std::cout << "Item" << count << " : " << item.toStdString() << std::endl;
     101  //   items.append(item);
     102  //   count++;
     103  // }
    73104
    74   listwidget->addItems(items);
     105  // listwidget->addItems(items);
    75106
    76107  // if (listwidget->isEnabled() == true) {
     
    79110}
    80111
    81 // void ListWidget::valuechanged(int value) {
    82 //   if (value != combobox_value) {
    83 //     visible_widget->setPalette(red_pal);
    84 //   } else {
    85 //     visible_widget->setPalette(black_pal);
    86 //   }
    87 // }
     112void ListWidget::SelectedItemChanged(int current_row) {
     113  if (current_row != current_item_row) {
     114    is_up_to_date = false;
     115    listwidget->setPalette(list_red_pal);
     116  } else {
     117    listwidget->setPalette(list_black_pal);
     118  }
     119}
     120
     121bool ListWidget::IsUptodate(void) {
     122  return is_up_to_date;
     123}
  • branches/mavlink/tools/FlairGCS/src/ListWidget.h

    r54 r56  
    1111class Layout;
    1212class QStringList;
     13class QListWidgetItem;
     14class QPalette;
    1315
    1416class ListWidget : public FormLayout {
     
    2224private:
    2325  QListWidget* listwidget;
     26  int current_item_row;
     27  bool is_up_to_date;
     28  QPalette list_red_pal;
     29  QPalette list_black_pal;
    2430  void XmlEvent(QDomElement dom);
    2531  void SetUptodate(void);
    2632  void Reset(void);
    2733  void LoadEvent(QDomElement dom);
     34  bool IsUptodate(void);
    2835
    29   // void ui_to_var(void);
    30   // void ui_to_xml(void);
     36  void ui_to_var(void);
     37  void ui_to_xml(void);
    3138
    3239private slots:
    33   // void valuechanged(int value);
     40  void SelectedItemChanged(int current_row);
    3441};
    3542
Note: See TracChangeset for help on using the changeset viewer.