Skip to content

Commit

Permalink
Refactor/improve utils methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinffernandez committed Aug 27, 2024
1 parent 24dce96 commit 36b2c46
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 204 deletions.
282 changes: 81 additions & 201 deletions src/gui/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,90 +19,27 @@

#include "utils.h"

QString Utils::appCommand(AppCmds c)
QString Utils::appCommand(AppCmds cmd)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
QString cmd;
switch (c) {
case CMD_COMPILE:
cmd = settings.value("Commands/comp", "Value not found in file qss-solver.ini").toString();
break;
case CMD_BUILD:
cmd = settings.value("Commands/build", "Value not found in file qss-solver.ini").toString();
break;
case CMD_SIMULATE:
cmd = settings.value("Commands/simulate", "Value not found in file qss-solver.ini").toString();
break;
case CMD_PLOT:
cmd = settings.value("Commands/plot", "Value not found in file qss-solver.ini").toString();
break;
case CMD_SBML:
cmd = settings.value("Commands/sbml", "Value not found in file qss-solver.ini").toString();
break;
case CMD_LOG:
cmd = settings.value("Commands/log", "Value not found in file qss-solver.ini").toString();
break;
default:
return QString();
}
return cmd;
return settings.value(appCommandsName(cmd), "Value not found in file qss-solver.ini").toString();
}

QString Utils::appDir(AppDirs d)
{
QDir dir(QCoreApplication::applicationDirPath());
dir.cd(_getDir(d));
dir.cd(getDir(d));
return dir.absolutePath();
}

