diff --git a/libs/librepcb/projecteditor/schematiceditor/fsm/ses_select.cpp b/libs/librepcb/projecteditor/schematiceditor/fsm/ses_select.cpp index 8278309a67..8ae8ebe5b1 100644 --- a/libs/librepcb/projecteditor/schematiceditor/fsm/ses_select.cpp +++ b/libs/librepcb/projecteditor/schematiceditor/fsm/ses_select.cpp @@ -459,8 +459,9 @@ bool SES_Select::removeSelectedItems() noexcept { } void SES_Select::openSymbolPropertiesDialog(SI_Symbol& symbol) noexcept { - SymbolInstancePropertiesDialog dialog(mProject, symbol.getComponentInstance(), - symbol, mUndoStack, &mEditor); + SymbolInstancePropertiesDialog dialog(mWorkspace, mProject, + symbol.getComponentInstance(), symbol, + mUndoStack, &mEditor); dialog.exec(); } diff --git a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp index 44e973c25e..8bc8a3287f 100644 --- a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp +++ b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,8 @@ #include #include #include +#include +#include #include #include @@ -52,9 +55,10 @@ namespace editor { ******************************************************************************/ SymbolInstancePropertiesDialog::SymbolInstancePropertiesDialog( - Project& project, ComponentInstance& cmp, SI_Symbol& symbol, - UndoStack& undoStack, QWidget* parent) noexcept + workspace::Workspace& ws, Project& project, ComponentInstance& cmp, + SI_Symbol& symbol, UndoStack& undoStack, QWidget* parent) noexcept : QDialog(parent), + mWorkspace(ws), mProject(project), mComponentInstance(cmp), mSymbol(symbol), @@ -74,13 +78,19 @@ SymbolInstancePropertiesDialog::SymbolInstancePropertiesDialog( // Component Library Element Attributes QString htmlLink("%2"); - mUi->lblCompLibName->setText(htmlLink.arg( - mComponentInstance.getLibComponent() - .getDirectory() - .getAbsPath() - .toQUrl() - .toString(), - *mComponentInstance.getLibComponent().getNames().value(localeOrder))); + mUi->lblCompLibName->setText( + htmlLink.arg( + mComponentInstance.getLibComponent() + .getDirectory() + .getAbsPath() + .toQUrl() + .toString(), + *mComponentInstance.getLibComponent().getNames().value(localeOrder)) + + " (" + + QString(tr("symbol variant \"%1\"")) + .arg(*mComponentInstance.getSymbolVariant().getNames().value( + localeOrder)) + + ")"); mUi->lblCompLibName->setToolTip( mComponentInstance.getLibComponent().getDescriptions().value( localeOrder) + @@ -89,11 +99,6 @@ SymbolInstancePropertiesDialog::SymbolInstancePropertiesDialog( .getDirectory() .getAbsPath() .toNative()); - mUi->lblSymbVarName->setText( - *mComponentInstance.getSymbolVariant().getNames().value(localeOrder)); - mUi->lblSymbVarName->setToolTip( - mComponentInstance.getSymbolVariant().getDescriptions().value( - localeOrder)); // Symbol Instance Attributes mUi->lblSymbInstName->setText(mSymbol.getName()); @@ -110,6 +115,41 @@ SymbolInstancePropertiesDialog::SymbolInstancePropertiesDialog( mSymbol.getLibSymbol().getDescriptions().value(localeOrder) + "

" + mSymbol.getLibSymbol().getDirectory().getAbsPath().toNative()); + // List Devices + try { + tl::optional device = mComponentInstance.getDefaultDeviceUuid(); + QSet deviceUuids = mWorkspace.getLibraryDb().getDevicesOfComponent( + mComponentInstance.getLibComponent().getUuid()); // can throw + foreach (const Uuid& deviceUuid, deviceUuids) { + FilePath devFp = + mWorkspace.getLibraryDb().getLatestDevice(deviceUuid); // can throw + if (devFp.isValid()) { + QString devName; + mWorkspace.getLibraryDb().getElementTranslations( + devFp, localeOrder, &devName); // can throw + mUi->cbxPreselectedDevice->addItem(devName, deviceUuid.toStr()); + } + } + mUi->cbxPreselectedDevice->model()->sort(0, Qt::AscendingOrder); + mUi->cbxPreselectedDevice->insertItem(0, ""); + int index = 0; + if (device) { + index = mUi->cbxPreselectedDevice->findData(device->toStr()); + if (index < 0) { + // Selected device not found in workspace libraries, show UUID instead. + mUi->cbxPreselectedDevice->insertItem(1, device->toStr(), + device->toStr()); + index = 1; + } + } + mUi->cbxPreselectedDevice->setCurrentIndex(index); + mUi->cbxPreselectedDevice->setEnabled(mUi->cbxPreselectedDevice->count() > + 1); + } catch (const Exception& e) { + qCritical() << "Could not list devices:" << e.getMsg(); + mUi->cbxPreselectedDevice->setEnabled(false); + } + // set focus to component instance name mUi->edtCompInstName->selectAll(); mUi->edtCompInstName->setFocus(); @@ -157,6 +197,10 @@ bool SymbolInstancePropertiesDialog::applyChanges() noexcept { mUi->edtCompInstName->text().trimmed())); // can throw cmdCmp->setValue(mUi->edtCompInstValue->toPlainText()); cmdCmp->setAttributes(mAttributes); + if (mUi->cbxPreselectedDevice->isEnabled()) { + cmdCmp->setDefaultDeviceUuid(Uuid::tryFromString( + mUi->cbxPreselectedDevice->currentData().toString())); + } transaction.append(cmdCmp.take()); // Symbol Instance diff --git a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.h b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.h index dffc07258c..1a3e2b1e2b 100644 --- a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.h +++ b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.h @@ -36,6 +36,10 @@ namespace librepcb { class UndoStack; class UndoCommand; +namespace workspace { +class Workspace; +} + namespace project { class Project; @@ -63,9 +67,10 @@ class SymbolInstancePropertiesDialog final : public QDialog { SymbolInstancePropertiesDialog() = delete; SymbolInstancePropertiesDialog(const SymbolInstancePropertiesDialog& other) = delete; - SymbolInstancePropertiesDialog(Project& project, ComponentInstance& cmp, - SI_Symbol& symbol, UndoStack& undoStack, - QWidget* parent) noexcept; + SymbolInstancePropertiesDialog(workspace::Workspace& ws, Project& project, + ComponentInstance& cmp, SI_Symbol& symbol, + UndoStack& undoStack, + QWidget* parent) noexcept; ~SymbolInstancePropertiesDialog() noexcept; // Operator Overloadings @@ -78,6 +83,7 @@ class SymbolInstancePropertiesDialog final : public QDialog { bool applyChanges() noexcept; private: // Data + workspace::Workspace& mWorkspace; Project& mProject; ComponentInstance& mComponentInstance; SI_Symbol& mSymbol; diff --git a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui index 8769e36668..44939dff6e 100644 --- a/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui +++ b/libs/librepcb/projecteditor/schematiceditor/symbolinstancepropertiesdialog.ui @@ -99,6 +99,32 @@ + + + Boards + + + + + + Pre-selected device: + + + + + + + + + + 20 + + + + + + + @@ -146,41 +172,6 @@ - - - - 0 - 0 - - - - Symbol Variant: - - - - - - - - 0 - 0 - - - - TextLabel - - - Qt::RichText - - - true - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse - - - - @@ -193,7 +184,7 @@ - +