Skip to content

Commit

Permalink
Relocated the code for loading the default symbol
Browse files Browse the repository at this point in the history
The code for reloading the default symbol was moved to SymbolWidget
class.
  • Loading branch information
andresmmera committed Aug 17, 2016
1 parent e935f0e commit 2c08997
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
28 changes: 2 additions & 26 deletions qucs/qucs-lib/qucslib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions qucs/qucs-lib/symbolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions qucs/qucs-lib/symbolwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QList>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QMessageBox>

#include "element.h"

Expand Down

0 comments on commit 2c08997

Please sign in to comment.