FFSM++  1.1.0
French Forest Sector Model ++
MainWindow.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3  * http://ffsm-project.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version, given the compliance with the *
9  * exceptions listed in the file COPYING that is distribued together *
10  * with this file. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 #ifndef MAINWINDOW_H
23 #define MAINWINDOW_H
24 
25 #include <iostream>
26 #include <string>
27 #include <sstream>
28 
29 #include <QMainWindow>
30 #include <QTextEdit>
31 #include <QLabel>
32 
33 #include "ui_MainWindow.h"
34 
35 // regmas headers..
36 #include "ThreadManager.h"
38 
39 using namespace std;
40 
41 //class ScenarioSelectionWidget;
42 
43 /// Main GUI interface
44 
45 /**
46 MainWindow derive from both the generic Qt QMainWindow and from Ui::MainWindow (the latter being the autmatically generated C++ code from QtDesigner).
47 <br>It implements code and functionality that can not be done in the QtDesigner.
48 */
49 
50 class MainWindow : public QMainWindow, public Ui::MainWindow {
51  Q_OBJECT
52 
53 public:
54  MainWindow(); ///< Constructor
55 
56  void setCurrentLogFileName(const QString &fileName);
57  void setCurrentModelFileName(const QString &fileName);
58  bool saveLogFile(const QString &logFileName);
59  QString strippedName(const QString &fullFileName);
60 
61  QString getModelFileName(){return curModelFileName;};
62  void setModelFileName(const QString curModelFileName_h){curModelFileName=curModelFileName_h;};
63 
64 public slots:
65  void setUnsavedStatus(bool unsavedStatus_h){unsavedStatus = unsavedStatus_h;};
66  void setOutputDirName(string outputDirName_h){outputDirName = outputDirName_h.c_str();};
67  void addLayer(QString layerName_h, QString layerLabel_h);
68  void switchToLayer(QString layerName_h);
69  void updatePixel(QString layerName_h, int x_h, int y_h, QColor color_h);
70  void updateImage(QString layerName_h, const QImage &image_h);
71  void switchToLayerFromLayerSelector(int layerIndex_h);
72  /// Change value to an existing item in the Status Viewer
73  void treeViewerItemChangeValue(string itemID, string newValue);
74  void treeViewerItemRemove(string itemID);
75  void treeViewerAddItem(string text, string itemID, string parentID); ///< e.g. manager_farmer_manager agents or agent_12345_ownedHa
76  void processLogArea(const QString& message_h);
77  void resetGUIForNewSimulation(); ///< Reset the graphical elements for a new simulation
78  ///// Send the request of getting the pixel info to the main thread
79  //void sendQueryToMainThread(int px_ID);
80  void receiveScenarioOptions(const QVector<QString> &scenarios_h);
81 
82 
83 signals:
84  void currentModelFilenameChanged (QString);
85  void selectedScenarioName(const QString &scenarioName_h);
86  void resized();
87 
88 protected:
89  void closeEvent(QCloseEvent *event); ///< Manage the event of closing the application
90  void resizeEvent(QResizeEvent *event); ///< Manage the event of resizing the application
91 
92 private slots:
93  void open();
94  bool save();
95  bool saveAs();
96  void startModelMainThread();
97  void stopModelMainThread();
98  void pauseOrResumeModelMainThread();
99  void openRecentFile(); //already in the ui file ????
100  void hideDebugMsgs(bool hide);
101  void about();
102  void showDocumentation();
103  void openResults();
104 
105 private:
106 
108  QLabel* yearSBLabel; ///< Status bar current year label
109  QLabel* mainSBLabel; ///< Status bar main label
111  QString outputDirName;
112  QString curLogFileName;
115  QStringList recentFiles;
116  enum { MaxRecentFiles = 5 };
117  QAction * recentFileActions[MaxRecentFiles];
118  QAction * separatorAction;
119  bool debugMsgsEnable; ///< Allow debug messages to be show in the logArea
121  /**
122  Ids are based on the name of the item:
123  - general
124  - general_{name}
125  - managers
126  - manager_{managerID}
127  - manager_{managerID}_{name}
128  - agents
129  - agent_{agentUniqueID}
130  - agent_{agentUniqueID}_{name}
131  */
132  map <string, QTreeWidgetItem*> svIndex; ///< Map containing the ID and the pointers to the status viewer
133 
134  void createStatusBar();
135  bool okToContinue();
136  void readSettings();
137  void writeSettings();
138  void updateRecentFileActions();
139 };
140 
141 #endif
QStringList recentFiles
Definition: MainWindow.h:115
QString getModelFileName()
Definition: MainWindow.h:61
def text(cat, text_h)
QString curBaseDirectory
Definition: MainWindow.h:114
QString curLogFileName
Definition: MainWindow.h:112
void setUnsavedStatus(bool unsavedStatus_h)
Definition: MainWindow.h:65
bool unsavedStatus
Definition: MainWindow.h:110
STL namespace.
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
Definition: ThreadManager.h:65
map< string, QTreeWidgetItem * > svIndex
Map containing the ID and the pointers to the status viewer.
Definition: MainWindow.h:132
QAction * separatorAction
Definition: MainWindow.h:118
void setModelFileName(const QString curModelFileName_h)
Definition: MainWindow.h:62
QLabel * yearSBLabel
Status bar current year label.
Definition: MainWindow.h:108
bool debugMsgsEnable
Allow debug messages to be show in the logArea.
Definition: MainWindow.h:119
QString curModelFileName
Definition: MainWindow.h:113
MainWindow()
Constructor.
Definition: MainWindow.cpp:39
void setOutputDirName(string outputDirName_h)
Definition: MainWindow.h:66
QLabel * mainSBLabel
Status bar main label.
Definition: MainWindow.h:109
QString outputDirName
Definition: MainWindow.h:111
ScenarioSelectionWidget * scenarioWidget
Definition: MainWindow.h:120
ThreadManager modelMainThread
Definition: MainWindow.h:107