void UnplacedComponentsDock::on_cbxSelectedComponent_currentIndexChanged(int index)
{
    QUuid componentUuid = mUi->cbxSelectedComponent->itemData(index, Qt::UserRole).toUuid();
    FilePath cmpFp = mProjectEditor.getWorkspace().getLibrary().getLatestComponent(componentUuid);
    if (cmpFp.isValid())
    {
        const library::Component* component = new library::Component(cmpFp);
        setSelectedComponent(component);
    }
    else
    {
        setSelectedComponent(nullptr);
    }
}
void UnplacedComponentsDock::setSelectedGenCompInstance(GenCompInstance* genComp) noexcept
{
    setSelectedComponent(nullptr);
    mUi->cbxSelectedComponent->clear();
    mSelectedGenComp = genComp;

    if (mBoard && mSelectedGenComp)
    {
        QStringList localeOrder = mProject.getSettings().getLocaleOrder();
        QSet<QUuid> components = mProjectEditor.getWorkspace().getLibrary().getComponentsOfGenericComponent(mSelectedGenComp->getGenComp().getUuid());
        foreach (const QUuid& compUuid, components)
        {
            // TODO: use library metadata instead of loading the XML files
            FilePath cmpFp = mProjectEditor.getWorkspace().getLibrary().getLatestComponent(compUuid);
            if (!cmpFp.isValid()) continue;
            const library::Component component(cmpFp);

            QUuid pkgUuid;
            mProjectEditor.getWorkspace().getLibrary().getComponentMetadata(cmpFp, &pkgUuid);
            FilePath pkgFp = mProjectEditor.getWorkspace().getLibrary().getLatestPackage(pkgUuid);
            const library::Package package(pkgFp);

            QString cmpName = component.getName(localeOrder);
            QString pkgName = package.getName(localeOrder);
            QString text = QString("%1 [%2]").arg(cmpName, pkgName);
            mUi->cbxSelectedComponent->addItem(text, compUuid);
        }
void PropertyPanel::setSelectedPort( ModulePort *port )
{
	if( this->port == port ) return;

//	if( this->port ) writePortProperties( false ); // rereading not necessary here

	this->port = port;
	if(port)
	{
		setSelectedComponent( port->owner );
		rereadPortProperties();
		portValueGroup->setEnabled( true );
		QString tipText = i18n("Tip: Just typing numbers or alphabetic characters starts entering constant values.");
		tipLabel->setText( tipText );
		tipLabel->show();

		// select port in combobox - bah, should be easier ;-)
		portCombo->setCurrentItem(
			portCombo->listBox()->index(
				portCombo->listBox()->findItem( port->description + " (" ) ) );
	}
	else
	{
		portValueGroup->setEnabled( false );
		tipLabel->hide();
	}
}
Esempio n. 4
0
void AddComponentDialog::searchComponents(const QString& input) {
  setSelectedComponent(nullptr);
  mUi->treeComponents->clear();

  // min. 2 chars to avoid freeze on entering first character due to huge result
  if (input.length() > 1) {
    SearchResult result = searchComponentsAndDevices(input);
    QHashIterator<FilePath, SearchResultComponent> cmpIt(result);
    while (cmpIt.hasNext()) {
      cmpIt.next();
      QTreeWidgetItem* cmpItem = new QTreeWidgetItem(mUi->treeComponents);
      cmpItem->setText(0, cmpIt.value().name);
      cmpItem->setData(0, Qt::UserRole, cmpIt.key().toStr());
      QHashIterator<FilePath, SearchResultDevice> devIt(cmpIt.value().devices);
      while (devIt.hasNext()) {
        devIt.next();
        QTreeWidgetItem* devItem = new QTreeWidgetItem(cmpItem);
        devItem->setText(0, devIt.value().name);
        devItem->setData(0, Qt::UserRole, devIt.key().toStr());
        devItem->setText(1, devIt.value().pkgName);
        devItem->setTextAlignment(1, Qt::AlignRight);
      }
      cmpItem->setText(1, QString("[%1]").arg(cmpIt.value().devices.count()));
      cmpItem->setTextAlignment(1, Qt::AlignRight);
      cmpItem->setExpanded(!cmpIt.value().match);
    }
  }

  mUi->treeComponents->sortByColumn(0, Qt::AscendingOrder);
}