Changeset 56 in flair-src
- Timestamp:
- Jul 28, 2016, 6:04:21 PM (8 years ago)
- Location:
- branches/mavlink/tools/FlairGCS/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mavlink/tools/FlairGCS/src/ListWidget.cpp
r54 r56 8 8 #include <QFormLayout> 9 9 #include <QLabel> 10 #include <QListWidgetItem> 11 #include <QPalette> 10 12 11 13 #include <iostream> 14 #include <sstream> 12 15 13 16 ListWidget::ListWidget(Layout *parent, int row, int col, QString name) … … 16 19 object_layout->addRow(new QLabel(name)); 17 20 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 18 31 // to avoid duplicates when adding items 19 32 SetIsExpandable(true); … … 29 42 ListWidget::~ListWidget() { delete listwidget; } 30 43 44 //received from the UAV / FlairCore 31 45 void 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 // } 32 51 if (dom.attribute("item") != "") { 33 52 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); 35 56 } 36 57 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; 41 62 } 42 63 } … … 44 65 45 66 void 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; 50 71 } 51 72 52 // void ListWidget::ui_to_var(void) { combobox_value = listwidget->currentIndex(); }73 void ListWidget::ui_to_var(void) { current_item_row = listwidget->currentRow(); } 53 74 54 // void ListWidget::ui_to_xml(void) { 55 // SetValue(QString::number(listwidget->currentIndex())); 56 // } 75 void 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 } 57 86 58 void ListWidget::Reset(void) { 59 // listwidget->setCurrentIndex(combobox_value); 87 void ListWidget::Reset(void) { 88 if (current_item_row != -1) { 89 listwidget->setCurrentRow(current_item_row); 90 } 60 91 } 61 92 … … 63 94 std::cout << "In LoadEvent" << std::endl; 64 95 // 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 // } 73 104 74 listwidget->addItems(items);105 // listwidget->addItems(items); 75 106 76 107 // if (listwidget->isEnabled() == true) { … … 79 110 } 80 111 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 // } 112 void 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 121 bool ListWidget::IsUptodate(void) { 122 return is_up_to_date; 123 } -
branches/mavlink/tools/FlairGCS/src/ListWidget.h
r54 r56 11 11 class Layout; 12 12 class QStringList; 13 class QListWidgetItem; 14 class QPalette; 13 15 14 16 class ListWidget : public FormLayout { … … 22 24 private: 23 25 QListWidget* listwidget; 26 int current_item_row; 27 bool is_up_to_date; 28 QPalette list_red_pal; 29 QPalette list_black_pal; 24 30 void XmlEvent(QDomElement dom); 25 31 void SetUptodate(void); 26 32 void Reset(void); 27 33 void LoadEvent(QDomElement dom); 34 bool IsUptodate(void); 28 35 29 //void ui_to_var(void);30 //void ui_to_xml(void);36 void ui_to_var(void); 37 void ui_to_xml(void); 31 38 32 39 private slots: 33 // void valuechanged(int value);40 void SelectedItemChanged(int current_row); 34 41 }; 35 42
Note:
See TracChangeset
for help on using the changeset viewer.