Version: 9.16.0
YACS::HMI::PropertyEditor Class Reference

A class to edit properties of a subject. More...

#include <PropertyEditor.hxx>

Inheritance diagram for YACS::HMI::PropertyEditor:
Collaboration diagram for YACS::HMI::PropertyEditor:

Public Slots

virtual void onAddProperty (QAction *action)
 Qt slot to add a property item in the table. More...
 
virtual void onRemoveProperty ()
 Qt slot to remove the selected item in the table. More...
 
virtual void onItemChanged (QTableWidgetItem *item)
 Qt slot to change the value of a property item in the table. More...
 
virtual void on_tb_options_toggled (bool checked)
 

Public Member Functions

 PropertyEditor (Subject *subject, QWidget *parent=0)
 
virtual ~PropertyEditor ()
 
void updateMenu ()
 Update the menu used to add properties with the already set properties. More...
 
void update ()
 Update the property items with their values in the subject. More...
 
void setProperties ()
 Update the subject properties with the values stored in the table. More...
 

Protected Attributes

Subject_subject
 
QTableWidget * _table
 
QToolBar * _bar
 
QAction * _removeAction
 
QAction * _addAction
 
QStringList _knownProperties
 
QStringList _propertyNames
 
bool _editing
 

Detailed Description

A class to edit properties of a subject.

Definition at line 35 of file PropertyEditor.hxx.

Constructor & Destructor Documentation

◆ PropertyEditor()

PropertyEditor::PropertyEditor ( Subject subject,
QWidget parent = 0 
)

Definition at line 47 of file PropertyEditor.cxx.

47 :QWidget(parent),_subject(subject),_editing(false)
48{
49 std::vector<std::string> v=_subject->knownProperties();
50 for (int i=0; i<v.size(); ++i)
51 {
52 _knownProperties << QString::fromStdString(v[i]);
53 }
54
55 _removeAction=new QAction(QIcon("icons:icon_minus.png"),"Remove Property",this);
56 _addAction=new QAction(QIcon("icons:icon_plus.png"),"Add Property",this);
57
58 _table=new QTableWidget;
59 _table->setColumnCount(2);
60 QStringList headers;
61 headers << "Name" << "Value";
62 _table->setHorizontalHeaderLabels(headers);
63 _table->verticalHeader()->hide();
64 _table->setSelectionMode(QAbstractItemView::SingleSelection);
65
66 connect(_table, SIGNAL(itemChanged(QTableWidgetItem *)),this, SLOT(onItemChanged(QTableWidgetItem *)));
67 connect(_removeAction, SIGNAL(triggered()), this, SLOT(onRemoveProperty()));
68
69 QHBoxLayout* hboxLayout = new QHBoxLayout();
70 hboxLayout->setMargin(0);
71 QToolButton* tb_options = new QToolButton();
72 tb_options->setCheckable(true);
73 QIcon icon;
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);
78 connect(tb_options, SIGNAL(toggled(bool)), this, SLOT(on_tb_options_toggled(bool)));
79
80 QLabel* label=new QLabel("Properties ");
81 QFont font;
82 font.setBold(true);
83 font.setWeight(75);
84 label->setFont(font);
85 hboxLayout->addWidget(label);
86
87 _bar=new QToolBar();
88
89 QToolButton* button=new QToolButton();
90 button->setDefaultAction(_addAction);
91 button->setPopupMode(QToolButton::InstantPopup);
92 _bar->addWidget(button);
93
94 button=new QToolButton();
95 button->setDefaultAction(_removeAction);
96 _bar->addWidget(button);
97 hboxLayout->addWidget(_bar);
98
99 QVBoxLayout *layout = new QVBoxLayout;
100 layout->setMargin(0);
101 layout->addLayout(hboxLayout);
102 layout->addWidget(_table);
103 setLayout(layout);
104
105 _table->hide();
106 _bar->hide();
107
108 update();
109 updateMenu();
110
111 _editing=true;
112}
virtual void onItemChanged(QTableWidgetItem *item)
Qt slot to change the value of a property item in the table.
virtual void onRemoveProperty()
Qt slot to remove the selected item in the table.
void update()
Update the property items with their values in the subject.
void updateMenu()
Update the menu used to add properties with the already set properties.
virtual void on_tb_options_toggled(bool checked)
virtual std::vector< std::string > knownProperties()

