Changeset 60 in flair-src for branches/mavlink/tools/FlairGCS/src
- Timestamp:
- 07/29/16 15:14:55 (8 years ago)
- Location:
- branches/mavlink/tools/FlairGCS/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mavlink/tools/FlairGCS/src/ListWidget.cpp
r56 r60 15 15 16 16 ListWidget::ListWidget(Layout *parent, int row, int col, QString name) 17 : FormLayout(parent, row, col, name, "ListWidget") { 17 : currentItemRow(-1), isUpToDate(true), 18 FormLayout(parent, row, col, name, "ListWidget") { 18 19 listwidget = new QListWidget(); 20 // construct the object in 2 times, to have the label above the list 19 21 object_layout->addRow(new QLabel(name)); 20 22 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 23 // modify the color palette to have the selected item text in red 24 palListRed.setColor(QPalette::HighlightedText, QColor(255, 0, 0)); 25 palListDefault.setColor(QPalette::HighlightedText, QColor(255, 255, 255)); 28 26 connect(listwidget, SIGNAL(currentRowChanged(int)), this, 29 27 SLOT(SelectedItemChanged(int))); 30 31 // to avoid duplicates when adding items 28 // to avoid duplicates when adding items 32 29 SetIsExpandable(true); 33 30 } 34 31 35 ListWidget::ListWidget(Layout *parent, int row, int col, QString name, QStringList& items) 32 ListWidget::ListWidget(Layout *parent, int row, int col, QString name, 33 QStringList &items) 36 34 : ListWidget(parent, row, col, name) { 37 35 if (!items.isEmpty()) { … … 40 38 } 41 39 42 ListWidget::~ListWidget() { delete listwidget; } 40 ListWidget::~ListWidget() { 41 if (listwidget) { 42 delete listwidget; 43 } 44 } 43 45 44 //received from the UAV / FlairCore45 46 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 // } 47 isUpToDate = false; 51 48 if (dom.attribute("item") != "") { 52 49 QString item = dom.attribute("item"); 53 QListWidgetItem* widget_item = new QListWidgetItem(item); 50 QListWidgetItem *widget_item = new QListWidgetItem(item); 51 // new item, so the text is red 54 52 widget_item->setForeground(Qt::red); 55 53 listwidget->addItem(widget_item); … … 57 55 if (dom.attribute("delete") != "") { 58 56 int row_to_del = dom.attribute("delete").toInt(); 59 QListWidgetItem *item_to_del = listwidget->takeItem(row_to_del);57 QListWidgetItem *item_to_del = listwidget->takeItem(row_to_del); 60 58 if (item_to_del) { 61 delete item_to_del; 59 delete item_to_del; 62 60 } 63 61 } … … 67 65 ui_to_var(); 68 66 ui_to_xml(); 69 listwidget->setPalette( list_black_pal);70 is _up_to_date = true;67 listwidget->setPalette(palListDefault); 68 isUpToDate = true; 71 69 } 72 70 73 void ListWidget::ui_to_var(void) { current_item_row = listwidget->currentRow(); } 71 void ListWidget::ui_to_var(void) { 72 currentItemRow = listwidget->currentRow(); 73 } 74 74 75 75 void ListWidget::ui_to_xml(void) { 76 76 SetValue(QString::number(listwidget->currentRow())); 77 // add the list of items78 for (int count = 0; count < listwidget->count(); count++) {77 // add the list of items 78 for (int count = 0; count < listwidget->count(); count++) { 79 79 std::string item; 80 80 std::ostringstream item_prop; 81 81 item_prop << "item" << count; 82 SetAttribute(QString::fromStdString(item_prop.str()), listwidget->item(count)->text()); 82 SetAttribute(QString::fromStdString(item_prop.str()), 83 listwidget->item(count)->text()); 83 84 listwidget->item(count)->setForeground(Qt::black); 84 85 } … … 86 87 87 88 void ListWidget::Reset(void) { 88 if (current _item_row != -1) {89 listwidget->setCurrentRow(current _item_row);89 if (currentItemRow != -1) { 90 listwidget->setCurrentRow(currentItemRow); 90 91 } 91 92 } 92 93 93 94 void ListWidget::LoadEvent(QDomElement dom) { 94 std::cout << "In LoadEvent" << std::endl; 95 // Parse the item list 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 // } 104 105 // listwidget->addItems(items); 106 107 // if (listwidget->isEnabled() == true) { 108 // listwidget->setCurrentIndex((dom.attribute("value")).toInt()); 109 // } 95 std::cout << "FlairGCS LoadEvent" << std::endl; 96 if (listwidget->isEnabled() == true) { 97 std::cout << "FlairGCS LoadEvent loading" << std::endl; 98 listwidget->clear(); 99 QStringList items; 100 int count = 0; 101 while (dom.hasAttribute("item" + QString::number(count))) { 102 listwidget->addItem(dom.attribute("item" + QString::number(count))); 103 count++; 104 } 105 } 110 106 } 111 107 112 108 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);109 if (current_row != currentItemRow) { 110 isUpToDate = false; 111 listwidget->setPalette(palListRed); 116 112 } else { 117 listwidget->setPalette( list_black_pal);113 listwidget->setPalette(palListDefault); 118 114 } 119 115 } 120 116 121 bool ListWidget::IsUptodate(void) { 122 return is_up_to_date; 123 } 117 bool ListWidget::IsUptodate(void) { return isUpToDate; } -
branches/mavlink/tools/FlairGCS/src/ListWidget.h
r56 r60 3 3 // CECILL-C License, Version 1.0. 4 4 // %flair:license} 5 /*! 6 * \file ListWidget.h 7 * \brief Class displaying a QListWidget on the ground station 8 * \author Thomas Fuhrmann, Copyright Heudiasyc UMR UTC/CNRS 7253 9 * \date 2016/07/26 10 * \version 1.0 11 */ 5 12 #ifndef LISTWIDGET_H 6 13 #define LISTWIDGET_H … … 14 21 class QPalette; 15 22 23 /*! \class ListWidget 24 * 25 * \brief Class displaying a QListWidget on the ground station 26 * 27 */ 16 28 class ListWidget : public FormLayout { 17 29 Q_OBJECT 18 30 19 31 public: 32 /** 33 * \brief Default constructor 34 * 35 * \param parent The parent widget 36 * \param[in] row The row where to position the widget 37 * \param[in] col The col where to position the widget 38 * \param[in] name The name of the widget 39 */ 20 40 ListWidget(Layout *parent, int row, int col, QString name); 21 ListWidget(Layout *parent, int row, int col, QString name, QStringList& items); 41 /** 42 * \brief Constructor with a list of default items 43 * 44 * \param parent The parent widget 45 * \param[in] row The row where to position the widget 46 * \param[in] col The col where to position the widget 47 * \param[in] name The name of the widget 48 * \param items List of items to display at creation 49 */ 50 ListWidget(Layout *parent, int row, int col, QString name, 51 QStringList &items); 52 /** 53 * \brief Destructor 54 */ 22 55 ~ListWidget(); 23 56 24 57 private: 25 QListWidget* listwidget; 26 int current_item_row; 27 bool is_up_to_date; 28 QPalette list_red_pal; 29 QPalette list_black_pal; 58 /** 59 * \brief Check if the widget is up to date. 60 * 61 * \return True if uptodate, False otherwise. 62 */ 63 bool IsUptodate(void); 64 /** 65 * \brief Sets the isUpToDate internal flag. 66 */ 67 void SetUptodate(void); 68 /** 69 * \brief Handler to process a new xml file. 70 * 71 * \param[in] dom The dom containing the xml file. 72 */ 30 73 void XmlEvent(QDomElement dom); 31 void SetUptodate(void); 74 /** 75 * \brief Reset the widget, load the internal parameters. 76 */ 77 32 78 void Reset(void); 79 /** 80 * \brief Handler to process the loading of the internal xml file. 81 * 82 * \param[in] dom The dom containing the xml file. 83 */ 33 84 void LoadEvent(QDomElement dom); 34 bool IsUptodate(void); 35 85 /** 86 * \brief Save the user interface variables state in the internal members. 87 */ 36 88 void ui_to_var(void); 89 /** 90 * \brief Save the user interface variables state in the internal xml file. 91 */ 37 92 void ui_to_xml(void); 93 /** 94 * Pointer to the managed QListWidget widget. 95 */ 96 QListWidget *listwidget; 97 /** 98 * The row of the currently selected item. 99 */ 100 int currentItemRow; 101 /** 102 * Flag to know if the widget is up to date. 103 */ 104 bool isUpToDate; 105 /** 106 * Redefined color palette. 107 * The highlight item's text appears in red. 108 */ 109 QPalette palListRed; 110 /** 111 * Redefined color palette. 112 * The highlight item's text appears in white (default). 113 */ 114 QPalette palListDefault; 38 115 39 116 private slots: 117 /** 118 * \brief Handle the change of the selected item. 119 * 120 * When the selected item has changed, the text of the newly selected item appears in red, 121 * to notify the user to apply the modification. 122 * 123 * \param[in] current_row The row of the currently selected item. 124 */ 40 125 void SelectedItemChanged(int current_row); 41 126 };
Note:
See TracChangeset
for help on using the changeset viewer.