show selected item from property window as well, cleanup

This commit is contained in:
Miodrag Milanovic 2018-07-15 09:49:19 +02:00
parent fcba866b63
commit bce235fad5
2 changed files with 201 additions and 256 deletions

View File

@ -29,16 +29,6 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
enum class ElementType
{
NONE,
BEL,
WIRE,
PIP,
NET,
CELL
};
class ElementTreeItem : public QTreeWidgetItem class ElementTreeItem : public QTreeWidgetItem
{ {
public: public:
@ -87,7 +77,8 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net
propertyEditor = new QtTreePropertyBrowser(this); propertyEditor = new QtTreePropertyBrowser(this);
propertyEditor->setFactoryForManager(variantManager, variantFactory); propertyEditor->setFactoryForManager(variantManager, variantFactory);
propertyEditor->setPropertiesWithoutValueMarked(true); propertyEditor->setPropertiesWithoutValueMarked(true);
connect(propertyEditor, SIGNAL(currentItemChanged(QtBrowserItem *)), this,
SLOT(onCurrentPropertyChanged(QtBrowserItem *)));
propertyEditor->show(); propertyEditor->show();
QLineEdit *lineEdit = new QLineEdit(); QLineEdit *lineEdit = new QLineEdit();
@ -301,12 +292,13 @@ void DesignWidget::updateTree()
cells_root->addChild(item.second); cells_root->addChild(item.second);
} }
} }
QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
void DesignWidget::addProperty(QtProperty *property, const QString &id)
{ {
propertyToId[property] = id; QtProperty *topItem = groupManager->addProperty(id);
idToProperty[id] = property; propertyToId[topItem] = id;
propertyEditor->addProperty(property); idToProperty[id] = topItem;
propertyEditor->addProperty(topItem);
return topItem;
} }
void DesignWidget::clearProperties() void DesignWidget::clearProperties()
@ -320,9 +312,89 @@ void DesignWidget::clearProperties()
idToProperty.clear(); idToProperty.clear();
} }
void DesignWidget::onCurrentPropertyChanged(QtBrowserItem *_item)
{
if (_item) {
QtProperty *selectedProperty = _item->property();
QString type = selectedProperty->propertyId();
IdString value = ctx->id(selectedProperty->valueText().toStdString());
std::vector<DecalXY> decals;
if (type == "BEL") {
BelId bel = ctx->getBelByName(value);
if (bel != BelId()) {
decals.push_back(ctx->getBelDecal(bel));
Q_EMIT selected(decals);
}
} else if (type == "WIRE") {
WireId wire = ctx->getWireByName(value);
if (wire != WireId()) {
decals.push_back(ctx->getWireDecal(wire));
Q_EMIT selected(decals);
}
} else if (type == "PIP") {
PipId pip = ctx->getPipByName(value);
if (pip != PipId()) {
decals.push_back(ctx->getPipDecal(pip));
Q_EMIT selected(decals);
}
} else if (type == "NET") {
} else if (type == "CELL") {
}
}
}
QString DesignWidget::getElementTypeName(ElementType type)
{
if (type == ElementType::NONE)
return "";
if (type == ElementType::BEL)
return "BEL";
if (type == ElementType::WIRE)
return "WIRE";
if (type == ElementType::PIP)
return "PIP";
if (type == ElementType::NET)
return "NET";
if (type == ElementType::CELL)
return "CELL";
return "";
}
ElementType DesignWidget::getElementTypeByName(QString type)
{
if (type == "BEL")
return ElementType::BEL;
if (type == "WIRE")
return ElementType::WIRE;
if (type == "PIP")
return ElementType::PIP;
if (type == "NET")
return ElementType::NET;
if (type == "CELL")
return ElementType::CELL;
return ElementType::NONE;
}
void DesignWidget::addProperty(QtProperty *topItem, int propertyType, const QString &name, QVariant value,
const ElementType &type)
{
QtVariantProperty *item = readOnlyManager->addProperty(propertyType, name);
item->setValue(value);
item->setPropertyId(getElementTypeName(type));
topItem->addSubProperty(item);
}
QtProperty *DesignWidget::addSubGroup(QtProperty *topItem, const QString &name)
{
QtProperty *item = groupManager->addProperty(name);
topItem->addSubProperty(item);
return item;
}
void DesignWidget::onItemSelectionChanged() void DesignWidget::onItemSelectionChanged()
{ {
if (treeWidget->selectedItems().size()== 0) return; if (treeWidget->selectedItems().size() == 0)
return;
QTreeWidgetItem *clickItem = treeWidget->selectedItems().at(0); QTreeWidgetItem *clickItem = treeWidget->selectedItems().at(0);
@ -344,28 +416,14 @@ void DesignWidget::onItemSelectionChanged()
decals.push_back(ctx->getBelDecal(bel)); decals.push_back(ctx->getBelDecal(bel));
Q_EMIT selected(decals); Q_EMIT selected(decals);
QtProperty *topItem = groupManager->addProperty("Bel"); QtProperty *topItem = addTopLevelProperty("Bel");
addProperty(topItem, "Bel");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name"); addProperty(topItem, QVariant::String, "Name", c.c_str(ctx));
nameItem->setValue(c.c_str(ctx)); addProperty(topItem, QVariant::String, "Type", ctx->belTypeToId(ctx->getBelType(bel)).c_str(ctx));
topItem->addSubProperty(nameItem); addProperty(topItem, QVariant::Bool, "Available", ctx->checkBelAvail(bel));
addProperty(topItem, QVariant::String, "Bound Cell", ctx->getBoundBelCell(bel).c_str(ctx), ElementType::CELL);
QtVariantProperty *typeItem = readOnlyManager->addProperty(QVariant::String, "Type"); addProperty(topItem, QVariant::String, "Conflicting Cell", ctx->getConflictingBelCell(bel).c_str(ctx),
typeItem->setValue(ctx->belTypeToId(ctx->getBelType(bel)).c_str(ctx)); ElementType::CELL);
topItem->addSubProperty(typeItem);
QtVariantProperty *availItem = readOnlyManager->addProperty(QVariant::Bool, "Available");
availItem->setValue(ctx->checkBelAvail(bel));
topItem->addSubProperty(availItem);
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Bound Cell");
cellItem->setValue(ctx->getBoundBelCell(bel).c_str(ctx));
topItem->addSubProperty(cellItem);
QtVariantProperty *conflictItem = readOnlyManager->addProperty(QVariant::String, "Conflicting Cell");
conflictItem->setValue(ctx->getConflictingBelCell(bel).c_str(ctx));
topItem->addSubProperty(conflictItem);
} else if (type == ElementType::WIRE) { } else if (type == ElementType::WIRE) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData(); IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
@ -374,74 +432,43 @@ void DesignWidget::onItemSelectionChanged()
decals.push_back(ctx->getWireDecal(wire)); decals.push_back(ctx->getWireDecal(wire));
Q_EMIT selected(decals); Q_EMIT selected(decals);
QtProperty *topItem = groupManager->addProperty("Wire"); QtProperty *topItem = addTopLevelProperty("Wire");
addProperty(topItem, "Wire");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name"); addProperty(topItem, QVariant::String, "Name", c.c_str(ctx));
nameItem->setValue(c.c_str(ctx)); addProperty(topItem, QVariant::Bool, "Available", ctx->checkWireAvail(wire));
topItem->addSubProperty(nameItem); addProperty(topItem, QVariant::String, "Bound Net", ctx->getBoundWireNet(wire).c_str(ctx), ElementType::NET);
addProperty(topItem, QVariant::String, "Conflicting Net", ctx->getConflictingWireNet(wire).c_str(ctx),
QtVariantProperty *availItem = readOnlyManager->addProperty(QVariant::Bool, "Available"); ElementType::NET);
availItem->setValue(ctx->checkWireAvail(wire));
topItem->addSubProperty(availItem);
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Bound Net");
cellItem->setValue(ctx->getBoundWireNet(wire).c_str(ctx));
topItem->addSubProperty(cellItem);
QtVariantProperty *conflictItem = readOnlyManager->addProperty(QVariant::String, "Conflicting Net");
conflictItem->setValue(ctx->getConflictingWireNet(wire).c_str(ctx));
topItem->addSubProperty(conflictItem);
QtProperty *belpinItem = addSubGroup(topItem, "BelPin Uphill");
BelPin uphill = ctx->getBelPinUphill(wire); BelPin uphill = ctx->getBelPinUphill(wire);
QtProperty *belpinItem = groupManager->addProperty("BelPin Uphill");
topItem->addSubProperty(belpinItem);
QtVariantProperty *belUphillItem = readOnlyManager->addProperty(QVariant::String, "Bel");
if (uphill.bel != BelId()) if (uphill.bel != BelId())
belUphillItem->setValue(ctx->getBelName(uphill.bel).c_str(ctx)); addProperty(belpinItem, QVariant::String, "Bel", ctx->getBelName(uphill.bel).c_str(ctx), ElementType::BEL);
else else
belUphillItem->setValue(""); addProperty(belpinItem, QVariant::String, "Bel", "", ElementType::BEL);
belpinItem->addSubProperty(belUphillItem);
QtVariantProperty *portUphillItem = readOnlyManager->addProperty(QVariant::String, "PortPin"); addProperty(belpinItem, QVariant::String, "PortPin", ctx->portPinToId(uphill.pin).c_str(ctx), ElementType::BEL);
portUphillItem->setValue(ctx->portPinToId(uphill.pin).c_str(ctx));
belpinItem->addSubProperty(portUphillItem);
QtProperty *downhillItem = groupManager->addProperty("BelPins Downhill"); QtProperty *downhillItem = addSubGroup(topItem, "BelPin Downhill");
topItem->addSubProperty(downhillItem);
for (const auto &item : ctx->getBelPinsDownhill(wire)) { for (const auto &item : ctx->getBelPinsDownhill(wire)) {
QString belname = ""; QString belname = "";
if (item.bel != BelId()) if (item.bel != BelId())
belname = ctx->getBelName(item.bel).c_str(ctx); belname = ctx->getBelName(item.bel).c_str(ctx);
QString pinname = ctx->portPinToId(item.pin).c_str(ctx); QString pinname = ctx->portPinToId(item.pin).c_str(ctx);
QtProperty *dhItem = groupManager->addProperty(belname + "-" + pinname); QtProperty *dhItem = addSubGroup(downhillItem, belname + "-" + pinname);
downhillItem->addSubProperty(dhItem); addProperty(dhItem, QVariant::String, "Bel", belname, ElementType::BEL);
addProperty(dhItem, QVariant::String, "PortPin", pinname);
QtVariantProperty *belItem = readOnlyManager->addProperty(QVariant::String, "Bel");
belItem->setValue(belname);
dhItem->addSubProperty(belItem);
QtVariantProperty *portItem = readOnlyManager->addProperty(QVariant::String, "PortPin");
portItem->setValue(pinname);
dhItem->addSubProperty(portItem);
} }
/* /*
QtProperty *pipsDownItem = groupManager->addProperty("Pips Downhill"); QtProperty *pipsDownItem = addSubGroup(downhillItem, "Pips Downhill");
topItem->addSubProperty(pipsDownItem);
for (const auto &item : ctx->getPipsDownhill(wire)) { for (const auto &item : ctx->getPipsDownhill(wire)) {
QtVariantProperty *pipItem = readOnlyManager->addProperty(QVariant::String, ""); addProperty(pipsDownItem, QVariant::String, "", ctx->getPipName(item).c_str(ctx), ElementType::PIP);
pipItem->setValue(ctx->getPipName(item).c_str(ctx));
pipsDownItem->addSubProperty(pipItem);
} }
QtProperty *pipsUpItem = groupManager->addProperty("Pips Uphill"); QtProperty *pipsUpItem = addSubGroup(downhillItem, "Pips Uphill");
topItem->addSubProperty(pipsUpItem);
for (const auto &item : ctx->getPipsUphill(wire)) { for (const auto &item : ctx->getPipsUphill(wire)) {
QtVariantProperty *pipItem = readOnlyManager->addProperty(QVariant::String, ""); addProperty(pipsUpItem, QVariant::String, "", ctx->getPipName(item).c_str(ctx), ElementType::PIP);
pipItem->setValue(ctx->getPipName(item).c_str(ctx));
pipsUpItem->addSubProperty(pipItem);
} }
*/ */
} else if (type == ElementType::PIP) { } else if (type == ElementType::PIP) {
@ -451,199 +478,108 @@ void DesignWidget::onItemSelectionChanged()
decals.push_back(ctx->getPipDecal(pip)); decals.push_back(ctx->getPipDecal(pip));
Q_EMIT selected(decals); Q_EMIT selected(decals);
QtProperty *topItem = groupManager->addProperty("Pip"); QtProperty *topItem = addTopLevelProperty("Pip");
addProperty(topItem, "Pip");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name"); addProperty(topItem, QVariant::String, "Name", c.c_str(ctx));
nameItem->setValue(c.c_str(ctx)); addProperty(topItem, QVariant::Bool, "Available", ctx->checkPipAvail(pip));
topItem->addSubProperty(nameItem); addProperty(topItem, QVariant::String, "Bound Net", ctx->getBoundPipNet(pip).c_str(ctx), ElementType::NET);
addProperty(topItem, QVariant::String, "Conflicting Net", ctx->getConflictingPipNet(pip).c_str(ctx),
QtVariantProperty *availItem = readOnlyManager->addProperty(QVariant::Bool, "Available"); ElementType::NET);
availItem->setValue(ctx->checkPipAvail(pip)); addProperty(topItem, QVariant::String, "Src Wire", ctx->getWireName(ctx->getPipSrcWire(pip)).c_str(ctx),
topItem->addSubProperty(availItem); ElementType::WIRE);
addProperty(topItem, QVariant::String, "Dest Wire", ctx->getWireName(ctx->getPipDstWire(pip)).c_str(ctx),
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Bound Net"); ElementType::WIRE);
cellItem->setValue(ctx->getBoundPipNet(pip).c_str(ctx));
topItem->addSubProperty(cellItem);
QtVariantProperty *conflictItem = readOnlyManager->addProperty(QVariant::String, "Conflicting Net");
conflictItem->setValue(ctx->getConflictingPipNet(pip).c_str(ctx));
topItem->addSubProperty(conflictItem);
QtVariantProperty *srcWireItem = readOnlyManager->addProperty(QVariant::String, "Src Wire");
srcWireItem->setValue(ctx->getWireName(ctx->getPipSrcWire(pip)).c_str(ctx));
topItem->addSubProperty(srcWireItem);
QtVariantProperty *destWireItem = readOnlyManager->addProperty(QVariant::String, "Dest Wire");
destWireItem->setValue(ctx->getWireName(ctx->getPipDstWire(pip)).c_str(ctx));
topItem->addSubProperty(destWireItem);
DelayInfo delay = ctx->getPipDelay(pip); DelayInfo delay = ctx->getPipDelay(pip);
QtProperty *delayItem = groupManager->addProperty("Delay");
topItem->addSubProperty(delayItem);
QtVariantProperty *raiseDelayItem = readOnlyManager->addProperty(QVariant::Double, "Raise");
raiseDelayItem->setValue(delay.raiseDelay());
delayItem->addSubProperty(raiseDelayItem);
QtVariantProperty *fallDelayItem = readOnlyManager->addProperty(QVariant::Double, "Fall");
fallDelayItem->setValue(delay.fallDelay());
delayItem->addSubProperty(fallDelayItem);
QtVariantProperty *avgDelayItem = readOnlyManager->addProperty(QVariant::Double, "Average");
avgDelayItem->setValue(delay.avgDelay());
delayItem->addSubProperty(avgDelayItem);
QtProperty *delayItem = addSubGroup(topItem, "Delay");
addProperty(delayItem, QVariant::Double, "Raise", delay.raiseDelay());
addProperty(delayItem, QVariant::Double, "Fall", delay.fallDelay());
addProperty(delayItem, QVariant::Double, "Average", delay.avgDelay());
} else if (type == ElementType::NET) { } else if (type == ElementType::NET) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData(); IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
NetInfo *net = ctx->nets.at(c).get(); NetInfo *net = ctx->nets.at(c).get();
QtProperty *topItem = groupManager->addProperty("Net"); QtProperty *topItem = addTopLevelProperty("Net");
addProperty(topItem, "Net");
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name"); addProperty(topItem, QVariant::String, "Name", net->name.c_str(ctx));
nameItem->setValue(net->name.c_str(ctx));
topItem->addSubProperty(nameItem);
QtProperty *driverItem = groupManager->addProperty("Driver"); QtProperty *driverItem = addSubGroup(topItem, "Driver");
topItem->addSubProperty(driverItem); addProperty(driverItem, QVariant::String, "Port", net->driver.port.c_str(ctx));
addProperty(driverItem, QVariant::Double, "Budget", net->driver.budget);
QtVariantProperty *portItem = readOnlyManager->addProperty(QVariant::String, "Port");
portItem->setValue(net->driver.port.c_str(ctx));
driverItem->addSubProperty(portItem);
QtVariantProperty *budgetItem = readOnlyManager->addProperty(QVariant::Double, "Budget");
budgetItem->setValue(net->driver.budget);
driverItem->addSubProperty(budgetItem);
QtVariantProperty *cellNameItem = readOnlyManager->addProperty(QVariant::String, "Cell");
if (net->driver.cell) if (net->driver.cell)
cellNameItem->setValue(net->driver.cell->name.c_str(ctx)); addProperty(driverItem, QVariant::String, "Cell", net->driver.cell->name.c_str(ctx), ElementType::CELL);
else else
cellNameItem->setValue(""); addProperty(driverItem, QVariant::String, "Cell", "", ElementType::CELL);
driverItem->addSubProperty(cellNameItem);
QtProperty *usersItem = groupManager->addProperty("Users"); QtProperty *usersItem = addSubGroup(topItem, "Users");
topItem->addSubProperty(usersItem);
for (auto &item : net->users) { for (auto &item : net->users) {
QtProperty *portItem = groupManager->addProperty(item.port.c_str(ctx)); QtProperty *portItem = addSubGroup(usersItem, item.port.c_str(ctx));
usersItem->addSubProperty(portItem);
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Port"); addProperty(portItem, QVariant::String, "Port", item.port.c_str(ctx));
nameItem->setValue(item.port.c_str(ctx)); addProperty(portItem, QVariant::Double, "Budget", item.budget);
portItem->addSubProperty(nameItem);
QtVariantProperty *budgetItem = readOnlyManager->addProperty(QVariant::Double, "Budget");
budgetItem->setValue(item.budget);
portItem->addSubProperty(budgetItem);
QtVariantProperty *userItem = readOnlyManager->addProperty(QVariant::String, "Cell");
if (item.cell) if (item.cell)
userItem->setValue(item.cell->name.c_str(ctx)); addProperty(portItem, QVariant::String, "Cell", item.cell->name.c_str(ctx), ElementType::CELL);
else else
userItem->setValue(""); addProperty(portItem, QVariant::String, "Cell", "", ElementType::CELL);
portItem->addSubProperty(userItem);
} }
QtProperty *attrsItem = groupManager->addProperty("Attributes"); QtProperty *attrsItem = addSubGroup(topItem, "Attributes");
topItem->addSubProperty(attrsItem);
for (auto &item : net->attrs) { for (auto &item : net->attrs) {
QtVariantProperty *attrItem = readOnlyManager->addProperty(QVariant::String, item.first.c_str(ctx)); addProperty(attrsItem, QVariant::String, item.first.c_str(ctx), item.second.c_str());
attrItem->setValue(item.second.c_str());
attrsItem->addSubProperty(attrItem);
} }
QtProperty *wiresItem = groupManager->addProperty("Wires"); QtProperty *wiresItem = addSubGroup(topItem, "Wires");
topItem->addSubProperty(wiresItem);
for (auto &item : net->wires) { for (auto &item : net->wires) {
auto name = ctx->getWireName(item.first).c_str(ctx); auto name = ctx->getWireName(item.first).c_str(ctx);
QtProperty *wireItem = groupManager->addProperty(name); QtProperty *wireItem = addSubGroup(wiresItem, name);
addProperty(wireItem, QVariant::String, "Name", name);
QtVariantProperty *nameItem = readOnlyManager->addProperty(QVariant::String, "Name");
nameItem->setValue(name);
wireItem->addSubProperty(nameItem);
QtVariantProperty *pipItem = readOnlyManager->addProperty(QVariant::String, "Pip");
if (item.second.pip != PipId()) if (item.second.pip != PipId())
pipItem->setValue(ctx->getPipName(item.second.pip).c_str(ctx)); addProperty(wireItem, QVariant::String, "Pip", ctx->getPipName(item.second.pip).c_str(ctx),
ElementType::PIP);
else else
pipItem->setValue(""); addProperty(wireItem, QVariant::String, "Pip", "", ElementType::PIP);
wireItem->addSubProperty(pipItem);
QtVariantProperty *strengthItem = readOnlyManager->addProperty(QVariant::Int, "Strength"); addProperty(wireItem, QVariant::Int, "Strength", (int)item.second.strength);
strengthItem->setValue((int)item.second.strength);
wireItem->addSubProperty(strengthItem);
wiresItem->addSubProperty(wireItem);
} }
} else if (type == ElementType::CELL) { } else if (type == ElementType::CELL) {
IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData(); IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
CellInfo *cell = ctx->cells.at(c).get(); CellInfo *cell = ctx->cells.at(c).get();
QtProperty *topItem = groupManager->addProperty("Cell"); QtProperty *topItem = addTopLevelProperty("Cell");
addProperty(topItem, "Cell");
QtVariantProperty *cellNameItem = readOnlyManager->addProperty(QVariant::String, "Name"); addProperty(topItem, QVariant::String, "Name", cell->name.c_str(ctx));
cellNameItem->setValue(cell->name.c_str(ctx)); addProperty(topItem, QVariant::String, "Type", cell->type.c_str(ctx));
topItem->addSubProperty(cellNameItem);
QtVariantProperty *cellTypeItem = readOnlyManager->addProperty(QVariant::String, "Type");
cellTypeItem->setValue(cell->type.c_str(ctx));
topItem->addSubProperty(cellTypeItem);
QtVariantProperty *cellBelItem = readOnlyManager->addProperty(QVariant::String, "Bel");
if (cell->bel != BelId()) if (cell->bel != BelId())
cellBelItem->setValue(ctx->getBelName(cell->bel).c_str(ctx)); addProperty(topItem, QVariant::String, "Bel", ctx->getBelName(cell->bel).c_str(ctx), ElementType::BEL);
else else
cellBelItem->setValue(""); addProperty(topItem, QVariant::String, "Bel", "", ElementType::BEL);
topItem->addSubProperty(cellBelItem); addProperty(topItem, QVariant::Int, "Bel strength", int(cell->belStrength));
QtVariantProperty *cellBelStrItem = readOnlyManager->addProperty(QVariant::Int, "Bel strength"); QtProperty *cellPortsItem = addSubGroup(topItem, "Ports");
cellBelStrItem->setValue(int(cell->belStrength));
topItem->addSubProperty(cellBelStrItem);
QtProperty *cellPortsItem = groupManager->addProperty("Ports");
topItem->addSubProperty(cellPortsItem);
for (auto &item : cell->ports) { for (auto &item : cell->ports) {
PortInfo p = item.second; PortInfo p = item.second;
QtProperty *portInfoItem = groupManager->addProperty(p.name.c_str(ctx)); QtProperty *portInfoItem = addSubGroup(cellPortsItem, p.name.c_str(ctx));
addProperty(portInfoItem, QVariant::String, "Name", p.name.c_str(ctx));
QtVariantProperty *portInfoNameItem = readOnlyManager->addProperty(QVariant::String, "Name"); addProperty(portInfoItem, QVariant::Int, "Type", int(p.type));
portInfoNameItem->setValue(p.name.c_str(ctx));
portInfoItem->addSubProperty(portInfoNameItem);
QtVariantProperty *portInfoTypeItem = readOnlyManager->addProperty(QVariant::Int, "Type");
portInfoTypeItem->setValue(int(p.type));
portInfoItem->addSubProperty(portInfoTypeItem);
QtVariantProperty *portInfoNetItem = readOnlyManager->addProperty(QVariant::String, "Net");
if (p.net) if (p.net)
portInfoNetItem->setValue(p.net->name.c_str(ctx)); addProperty(portInfoItem, QVariant::String, "Net", p.net->name.c_str(ctx), ElementType::NET);
else else
portInfoNetItem->setValue(""); addProperty(portInfoItem, QVariant::String, "Net", "", ElementType::NET);
portInfoItem->addSubProperty(portInfoNetItem);
cellPortsItem->addSubProperty(portInfoItem);
} }
QtProperty *cellAttrItem = groupManager->addProperty("Attributes"); QtProperty *cellAttrItem = addSubGroup(topItem, "Attributes");
topItem->addSubProperty(cellAttrItem);
for (auto &item : cell->attrs) { for (auto &item : cell->attrs) {
QtVariantProperty *attrItem = readOnlyManager->addProperty(QVariant::String, item.first.c_str(ctx)); addProperty(cellAttrItem, QVariant::String, item.first.c_str(ctx), item.second.c_str());
attrItem->setValue(item.second.c_str());
cellAttrItem->addSubProperty(attrItem);
} }
QtProperty *cellParamsItem = groupManager->addProperty("Parameters"); QtProperty *cellParamsItem = addSubGroup(topItem, "Parameters");
topItem->addSubProperty(cellParamsItem);
for (auto &item : cell->params) { for (auto &item : cell->params) {
QtVariantProperty *paramItem = readOnlyManager->addProperty(QVariant::String, item.first.c_str(ctx)); addProperty(cellParamsItem, QVariant::String, item.first.c_str(ctx), item.second.c_str());
paramItem->setValue(item.second.c_str());
cellParamsItem->addSubProperty(paramItem);
} }
QtProperty *cellPinsItem = groupManager->addProperty("Pins"); QtProperty *cellPinsItem = groupManager->addProperty("Pins");
@ -652,17 +588,10 @@ void DesignWidget::onItemSelectionChanged()
std::string cell_port = item.first.c_str(ctx); std::string cell_port = item.first.c_str(ctx);
std::string bel_pin = item.second.c_str(ctx); std::string bel_pin = item.second.c_str(ctx);
QtProperty *pinGroupItem = groupManager->addProperty((cell_port + " -> " + bel_pin).c_str()); QtProperty *pinGroupItem = addSubGroup(cellPortsItem, (cell_port + " -> " + bel_pin).c_str());
QtVariantProperty *cellItem = readOnlyManager->addProperty(QVariant::String, "Cell"); addProperty(pinGroupItem, QVariant::String, "Cell", cell_port.c_str(), ElementType::CELL);
cellItem->setValue(cell_port.c_str()); addProperty(pinGroupItem, QVariant::String, "Bel", bel_pin.c_str(), ElementType::BEL);
pinGroupItem->addSubProperty(cellItem);
QtVariantProperty *belItem = readOnlyManager->addProperty(QVariant::String, "Bel");
belItem->setValue(bel_pin.c_str());
pinGroupItem->addSubProperty(belItem);
cellPinsItem->addSubProperty(pinGroupItem);
} }
} }
} }

