iLand
helper.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19
20#ifndef HELPER_H
21#define HELPER_H
22
23#include <QtCore>
24#include <QtCore/QRect>
25#include <QtCore/QString>
26#include <limits>
27#define QUIETDEBUG(x) if (!Helper::quiet()) { qDebug() << x; }
28
34class Helper
35{
36public:
37 Helper();
38 static QString loadTextFile(const QString& fileName);
39 static void saveToTextFile(const QString& fileName, const QString& text);
40 static QByteArray loadFile(const QString &fileName);
41 static void saveToFile(const QString &fileName, const QByteArray &data);
42 static void msg(const QString &message, QWidget *parent=0);
43 static bool question(const QString &message, QWidget *parent=0);
44 static QString userValue(const QString &message, const QString defaultValue, QWidget *parent=0);
47 static QString fileDialog(const QString &title, const QString &start_directory="", const QString &filter="", QWidget *parent=0);
48 static bool quiet() { return m_NoDebug || m_quiet; }
49 static bool debugEnabled() { return !m_NoDebug; }
50 static void setQuiet(bool quiet) { m_quiet = quiet; }
51 static void setDebugEnabled(bool enable) { m_NoDebug = !enable; }
52 static void openHelp(const QString& topic);
53 static QString stripHtml(const QString &source);
54
55
56
57 static QString currentRevision();
58
59private:
60 static bool m_quiet;
61 static bool m_NoDebug;
62};
63
64
65
69{
70public:
71 // available states
72 UpdateState(): mCurrentVal(0), mVal(0) {}
73 bool needsUpdate(); // needs local state-object an update?
74 void update(); // update with master
75 int value() const { return mVal; } // return current value
76 void invalidate(bool self=false); // master object enters a new state
77 void addChild(UpdateState* state) { mChilds.push_back(state); }
78 void saveState(UpdateState* state);
79 bool hasChanged(UpdateState* state);
80private:
81 int mCurrentVal; // state of last explicit "update"
82 int mVal; // current state
83 QVector<UpdateState*> mChilds;
84 QMap<UpdateState*, int> mSavedStates;
85};
86
87
88#endif // HELPER_H
Helper contains a bunch of (static) helper functions.
Definition: helper.h:35
static QString loadTextFile(const QString &fileName)
Definition: helper.cpp:51
static bool debugEnabled()
Definition: helper.h:49
static void msg(const QString &message, QWidget *parent=0)
Definition: helper.cpp:115
static void openHelp(const QString &topic)
Definition: helper.cpp:152
static void saveToFile(const QString &fileName, const QByteArray &data)
Definition: helper.cpp:88
Helper()
Definition: helper.cpp:39
static bool quiet()
Definition: helper.h:48
static void setDebugEnabled(bool enable)
Definition: helper.h:51
static QString stripHtml(const QString &source)
Definition: helper.cpp:167
static void saveToTextFile(const QString &fileName, const QString &text)
Definition: helper.cpp:64
static void setQuiet(bool quiet)
Definition: helper.h:50
static bool question(const QString &message, QWidget *parent=0)
Definition: helper.cpp:124
static QString userValue(const QString &message, const QString defaultValue, QWidget *parent=0)
ask the user for a input value
Definition: helper.cpp:100
static QString currentRevision()
svn revision number
Definition: helper.cpp:43
static QString fileDialog(const QString &title, const QString &start_directory="", const QString &filter="", QWidget *parent=0)
open a File Dialog and let the user choose a file.
Definition: helper.cpp:134
static QByteArray loadFile(const QString &fileName)
Definition: helper.cpp:74
UpdateState details missing.
Definition: helper.h:69
UpdateState()
Definition: helper.h:72
void addChild(UpdateState *state)
Definition: helper.h:77
bool hasChanged(UpdateState *state)
Definition: helper.cpp:196
int value() const
Definition: helper.h:75
void invalidate(bool self=false)
UpdateState.
Definition: helper.cpp:184
void update()
Definition: helper.cpp:204
void saveState(UpdateState *state)
Definition: helper.cpp:192
bool needsUpdate()
Definition: helper.cpp:209