From 0ef0b067d704f9931df1ea38046191a39e3f6635 Mon Sep 17 00:00:00 2001 From: Vadim Kuznetsov Date: Mon, 2 Sep 2024 16:53:24 +0300 Subject: [PATCH] Put relative path for libcomps except user libraries --- qucs/qucs.cpp | 8 ++++---- qucs/qucs.h | 2 +- qucs/qucslib_common.h | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/qucs/qucs.cpp b/qucs/qucs.cpp index bba0186e1..e39dfe846 100644 --- a/qucs/qucs.cpp +++ b/qucs/qucs.cpp @@ -603,7 +603,7 @@ void QucsApp::fillLibrariesTreeView () // newitem->setBackground topitems.append (newitem); - populateLibTreeFromDir(QucsSettings.LibDir, topitems); + populateLibTreeFromDir(QucsSettings.LibDir, topitems, true); // make the user libraries section header newitem = new QTreeWidgetItem((QTreeWidget*)0, QStringList("User Libraries")); @@ -620,14 +620,14 @@ void QucsApp::fillLibrariesTreeView () newitem->setFont (0, sectionFont); topitems.append (newitem); if (!ProjName.isEmpty()) { - populateLibTreeFromDir(QucsSettings.QucsWorkDir.absolutePath(), topitems); + populateLibTreeFromDir(QucsSettings.QucsWorkDir.absolutePath(), topitems, true); } libTreeWidget->insertTopLevelItems(0, topitems); } -bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList &topitems) +bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList &topitems, bool relpath) { QDir LibDir(LibDirPath); QStringList LibFiles = LibDir.entryList(QStringList("*.lib"), QDir::Files, QDir::Name); @@ -643,7 +643,7 @@ bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList &topitems); + bool populateLibTreeFromDir(const QString &LibDirPath, QList &topitems, bool relpath = false); void saveSettings(); QWidget *getSchematicWidget(QucsDoc *Doc); diff --git a/qucs/qucslib_common.h b/qucs/qucslib_common.h index 2852c4c70..e8f3ae051 100644 --- a/qucs/qucslib_common.h +++ b/qucs/qucslib_common.h @@ -219,11 +219,14 @@ inline int makeModelString (QString libPath, QString compname, QString compstrin } -inline int parseQucsComponentLibrary (QString libPath, ComponentLibrary &library, LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL) +inline int parseQucsComponentLibrary (QString libPath, ComponentLibrary &library, + LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL, bool relpath = false) { int Start, End, NameStart, NameEnd; QString filename = getLibAbsPath(libPath); + QFileInfo inf(filename); + QString relName = inf.baseName(); QFile file (filename); @@ -309,7 +312,11 @@ inline int parseQucsComponentLibrary (QString libPath, ComponentLibrary &library component.definition = LibraryString.mid(Start, End-Start); // construct model string - int result = makeModelString (libPath, component.name, component.definition, component.modelString, library.defaultSymbol); + QString libName = libPath; + if (relpath) { + libName = relName; + } + int result = makeModelString (libName, component.name, component.definition, component.modelString, library.defaultSymbol); if (result != QUCS_COMP_LIB_OK) return result; library.components.append (component); @@ -486,9 +493,10 @@ inline int parseSPICEComponentLibrary (QString libPath, ComponentLibrary &librar return QUCS_COMP_LIB_OK; } -inline int parseComponentLibrary (QString filename, ComponentLibrary &library, LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL) +inline int parseComponentLibrary (QString filename, ComponentLibrary &library, + LIB_PARSE_WHAT what = QUCS_COMP_LIB_FULL, bool relpath = false) { - int r = parseQucsComponentLibrary(filename,library,what); + int r = parseQucsComponentLibrary(filename,library,what,relpath); if (r!=QUCS_COMP_LIB_OK) { r = parseSPICEComponentLibrary(filename,library); }