View File

@ -21,6 +21,7 @@
#define DESIGNWIDGET_H #define DESIGNWIDGET_H
#include <QTreeWidget> #include <QTreeWidget>
#include <QVariant>
#include "nextpnr.h" #include "nextpnr.h"
#include "qtgroupboxpropertybrowser.h" #include "qtgroupboxpropertybrowser.h"
#include "qtpropertymanager.h" #include "qtpropertymanager.h"
@ -29,6 +30,16 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
enum class ElementType
{
NONE,
BEL,
WIRE,
PIP,
NET,
CELL
};
class DesignWidget : public QWidget class DesignWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -38,9 +49,13 @@ class DesignWidget : public QWidget
~DesignWidget(); ~DesignWidget();
private: private:
void addProperty(QtProperty *property, const QString &id);
void clearProperties(); void clearProperties();
QtProperty *addTopLevelProperty(const QString &id);
QtProperty *addSubGroup(QtProperty *topItem, const QString &name);
void addProperty(QtProperty *topItem, int propertyType, const QString &name, QVariant value,
const ElementType &type = ElementType::NONE);
QString getElementTypeName(ElementType type);
ElementType getElementTypeByName(QString type);
Q_SIGNALS: Q_SIGNALS:
void info(std::string text); void info(std::string text);
void selected(std::vector<DecalXY> decal); void selected(std::vector<DecalXY> decal);
@ -49,6 +64,7 @@ class DesignWidget : public QWidget
void prepareMenu(const QPoint &pos); void prepareMenu(const QPoint &pos);
void onItemSelectionChanged(); void onItemSelectionChanged();
void selectObject(); void selectObject();
void onCurrentPropertyChanged(QtBrowserItem *_item);
public Q_SLOTS: public Q_SLOTS:
void newContext(Context *ctx); void newContext(Context *ctx);
void updateTree(); void updateTree();