Changeset 54 in flair-src for branches/mavlink/tools/FlairGCS


Ignore:
Timestamp:
07/27/16 17:43:01 (8 years ago)
Author:
Thomas Fuhrmann
Message:

Default xml configuration is working with ListWidget

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

Legend:

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

    r48 r54  
    2323#include <QGridLayout>
    2424#include "ListWidget.h"
     25#include <QStringList>
    2526
    2627Layout::Layout(QWidget *parent, XmlWidget *xml, QString name, QString type)
     
    250251  }
    251252  if (type == "ListWidget") {
    252     widget = new ListWidget(this, row, col, name);
     253    // Parse the item list   
     254    QStringList items;
     255    int count = 0;
     256    while (dom.hasAttribute("item" + QString::number(count))) {
     257      QString item = dom.attribute("item" + QString::number(count));
     258      items.append(item);
     259      count++;
     260    }
     261    widget = new ListWidget(this, row, col, name, items);
    253262  }
    254263
  • branches/mavlink/tools/FlairGCS/src/ListWidget.cpp

    r48 r54  
    1414    : FormLayout(parent, row, col, name, "ListWidget") {
    1515  listwidget = new QListWidget();
    16   // listwidget->setCurrentIndex(value);
    17 
    18   // combobox_value = value;
    19 
    20   // object_layout->addRow(name, listwidget);
    2116  object_layout->addRow(new QLabel(name));
    2217  object_layout->addRow(listwidget);
     18  // to avoid duplicates when adding items
     19  SetIsExpandable(true);
     20}
    2321
    24   // connect(listwidget, SIGNAL(currentIndexChanged(int)), this,
    25   //         SLOT(valuechanged(int)));
    26 
    27   // SetValue(QString::number(combobox_value));
    28 
    29   // pour ne pas faire de doublons qd on ajoute des items
    30   SetIsExpandable(true);
     22ListWidget::ListWidget(Layout *parent, int row, int col, QString name, QStringList& items)
     23    : ListWidget(parent, row, col, name) {
     24  if (!items.isEmpty()) {
     25    listwidget->addItems(items);
     26  }
    3127}
    3228
     
    4137    QListWidgetItem* current_item = listwidget->currentItem();
    4238    listwidget->removeItemWidget(current_item);
    43     if (current_item) { delete current_item; }
     39    if (current_item) {
     40      delete current_item;
     41    }
    4442  }
    4543}
     
    4846  // ui_to_var();
    4947  // ui_to_xml();
     48  std::cout << "SetUptodate" << std::endl;
    5049  visible_widget->setPalette(black_pal);
    5150}
     
    6261
    6362void ListWidget::LoadEvent(QDomElement dom) {
    64   if (listwidget->isEnabled() == true) {
     63  std::cout << "In LoadEvent" << std::endl;
     64  // 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  }
     73
     74  listwidget->addItems(items);
     75
     76  // if (listwidget->isEnabled() == true) {
    6577    // listwidget->setCurrentIndex((dom.attribute("value")).toInt());
    66   }
     78  // }
    6779}
    6880
  • branches/mavlink/tools/FlairGCS/src/ListWidget.h

    r48 r54  
    1010class QListWidget;
    1111class Layout;
     12class QStringList;
    1213
    1314class ListWidget : public FormLayout {
     
    1617public:
    1718  ListWidget(Layout *parent, int row, int col, QString name);
     19  ListWidget(Layout *parent, int row, int col, QString name, QStringList& items);
    1820  ~ListWidget();
    1921
Note: See TracChangeset for help on using the changeset viewer.