19 : mItemType(itype), mId(id_), mPinName(pinName), mPinDirection(dir), mPinType(ptype), mNetName(netName), mIndex(inx)
36 return ( mIndex ?
"descending" :
"ascending");
44 Q_ASSERT(
data.size() >= 5);
45 mPinName =
data[0].toString();
46 mPinDirection = enum_from_string<PinDirection>(
data[1].toString().toStdString());
47 mPinType = enum_from_string<PinType>(
data[2].toString().toStdString());
48 mNetName =
data[3].toString();
49 mIndex =
data[4].toInt();
57 mPinName =
data.toString();
60 mPinDirection = enum_from_string<PinDirection>(
data.toString().toStdString());
63 mPinType = enum_from_string<PinType>(
data.toString().toStdString());
66 mNetName =
data.toString();
69 mIndex =
data.toInt();
135 types <<
"pintreemodel/item";
141 if (indexes.size() != 5)
149 stream <<
type << item->
id();
153 data->setData(
"pintreemodel/item", encodedData);
169 auto droppedItem = (
type ==
"group") ?
static_cast<PortTreeItem*
>(mIdToGroupItem.value(
id)) :
static_cast<PortTreeItem*
>(mIdToPinItem.value(
id));
183 if(!dropPositionItem)
186 dndGroupBetweenGroup(droppedItem, row);
196 dndGroupOnGroup(droppedItem, parentGroupItem, row);
200 dndGroupOnGroup(droppedItem, dropPositionItem);
205 if(!dropPositionItem)
208 dndPinBetweenGroup(droppedItem, row);
213 dndPinBetweenPin(droppedItem, dropPositionItem, row);
223 dndPinBetweenPin(droppedItem, parentGroupItem, row);
227 dndPinOnGroup(droppedItem, dropPositionItem);
239 if(!
data->formats().contains(
"pintreemodel/item"))
return false;
242 auto encItem =
data->data(
"pintreemodel/item");
264 if(itRow == row || ((itRow+1) == row))
272 auto item = mIdToPinItem[
id];
273 if((!parentItem && item->getParent()->getChildCount() == 1)
274 || (item->getParent() == parentItem && row == -1)
275 || item == parentItem )
279 if(item->getParent() == parentItem)
281 auto itRow = item->getOwnRow();
282 if(itRow == row || ((itRow+1) == row))
293 mNameToTreeItem.clear();
294 mIdToGroupItem.clear();
295 mIdToPinItem.clear();
305 if(pinGroup->empty())
310 pinGroup->get_type(), pinGroup->is_ascending() ? 0 : 1);
311 mIdToGroupItem.insert(pinGroup->get_id(), pinGroupItem);
312 for(
ModulePin* pin : pinGroup->get_pins())
317 pin->get_direction(),
319 pin->get_group().second,
323 mIdToPinItem.insert(pin->get_id(), pinItem);
325 mNameToTreeItem.insert(pinGroupName, pinGroupItem);
398 return pin->get_net();
406 if (!mModule)
return -1;
420 if (m != mModule)
return;
433 ptiGroup = mIdToGroupItem.value(pgid);
436 log_warning(
"gui",
"Cannot handle event for pin group ID={}, tree item does not exist.", pgid);
444 log_warning(
"gui",
"Cannot handle event for pin group ID={}, no such group.", pgid);
452 ptiPin = mIdToPinItem.value(pgid);
455 log_warning(
"gui",
"Cannot handle event for pin ID={}, tree item does not exist.", pgid);
463 log_warning(
"gui",
"Cannot handle event for pin ID={}, no such pid.", pgid);
467 pgroup = pgPair.first;
470 ptiGroup = mIdToGroupItem.value(pgroup->
get_id());
486 mIdToGroupItem.insert(ptiGroup->
id(), ptiGroup);
494 removeItem(ptiGroup);
511 removeItem(ptiGroup);
516 if (!pgroup || !ptiGroup)
518 log_warning(
"gui",
"Cannot handle pin create event for pin ID={}, pin is not assigned to any group.", pgid);
531 mIdToPinItem.insert(ptiPin->
id(), ptiPin);
532 insertItem(ptiPin, ptiGroup, pinRow);
533 updateGroupIndex(ptiGroup);
538 if (!pgroup || !ptiGroup)
540 log_warning(
"gui",
"Cannot handle pin reorder event for pin ID={}, pin is not assigned to any group.", pgid);
544 insertItem(ptiPin, ptiGroup, pinRow);
545 updateGroupIndex(ptiGroup);
550 if (!pgroup || !ptiGroup)
552 log_warning(
"gui",
"Cannot handle pin assign event for pin ID={}, pin is not assigned to any group.", pgid);
556 insertItem(ptiPin, ptiGroup, pinRow);
557 updateGroupIndex(ptiGroup);
580 if (dataChangedIndex.
isValid())
595 for(
const auto &pin : srcgroup->get_pins())
596 pins.append(pin->get_id());
597 if (
pins.isEmpty())
return;
602 if (act) act->
exec();
608 void ModulePinsTreeModel::dndGroupBetweenGroup(PortTreeItem *droppedGroup,
int row)
610 int ownRow = droppedGroup->getOwnRow();
612 auto desiredIdx = bottomEdge ? row-1 : row;
613 if(ownRow < row && !bottomEdge) desiredIdx--;
619 void ModulePinsTreeModel::dndPinOnGroup(PortTreeItem *droppedPin, BaseTreeItem *onDroppedGroup)
626 void ModulePinsTreeModel::dndPinBetweenPin(PortTreeItem *droppedPin, BaseTreeItem *onDroppedParent,
int row)
628 int desiredIdx = row;
629 ActionPingroup* act =
nullptr;
630 if(droppedPin->getParent() == onDroppedParent)
632 int ownRow = droppedPin->getOwnRow();
633 bool bottomEdge = row == onDroppedParent->getChildCount();
634 desiredIdx = bottomEdge ? row-1 : row;
635 if(ownRow < row && !bottomEdge) desiredIdx--;
647 void ModulePinsTreeModel::dndPinBetweenGroup(PortTreeItem *droppedPin,
int row)
653 if (!pinToMove)
return;
661 void ModulePinsTreeModel::updateGroupIndex(PortTreeItem* groupItem)
665 for (ModulePin* pin : pg->get_pins())
667 int inx = pg->get_index(pin).get();
668 PortTreeItem* pinItem = mIdToPinItem.value(pin->get_id());
670 pinItem->setIndex(inx);
678 void ModulePinsTreeModel::insertItem(PortTreeItem* item, BaseTreeItem* parent,
int index)
685 item->itemType() ==
PortTreeItem::Pin ? mIdToPinItem.insert(item->id(), item) : mIdToGroupItem.insert(item->id(), item);
689 void ModulePinsTreeModel::removeItem(PortTreeItem* item)
692 item->getParent()->removeChild(item);
696 item->itemType() ==
PortTreeItem::Pin ? mIdToPinItem.remove(item->id()) : mIdToGroupItem.remove(item->id());
static ActionPingroup * addPinToNewGroup(const Module *m, const QString &name, u32 pinId, int grpRow=-1)
static ActionPingroup * addPinToExistingGroup(const Module *m, u32 grpId, u32 pinId, int pinRow=-1)
static ActionPingroup * addPinsToExistingGroup(const Module *m, u32 grpId, QList< u32 > pinIds, int pinRow=-1)
const std::string & get_name() const
const std::pair< PinGroup< T > *, i32 > & get_group() const
PinDirection get_direction() const
(Future) Base class for all tree models related to the details widget.
virtual BaseTreeItem * getParent() const
virtual int getChildCount() const
virtual void appendChild(BaseTreeItem *child)
The BaseTreeModel implements generic standard functions of a tree model.
QModelIndex getIndexFromItem(BaseTreeItem *item) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setHeaderLabels(const QStringList &label)
BaseTreeItem * getItemFromIndex(QModelIndex index) const
std::vector< ModulePin * > get_pins(const std::function< bool(ModulePin *)> &filter=nullptr) const
ModulePin * get_pin_by_id(const u32 id) const
std::vector< PinGroup< ModulePin > * > get_pin_groups(const std::function< bool(PinGroup< ModulePin > *)> &filter=nullptr) const
PinGroup< ModulePin > * get_pin_group_by_id(const u32 id) const
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
ModulePinsTreeModel(QObject *parent=nullptr)
QStringList mimeTypes() const override
Net * getNetFromItem(PortTreeItem *item)
QMimeData * mimeData(const QModelIndexList &indexes) const override
void handleModulePortsChanged(Module *m, PinEvent pev, u32 pgid)
Qt::ItemFlags flags(const QModelIndex &index) const override
int getRepresentedModuleId()
void setModule(Module *m)
void numberOfPortsChanged(const int newNumber)
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
const std::string & get_name() const
Module * get_module_by_id(u32 module_id) const
void modulePortsChanged(Module *m, PinEvent pev, u32 pgid) const
const std::string & get_name() const
bool is_ascending() const
PinDirection get_direction() const
void setPinDirection(PinDirection dir)
void setPinType(PinType ptype)
void appendData(QVariant data) override
void setDataAtIndex(int index, QVariant &data) override
void setData(QList< QVariant > data) override
int getColumnCount() const override
void setName(const QString &nam)
QVariant getData(int column) const override
static QString pyCodeModulePinGroup(u32 moduleId, u32 groupId)
static QString pyCodeModulePinById(u32 moduleId, u32 pinId)
#define log_warning(channel,...)
int pinGroupIndex(const Module *mod, const PinGroup< ModulePin > *pgrp)
@ PinTypeChange
pin renamed
@ GroupReorder
changed PinDirection attribute of group (like input)
@ PinDirChange
changed PinType attribute of pin (like data)
@ PinCreate
moved group to a new position within containing module
@ GroupTypeChange
pin group renamed
@ PinRename
pin assigned to new group
@ PinAssignToGroup
new pin created
@ PinDelete
moved pin to a new position within containing group
@ GroupRename
new pin group created
@ GroupDirChange
changed PinType attribute of group (like data)
@ PinReorder
changed PinDirection attribute of pin (like input)
int pinIndex2Row(const ModulePin *pin, int index)
NetlistRelay * gNetlistRelay
QString generateGroupName(const Module *mod, const ModulePin *pin)
std::string enum_to_string(T e)
std::vector< PinInformation > pins
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
QModelIndex createIndex(int row, int column, void *ptr) const const
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
void * internalPointer() const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
bool contains(const T &value) const const
QString fromStdString(const std::string &str)