bool Utils::isSet(AppFlags f)
bool Utils::isSet(AppFlags flag)
{
QString _val;
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
switch (f) {
case FLG_FLAGS:
_val = settings.value("Flags/flags", "Value not found in file qss-solver.ini").toString();
break;
case FLG_DEBUG:
_val = settings.value("Flags/dbgflags", "Value not found in file qss-solver.ini").toString();
break;
case FLG_DBG_ALL:
_val = settings.value("Flags/dbgAll", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_INIT_VALUES:
_val = settings.value("Flags/dbgInitValues", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_EXTERNAL_EVENT:
_val = settings.value("Flags/dbgExternalEvent", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_MEMORY:
_val = settings.value("Flags/dbgMemory", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_SYNCHRONIZE:
_val = settings.value("Flags/dbgSynchronize", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_STEP_INFO:
_val = settings.value("Flags/dbgStepInfo", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_VAR_CHANGES:
_val = settings.value("Flags/dbgVarChanges", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_WAIT_FOR:
_val = settings.value("Flags/dbgWaitFor", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_WEIGHTS:
_val = settings.value("Flags/dbgWeights", "Value not found in file qss-solver.ini").toString();
return _val == "true";
case FLG_DBG_DT:
_val = settings.value("Flags/dbgDt", "Value not found in file qss-solver.ini").toString();
return _val == "true";
default:
return _val.isEmpty();
}
return _val.isEmpty();
QString val = settings.value(appFlagName(flag), "Value not found in file qss-solver.ini").toString();
return val.isEmpty();
}

QString Utils::_getDebugValue()
QString Utils::getDebugValue()
{
QString dbg;
if (isSet(FLG_DBG_ALL)) {
Expand Down Expand Up @@ -138,212 +75,155 @@ QString Utils::_getDebugValue()
return dbg;
}

QString Utils::appFlag(AppFlags f)
QString Utils::appFlag(AppFlags flag)
{
QString val;
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
if (flag == FLG_DEBUG) {
val = getDebugValue();
} else {
val = settings.value(appFlagName(flag), "Value not found in file qss-solver.ini").toString();
}
return val;
}

QString Utils::relativePath(AppDirs d) { return getDir(d); }

QString Utils::getDir(AppDirs dir)
{
QString _val;
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
switch (f) {
QString path = settings.value(appDirsName(dir), "Value not found in file qss-solver.ini").toString();
return path;
}

void Utils::setCommand(AppCmds cmd, QString value)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
settings.setValue(appCommandsName(cmd), value);
}

QString Utils::appFlagName(AppFlags flag)
{
QString flag_name("Flags/");
switch (flag) {
case FLG_FLAGS:
_val = settings.value("Flags/flags", "Value not found in file qss-solver.ini").toString();
break;
case FLG_DEBUG:
_val = _getDebugValue();
flag_name.append("flags");
break;
case FLG_DBG_ALL:
_val = settings.value("Flags/dbgAll", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgAll");
break;
case FLG_DBG_INIT_VALUES:
_val = settings.value("Flags/dbgInitValues", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgInitValues");
break;
case FLG_DBG_EXTERNAL_EVENT:
_val = settings.value("Flags/dbgExternalEvent", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgExternalEvent");
break;
case FLG_DBG_MEMORY:
_val = settings.value("Flags/dbgMemory", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgMemory");
break;
case FLG_DBG_SYNCHRONIZE:
_val = settings.value("Flags/dbgSynchronize", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgSynchronize");
break;
case FLG_DBG_STEP_INFO:
_val = settings.value("Flags/dbgStepInfo", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgStepInfo");
break;
case FLG_DBG_VAR_CHANGES:
_val = settings.value("Flags/dbgVarChanges", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgVarChanges");
break;
case FLG_DBG_WAIT_FOR:
_val = settings.value("Flags/dbgWaitFor", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgWaitFor");
break;
case FLG_DBG_WEIGHTS:
_val = settings.value("Flags/dbgWeights", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgWeights");
break;
case FLG_DBG_DT:
_val = settings.value("Flags/dbgDt", "Value not found in file qss-solver.ini").toString();
flag_name.append("dbgDt");
break;
case FLG_PLOT:
_val = settings.value("Flags/plotflags", "Value not found in file qss-solver.ini").toString();
break;
case FLG_VERSION:
_val = settings.value("Flags/version", "Value not found in file qss-solver.ini").toString();
break;
case FLG_BRANCH:
_val = settings.value("Flags/branch", "Value not found in file qss-solver.ini").toString();
flag_name.append("plotflags");
break;
default:
break;
}
return _val;
return flag_name;
}

QString Utils::relativePath(AppDirs d) { return _getDir(d); }

QString Utils::_getDir(AppDirs d)
QString Utils::appCommandsName(AppCmds cmd)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
QString path;
switch (d) {
case MMOC_SOURCE:
path = settings.value("src", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_MODELS:
path = settings.value("models", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_OUTPUT:
path = settings.value("output", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_BUILD:
path = settings.value("build", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_ENGINE:
path = settings.value("engine", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_LIBS:
path = settings.value("libs", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_BIN:
path = settings.value("bin", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_PACKAGES:
path = settings.value("packages", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_LIBRARIES:
path = settings.value("libraries", "Value not found in file qss-solver.ini").toString();
break;
case MMOC_INCLUDE:
path = settings.value("include", "Value not found in file qss-solver.ini").toString();
break;
default:
return QString();
}
return path;
}

void Utils::setCommand(AppCmds c, QString value)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
switch (c) {
QString command_name("Commands/");
switch (cmd) {
case CMD_COMPILE:
settings.setValue("Commands/comp", value);
command_name.append("comp");
break;
case CMD_BUILD:
settings.setValue("Commands/build", value);
command_name.append("build");
break;
case CMD_SIMULATE:
settings.setValue("Commands/simulate", value);
command_name.append("simulate");
break;
case CMD_PLOT:
settings.setValue("Commands/plot", value);
command_name.append("plot");
break;
case CMD_SBML:
settings.setValue("Commands/sbml", value);
command_name.append("sbml");
break;
case CMD_LOG:
settings.setValue("Commands/log", value);
command_name.append("log");
break;
default:
break;
}
return command_name;
}

void Utils::setDir(AppDirs d, QString value)
QString Utils::appDirsName(AppDirs dir)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
switch (d) {
QString dir_name;
switch (dir) {
case MMOC_SOURCE:
settings.setValue("src", value);
dir_name = "src";
break;
case MMOC_MODELS:
settings.setValue("models", value);
dir_name = "models";
break;
case MMOC_OUTPUT:
settings.setValue("output", value);
dir_name = "output";
break;
case MMOC_BUILD:
settings.setValue("build", value);
dir_name = "build";
break;
case MMOC_ENGINE:
settings.setValue("engine", value);
dir_name = "engine";
break;
case MMOC_LIBS:
settings.setValue("libs", value);
dir_name = "libs";
break;
case MMOC_BIN:
settings.setValue("bin", value);
dir_name = "bin";
break;
case MMOC_PACKAGES:
settings.setValue("packages", value);
dir_name = "packages";
break;
case MMOC_LIBRARIES:
settings.setValue("libraries", value);
dir_name = "libraries";
break;
case MMOC_INCLUDE:
settings.setValue("include", value);
dir_name = "include";
break;
default:
break;
}
return dir_name;
}

void Utils::setFlag(AppFlags f, QString value)
void Utils::setDir(AppDirs dir, QString value)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
switch (f) {
case FLG_FLAGS:
settings.setValue("Flags/flags", value);
break;
case FLG_DBG_ALL:
settings.setValue("Flags/dbgAll", value);
break;
case FLG_DBG_INIT_VALUES:
settings.setValue("Flags/dbgInitValues", value);
break;
case FLG_DBG_EXTERNAL_EVENT:
settings.setValue("Flags/dbgExternalEvent", value);
break;
case FLG_DBG_MEMORY:
settings.setValue("Flags/dbgMemory", value);
break;
case FLG_DBG_SYNCHRONIZE:
settings.setValue("Flags/dbgSynchronize", value);
break;
case FLG_DBG_STEP_INFO:
settings.setValue("Flags/dbgStepInfo", value);
break;
case FLG_DBG_VAR_CHANGES:
settings.setValue("Flags/dbgVarChanges", value);
break;
case FLG_DBG_WAIT_FOR:
settings.setValue("Flags/dbgWaitFor", value);
break;
case FLG_DBG_WEIGHTS:
settings.setValue("Flags/dbgWeights", value);
break;
case FLG_DBG_DT:
settings.setValue("Flags/dbgDt", value);
break;
case FLG_PLOT:
settings.setValue("Flags/plotflags", value);
break;
default:
break;
}
settings.setValue(appDirsName(dir), value);
}

void Utils::setFlag(AppFlags flag, QString value)
{
QSettings settings(QCoreApplication::applicationDirPath() + "/qss-solver.ini", QSettings::IniFormat);
settings.setValue(appFlagName(flag), value);
}
9 changes: 6 additions & 3 deletions src/gui/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class Utils {
void setDir(AppDirs d, QString value);
void setFlag(AppFlags f, QString value);

private:
QString _getDir(AppDirs d);
QString _getDebugValue();
protected:
QString getDir(AppDirs dir);
QString getDebugValue();
QString appFlagName(AppFlags flag);
QString appDirsName(AppDirs dir);
QString appCommandsName(AppCmds cmd);
};

0 comments on commit 36b2c46

Please sign in to comment.