Skip to content

Commit

Permalink
Put relative path for libcomps except user libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3xdh committed Sep 2, 2024
1 parent a5f4223 commit 0ef0b06
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions qucs/qucs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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<QTreeWidgetItem *> &topitems)
bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems, bool relpath)
{
QDir LibDir(LibDirPath);
QStringList LibFiles = LibDir.entryList(QStringList("*.lib"), QDir::Files, QDir::Name);
Expand All @@ -643,7 +643,7 @@ bool QucsApp::populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidge

ComponentLibrary parsedlibrary;

int result = parseComponentLibrary (libPath , parsedlibrary);
int result = parseComponentLibrary (libPath , parsedlibrary, QUCS_COMP_LIB_FULL, relpath);
QStringList nameAndFileName;
nameAndFileName.append (parsedlibrary.name);
nameAndFileName.append (LibDirPath + *it);
Expand Down
2 changes: 1 addition & 1 deletion qucs/qucs.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private slots:
void updateRecentFilesList(QString s);
void successExportMessages(bool ok);
void fillLibrariesTreeView (void);
bool populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems);
bool populateLibTreeFromDir(const QString &LibDirPath, QList<QTreeWidgetItem *> &topitems, bool relpath = false);
void saveSettings();
QWidget *getSchematicWidget(QucsDoc *Doc);

Expand Down
16 changes: 12 additions & 4 deletions qucs/qucslib_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0ef0b06

Please sign in to comment.