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  if (mAssignedGroupNames.contains(newName))
459  {
460  log_warning("gui", "Pin group name '{}' not available, another group with that name exists.", newName.toStdString());
461  return false;
462  }
463  if (!mAssignedPinNames.contains(newName))
464  {
465  return true;
466  }
467  // Pin with intended new name exists. However, this is OK if pin is part of this group.
468  for (BaseTreeItem* bti : treeItem->getChildren())
469  {
470  if (static_cast<PinItem*>(bti)->getName() == newName)
471  return true;
472  }
473  log_warning("gui", "Pin group name '{}' not available, another group contains a pin with that name.", newName.toStdString());
474  return false;
475  }
476  else{
477  //get group name
478  QString groupName = static_cast<PinItem*>(treeItem->getParent())->getName();
479  //check if pin can be named after the group
480  if(groupName == newName && !mAssignedPinNames.contains(newName))
481  {
482  return true;
483  }
484  //check if other group or pin has the name
485  else{
486  return !(mAssignedGroupNames.contains(newName) || mAssignedPinNames.contains(newName));
487  }
488  }
489  }
490 
491  void PinModel::handleInvalidPinUpdate(PinItem* pinItem)
492  {
493  if(!isNameAvailable(pinItem->getName(), pinItem)
494  || pinItem->getDirection() == PinDirection::none)
495  return; // Pin is not valid
496 
497  //pin is valid
498  pinItem->setItemType(PinItem::TreeItemType::Pin);
499  mInvalidPins.removeAll(pinItem);
500 
501  //checks if the groups status is affected and if so it updates the group
502  auto pinGroup = static_cast<PinItem*>(pinItem->getParent());
503  handleInvalidGroupUpdate(pinGroup);
504  }
505 
506  void PinModel::handleInvalidGroupUpdate(PinItem* groupItem){
507  bool isValid = true;
508 
509  //calculate new direction
510  //handleGroupDirectionUpdate(groupItem);
511 
512  //check each pin in the group if its valid or not
513  QList<PinItem*> childs = QList<PinItem*>();
514  for(auto baseTreeItem : groupItem->getChildren()){
515  auto childPin = static_cast<PinItem*>(baseTreeItem);
516  //if the child is invalid then the group cant be valid
517  if(childPin->getItemType() == PinItem::TreeItemType::InvalidPin){
518  isValid = false;
519  break;
520  }
521  if(childPin->getItemType() != PinItem::TreeItemType::PinCreator)
522  childs.append(childPin);
523  }
524 
525  if(isValid){
526 
527  groupItem->setItemType(PinItem::TreeItemType::PinGroup);
528  /*
529  mInvalidGroups.removeAll(groupItem);
530  PINGROUP* pinGroup = new PINGROUP;
531  pinGroup->id = groupItem->id();
532  pinGroup->name = groupItem->getName();
533  pinGroup->direction = enum_from_string<PinDirection>(groupItem->getDirection().toStdString());
534  pinGroup->type = enum_from_string<PinType>(groupItem->getType().toStdString());
535 
536  //add children to pinGroup
537  for(auto pin : childs){
538  PIN* pinStruct = new PIN;
539  pinStruct->name = pin->getName();
540  pinStruct->id = pin->id();
541  pinStruct->direction = enum_from_string<PinDirection>(pin->getDirection().toStdString());
542  pinStruct->type = enum_from_string<PinType>(pin->getType().toStdString());
543  pinGroup->pins.append(pinStruct);
544  }
545  mPinGroups.append(pinGroup);*/
546  }
547  }
548 
549  void PinModel::handleGroupDirectionUpdate(PinItem* groupItem, PinDirection direction){
551  //direction was chosen manually
552  groupItem->setDirection(QString::fromStdString(enum_to_string(direction)));
553  return;
554  }
555 
556  //direction has to be calculated based on contained pins
557 
558  //bitmask with inout = 2³, out = 2², in = 2¹, internal = 2⁰
559  /*int directionMask = 0;
560 
561  for(BaseTreeItem* pin : groupItem->getChildren()){
562  QString dir = static_cast<PinItem*>(pin)->getDirection();
563  if(dir.toStdString() == enum_to_string(PinDirection::inout))
564  directionMask = directionMask | (1 << 3);
565  else if(dir.toStdString() == enum_to_string(PinDirection::output))
566  directionMask = directionMask | (1 << 2);
567  else if(dir.toStdString() == enum_to_string(PinDirection::input))
568  directionMask = directionMask | 1 << 1;
569  else if(dir.toStdString() == enum_to_string(PinDirection::internal))
570  directionMask = directionMask | 1;
571 
572  //if all bits are set then break
573  if(directionMask >= (1 << 4) - 1)
574  break;
575  }
576 
577 
578  PinDirection calcDir = enum_from_string<PinDirection>(groupItem->getDirection().toStdString());
579 
580  //inout or in and out was set
581  if(directionMask >= (1 << 3) || (directionMask & (1<<2) && directionMask & (1<<1))){
582  calcDir = PinDirection::inout;
583  }
584  //inout is not set and in and out are not set simultaneously
585  else if(directionMask >= 1<<2){
586  calcDir = PinDirection::output;
587  }
588  else if(directionMask > 1){
589  calcDir = PinDirection::input;
590  }
591  else if(directionMask > 0){
592  calcDir = PinDirection::internal;
593  }
594 
595  //else it should stay to what it was before
596 
597  //set calculated direction
598  groupItem->setDirection(QString::fromStdString(enum_to_string(calcDir)));*/
599  }
600 
601  void PinModel::printGateMember()
602  {
603  qInfo() << "Printing PinGroups and Pins";
604  for(auto pinGroup : getPinGroups()){
605  qInfo() << "PinGroup: " << pinGroup->getName() << " " << pinGroup->getId();
606  for(auto item : pinGroup->getChildren()){
607  PinItem* pin = static_cast<PinItem*>(item);
608  qInfo() << " Pin: " << pin->getName() << " " << pin->getId();
609  }
610  }
611  }
612 
613  u32 PinModel::getNextId(PinItem::TreeItemType type)
614  {
615  QSet<u32> takenGroupIds = QSet<u32>();
616  QSet<u32> takenPinIds = QSet<u32>();
617 
618  //get all currently taken ids
619  for(auto item : getPinGroups()){
620  PinItem* pinGroup = static_cast<PinItem*>(item);
621  takenGroupIds.insert(pinGroup->getId());
622  for(auto item : pinGroup->getChildren()){
623  PinItem* pin = static_cast<PinItem*>(item);
624  takenPinIds.insert(pin->getId());
625  }
626  }
627 
628  //find next available id
629  u32 counter = 1;
630  // can result in an endless loop if 2^32 ids are taken
631 
633  while(takenGroupIds.contains(counter)){
634  counter++;
635  }
636  }
637  else if(type == PinItem::TreeItemType::Pin){
638  while(takenPinIds.contains(counter)){
639  counter++;
640  }
641  }
642  else{
643  return 0;
644  }
645 
646  return counter;
647  }
648 
650  {
651  QList<PinItem*> retval;
652  for (BaseTreeItem* bti : mRootItem->getChildren())
653  {
654  PinItem* grp = static_cast<PinItem*>(bti);
655  if (grp->getItemType() != PinItem::TreeItemType::PinGroup) continue;
656  retval.append(grp);
657  }
658  return retval;
659  }
660 
662  {
663  //check index
664  if(!index.isValid()) return;
665  //get item from index
666  auto item = static_cast<PinItem*>(getItemFromIndex(index));
667 
668  if(!item)
669  return;
670 
671  //remove item from the PinItem list
672 
673  //check the type of the item
674  PinItem::TreeItemType type = item->getItemType();
676  //handle group deletion
677  beginRemoveRows(index, 0, 0);
678  //delete all pins of the pingroup
679  for(auto i : item->getChildren()){
680  item->removeChild(i);
681  }
682  //delete the group
683  getRootItem()->removeChild(item);
684 
685  /*for(auto item : getPinGroups()){
686  PinItem* group = static_cast<PinItem*>(item);
687  //delete all pins from the group and free group afterward
688  if(group->getId() == item->getId()){
689  for(auto pin : group->getChildren()){
690  delete(pin);
691  }
692  delete(group);
693  break;
694  }
695  }*/
696  //remove actual modelItem
697 
698  endRemoveRows();
699  handleItemRemoved(item);
700  }
702  //handle pin deletion
703 
704  //get the parent group of the pin
705  PinItem* parentGroup = static_cast<PinItem*>(item->getParent());
706  /*
707  for(auto item : getPinGroups()){
708  PinItem* group = static_cast<PinItem*>(item);
709  if(group->getId() == parentGroup->getId()){
710  //delete pin from the group
711  for(auto itemPin : group->getChildren()){
712  PinItem* pin = static_cast<PinItem*>(itemPin);
713  if(pin->getId() == item->getId()){
714  group->removeChild(pin);
715  delete(pin);
716  break;
717  }
718  }
719  break;
720  }
721  }*/
722  //remove actual modelItem
723  beginRemoveRows(index, 0, 0);
724  parentGroup->removeChild(item);
725  endRemoveRows();
726  handleItemRemoved(item);
727  }
728  }
729 
730  void PinModel::handleItemRemoved(PinItem* item)
731  {
732 
733  //TODO reorganize name handling
734  //remove name from assigned list
736  //name should be unique amongst pingroups so this can be deleted
737  mAssignedGroupNames.remove(item->getName());
738  mAssignedPinNames.remove(item->getName());
739  }
740  else{
741  //item was a pin so we have to check if the parent group is assigned to that name, otherwise it can be freed
742  mAssignedPinNames.remove(item->getName());
743  }
744  }
745 
747  {
748  QList<PinItem*> inputPins;
749  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
750  {
751  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
752  for(BaseTreeItem* item : pinGroup->getChildren()){
753  PinItem* pin = static_cast<PinItem*>(item);
754  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
755  if (pin->getDirection() == PinDirection::input || pin->getDirection() == PinDirection::inout) inputPins.append(pin);
756  }
757  }
758  return inputPins;
759  }
760 
762  {
763  QList<PinItem*> outputPins;
764  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
765  {
766  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
767  for(BaseTreeItem* item : pinGroup->getChildren()){
768  PinItem* pin = static_cast<PinItem*>(item);
769  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
770  if (pin->getDirection() == PinDirection::output || pin->getDirection() == PinDirection::inout) outputPins.append(pin);
771  }
772  }
773  return outputPins;
774  }
775 
776 }
(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:746
PinModel(QObject *parent=nullptr)
Definition: pin_model.cpp:7
QList< PinItem * > getOutputPins()
Definition: pin_model.cpp:761
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:649
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:661
void handleEditType(QModelIndex index, const QString &typeString)
Definition: pin_model.cpp:308
#define log_warning(channel,...)
Definition: log.h:76
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