// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} #include "ListWidget.h" #include "Layout.h" #include #include #include #include ListWidget::ListWidget(Layout *parent, int row, int col, QString name) : FormLayout(parent, row, col, name, "ListWidget") { listwidget = new QListWidget(); object_layout->addRow(new QLabel(name)); object_layout->addRow(listwidget); // to avoid duplicates when adding items SetIsExpandable(true); } ListWidget::ListWidget(Layout *parent, int row, int col, QString name, QStringList& items) : ListWidget(parent, row, col, name) { if (!items.isEmpty()) { listwidget->addItems(items); } } ListWidget::~ListWidget() { delete listwidget; } void ListWidget::XmlEvent(QDomElement dom) { if (dom.attribute("item") != "") { QString item = dom.attribute("item"); listwidget->addItem(item); } if (dom.attribute("delete") != "") { QListWidgetItem* current_item = listwidget->currentItem(); listwidget->removeItemWidget(current_item); if (current_item) { delete current_item; } } } void ListWidget::SetUptodate(void) { // ui_to_var(); // ui_to_xml(); std::cout << "SetUptodate" << std::endl; visible_widget->setPalette(black_pal); } // void ListWidget::ui_to_var(void) { combobox_value = listwidget->currentIndex(); } // void ListWidget::ui_to_xml(void) { // SetValue(QString::number(listwidget->currentIndex())); // } void ListWidget::Reset(void) { // listwidget->setCurrentIndex(combobox_value); } void ListWidget::LoadEvent(QDomElement dom) { std::cout << "In LoadEvent" << std::endl; // Parse the item list QStringList items; int count = 0; while (dom.hasAttribute("item" + QString::number(count))) { QString item = dom.attribute("item" + QString::number(count)); std::cout << "Item" << count << " : " << item.toStdString() << std::endl; items.append(item); count++; } listwidget->addItems(items); // if (listwidget->isEnabled() == true) { // listwidget->setCurrentIndex((dom.attribute("value")).toInt()); // } } // void ListWidget::valuechanged(int value) { // if (value != combobox_value) { // visible_widget->setPalette(red_pal); // } else { // visible_widget->setPalette(black_pal); // } // }