Skip to content

Commit 7c40d55

Browse files
committed
Improved pin/pingroup model functionality for wizard
1 parent ad05389 commit 7c40d55

File tree

3 files changed

+71
-15
lines changed

3 files changed

+71
-15
lines changed

plugins/gui/include/gui/pin_model/pin_model.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <QAbstractItemModel>
3737
#include <QModelIndex>
3838
#include <QVariant>
39+
#include <QMessageBox>
40+
#include <QPushButton>
3941
#include <array>
4042
#include <set>
4143

plugins/gui/src/pin_model/pin_delegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace hal
3434
}
3535
case 1: {
3636
//dont create a widget for dummyEntries
37-
if(itemType != PinItem::TreeItemType::Pin && itemType != PinItem::TreeItemType::InvalidPin)
37+
if(itemType == PinItem::TreeItemType::GroupCreator || itemType == PinItem::TreeItemType::PinCreator)
3838
return nullptr;
3939
auto comboBox = new QComboBox(parent);
4040
//TODO provide enum to string method
@@ -135,7 +135,7 @@ namespace hal
135135
case 1:{
136136
//direction column
137137
//TODO currently only pins can change the direction while groups does not allow modification
138-
if(itemType != PinItem::TreeItemType::Pin && itemType != PinItem::TreeItemType::InvalidPin)
138+
if(itemType == PinItem::TreeItemType::GroupCreator || itemType == PinItem::TreeItemType::PinCreator)
139139
break;
140140
auto comboBox = static_cast<QComboBox*>(editor);
141141
QString text = comboBox->currentText();

plugins/gui/src/pin_model/pin_model.cpp

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,64 @@ namespace hal
232232

233233
switch(itemType){
234234
case PinItem::TreeItemType::PinGroup:
235+
/*{
236+
pinItem->setDirection(direction);
237+
qInfo()<<pinItem->getChildren().length();
238+
for(auto child : pinItem->getChildren()) //set same direction for all pins of the pingroup
239+
{
240+
PinItem* pin = static_cast<PinItem*>(child);
241+
qInfo()<<"1";
242+
pin->setDirection(direction);
243+
}
244+
handleInvalidGroupUpdate(pinItem);
245+
//qInfo()<<"handleEditDirection PinGroup";
246+
break;
247+
}*/
235248
case PinItem::TreeItemType::InvalidPinGroup:{
236-
handleGroupDirectionUpdate(pinItem, enum_from_string<PinDirection>(direction.toStdString()));
249+
pinItem->setDirection(direction);
250+
for(auto child : pinItem->getChildren()) //set same direction for all pins of the pingroup
251+
{
252+
PinItem* pin = static_cast<PinItem*>(child);
253+
if(pin->getItemType() == PinItem::TreeItemType::Pin || pin->getItemType() == PinItem::TreeItemType::InvalidPin){
254+
pin->setDirection(direction);
255+
handleInvalidPinUpdate(pin);
256+
}
257+
}
258+
handleInvalidGroupUpdate(pinItem);
237259
break;
238260
}
239-
case PinItem::TreeItemType::Pin:{
261+
case PinItem::TreeItemType::Pin:
262+
/*{
240263
pinItem->setDirection(direction);
241264
//get the groupItem and update it
242-
auto groupItem = static_cast<PinItem*>(pinItem->getParent());
243-
handleGroupDirectionUpdate(groupItem);
265+
//auto groupItem = static_cast<PinItem*>(pinItem->getParent());
266+
//handleGroupDirectionUpdate(groupItem);
267+
handleInvalidPinUpdate(pinItem);
244268
break;
245-
}
269+
}*/
246270
case PinItem::TreeItemType::InvalidPin:{
247-
pinItem->setDirection(direction);
248-
handleInvalidPinUpdate(pinItem);
271+
QMessageBox warning;
272+
QPushButton* acceptBtn = warning.addButton(tr("Continue with changes"), QMessageBox::AcceptRole);
273+
QPushButton* abortBtn = warning.addButton(QMessageBox::Abort);
274+
PinItem* parentGroup = static_cast<PinItem*>(pinItem->getParent());
275+
warning.setWindowTitle("New pin creation");
276+
warning.setText(QString("You are about to create an %1 pin in an %2 pin group")
277+
.arg(direction)
278+
.arg(parentGroup->getDirection()));
279+
if(direction != parentGroup->getDirection())
280+
{
281+
warning.exec();
282+
if(warning.clickedButton() == acceptBtn){
283+
pinItem->setDirection(direction);
284+
handleInvalidPinUpdate(pinItem);
285+
}
286+
}
287+
else
288+
{
289+
pinItem->setDirection(direction);
290+
handleInvalidPinUpdate(pinItem);
291+
}
292+
249293
break;
250294
}
251295
}
@@ -259,13 +303,24 @@ namespace hal
259303

260304
switch (itemType)
261305
{
306+
case PinItem::TreeItemType::InvalidPin:
262307
case PinItem::TreeItemType::Pin: {
263308
pinItem->setType(type);
309+
handleInvalidPinUpdate(pinItem);
264310
break;
265311
}
266-
case PinItem::TreeItemType::InvalidPin: {
312+
case PinItem::TreeItemType::InvalidPinGroup:
313+
case PinItem::TreeItemType::PinGroup: {
267314
pinItem->setType(type);
268-
handleInvalidPinUpdate(pinItem);
315+
for(auto child : pinItem->getChildren()) //set same direction for all pins of the pingroup
316+
{
317+
PinItem* pin = static_cast<PinItem*>(child);
318+
if(pin->getItemType() == PinItem::TreeItemType::Pin || pin->getItemType() == PinItem::TreeItemType::InvalidPin){
319+
pin->setType(type);
320+
handleInvalidPinUpdate(pin);
321+
}
322+
}
323+
handleInvalidGroupUpdate(pinItem);
269324
break;
270325
}
271326
}
@@ -374,7 +429,6 @@ namespace hal
374429

375430
void PinModel::handleInvalidPinUpdate(PinItem* pinItem)
376431
{
377-
378432
if(!isNameAvailable(pinItem->getName(), pinItem)
379433
|| enum_from_string<PinDirection>(pinItem->getDirection().toStdString()) == PinDirection::none)
380434
return; // Pin is not valid
@@ -393,7 +447,7 @@ namespace hal
393447
bool isValid = true;
394448

395449
//calculate new direction
396-
handleGroupDirectionUpdate(groupItem);
450+
//handleGroupDirectionUpdate(groupItem);
397451

398452
//check each pin in the group if its valid or not
399453
QList<PinItem*> childs = QList<PinItem*>();
@@ -442,7 +496,7 @@ namespace hal
442496
//direction has to be calculated based on contained pins
443497

444498
//bitmask with inout = 2³, out = 2², in = 2¹, internal = 2⁰
445-
int directionMask = 0;
499+
/*int directionMask = 0;
446500
447501
for(BaseTreeItem* pin : groupItem->getChildren()){
448502
QString dir = static_cast<PinItem*>(pin)->getDirection();
@@ -481,7 +535,7 @@ namespace hal
481535
//else it should stay to what it was before
482536
483537
//set calculated direction
484-
groupItem->setDirection(QString::fromStdString(enum_to_string(calcDir)));
538+
groupItem->setDirection(QString::fromStdString(enum_to_string(calcDir)));*/
485539
}
486540

487541
void PinModel::printGateMember()

0 commit comments

Comments
 (0)