HAL
pin_model.cpp
Go to the documentation of this file.
4 
5 namespace hal
6 {
8  {
9  // use root item to store header information
10  setHeaderLabels(QStringList() << "Name" << "Direction" << "Type");
11  mAssignedGroupNames = QSet<QString>();
12  mAssignedPinNames = QSet<QString>();
13  mEditable = false;
14 
15  //connect(this, &PinModel::dataChanged, this, &PinModel::handleInvalidGroupUpdate);
16  }
17 
18  PinModel::PinModel(QObject* parent, bool editable) : BaseTreeModel(parent)
19  {
20  // use root item to store header information
21  setHeaderLabels(QStringList() << "Name" << "Direction" << "Type");
22  mAssignedGroupNames = QSet<QString>();
23  mAssignedPinNames = QSet<QString>();
24  mEditable = editable;
25  }
26 
29  }
30 
31 
33  {
34  if(!index.isValid()) return Qt::ItemFlags();
35  if(!mEditable)
37 
39  }
40 
42 
43  //TODO change font of dummy entries
44  clear();
45 
46 
47  //get all pins of a given gate if it exists
48  /*if(gate){
49  for (auto pinGroup : gate->get_pin_groups())
50  {
51  PINGROUP* groupStruct = new PINGROUP;
52  groupStruct->name = QString::fromStdString(pinGroup->get_name());
53  groupStruct->id = pinGroup->get_id();
54  groupStruct->direction = pinGroup->get_direction();
55  groupStruct->type = pinGroup->get_type();
56  for (auto pin : pinGroup->get_pins())
57  {
58  PIN* pinStruct = new PIN;
59  pinStruct->name = QString::fromStdString(pin->get_name());
60  pinStruct->id = pin->get_id();
61  pinStruct->direction = pin->get_direction();
62  pinStruct->type = pin->get_type();
63  groupStruct->pins.append(pinStruct);
64  }
65  mPinGroups.append(groupStruct);
66  }
67  }*/
68 
69  QList<PinItem*> tempGroupList;
70 
71  if(gate){
72  for (auto pinGroup : gate->get_pin_groups())
73  {
75  groupStruct->setName(QString::fromStdString(pinGroup->get_name()));
76  groupStruct->setId(pinGroup->get_id());
77  groupStruct->setDirection(pinGroup->get_direction());
78  groupStruct->setType(pinGroup->get_type());
79  for (auto pin : pinGroup->get_pins())
80  {
81  PinItem* pinStruct = new PinItem(PinItem::TreeItemType::Pin);
82  pinStruct->setName(QString::fromStdString(pin->get_name()));
83  pinStruct->setId(pin->get_id());
84  pinStruct->setDirection(pin->get_direction());
85  pinStruct->setType(pin->get_type());
86  groupStruct->appendChild(pinStruct);
87  }
88  tempGroupList.append(groupStruct);
89  }
90  }
91 
93  for(auto group : tempGroupList){
94  auto groupItem = new PinItem(PinItem::TreeItemType::PinGroup);
95  //get all infos for that group
96  PinDirection groupDirection = group->getDirection();
97  PinType groupType = group->getPinType();
98 
99  //create group item
100  groupItem->setName(group->getName());
101  groupItem->setDirection(groupDirection);
102  groupItem->setType(groupType);
103  for (auto item : group->getChildren())
104  {
105  auto pinItem = new PinItem(PinItem::TreeItemType::Pin);
106  PinItem* pin = static_cast<PinItem*>(item);
107 
108  //get all infos for that pin
109  PinDirection pinDirection = pin->getDirection();
110  PinType pinType = pin->getPinType();
111 
112  pinItem->setName(pin->getName());
113  pinItem->setDirection(pinDirection);
114  pinItem->setType(pinType);
115 
116  groupItem->appendChild(pinItem);
117 
118  //add pinItem to the mapped name
119  mAssignedPinNames.insert(pinItem->getName());
120  }
121 
122  //add dummy to each group if model is editable
123  if(mEditable)
124  {
125  auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
126  dummyPin->setData(QList<QVariant>() << "create new pin ...");
127  groupItem->appendChild(dummyPin);
128  }
129 
130  mRootItem->appendChild(groupItem);
131 
132  //add groupItem to mapped name
133  //add pinItem to the mapped name
134  mAssignedGroupNames.insert(groupItem->getName());
135  }
136 
137  //create dummy for the group creator if model is editable
138  if(mEditable)
139  {
140  auto dummyGroup = new PinItem(PinItem::TreeItemType::GroupCreator);
141  dummyGroup->setData(QList<QVariant>() << "create new pingroup ...");
142  mRootItem->appendChild(dummyGroup);
143  }
144 
145  endResetModel();
146  }
147 
148  void PinModel::handleEditName(QModelIndex index, const QString& input)
149  {
150  if(!index.isValid()) return;
151  //TODO handle text edited from PinDelegate
152  auto pinItem = static_cast<PinItem*>(index.internalPointer());
153  auto itemType = pinItem->getItemType();
154 
155  switch(itemType){
157  //qInfo() << "was Group: " << pinItem->getName();
158  if (renamePinGroup(pinItem, input))
159  pinItem->setName(input);
160 
161  break;
162  }
164  //qInfo() << "was Pin: " << pinItem->getName();
165  if(renamePin(pinItem, input))
166  pinItem->setName(input);
167  break;
168  }
170  //TODO also check pin names when a group is created - otherwise a group with e.g name I1 will create a pin with the same name but this one isnt checked
171 
172  //qInfo() << "was GroupCreator: " << pinItem->getName();
173  // creates a new pingroup with a pin which is not valid until edited
174 
175  if(!renamePinGroup(pinItem, input))
176  return;
177 
178  pinItem->setFields(input, getNextId(PinItem::TreeItemType::PinGroup), PinDirection::none, PinType::none);
179  pinItem->setItemType(PinItem::TreeItemType::InvalidPinGroup);
180  mInvalidGroups.append(pinItem);
181 
182  beginInsertRows(index.parent(), 0, 0);
183  // add initial pin to pingroup
184  auto initialPin = new PinItem(PinItem::TreeItemType::InvalidPin);
185  initialPin->setFields(input, 0, PinDirection::none, PinType::none);
186  pinItem->appendChild(initialPin);
187 
188  mAssignedPinNames.insert(input);
189 
190  //add new dummypin to the group
191  auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
192  //dummyPin->setData(QList<QVariant>() << "create new pin ...");
193  pinItem->appendChild(dummyPin);
194 
195  //add new dummygroup after entry
196  auto dummyGroup = new PinItem(PinItem::TreeItemType::GroupCreator);
197  //dummyGroup->setData(QList<QVariant>() << "create new group ...");
198  pinItem->getParent()->appendChild(dummyGroup);
199 
200 
201  //create new pinGroupStruct and add it to the list of pingroups
202  PinItem* newPinGroup = new PinItem(PinItem::TreeItemType::PinGroup);
203  newPinGroup->setId(pinItem->getId());
204  newPinGroup->setName(pinItem->getName());
205  newPinGroup->setDirection(pinItem->getDirection());
206  newPinGroup->setType(pinItem->getPinType());
207  endInsertRows();
208 
209  //add pin to group
210  //addPinToPinGroup(initialPin, pinItem);
211 
213  break;
214  }
216  //qInfo() << "was PinCreator: " << pinItem->getName();
217  // creates a new pin which is not valid until now nor created via gate->create_pin()
218  if(!renamePin(pinItem, input))
219  break;
220  PinItem* parentGroup = static_cast<PinItem*>(pinItem->getParent());
221  PinDirection pdir = parentGroup->getDirection();
222  PinType ptype = parentGroup->getPinType();
223  pinItem->setFields(input, getNextId(PinItem::TreeItemType::Pin), pdir, ptype);
224  if(pdir != PinDirection::none) pinItem->setItemType(PinItem::TreeItemType::Pin);
225  else pinItem->setItemType(PinItem::TreeItemType::InvalidPin);
226  mInvalidPins.append(pinItem);
227 
229  //add new dummy after entry
230  auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
231  //dummyPin->setData(QList<QVariant>() << "create new pin ...");
232  pinItem->getParent()->appendChild(dummyPin);
233  endInsertRows();
234 
235  //add pinItem to pinGroups
236  //auto pinGroup = static_cast<PinItem*>(pinItem->getParent());
237  //addPinToPinGroup(pinItem, pinGroup);
238 
240  break;
241  }
243  if(renamePin(pinItem, input))
244  pinItem->setName(input);
245  break;
246  }
247  }
248 
250  }
251 
252  void PinModel::handleEditDirection(QModelIndex index, const QString& directionString)
253  {
254  if(!index.isValid()) return;
255  //TODO handle direction edited from PinDelegate
256  auto pinItem = static_cast<PinItem*>(index.internalPointer());
257  auto itemType = pinItem->getItemType();
258 
259  PinDirection oldDirection = pinItem->getDirection();
260  PinDirection pinDirection = enum_from_string<PinDirection>(directionString.toStdString());
261 
262  switch(itemType){
265  pinItem->setDirection(directionString);
266  for(auto child : pinItem->getChildren()) //set same direction for all pins of the pingroup
267  {
268  PinItem* pin = static_cast<PinItem*>(child);
270  pin->setDirection(directionString);
271  handleInvalidPinUpdate(pin);
272  }
273  }
274  handleInvalidGroupUpdate(pinItem);
275  break;
276  }
279  QMessageBox warning;
280  QPushButton* acceptBtn = warning.addButton(tr("Continue with changes"), QMessageBox::AcceptRole);
281  QPushButton* abortBtn = warning.addButton(QMessageBox::Abort);
282  PinItem* parentGroup = static_cast<PinItem*>(pinItem->getParent());
283  warning.setWindowTitle("New pin creation");
284  warning.setText(QString("You are about to create an %1 pin in an %2 pin group")
285  .arg(directionString)
286  .arg(parentGroup->getDirectionAsText()));
287  if(pinDirection != parentGroup->getDirection())
288  {
289  warning.exec();
290  if(warning.clickedButton() == acceptBtn){
291  pinItem->setDirection(pinDirection);
292  handleInvalidPinUpdate(pinItem);
293  }
294  }
295  else
296  {
297  pinItem->setDirection(pinDirection);
298  handleInvalidPinUpdate(pinItem);
299  }
300  break;
301  }
302  }
304  if (oldDirection == PinDirection::none)
306  }
307 
308  void PinModel::handleEditType(QModelIndex index, const QString& typeString)
309  {
310  if(!index.isValid()) return;
311  auto pinItem = static_cast<PinItem*>(index.internalPointer());
312  auto itemType = pinItem->getItemType();
313 
314  PinType pinType = enum_from_string<PinType>(typeString.toStdString());
315 
316  switch (itemType)
317  {
319  pinItem->setType(pinType);
320  handleInvalidPinUpdate(pinItem);
321  break;
322  }
324  pinItem->setType(pinType);
325  break;
326  }
328  pinItem->setType(pinType);
329  for(auto child : pinItem->getChildren()) //set same type for all pins of the pingroup
330  {
331  PinItem* pin = static_cast<PinItem*>(child);
333  pin->setType(pinType);
334  handleInvalidPinUpdate(pin);
335  }
336  }
337  handleInvalidGroupUpdate(pinItem);
338  break;
339  }
341  pinItem->setType(pinType);
342  //PinModel::PINGROUP* pinGroup = static_cast<PinModel::PINGROUP*>(pinItem);
343 
344  /*for(auto child : pinItem->getChildren()) //set same type for all pins of the pingroup
345  {
346  PinItem* pin = static_cast<PinItem*>(child);
347  if(pin->getItemType() == PinItem::TreeItemType::Pin || pin->getItemType() == PinItem::TreeItemType::InvalidPin){
348  pin->setType(type);
349  }
350  }*/
351 
352  for(auto group : getPinGroups()){
353  if(group->getName() == pinItem->getName()){
354  for(auto item : group->getChildren()){
355  PinItem* pin = static_cast<PinItem*>(item);
356  pin->setType(pinType);
357  }
358  break;
359  }
360  }
361  }
362  }
364  }
365 
366 
367  void PinModel::addPinToPinGroup(PinItem* pinItem, PinItem* groupItem)
368  {
369  QModelIndex index = getIndexFromItem(groupItem);
370  if(!index.isValid()) return;
371  beginInsertRows(index, groupItem->getChildCount(), groupItem->getChildCount());
372  groupItem->appendChild(pinItem);
373  endInsertRows();
374  }
375 
376 
377  bool PinModel::renamePin(PinItem* pinItem, const QString& newName)
378  {
379  //TODO change pinItems name within function and not after its call
380 
381  QString name = newName;
382  QRegExp rx("[A-Za-z]([A-Za-z]|\\d|_|\\(|\\))*");
383  QValidator* val = new QRegExpValidator(rx, this);
384  int pos = 0;
385  if(val->validate(name, pos) != QValidator::Acceptable) return false;
386 
387  //Check if name is already in use
388  if(isNameAvailable(newName, pinItem)){
389  //delete old name from being assigned and add new name
390  mAssignedPinNames.remove(pinItem->getName());
391  mAssignedPinNames.insert(newName);
392 
393  //rename PinItem
394  pinItem->setName(newName);
395 
396  //rename pin within pinGroup
397  auto pinGroup = static_cast<PinItem*>(pinItem->getParent());
398  for(auto group : getPinGroups()){
399  if(group->getName() == pinGroup->getName()){
400  for(auto item : group->getChildren()){
401  PinItem* pin = static_cast<PinItem*>(item);
402  if(pin->getId() == pinItem->getId()){
403  pin->setName(newName);
404  break;
405  }
406  }
407  break;
408  }
409  }
410  return true;
411  }
412 
413  return false;
414  }
415 
416  bool PinModel::renamePinGroup(PinItem* groupItem, const QString& newName)
417  {
418  //TODO change pinItems name within function and not after its call
419 
420  QString name = newName;
421  QRegExp rx("[A-Za-z]([A-Za-z]|\\d|_|\\(|\\))*");
422  QValidator* val = new QRegExpValidator(rx, this);
423  int pos = 0;
424  if(val->validate(name, pos) != QValidator::Acceptable) return false;
425  //Check if name is already in use
426  if(isNameAvailable(newName, groupItem)){
427  //delete old name from being assigned and add new name
428  mAssignedGroupNames.remove(groupItem->getName());
429  mAssignedGroupNames.insert(newName);
430 
431  //rename PinItem
432 
433  groupItem->setName(newName);
434 
435  //rename corresponding pinGroup
436  /*for(auto group : getPinGroups()){
437  if(group->getId() == groupItem->getId()){
438  //stop here
439  group->setName(newName);
440  break;
441  }
442  }*/
443  return true;
444  }
445 
446  return false;
447  }
448 
449  bool PinModel::isNameAvailable(const QString& newName, PinItem* treeItem){
450  //check if the new name is the same as the old one
451  if(newName == treeItem->getName())
452  return true;
453 
454  //get type of the pin item
455  PinItem::TreeItemType type = treeItem->getItemType();
457  if(isGroup){
458  return !(mAssignedGroupNames.contains(newName) || mAssignedPinNames.contains(newName));
459  }else{
460  //get group name
461  QString groupName = static_cast<PinItem*>(treeItem->getParent())->getName();
462  //check if pin can be named after the group
463  if(groupName == newName && !mAssignedPinNames.contains(newName))
464  {
465  return true;
466  }
467  //check if other group or pin has the name
468  else{
469  return !(mAssignedGroupNames.contains(newName) || mAssignedPinNames.contains(newName));
470  }
471  }
472  }
473 
474  void PinModel::handleInvalidPinUpdate(PinItem* pinItem)
475  {
476  if(!isNameAvailable(pinItem->getName(), pinItem)
477  || pinItem->getDirection() == PinDirection::none)
478  return; // Pin is not valid
479 
480  //pin is valid
481  pinItem->setItemType(PinItem::TreeItemType::Pin);
482  mInvalidPins.removeAll(pinItem);
483 
484  //checks if the groups status is affected and if so it updates the group
485  auto pinGroup = static_cast<PinItem*>(pinItem->getParent());
486  handleInvalidGroupUpdate(pinGroup);
487  }
488 
489  void PinModel::handleInvalidGroupUpdate(PinItem* groupItem){
490  bool isValid = true;
491 
492  //calculate new direction
493  //handleGroupDirectionUpdate(groupItem);
494 
495  //check each pin in the group if its valid or not
496  QList<PinItem*> childs = QList<PinItem*>();
497  for(auto baseTreeItem : groupItem->getChildren()){
498  auto childPin = static_cast<PinItem*>(baseTreeItem);
499  //if the child is invalid then the group cant be valid
500  if(childPin->getItemType() == PinItem::TreeItemType::InvalidPin){
501  isValid = false;
502  break;
503  }
504  if(childPin->getItemType() != PinItem::TreeItemType::PinCreator)
505  childs.append(childPin);
506  }
507 
508  if(isValid){
509 
510  groupItem->setItemType(PinItem::TreeItemType::PinGroup);
511  /*
512  mInvalidGroups.removeAll(groupItem);
513  PINGROUP* pinGroup = new PINGROUP;
514  pinGroup->id = groupItem->id();
515  pinGroup->name = groupItem->getName();
516  pinGroup->direction = enum_from_string<PinDirection>(groupItem->getDirection().toStdString());
517  pinGroup->type = enum_from_string<PinType>(groupItem->getType().toStdString());
518 
519  //add children to pinGroup
520  for(auto pin : childs){
521  PIN* pinStruct = new PIN;
522  pinStruct->name = pin->getName();
523  pinStruct->id = pin->id();
524  pinStruct->direction = enum_from_string<PinDirection>(pin->getDirection().toStdString());
525  pinStruct->type = enum_from_string<PinType>(pin->getType().toStdString());
526  pinGroup->pins.append(pinStruct);
527  }
528  mPinGroups.append(pinGroup);*/
529  }
530  }
531 
532  void PinModel::handleGroupDirectionUpdate(PinItem* groupItem, PinDirection direction){
534  //direction was chosen manually
535  groupItem->setDirection(QString::fromStdString(enum_to_string(direction)));
536  return;
537  }
538 
539  //direction has to be calculated based on contained pins
540 
541  //bitmask with inout = 2³, out = 2², in = 2¹, internal = 2⁰
542  /*int directionMask = 0;
543 
544  for(BaseTreeItem* pin : groupItem->getChildren()){
545  QString dir = static_cast<PinItem*>(pin)->getDirection();
546  if(dir.toStdString() == enum_to_string(PinDirection::inout))
547  directionMask = directionMask | (1 << 3);
548  else if(dir.toStdString() == enum_to_string(PinDirection::output))
549  directionMask = directionMask | (1 << 2);
550  else if(dir.toStdString() == enum_to_string(PinDirection::input))
551  directionMask = directionMask | 1 << 1;
552  else if(dir.toStdString() == enum_to_string(PinDirection::internal))
553  directionMask = directionMask | 1;
554 
555  //if all bits are set then break
556  if(directionMask >= (1 << 4) - 1)
557  break;
558  }
559 
560 
561  PinDirection calcDir = enum_from_string<PinDirection>(groupItem->getDirection().toStdString());
562 
563  //inout or in and out was set
564  if(directionMask >= (1 << 3) || (directionMask & (1<<2) && directionMask & (1<<1))){
565  calcDir = PinDirection::inout;
566  }
567  //inout is not set and in and out are not set simultaneously
568  else if(directionMask >= 1<<2){
569  calcDir = PinDirection::output;
570  }
571  else if(directionMask > 1){
572  calcDir = PinDirection::input;
573  }
574  else if(directionMask > 0){
575  calcDir = PinDirection::internal;
576  }
577 
578  //else it should stay to what it was before
579 
580  //set calculated direction
581  groupItem->setDirection(QString::fromStdString(enum_to_string(calcDir)));*/
582  }
583 
584  void PinModel::printGateMember()
585  {
586  qInfo() << "Printing PinGroups and Pins";
587  for(auto pinGroup : getPinGroups()){
588  qInfo() << "PinGroup: " << pinGroup->getName() << " " << pinGroup->getId();
589  for(auto item : pinGroup->getChildren()){
590  PinItem* pin = static_cast<PinItem*>(item);
591  qInfo() << " Pin: " << pin->getName() << " " << pin->getId();
592  }
593  }
594  }
595 
596  u32 PinModel::getNextId(PinItem::TreeItemType type)
597  {
598  QSet<u32> takenGroupIds = QSet<u32>();
599  QSet<u32> takenPinIds = QSet<u32>();
600 
601  //get all currently taken ids
602  for(auto item : getPinGroups()){
603  PinItem* pinGroup = static_cast<PinItem*>(item);
604  takenGroupIds.insert(pinGroup->getId());
605  for(auto item : pinGroup->getChildren()){
606  PinItem* pin = static_cast<PinItem*>(item);
607  takenPinIds.insert(pin->getId());
608  }
609  }
610 
611  //find next available id
612  u32 counter = 1;
613  // can result in an endless loop if 2^32 ids are taken
614 
616  while(takenGroupIds.contains(counter)){
617  counter++;
618  }
619  }
620  else if(type == PinItem::TreeItemType::Pin){
621  while(takenPinIds.contains(counter)){
622  counter++;
623  }
624  }
625  else{
626  return 0;
627  }
628 
629  return counter;
630  }
631 
633  {
634  QList<PinItem*> retval;
635  for (BaseTreeItem* bti : mRootItem->getChildren())
636  {
637  PinItem* grp = static_cast<PinItem*>(bti);
638  if (grp->getItemType() != PinItem::TreeItemType::PinGroup) continue;
639  retval.append(grp);
640  }
641  return retval;
642  }
643 
645  {
646  //check index
647  if(!index.isValid()) return;
648  //get item from index
649  auto item = static_cast<PinItem*>(getItemFromIndex(index));
650 
651  if(!item)
652  return;
653 
654  //remove item from the PinItem list
655 
656  //check the type of the item
657  PinItem::TreeItemType type = item->getItemType();
659  //handle group deletion
660  beginRemoveRows(index, 0, 0);
661  //delete all pins of the pingroup
662  for(auto i : item->getChildren()){
663  item->removeChild(i);
664  }
665  //delete the group
666  getRootItem()->removeChild(item);
667 
668  /*for(auto item : getPinGroups()){
669  PinItem* group = static_cast<PinItem*>(item);
670  //delete all pins from the group and free group afterward
671  if(group->getId() == item->getId()){
672  for(auto pin : group->getChildren()){
673  delete(pin);
674  }
675  delete(group);
676  break;
677  }
678  }*/
679  //remove actual modelItem
680 
681  endRemoveRows();
682  handleItemRemoved(item);
683  }
685  //handle pin deletion
686 
687  //get the parent group of the pin
688  PinItem* parentGroup = static_cast<PinItem*>(item->getParent());
689  /*
690  for(auto item : getPinGroups()){
691  PinItem* group = static_cast<PinItem*>(item);
692  if(group->getId() == parentGroup->getId()){
693  //delete pin from the group
694  for(auto itemPin : group->getChildren()){
695  PinItem* pin = static_cast<PinItem*>(itemPin);
696  if(pin->getId() == item->getId()){
697  group->removeChild(pin);
698  delete(pin);
699  break;
700  }
701  }
702  break;
703  }
704  }*/
705  //remove actual modelItem
706  beginRemoveRows(index, 0, 0);
707  parentGroup->removeChild(item);
708  endRemoveRows();
709  handleItemRemoved(item);
710  }
711  }
712 
713  void PinModel::handleItemRemoved(PinItem* item)
714  {
715 
716  //TODO reorganize name handling
717  //remove name from assigned list
719  //name should be unique amongst pingroups so this can be deleted
720  mAssignedGroupNames.remove(item->getName());
721  mAssignedPinNames.remove(item->getName());
722  }
723  else{
724  //item was a pin so we have to check if the parent group is assigned to that name, otherwise it can be freed
725  mAssignedPinNames.remove(item->getName());
726  }
727  }
728 
730  {
731  QList<PinItem*> inputPins;
732  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
733  {
734  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
735  for(BaseTreeItem* item : pinGroup->getChildren()){
736  PinItem* pin = static_cast<PinItem*>(item);
737  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
738  if (pin->getDirection() == PinDirection::input || pin->getDirection() == PinDirection::inout) inputPins.append(pin);
739  }
740  }
741  return inputPins;
742  }
743 
745  {
746  QList<PinItem*> outputPins;
747  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
748  {
749  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
750  for(BaseTreeItem* item : pinGroup->getChildren()){
751  PinItem* pin = static_cast<PinItem*>(item);
752  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
753  if (pin->getDirection() == PinDirection::output || pin->getDirection() == PinDirection::inout) outputPins.append(pin);
754  }
755  }
756  return outputPins;
757  }
758 
759 }
(Future) Base class for all tree models related to the details widget.
virtual QList< BaseTreeItem * > getChildren() const
virtual bool removeChild(BaseTreeItem *child)
virtual int getChildCount() const
virtual void appendChild(BaseTreeItem *child)
The BaseTreeModel implements generic standard functions of a tree model.
QModelIndex getIndexFromItem(BaseTreeItem *item) const
RootTreeItem * mRootItem
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
virtual void clear()
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
BaseTreeItem * getRootItem() const
void setHeaderLabels(const QStringList &label)
BaseTreeItem * getItemFromIndex(QModelIndex index) const
std::vector< PinGroup< GatePin > * > get_pin_groups(const std::function< bool(PinGroup< GatePin > *)> &filter=nullptr) const
Definition: gate_type.cpp:548
An item in the PinModel.
Definition: pin_item.h:48
QString getName() const
Definition: pin_item.cpp:81
void setId(u32 newId)
Definition: pin_item.cpp:72
PinDirection getDirection() const
Definition: pin_item.cpp:96
TreeItemType getItemType() const
Definition: pin_item.cpp:132
PinType getPinType() const
Definition: pin_item.cpp:86
void setName(const QString &name)
Definition: pin_item.cpp:111
void setType(const QString &type)
Definition: pin_item.cpp:121
QString getDirectionAsText() const
Definition: pin_item.cpp:101
void setDirection(const QString &direction)
Definition: pin_item.cpp:116
QList< PinItem * > getInputPins()
Definition: pin_model.cpp:729
PinModel(QObject *parent=nullptr)
Definition: pin_model.cpp:7
QList< PinItem * > getOutputPins()
Definition: pin_model.cpp:744
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: pin_model.cpp:32
void handleEditDirection(QModelIndex index, const QString &directionString)
Definition: pin_model.cpp:252
QList< PinItem * > getPinGroups() const
Definition: pin_model.cpp:632
void setGate(GateType *gate)
Definition: pin_model.cpp:41
void handleEditName(QModelIndex index, const QString &input)
Definition: pin_model.cpp:148
void editNewDone(QModelIndex index)
void handleDeleteItem(QModelIndex index)
Definition: pin_model.cpp:644
void handleEditType(QModelIndex index, const QString &typeString)
Definition: pin_model.cpp:308
PinDirection
Definition: pin_direction.h:36
PinType
Definition: pin_type.h:36
std::string enum_to_string(T e)
Definition: enums.h:52
quint32 u32
PinType type
PinDirection direction
std::string name
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
void append(const T &value)
void addButton(QAbstractButton *button, QMessageBox::ButtonRole role)
QAbstractButton * clickedButton() const const
virtual int exec() override
void setWindowTitle(const QString &title)
void setText(const QString &text)
void * internalPointer() const const
bool isValid() const const
QModelIndex parent() const const
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
bool contains(const T &value) const const
QSet::iterator insert(const T &value)
bool remove(const T &value)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
std::string toStdString() const const
typedef ItemFlags
virtual QValidator::State validate(QString &input, int &pos) const const=0