23 : mItemType(itype), mId(id_), mPinName(pinName), mPinDirection(dir), mPinType(ptype), mNetName(netName)
44 mPinName =
data[0].toString();
45 mPinDirection = enum_from_string<PinDirection>(
data[1].toString().toStdString());
46 mPinType = enum_from_string<PinType>(
data[2].toString().toStdString());
47 mNetName =
data[3].toString();
55 mPinName =
data.toString();
58 mPinDirection = enum_from_string<PinDirection>(
data.toString().toStdString());
61 mPinType = enum_from_string<PinType>(
data.toString().toStdString());
64 mNetName =
data.toString();
129 types <<
"pintreemodel/item";
135 if (indexes.size() != 4)
143 stream <<
type << item->
id();
147 data->setData(
"pintreemodel/item", encodedData);
163 auto droppedItem = (
type ==
"group") ?
static_cast<PortTreeItem*
>(mIdToGroupItem.value(
id)) :
static_cast<PortTreeItem*
>(mIdToPinItem.value(
id));
180 dndGroupBetweenGroup(droppedItem, row);
185 dndGroupOnGroup(droppedItem, parentItem);
193 dndPinBetweenGroup(droppedItem, row);
198 dndPinBetweenPin(droppedItem, parentItem, row);
203 dndPinOnGroup(droppedItem, parentItem);
215 if(!
data->formats().contains(
"pintreemodel/item"))
return false;
218 auto encItem =
data->data(
"pintreemodel/item");
240 if(itRow == row || ((itRow+1) == row))
248 auto item = mIdToPinItem[
id];
249 if((!parentItem && item->getParent()->getChildCount() == 1) || (item->getParent() == parentItem && row == -1) || item == parentItem
253 if(item->getParent() == parentItem)
255 auto itRow = item->getOwnRow();
256 if(itRow == row || ((itRow+1) == row))
267 mNameToTreeItem.clear();
268 mIdToGroupItem.clear();
269 mIdToPinItem.clear();
280 if(pinGroup->empty())
285 mIdToGroupItem.insert(pinGroup->get_id(), pinGroupItem);
286 for(
ModulePin* pin : pinGroup->get_pins())
291 pin->get_direction(),
296 mIdToPinItem.insert(pin->get_id(), pinItem);
298 mNameToTreeItem.insert(pinGroupName, pinGroupItem);
371 return pin->get_net();
379 if (!mModule)
return -1;
393 if (m != mModule)
return;
406 ptiGroup = mIdToGroupItem.value(pgid);
409 log_warning(
"gui",
"Cannot handle event for pin group ID={}, tree item does not exist.", pgid);
417 log_warning(
"gui",
"Cannot handle event for pin group ID={}, no such group.", pgid);
425 ptiPin = mIdToPinItem.value(pgid);
428 log_warning(
"gui",
"Cannot handle event for pin ID={}, tree item does not exist.", pgid);
436 log_warning(
"gui",
"Cannot handle event for pin ID={}, no such pid.", pgid);
440 pgroup = pgPair.first;
443 ptiGroup = mIdToGroupItem.value(pgroup->
get_id());
458 mIdToGroupItem.insert(ptiGroup->
id(), ptiGroup);
466 removeItem(ptiGroup);
483 removeItem(ptiGroup);
488 if (!pgroup || !ptiGroup)
490 log_warning(
"gui",
"Cannot handle pin create event for pin ID={}, pin is not assigned to any group.", pgid);
502 mIdToPinItem.insert(ptiPin->
id(), ptiPin);
503 insertItem(ptiPin, ptiGroup, pinRow);
508 if (!pgroup || !ptiGroup)
510 log_warning(
"gui",
"Cannot handle pin reorder event for pin ID={}, pin is not assigned to any group.", pgid);
514 insertItem(ptiPin, ptiGroup, pinRow);
519 if (!pgroup || !ptiGroup)
521 log_warning(
"gui",
"Cannot handle pin assign event for pin ID={}, pin is not assigned to any group.", pgid);
525 insertItem(ptiPin, ptiGroup, pinRow);
548 if (dataChangedIndex.
isValid())
563 for(
const auto &pin : srcgroup->get_pins())
564 pins.append(pin->get_id());
565 if (
pins.isEmpty())
return;
571 if (act) act->
exec();
577 void ModulePinsTreeModel::dndGroupBetweenGroup(PortTreeItem *droppedGroup,
int row)
579 int ownRow = droppedGroup->getOwnRow();
581 auto desiredIdx = bottomEdge ? row-1 : row;
582 if(ownRow < row && !bottomEdge) desiredIdx--;
588 void ModulePinsTreeModel::dndPinOnGroup(PortTreeItem *droppedPin, BaseTreeItem *onDroppedGroup)
595 void ModulePinsTreeModel::dndPinBetweenPin(PortTreeItem *droppedPin, BaseTreeItem *onDroppedParent,
int row)
597 int desiredIdx = row;
598 ActionPingroup* act =
nullptr;
599 if(droppedPin->getParent() == onDroppedParent)
601 int ownRow = droppedPin->getOwnRow();
602 bool bottomEdge = row == onDroppedParent->getChildCount();
603 desiredIdx = bottomEdge ? row-1 : row;
604 if(ownRow < row && !bottomEdge) desiredIdx--;
616 void ModulePinsTreeModel::dndPinBetweenGroup(PortTreeItem *droppedPin,
int row)
622 if (!pinToMove)
return;
630 void ModulePinsTreeModel::insertItem(PortTreeItem* item, BaseTreeItem* parent,
int index)
637 item->itemType() ==
PortTreeItem::Pin ? mIdToPinItem.insert(item->id(), item) : mIdToGroupItem.insert(item->id(), item);
640 void ModulePinsTreeModel::removeItem(PortTreeItem* item)
643 item->getParent()->removeChild(item);
647 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 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
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)
virtual void setObject(const UserActionObject &obj)
The UserActionObject class represents a single object used in UserAction.
#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)