From 2c0899799bf782d5446dced5c06fd5bb147e4ef1 Mon Sep 17 00:00:00 2001 From: andresmmera Date: Wed, 17 Aug 2016 11:00:58 +0200 Subject: [PATCH] Relocated the code for loading the default symbol The code for reloading the default symbol was moved to SymbolWidget class. --- qucs/qucs-lib/qucslib.cpp | 28 ++-------------------------- qucs/qucs-lib/symbolwidget.cpp | 23 +++++++++++++++++++++++ qucs/qucs-lib/symbolwidget.h | 1 + 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/qucs/qucs-lib/qucslib.cpp b/qucs/qucs-lib/qucslib.cpp index 376d852357..f254560f15 100644 --- a/qucs/qucs-lib/qucslib.cpp +++ b/qucs/qucs-lib/qucslib.cpp @@ -511,34 +511,10 @@ void QucsLib::slotShowComponent(QListWidgetItem *Item) return; } - if(!content.isEmpty()) - Symbol->setSymbol(content, LibName, Item->text()); - else - { - //Load the default symbol for the current Qucs library - ComponentLibrary parsedlib; - QString libpath = QucsSettings.LibDir + LibName + ".lib"; - int result = parseComponentLibrary (libpath, parsedlib); - - switch (result)//Check if the library was properly loaded - { - case QUCS_COMP_LIB_IO_ERROR: - QMessageBox::critical(0, tr ("Error"), tr("Cannot open \"%1\".").arg (libpath)); - return; - case QUCS_COMP_LIB_CORRUPT: - QMessageBox::critical(0, tr("Error"), tr("Library is corrupt.")); - return; - default: - break; - } - - // copy the contents of default symbol section to a string - DefaultSymbol = parsedlib.defaultSymbol; - if(!DefaultSymbol.isEmpty()) // has library a default symbol ? - Symbol->setSymbol(DefaultSymbol, LibName, Item->text()); - } + Symbol->setSymbol(content, LibName, Item->text()); + // change currently selected category, so the user will // learn where the component comes from Library->setCurrentIndex(i); diff --git a/qucs/qucs-lib/symbolwidget.cpp b/qucs/qucs-lib/symbolwidget.cpp index 5cffd42522..4e842c1e4a 100644 --- a/qucs/qucs-lib/symbolwidget.cpp +++ b/qucs/qucs-lib/symbolwidget.cpp @@ -360,6 +360,29 @@ int SymbolWidget::createSymbol(const QString& Lib_, const QString& Comp_) int SymbolWidget::setSymbol( QString& SymbolString, const QString& Lib_, const QString& Comp_) { + if (SymbolString.isEmpty())//Whenever SymbolString is empty, it tries to load the default symbol + { + //Load the default symbol for the current Qucs library + ComponentLibrary parsedlib; + QString libpath = QucsSettings.LibDir + Lib_ + ".lib"; + int result = parseComponentLibrary (libpath, parsedlib); + + switch (result)//Check if the library was properly loaded + { + case QUCS_COMP_LIB_IO_ERROR: + QMessageBox::critical(0, tr ("Error"), tr("Cannot open \"%1\".").arg (libpath)); + return -1; + case QUCS_COMP_LIB_CORRUPT: + QMessageBox::critical(0, tr("Error"), tr("Library is corrupt.")); + return -1; + default: + break; + } + + // copy the contents of default symbol section to a string + SymbolString = parsedlib.defaultSymbol; + } + Arcs.clear(); Lines.clear(); Rects.clear(); diff --git a/qucs/qucs-lib/symbolwidget.h b/qucs/qucs-lib/symbolwidget.h index 5f20efa834..f1479c0cf5 100644 --- a/qucs/qucs-lib/symbolwidget.h +++ b/qucs/qucs-lib/symbolwidget.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "element.h"