22 #include <QVBoxLayout>
23 #include <QToolButton>
28 #include <QActionGroup>
29 #include <QHeaderView>
31 #include <QInputDialog>
32 #include <QMessageBox>
39 using namespace YACS::HMI;
50 for (
int i=0;
i<v.size(); ++
i)
55 _removeAction=
new QAction(QIcon(
"icons:icon_minus.png"),
"Remove Property",
this);
56 _addAction=
new QAction(QIcon(
"icons:icon_plus.png"),
"Add Property",
this);
61 headers <<
"Name" <<
"Value";
62 _table->setHorizontalHeaderLabels(headers);
63 _table->verticalHeader()->hide();
64 _table->setSelectionMode(QAbstractItemView::SingleSelection);
66 connect(
_table, SIGNAL(itemChanged(QTableWidgetItem *)),
this, SLOT(
onItemChanged(QTableWidgetItem *)));
69 QHBoxLayout* hboxLayout =
new QHBoxLayout();
70 hboxLayout->setMargin(0);
71 QToolButton* tb_options =
new QToolButton();
72 tb_options->setCheckable(
true);
74 icon.addFile(
"icons:icon_down.png");
75 icon.addFile(
"icons:icon_up.png", QSize(), QIcon::Normal, QIcon::On);
76 tb_options->setIcon(icon);
77 hboxLayout->addWidget(tb_options);
80 QLabel* label=
new QLabel(
"Properties ");
85 hboxLayout->addWidget(label);
89 QToolButton* button=
new QToolButton();
91 button->setPopupMode(QToolButton::InstantPopup);
92 _bar->addWidget(button);
94 button=
new QToolButton();
96 _bar->addWidget(button);
97 hboxLayout->addWidget(
_bar);
99 QVBoxLayout *layout =
new QVBoxLayout;
100 layout->setMargin(0);
101 layout->addLayout(hboxLayout);
102 layout->addWidget(
_table);
123 DEBTRACE(
"PropertyEditor::onRemoveProperty");
124 QList<QTableWidgetItem *> litems=
_table->selectedItems();
127 QTableWidgetItem *item =litems.first();
140 DEBTRACE(
"PropertyEditor::onAddProperty " << action->text().toStdString());
142 QString text=action->text();
143 if(text ==
"Other ...")
145 text = QInputDialog::getText(
this, tr(
"New Property"),tr(
"Name:"), QLineEdit::Normal,
"", &ok);
146 if (!ok || text.isEmpty())
152 QMessageBox::warning ( 0,
"Property already defined",
"Property already defined");
157 int row=
_table->rowCount();
158 _table->setRowCount(row+1);
160 QTableWidgetItem *newItem =
new QTableWidgetItem(text);
161 newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable);
162 _table->setItem(row,0, newItem);
164 newItem =
new QTableWidgetItem();
165 _table->setItem(row,1, newItem);
188 DEBTRACE(
"PropertyEditor::update " );
190 QTableWidgetItem *newItem;
195 for (std::map<std::string, std::string>::iterator it = props.begin(); it != props.end(); ++it)
197 _table->setRowCount(row+1);
198 QTableWidgetItem *newItem =
new QTableWidgetItem(it->first.c_str());
199 newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable);
200 _table->setItem(row,0, newItem);
202 newItem =
new QTableWidgetItem(it->second.c_str());
203 _table->setItem(row,1, newItem);
215 DEBTRACE(
"PropertyEditor::updateMenu " );
216 QMenu* menu=
new QMenu;
219 QActionGroup* actGroup=
new QActionGroup(
this);
220 connect(actGroup, SIGNAL(triggered(QAction*)),
this, SLOT(
onAddProperty(QAction*)));
229 menu->addAction(anAction);
231 anAction= actGroup->addAction(
"Other ...");
232 menu->addAction(anAction);
233 anAction->setData(QVariant(
"..."));
241 DEBTRACE(
"PropertyEditor::setProperties " );
242 QTableWidgetItem *item;
245 std::map<std::string,std::string> props;
246 for (
int i = 0;
i <
_table->rowCount(); ++
i)
249 name=item->data(Qt::DisplayRole).toString().toStdString();
251 value=item->data(Qt::DisplayRole).toString().toStdString();
261 DEBTRACE(
"PropertyEditor::on_tb_options_toggled " << checked);