iLand
Public Types | Public Member Functions | Static Public Member Functions | List of all members
GlobalSettings Class Reference

General settings and globally available data. More...

#include <globalsettings.h>

Public Types

enum  DebugOutputs {
  dTreeNPP =1 , dTreePartition =2 , dTreeGrowth =4 , dStandGPP =8 ,
  dWaterCycle =16 , dDailyResponses =32 , dEstablishment =64 , dSaplingGrowth =128 ,
  dCarbonCycle =256 , dPerformance =512
}
 

Public Member Functions

 ~GlobalSettings ()
 
Modelmodel () const
 
ModelControllercontroller () const
 
void setModel (Model *model)
 
void setModelController (ModelController *mc)
 
int currentYear () const
 
void setCurrentYear (const int year)
 
QString executeJavascript (const QString &command)
 access the global QScriptEngine used throughout the model for all Javascript related functionality. More...
 
QString executeJSFunction (const QString function_name)
 execute a javasript function in the global context More...
 
QJSEngine * scriptEngine () const
 
void resetScriptEngine ()
 re-creates the script engine (when the Model is re-created) More...
 
SystemStatisticssystemStatistics ()
 
void setDebugOutput (const int debug)
 
void setDebugOutput (const DebugOutputs dbg, const bool enable=true)
 enable/disable a specific output type. More...
 
bool isDebugEnabled (const DebugOutputs dbg)
 returns true, if a specific debug outut type is enabled. More...
 
int currentDebugOutput () const
 
QString debugOutputName (const DebugOutputs d)
 returns the name attached to 'd' or an empty string if not found More...
 
DebugOutputs debugOutputId (const QString debug_name)
 returns the DebugOutputs bit or 0 if not found More...
 
DebugListdebugList (const int ID, const DebugOutputs dbg)
 returns a ref to a list ready to be filled with debug output of a type/id combination. More...
 
const QList< const DebugList * > debugLists (const int ID, const DebugOutputs dbg)
 return a list of debug outputs More...
 
QStringList debugListCaptions (const DebugOutputs dbg)
 returns stringlist of captions for a specific output type More...
 
QList< QPair< QString, QVariant > > debugValues (const int ID)
 all debug values for object with given ID More...
 
void clearDebugLists ()
 clear all debug data More...
 
QStringList debugDataTable (GlobalSettings::DebugOutputs type, const QString separator, const QString fileName=QString(), const bool do_append=false)
 output for all available items (trees, ...) in table form or write to a file More...
 
QSqlDatabase dbin ()
 
QSqlDatabase dbout ()
 
QSqlDatabase dbclimate ()
 
QString path (const QString &fileName, const QString &type="home")
 extend the file to a full absoulte path of the given type (temp, home, ...). More...
 
bool fileExists (const QString &fileName, const QString &type="home")
 returns true if file fileName exists. More...
 
const XmlHelpersettings () const
 
void loadProjectFile (const QString &fileName)
 
bool setupDatabaseConnection (const QString &dbname, const QString &fileName, bool fileMustExist)
 
void clearDatabaseConnections ()
 shutdown and clear connections More...
 
OutputManageroutputManager ()
 
void setupDirectories (QDomElement pathNode, const QString &projectFilePath)
 
void printDirectories () const
 

Static Public Member Functions

static GlobalSettingsinstance ()
 

Detailed Description

General settings and globally available data.

This class contains various global structures/definitions.

This class is a Singleton and accessed via the static instance() function.

various (textual) meta data (SettingMetaData)
global database connections
There are two defined global database connections dbin() and dbout() with the names "in" and "out". They are setup with setupDatabaseConnection(). Currently, only SQLite DBs are supported. Use dbin() and dbout() to faciliate those database connections:
...
QSqlQuery query(GlobalSettings::instance()->dbin());
query.exec(...);
...
static GlobalSettings * instance()
Definition: globalsettings.h:51
QSqlDatabase dbin()
Definition: globalsettings.h:96
Helpers with file Paths
the actual project file is parsed for path defined in the <path> section. Use the path() function to expand a fileName to a iLand-Path. To check if a file exists, you could use fileExists(). Available paths:
  • home: the project's home directory. All other directories can be defined relative to this dir.
  • lip: path for the storage of LIP (aka binary Stamp files) (default: home/lip)
  • database: base path for SQLite database files (default: home/database)
  • temp: path for storage of temporary files (default: home/temp)
  • log: storage for log-files (default: home/log)
  • exe: the path to the executable file.
    // home is "e:/iland/test", temp is "c:\temp" and log is omitted in project-file:
    QString p;
    p = Globals->path("somestuff.txt", "temp"); // > c:\temp\somestuff.txt
    p = Globals->path("e:\averyspecial\place.txt", "temp"); // -> e:\averyspecial\place.txt
    // (abs. path is not changed)
    p = Globals->path("log123.txt", "log"); // -> e:/iland/test/log/log123.txt (default for log)
    #define Globals
    shortcut to the GlobalSettings Singleton object.
    Definition: globalsettings.h:163
Fine-Grained debugging outputs
The enumeration DebugOutputs defines a list of realms (uses binary notation: 1,2,4,8,...!). Use setDebugOutput() to enable/disable such an output. Use isDebugEnabled() to test inside the code if the generation of debug output for a specific type is enabled. Internally, this is a single bitwise operation which is very fast. Call debugLists() to retrieve a list of lists of data that fit specific criteria.
// use something like that somewhere in a tree-growth-related routine:
DebugList &out = GlobalSettings::instance()->debugList(mId, GlobalSettings::dTreeGrowth); // get a ref to the list
out << hd_growth << factor_diameter << delta_d_estimate << d_increment; // fill with data
}
); // only in debugmode
DebugList & debugList(const int ID, const DebugOutputs dbg)
returns a ref to a list ready to be filled with debug output of a type/id combination.
Definition: globalsettings.cpp:221
bool isDebugEnabled(const DebugOutputs dbg)
returns true, if a specific debug outut type is enabled.
Definition: globalsettings.h:82
@ dTreeGrowth
Definition: globalsettings.h:76
#define DBGMODE(stmts)
Definition: global.h:66
QList< QVariant > DebugList
Definition: globalsettings.h:38

Member Enumeration Documentation

◆ DebugOutputs

Enumerator
dTreeNPP 
dTreePartition 
dTreeGrowth 
dStandGPP 
dWaterCycle 
dDailyResponses 
dEstablishment 
dSaplingGrowth 
dCarbonCycle 
dPerformance 

Constructor & Destructor Documentation

◆ ~GlobalSettings()

GlobalSettings::~GlobalSettings ( )

Member Function Documentation

◆ clearDatabaseConnections()

void GlobalSettings::clearDatabaseConnections ( )

shutdown and clear connections

◆ clearDebugLists()

void GlobalSettings::clearDebugLists ( )

clear all debug data

◆ controller()

ModelController * GlobalSettings::controller ( ) const
inline

◆ currentDebugOutput()

int GlobalSettings::currentDebugOutput ( ) const
inline

◆ currentYear()

int GlobalSettings::currentYear ( ) const
inline

◆ dbclimate()

QSqlDatabase GlobalSettings::dbclimate ( )
inline

◆ dbin()

QSqlDatabase GlobalSettings::dbin ( )
inline

◆ dbout()

QSqlDatabase GlobalSettings::dbout ( )
inline

◆ debugDataTable()

QStringList GlobalSettings::debugDataTable ( GlobalSettings::DebugOutputs  type,
const QString  separator,
const QString  fileName = QString(),
const bool  do_append = false 
)

output for all available items (trees, ...) in table form or write to a file

◆ debugList()

DebugList & GlobalSettings::debugList ( const int  ID,
const DebugOutputs  dbg 
)

returns a ref to a list ready to be filled with debug output of a type/id combination.

◆ debugListCaptions()

QStringList GlobalSettings::debugListCaptions ( const DebugOutputs  dbg)

returns stringlist of captions for a specific output type

◆ debugLists()

const QList< const DebugList * > GlobalSettings::debugLists ( const int  ID,
const DebugOutputs  dbg 
)

return a list of debug outputs

◆ debugOutputId()

GlobalSettings::DebugOutputs GlobalSettings::debugOutputId ( const QString  debug_name)

returns the DebugOutputs bit or 0 if not found

◆ debugOutputName()

QString GlobalSettings::debugOutputName ( const DebugOutputs  d)

returns the name attached to 'd' or an empty string if not found

returns the DebugOutputs bit or 0 if not found

◆ debugValues()

QList< QPair< QString, QVariant > > GlobalSettings::debugValues ( const int  ID)

all debug values for object with given ID

◆ executeJavascript()

QString GlobalSettings::executeJavascript ( const QString &  command)

access the global QScriptEngine used throughout the model for all Javascript related functionality.

◆ executeJSFunction()

QString GlobalSettings::executeJSFunction ( const QString  function_name)

execute a javasript function in the global context

◆ fileExists()

bool GlobalSettings::fileExists ( const QString &  fileName,
const QString &  type = "home" 
)

returns true if file fileName exists.

◆ instance()

static GlobalSettings * GlobalSettings::instance ( )
inlinestatic

◆ isDebugEnabled()

bool GlobalSettings::isDebugEnabled ( const DebugOutputs  dbg)
inline

returns true, if a specific debug outut type is enabled.

◆ loadProjectFile()

void GlobalSettings::loadProjectFile ( const QString &  fileName)

◆ model()

Model * GlobalSettings::model ( ) const
inline

◆ outputManager()

OutputManager * GlobalSettings::outputManager ( )
inline

◆ path()

QString GlobalSettings::path ( const QString &  fileName,
const QString &  type = "home" 
)

extend the file to a full absoulte path of the given type (temp, home, ...).

If file is already an absolute path, nothing is done.

See also
setupDirectories().

◆ printDirectories()

void GlobalSettings::printDirectories ( ) const

◆ resetScriptEngine()

void GlobalSettings::resetScriptEngine ( )

re-creates the script engine (when the Model is re-created)

◆ scriptEngine()

QJSEngine * GlobalSettings::scriptEngine ( ) const
inline

◆ setCurrentYear()

void GlobalSettings::setCurrentYear ( const int  year)
inline

◆ setDebugOutput() [1/2]

void GlobalSettings::setDebugOutput ( const DebugOutputs  dbg,
const bool  enable = true 
)

enable/disable a specific output type.

◆ setDebugOutput() [2/2]

void GlobalSettings::setDebugOutput ( const int  debug)
inline

◆ setModel()

void GlobalSettings::setModel ( Model model)
inline

◆ setModelController()

void GlobalSettings::setModelController ( ModelController mc)
inline

◆ settings()

const XmlHelper & GlobalSettings::settings ( ) const
inline

◆ setupDatabaseConnection()

bool GlobalSettings::setupDatabaseConnection ( const QString &  dbname,
const QString &  fileName,
bool  fileMustExist 
)

◆ setupDirectories()

void GlobalSettings::setupDirectories ( QDomElement  pathNode,
const QString &  projectFilePath 
)

◆ systemStatistics()

SystemStatistics * GlobalSettings::systemStatistics ( )
inline

The documentation for this class was generated from the following files: