Version: 8.3.0
YACS::HMI::TablePortsEdition Class Reference

#include <TablePortsEdition.hxx>

Inheritance diagram for YACS::HMI::TablePortsEdition:
Collaboration diagram for YACS::HMI::TablePortsEdition:

Public Slots

void on_pb_up_clicked ()
 
void on_pb_down_clicked ()
 
void on_pb_insert_clicked ()
 
void on_pb_remove_clicked ()
 
void oncb_insert_activated (const QString &text)
 
void oncb_insert_popupHide ()
 
void oncb_insert_popupShow ()
 

Public Member Functions

 TablePortsEdition (bool inPorts, QWidget *parent=0)
 
virtual ~TablePortsEdition ()
 
void setNode (SubjectElementaryNode *node)
 
virtual void setEditablePorts (bool isEditable)
 
virtual void adjustColumns ()
 

Protected Member Functions

void upOrDown (int isUp)
 

Protected Attributes

bool _inPorts
 
SubjectElementaryNode_node
 
int _nbUp
 

Detailed Description

Definition at line 56 of file TablePortsEdition.hxx.

Constructor & Destructor Documentation

TablePortsEdition::TablePortsEdition ( bool  inPorts,
QWidget parent = 0 
)

Definition at line 86 of file TablePortsEdition.cxx.

References _inPorts, _nbUp, _node, DEBTRACE, oncb_insert_activated(), oncb_insert_popupHide(), and oncb_insert_popupShow().

87 {
88  DEBTRACE("TablePortsEdition::TablePortsEdition");
89  setupUi(this);
90  _inPorts = inPorts;
91  _node = 0;
92  _nbUp = 0;
93  if (tv_ports->horizontalHeader())
94  tv_ports->horizontalHeader()->setStretchLastSection(true);
95 
96  delete cb_insert;
97  cb_insert = new YComboBox(layoutWidget);
98  gridLayout1->addWidget(cb_insert, 0, 4, 1, 1);
99  cb_insert->setToolTip("port creation: select a port type");
100 
101  connect(cb_insert, SIGNAL(popupHide()),
102  this, SLOT(oncb_insert_popupHide()));
103  connect(cb_insert, SIGNAL(popupShow()),
104  this, SLOT(oncb_insert_popupShow()));
105 
106  connect(cb_insert, SIGNAL(activated(const QString&)),
107  this, SLOT(oncb_insert_activated(const QString&)));
108 }
TablePortsEdition::~TablePortsEdition ( )
virtual

Definition at line 110 of file TablePortsEdition.cxx.

References DEBTRACE.

111 {
112  DEBTRACE("TablePortsEdition::~TablePortsEdition");
113 }

Member Function Documentation

void TablePortsEdition::adjustColumns ( )
virtual

Definition at line 286 of file TablePortsEdition.cxx.

References DEBTRACE, YACS::HMI::YLabel, and YACS::HMI::YType.

Referenced by YACS::HMI::EditionElementaryNode::synchronize().

287 {
288  DEBTRACE("TablePortsEdition::adjustColumns");
289  if (!tv_ports->isColumnHidden(YLabel))
290  tv_ports->resizeColumnToContents(YLabel);
291  if (!tv_ports->isColumnHidden(YType))
292  tv_ports->resizeColumnToContents(YType);
293 }
void TablePortsEdition::on_pb_down_clicked ( )
slot

Definition at line 127 of file TablePortsEdition.cxx.

References _nbUp, DEBTRACE, and upOrDown().

128 {
129  DEBTRACE("TablePortsEdition::on_pb_down_clicked");
130  upOrDown(0); // --- 0 means go down one step
131  _nbUp = 0;
132 }
void TablePortsEdition::on_pb_insert_clicked ( )
slot

Definition at line 176 of file TablePortsEdition.cxx.

References _nbUp, DEBTRACE, YACS::HMI::Subject::getName(), YACS::HMI::SubjectNode::getNode(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::QtGuiContext::getSchemaModel(), YACS::ENGINE::ElementaryNode::getSetOfInputPort(), YACS::ENGINE::ElementaryNode::getSetOfOutputPort(), YACS::HMI::SchemaItem::getSubject(), YACS::HMI::SchemaItem::parent(), and YASSERT.

177 {
178  DEBTRACE("TablePortsEdition::on_pb_insert_clicked");
180  SubjectDataPort *spBefore = 0;
181  _nbUp = 0;
182 
183  QModelIndexList items = tv_ports->selectionModel()->selection().indexes();
184  QModelIndex index;
185  if (!items.isEmpty()) index = items.first();
186  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
187  if (!item)
188  return;
189 
190  Subject *sub = item->getSubject();
191  DEBTRACE(sub->getName());
192  spBefore = dynamic_cast<SubjectDataPort*>(sub);
193  DataPort *port = spBefore->getPort();
194 
195  bool isInput = false;
196  if (dynamic_cast<SubjectInputPort*>(spBefore))
197  isInput = true;
198 
199  sub = item->parent()->getSubject();
200  SubjectElementaryNode* sen = dynamic_cast<SubjectElementaryNode*>(sub);
201  YASSERT(sen);
202  ElementaryNode* father = dynamic_cast<ElementaryNode*>(sen->getNode());
203 
204  if (isInput)
205  {
206  int rang = 0;
207  list<InputPort*> plist = father->getSetOfInputPort();
208  list<InputPort*>::iterator pos = plist.begin();
209  for (; (*pos) != port; pos++)
210  rang++;
211  _nbUp = plist.size() -rang;
212  }
213  else
214  {
215  int rang = 0;
216  list<OutputPort*> plist = father->getSetOfOutputPort();
217  list<OutputPort*>::iterator pos = plist.begin();
218  for (; (*pos) != port; pos++)
219  rang++;
220  _nbUp = plist.size() -rang;
221  }
222 
223  DEBTRACE(_nbUp);
224  cb_insert->showPopup();
225 }
void TablePortsEdition::on_pb_remove_clicked ( )
slot

Definition at line 264 of file TablePortsEdition.cxx.

References YACS::HMI::GenericGui::_guiEditor, DEBTRACE, YACS::HMI::GuiEditor::DeleteSubject(), YACS::HMI::QtGuiContext::getGMain(), YACS::HMI::Subject::getName(), YACS::HMI::Subject::getParent(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::QtGuiContext::getSchemaModel(), and YACS::HMI::SchemaItem::getSubject().

265 {
266  DEBTRACE("TablePortsEdition::on_pb_remove_clicked");
268  SubjectDataPort *spToRemove = 0;
269  QModelIndexList items = tv_ports->selectionModel()->selection().indexes();
270  QModelIndex index;
271  if (!items.isEmpty()) index = items.first();
272  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
273  if (item)
274  {
275  Subject *sub = item->getSubject();
276  DEBTRACE(sub->getName());
277  spToRemove = dynamic_cast<SubjectDataPort*>(sub);
278  }
279  if (spToRemove)
280  {
282  spToRemove);
283  }
284 }
void TablePortsEdition::on_pb_up_clicked ( )
slot

Definition at line 120 of file TablePortsEdition.cxx.

References _nbUp, DEBTRACE, and upOrDown().

121 {
122  DEBTRACE("TablePortsEdition::on_pb_up_clicked");
123  upOrDown(1);// --- n>0 means go up n steps
124  _nbUp = 0;
125 }
void TablePortsEdition::oncb_insert_activated ( const QString &  text)
slot

Definition at line 227 of file TablePortsEdition.cxx.

References YACS::HMI::GenericGui::_guiEditor, _inPorts, _nbUp, _node, YACS::HMI::GuiEditor::CreateInputPort(), YACS::HMI::GuiEditor::CreateOutputPort(), DEBTRACE, YACS::HMI::CatalogWidget::getCatalogFromType(), YACS::HMI::GenericGui::getCatalogWidget(), YACS::HMI::GuiContext::getCurrentCatalog(), YACS::HMI::QtGuiContext::getGMain(), YACS::HMI::Subject::getName(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::SchemaItem::getSubject(), YACS::HMI::SubjectElementaryNode::OrderDataPorts(), and YASSERT.

Referenced by TablePortsEdition().

228 {
229  DEBTRACE("TablePortsEdition::oncb_insert_activated " << text.toStdString());
230  SubjectDataPort *spBefore = 0;
231  QModelIndexList items = tv_ports->selectionModel()->selection().indexes();
232  QModelIndex index;
233  if (!items.isEmpty()) index = items.first();
234  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
235  if (item)
236  {
237  Subject *sub = item->getSubject();
238  DEBTRACE(sub->getName());
239  spBefore = dynamic_cast<SubjectDataPort*>(sub);
240  }
241  string portType = text.toStdString();
242  QStringList defaultTypes;
243  defaultTypes << "Int" << "Double" << "String" << "Bool";
244  if (defaultTypes.contains(text))
245  portType = text.toLower().toStdString();
246  YACS::ENGINE::Catalog *catalog =
248  if (!catalog) catalog = QtGuiContext::getQtCurrent()->getCurrentCatalog();
249  YASSERT(catalog);
251  SubjectDataPort * sdp = 0;
252  if (_inPorts)
253  sdp = editor->CreateInputPort(_node, "", catalog, portType, spBefore);
254  else
255  sdp = editor->CreateOutputPort(_node, "", catalog, portType, spBefore);
256  if (_nbUp)
257  {
258  DEBTRACE("move up created port " << _nbUp);
259  _node->OrderDataPorts(sdp, _nbUp);
260  _nbUp = 0;
261  }
262 }
void TablePortsEdition::oncb_insert_popupHide ( )
slot

Definition at line 338 of file TablePortsEdition.cxx.

References _nbUp, and DEBTRACE.

Referenced by TablePortsEdition().

339 {
340  DEBTRACE("TablePortsEdition::oncb_insert_popupHide");
341  if (cb_insert->currentIndex() < 0)
342  _nbUp = 0; // --- no selection, no port creation, no move
343  DEBTRACE(_nbUp);
344 }
void TablePortsEdition::oncb_insert_popupShow ( )
slot

Definition at line 346 of file TablePortsEdition.cxx.

References DEBTRACE.

Referenced by TablePortsEdition().

347 {
348  DEBTRACE("TablePortsEdition::oncb_insert_popupShow");
349 }
void TablePortsEdition::setEditablePorts ( bool  isEditable)
virtual

Definition at line 296 of file TablePortsEdition.cxx.

References DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::YState, YACS::HMI::YType, and YACS::HMI::YValue.

Referenced by YACS::HMI::EditionElementaryNode::setEditablePorts().

297 {
298  DEBTRACE("TablePortsEdition::setEditablePorts " << isEditable);
299  if (QtGuiContext::getQtCurrent()->isEdition())
300  {
301  tv_ports->setColumnHidden(YType, false);
302  tv_ports->setColumnHidden(YValue, false);
303  }
304  else
305  {
306  isEditable = false; // --- no edition in execution !
307  tv_ports->setColumnHidden(YType, true);
308  tv_ports->setColumnHidden(YState, false);
309  }
310 
311  if (tv_ports->verticalHeader())
312  tv_ports->verticalHeader()->setVisible(false);
313 
314 
315  pb_up->setEnabled(isEditable);
316  pb_down->setEnabled(isEditable);
317  pb_insert->setEnabled(isEditable);
318  pb_remove->setEnabled(isEditable);
319  cb_insert->setEnabled(isEditable);
320  if (isEditable)
321  {
322  pb_up->show();
323  pb_down->show();
324  pb_insert->show();
325  pb_remove->show();
326  cb_insert->show();
327  }
328  else
329  {
330  pb_up->hide();
331  pb_down->hide();
332  pb_insert->hide();
333  pb_remove->hide();
334  cb_insert->hide();
335  }
336 }
void TablePortsEdition::setNode ( SubjectElementaryNode node)

Definition at line 115 of file TablePortsEdition.cxx.

References _node.

Referenced by YACS::HMI::EditionElementaryNode::synchronize().

116 {
117  _node = node;
118 }
void TablePortsEdition::upOrDown ( int  isUp)
protected

move up or down the port in the list of ports. when isUp = 0, go down one step, when isUp = n>0, go up n steps.

Definition at line 138 of file TablePortsEdition.cxx.

References YACS::HMI::Scene::_autoComputeLinks, YACS::HMI::QtGuiContext::_mapOfSceneItem, DEBTRACE, YACS::HMI::Subject::getName(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::QtGuiContext::getSchemaModel(), YACS::HMI::SchemaItem::getSubject(), YACS::HMI::GuiContext::getSubjectProc(), YACS::HMI::SchemaItem::modelIndex(), YACS::HMI::SubjectElementaryNode::OrderDataPorts(), YACS::HMI::SchemaItem::parent(), YACS::HMI::SceneComposedNodeItem::rebuildLinks(), and YASSERT.

Referenced by on_pb_down_clicked(), and on_pb_up_clicked().

139 {
141  SubjectDataPort *spToMove = 0;
142 
143  QModelIndexList items = tv_ports->selectionModel()->selection().indexes();
144  QModelIndex index;
145  if (!items.isEmpty()) index = items.first();
146  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
147 
148  if (item)
149  {
150  Subject *sub = item->getSubject();
151  DEBTRACE(sub->getName());
152  spToMove = dynamic_cast<SubjectDataPort*>(sub);
153  }
154 
155  if (spToMove)
156  {
157  Subject *sub = item->parent()->getSubject();
158  SubjectElementaryNode* sen = dynamic_cast<SubjectElementaryNode*>(sub);
159  YASSERT(sen);
160  sen->OrderDataPorts(spToMove,isUp);
162  {
165  SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
166  proc->rebuildLinks();
167  }
168 
169  QItemSelectionModel *selectionModel = tv_ports->selectionModel();
170  QModelIndex topLeft=item->modelIndex(0);
171  QItemSelection selection(topLeft, topLeft);
172  selectionModel->select(selection, QItemSelectionModel::Select);
173  }
174 }

Member Data Documentation

bool YACS::HMI::TablePortsEdition::_inPorts
protected

Definition at line 78 of file TablePortsEdition.hxx.

Referenced by oncb_insert_activated(), and TablePortsEdition().

int YACS::HMI::TablePortsEdition::_nbUp
protected
SubjectElementaryNode* YACS::HMI::TablePortsEdition::_node
protected

Definition at line 79 of file TablePortsEdition.hxx.

Referenced by oncb_insert_activated(), setNode(), and TablePortsEdition().


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