References _addAction, _bar, _editing, _knownProperties, _removeAction, _subject, _table, yacsorb.CORBAEngineTest::i, YACS::HMI::Subject::knownProperties(), on_tb_options_toggled(), onItemChanged(), onRemoveProperty(), update(), and updateMenu().

◆ ~PropertyEditor()

PropertyEditor::~PropertyEditor ( )
virtual

Definition at line 114 of file PropertyEditor.cxx.

115{
116}

Member Function Documentation

◆ on_tb_options_toggled

void PropertyEditor::on_tb_options_toggled ( bool  checked)
virtualslot

Definition at line 259 of file PropertyEditor.cxx.

260{
261 DEBTRACE("PropertyEditor::on_tb_options_toggled " << checked);
262 if(checked)
263 {
264 _table->show();
265 _bar->show();
266 }
267 else
268 {
269 _table->hide();
270 _bar->hide();
271 }
272}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _bar, _table, and DEBTRACE.

Referenced by PropertyEditor().

◆ onAddProperty

void PropertyEditor::onAddProperty ( QAction *  action)
virtualslot

Qt slot to add a property item in the table.

Parameters
action: the triggered action

Definition at line 138 of file PropertyEditor.cxx.

139{
140 DEBTRACE("PropertyEditor::onAddProperty " << action->text().toStdString());
141 bool ok;
142 QString text=action->text();
143 if(text == "Other ...")
144 {
145 text = QInputDialog::getText(this, tr("New Property"),tr("Name:"), QLineEdit::Normal, "", &ok);
146 if (!ok || text.isEmpty())
147 return;
148 }
149
150 if(_propertyNames.contains(text))
151 {
152 QMessageBox::warning ( 0, "Property already defined", "Property already defined");
153 return;
154 }
155
156 _editing=false;
157 int row=_table->rowCount();
158 _table->setRowCount(row+1);
159
160 QTableWidgetItem *newItem = new QTableWidgetItem(text);
161 newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable);
162 _table->setItem(row,0, newItem);
163
164 newItem = new QTableWidgetItem();
165 _table->setItem(row,1, newItem);
166 _propertyNames << text;
167 _editing=true;
168 updateMenu();
169}

References _editing, _propertyNames, _table, DEBTRACE, and updateMenu().

Referenced by updateMenu().

◆ onItemChanged

void PropertyEditor::onItemChanged ( QTableWidgetItem *  item)
virtualslot

Qt slot to change the value of a property item in the table.

Parameters
item: the item changed

Definition at line 175 of file PropertyEditor.cxx.

176{
177 DEBTRACE("PropertyEditor::onItemChanged " << _editing);
178 if(!_editing)
179 return;
181}
void setProperties()
Update the subject properties with the values stored in the table.

References _editing, DEBTRACE, and setProperties().

Referenced by PropertyEditor().

◆ onRemoveProperty

void PropertyEditor::onRemoveProperty ( )
virtualslot

Qt slot to remove the selected item in the table.

Definition at line 121 of file PropertyEditor.cxx.

122{
123 DEBTRACE("PropertyEditor::onRemoveProperty");
124 QList<QTableWidgetItem *> litems=_table->selectedItems();
125 if(litems.isEmpty())
126 return;
127 QTableWidgetItem *item =litems.first();
128 _propertyNames.removeOne(item->text());
129 _table->removeRow(_table->row(item));
130 updateMenu();
132}

References _propertyNames, _table, DEBTRACE, setProperties(), and updateMenu().

Referenced by PropertyEditor().

◆ setProperties()

void PropertyEditor::setProperties ( )

Update the subject properties with the values stored in the table.

Definition at line 239 of file PropertyEditor.cxx.

240{
241 DEBTRACE("PropertyEditor::setProperties " );
242 QTableWidgetItem *item;
243 std::string name;
244 std::string value;
245 std::map<std::string,std::string> props;
246 for (int i = 0; i < _table->rowCount(); ++i)
247 {
248 item=_table->item(i,0);
249 name=item->data(Qt::DisplayRole).toString().toStdString();
250 item=_table->item(i,1);
251 value=item->data(Qt::DisplayRole).toString().toStdString();
252 props[name]=value;
253 }
254 bool ret=_subject->setProperties(props);
255 if(!ret)
256 Message mess;
257}
virtual bool setProperties(std::map< std::string, std::string > properties)

References _subject, _table, DEBTRACE, yacsorb.CORBAEngineTest::i, and YACS::HMI::Subject::setProperties().

Referenced by onItemChanged(), and onRemoveProperty().

◆ update()

void PropertyEditor::update ( )

Update the property items with their values in the subject.

Definition at line 186 of file PropertyEditor.cxx.

187{
188 DEBTRACE("PropertyEditor::update " );
189 _editing=false;
190 QTableWidgetItem *newItem;
191 int row=0;
192 _table->setRowCount(0);
193 _propertyNames << QStringList();
194 std::map<std::string,std::string> props=_subject->getProperties();
195 for (std::map<std::string, std::string>::iterator it = props.begin(); it != props.end(); ++it)
196 {
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);
201
202 newItem = new QTableWidgetItem(it->second.c_str());
203 _table->setItem(row,1, newItem);
204 _propertyNames << it->first.c_str();
205 row=row+1;
206 }
207 _editing=true;
208}
virtual std::map< std::string, std::string > getProperties()

References _editing, _propertyNames, _subject, _table, DEBTRACE, and YACS::HMI::Subject::getProperties().

Referenced by gui.graph.MyCanvas::customEvent(), PropertyEditor(), YACS::HMI::EditionBloc::update(), YACS::HMI::EditionComponent::update(), YACS::HMI::EditionDataLink::update(), and YACS::HMI::EditionSalomeNode::update().

◆ updateMenu()

void PropertyEditor::updateMenu ( )

Update the menu used to add properties with the already set properties.

Definition at line 213 of file PropertyEditor.cxx.

214{
215 DEBTRACE("PropertyEditor::updateMenu " );
216 QMenu* menu=new QMenu;
217 _addAction->setMenu(menu);
218
219 QActionGroup* actGroup=new QActionGroup(this);
220 connect(actGroup, SIGNAL(triggered(QAction*)), this, SLOT(onAddProperty(QAction*)));
221
222 QAction* anAction;
223 for (int i = 0; i < _knownProperties.size(); ++i)
224 {
225 if(_propertyNames.contains(_knownProperties.at(i)))
226 continue;
227 anAction= actGroup->addAction(_knownProperties.at(i));
228 anAction->setData(QVariant(_knownProperties.at(i)));
229 menu->addAction(anAction);
230 }
231 anAction= actGroup->addAction("Other ...");
232 menu->addAction(anAction);
233 anAction->setData(QVariant("..."));
234}
virtual void onAddProperty(QAction *action)
Qt slot to add a property item in the table.

References _addAction, _knownProperties, _propertyNames, DEBTRACE, yacsorb.CORBAEngineTest::i, and onAddProperty().

Referenced by onAddProperty(), onRemoveProperty(), and PropertyEditor().

Member Data Documentation

◆ _addAction

QAction* YACS::HMI::PropertyEditor::_addAction
protected

Definition at line 57 of file PropertyEditor.hxx.

Referenced by PropertyEditor(), and updateMenu().

◆ _bar

QToolBar* YACS::HMI::PropertyEditor::_bar
protected

Definition at line 55 of file PropertyEditor.hxx.

Referenced by on_tb_options_toggled(), and PropertyEditor().

◆ _editing

bool YACS::HMI::PropertyEditor::_editing
protected

Definition at line 60 of file PropertyEditor.hxx.

Referenced by onAddProperty(), onItemChanged(), PropertyEditor(), and update().

◆ _knownProperties

QStringList YACS::HMI::PropertyEditor::_knownProperties
protected

Definition at line 58 of file PropertyEditor.hxx.

Referenced by PropertyEditor(), and updateMenu().

◆ _propertyNames

QStringList YACS::HMI::PropertyEditor::_propertyNames
protected

Definition at line 59 of file PropertyEditor.hxx.

Referenced by onAddProperty(), onRemoveProperty(), update(), and updateMenu().

◆ _removeAction

QAction* YACS::HMI::PropertyEditor::_removeAction
protected

Definition at line 56 of file PropertyEditor.hxx.

Referenced by PropertyEditor().

◆ _subject

Subject* YACS::HMI::PropertyEditor::_subject
protected

Definition at line 53 of file PropertyEditor.hxx.

Referenced by PropertyEditor(), setProperties(), and update().

◆ _table

QTableWidget* YACS::HMI::PropertyEditor::_table
protected

The documentation for this class was generated from the following files: