Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
671 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
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
 
15 Werner 20
#ifndef HELPER_H
21
#define HELPER_H
22
 
55 Werner 23
#include <QtCore>
421 werner 24
#include <QtCore/QRect>
25
#include <QtCore/QString>
401 werner 26
#include <limits>
400 werner 27
#include <limits>
15 Werner 28
#define QUIETDEBUG(x) if (!Helper::quiet()) { qDebug() << x; }
29
 
30
/** Helper contains a bunch of (static) helper functions.
31
  * including simplifed functions to read/write plain text files (loadTextFile(), saveToTextFile()),
32
  * funcitons to show message dialogs (msg(), question()), and functions to control the amount of
33
  * debug outputs (quiet(), debugEnabled()).
34
  */
35
class Helper
36
{
37
public:
38
    Helper();
39
    static QString loadTextFile(const QString& fileName);
40
    static void saveToTextFile(const QString& fileName, const QString& text);
151 iland 41
    static QByteArray loadFile(const QString &fileName);
42
    static void saveToFile(const QString &fileName, const QByteArray &data);
15 Werner 43
    static void msg(const QString &message, QWidget *parent=0);
44
    static bool question(const QString &message, QWidget *parent=0);
702 werner 45
    static QString userValue(const QString &message, const QString defaultValue, QWidget *parent=0); ///< ask the user for a input value
54 Werner 46
    /// open a File Dialog and let the user choose a file.
47
    /// @return the filename selected by the user, an empty string if user cancels.
1053 werner 48
    static QString fileDialog(const QString &title, const QString &start_directory="", const QString &filter="", QWidget *parent=0);
15 Werner 49
    static bool quiet() { return m_NoDebug || m_quiet; }
50
    static bool debugEnabled() { return !m_NoDebug; }
51
    static void setQuiet(bool quiet) { m_quiet = quiet; }
52
    static void setDebugEnabled(bool enable) { m_NoDebug = !enable; }
53
    static void openHelp(const QString& topic);
54
    static QString stripHtml(const QString &source);
40 Werner 55
 
199 werner 56
 
877 werner 57
 
199 werner 58
    static QString currentRevision(); ///< svn revision number
59
 
15 Werner 60
private:
61
    static bool m_quiet;
62
    static bool m_NoDebug;
63
};
64
 
65
 
79 Werner 66
 
15 Werner 67
/** UpdateState details missing.
68
  */
69
class UpdateState
70
{
71
public:
72
    // available states
73
    UpdateState(): mCurrentVal(0), mVal(0) {}
74
    bool needsUpdate(); // needs local state-object an update?
75
    void update(); // update with master
145 Werner 76
    int value() const { return mVal; } // return current value
15 Werner 77
    void invalidate(bool self=false); // master object enters a new state
78
    void addChild(UpdateState* state) { mChilds.push_back(state); }
79
    void saveState(UpdateState* state);
80
    bool hasChanged(UpdateState* state);
81
private:
82
    int mCurrentVal; // state of last explicit "update"
83
    int mVal; // current state
84
    QVector<UpdateState*> mChilds;
85
    QMap<UpdateState*, int> mSavedStates;
86
};
87
 
49 Werner 88
 
15 Werner 89
#endif // HELPER_H