Skip to content

Commit

Permalink
removed redundancy and double elements in the pinModel
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed May 23, 2024
1 parent fa32f9f commit 2f6b4d8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace hal

QString mName;
QStringList mProperties;
QList<PinItem*> mPingroups;
//QList<PinItem*> mPingroups;
PinModel* mPinModel;
GateLibraryTabPin* mPinTab;

Expand Down
3 changes: 3 additions & 0 deletions plugins/gui/include/gui/pin_model/pin_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace hal
void setDirection(const QString& direction);
void setId(u32 newId);
void setType(const QString& type);

void setDirection(PinDirection direction);
void setType(PinType type);

Expand All @@ -92,6 +93,8 @@ namespace hal
TreeItemType mItemType;
u32 mId;
QString mName;

//enum
QString mDirection;
QString mType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace hal

mName = generalInfoPage->getName();
mProperties = generalInfoPage->getProperties();
mPingroups = pinsPage->getPingroups();
//mPingroups = pinsPage->getPingroups();

this->close();
}
Expand Down
11 changes: 11 additions & 0 deletions plugins/gui/src/pin_model/pin_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ namespace hal

QVariant PinItem::getData(int column) const
{
switch(mItemType){
case TreeItemType::GroupCreator:
if(!column) return "create new pingroup...";
return QVariant();
case TreeItemType::PinCreator:
if(!column) return "create new pin...";
return QVariant();
default:
break;
}

switch (column){
case 0:
return QVariant(mName);
Expand Down
31 changes: 12 additions & 19 deletions plugins/gui/src/pin_model/pin_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,25 @@ namespace hal

//add new dummypin to the group
auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
dummyPin->setData(QList<QVariant>() << "create new pin ...");
//dummyPin->setData(QList<QVariant>() << "create new pin ...");
pinItem->appendChild(dummyPin);

//add new dummygroup after entry
auto dummyGroup = new PinItem(PinItem::TreeItemType::GroupCreator);
dummyGroup->setData(QList<QVariant>() << "create new group ...");
//dummyGroup->setData(QList<QVariant>() << "create new group ...");
pinItem->getParent()->appendChild(dummyGroup);
endInsertRows();


//create new pinGroupStruct and add it to the list of pingroups
PinItem* newPinGroup = new PinItem(PinItem::TreeItemType::PinGroup);
newPinGroup->setId(pinItem->getId());
newPinGroup->setName(pinItem->getName());
newPinGroup->setDirection(pinItem->getDirection());
newPinGroup->setType(pinItem->getType());
endInsertRows();

//add pin to group
addPinToPinGroup(initialPin, pinItem);
//addPinToPinGroup(initialPin, pinItem);

break;
}
Expand All @@ -214,7 +215,7 @@ namespace hal
beginInsertRows(index.parent(),0,0);
//add new dummy after entry
auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
dummyPin->setData(QList<QVariant>() << "create new pin ...");
//dummyPin->setData(QList<QVariant>() << "create new pin ...");
pinItem->getParent()->appendChild(dummyPin);
endInsertRows();

Expand Down Expand Up @@ -361,19 +362,10 @@ namespace hal

void PinModel::addPinToPinGroup(PinItem* pinItem, PinItem* groupItem)
{
for(auto pinGroup : getPinGroups()){
//PinItem* pinGroup = static_cast<PinItem*>(item);
if(pinGroup->getId() == groupItem->getId()){
PinItem* pin = new PinItem(PinItem::TreeItemType::Pin);
pin->setId(pinItem->getId());
pin->setName(pinItem->getName());
pin->setDirection(pinItem->getDirection());
pin->setType(pinItem->getType());

pinGroup->appendChild(pin);
break;
}
}
QModelIndex index = getIndexFromItem(groupItem);
beginInsertRows(index, groupItem->getChildCount(), groupItem->getChildCount());
groupItem->appendChild(pinItem);
endInsertRows();
}


Expand Down Expand Up @@ -641,6 +633,7 @@ namespace hal
PinItem::TreeItemType type = item->getItemType();
if(type == PinItem::TreeItemType::PinGroup || type == PinItem::TreeItemType::InvalidPinGroup){
//handle group deletion
beginRemoveRows(index, 0, 0);
for(auto item : getPinGroups()){
PinItem* group = static_cast<PinItem*>(item);
//delete all pins from the group and free group afterward
Expand All @@ -653,7 +646,7 @@ namespace hal
}
}
//remove actual modelItem
beginRemoveRows(index, 0, 0);

getRootItem()->removeChild(item);
endRemoveRows();
handleItemRemoved(item);
Expand Down

0 comments on commit 2f6b4d8

Please sign in to comment.