FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
MainWindow Class Reference

Main GUI interface. More...

#include <MainWindow.h>

Inheritance diagram for MainWindow:
Collaboration diagram for MainWindow:

Public Slots

void setUnsavedStatus (bool unsavedStatus_h)
 

Signals

void currentModelFilenameChanged (QString)
 
void selectedScenarioName (const QString &scenarioName_h)
 
void resized ()
 

Public Member Functions

 MainWindow ()
 Constructor

 
void setCurrentLogFileName (const QString &fileName)
 
void setCurrentModelFileName (const QString &fileName)
 
bool saveLogFile (const QString &logFileName)
 
QString strippedName (const QString &fullFileName)
 
QString getModelFileName ()
 
void setModelFileName (const QString curModelFileName_h)
 
void setOutputDirName (string outputDirName_h)
 
void addLayer (QString layerName_h, QString layerLabel_h)
 
void switchToLayer (QString layerName_h)
 
void updatePixel (QString layerName_h, int x_h, int y_h, QColor color_h)
 
void updateImage (QString layerName_h, const QImage &image_h)
 
void switchToLayerFromLayerSelector (int layerIndex_h)
 
void treeViewerItemChangeValue (string itemID, string newValue)
 Change value to an existing item in the Status Viewer.
 
void treeViewerItemRemove (string itemID)
 
void treeViewerAddItem (string text, string itemID, string parentID)
 e.g. manager_farmer_manager agents or agent_12345_ownedHa
 
void processLogArea (const QString &message_h)
 
void resetGUIForNewSimulation ()
 Reset the graphical elements for a new simulation // Send the request of getting the pixel info to the main thread.
 
void receiveScenarioOptions (const QVector< QString > &scenarios_h)
 

Protected Member Functions

void closeEvent (QCloseEvent *event)
 Manage the event of closing the application.
 
void resizeEvent (QResizeEvent *event)
 Manage the event of resizing the application.
 

Private Types

enum  { MaxRecentFiles = 5 }
 

Private Slots

void open ()
 
bool save ()
 
bool saveAs ()
 
void startModelMainThread ()
 
void stopModelMainThread ()
 
void pauseOrResumeModelMainThread ()
 
void openRecentFile ()
 
void hideDebugMsgs (bool hide)
 
void about ()
 
void showDocumentation ()
 
void openResults ()
 

Private Member Functions

void createStatusBar ()
 
bool okToContinue ()
 
void readSettings ()
 
void writeSettings ()
 
void updateRecentFileActions ()
 

Private Attributes

ThreadManager modelMainThread
 
QLabel * yearSBLabel
 Status bar current year label.
 
QLabel * mainSBLabel
 Status bar main label.
 
bool unsavedStatus
 
QString outputDirName
 
QString curLogFileName
 
QString curModelFileName
 
QString curBaseDirectory
 
QStringList recentFiles
 
QAction * recentFileActions [MaxRecentFiles]
 
QAction * separatorAction
 
bool debugMsgsEnable
 Allow debug messages to be show in the logArea.
 
ScenarioSelectionWidgetscenarioWidget
 
map< string, QTreeWidgetItem * > svIndex
 Map containing the ID and the pointers to the status viewer.
 

Detailed Description

Main GUI interface.

MainWindow derive from both the generic Qt QMainWindow and from Ui::MainWindow (the latter being the autmatically generated C++ code from QtDesigner).
It implements code and functionality that can not be done in the QtDesigner.

Definition at line 50 of file MainWindow.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
MaxRecentFiles 

Definition at line 116 of file MainWindow.h.

116{ MaxRecentFiles = 5 };

Constructor & Destructor Documentation

◆ MainWindow()

Constructor

It setup the Gui from the QTDesiger autogenerated code and connect various GUI signal/slots

Definition at line 39 of file MainWindow.cpp.

39 {
40 yearSBLabel=NULL;
41 mainSBLabel=NULL;
42 for (uint i=0;i<MaxRecentFiles;i++) recentFileActions[i] = NULL;
43 separatorAction=NULL;
44
45 setupUi(this);
46 unsavedStatus=false;
47 curModelFileName="data/ffsmInput.ods";
48 curBaseDirectory = QApplication::applicationDirPath();
49 curBaseDirectory.append("/data/");
50 //curBaseDirectory = "data/";
51 outputDirName="output/";
55 debugMsgsEnable = true;
56
57 for (int i = 0; i < MaxRecentFiles; ++i) {
58 recentFileActions[i] = new QAction(this);
59 recentFileActions[i]->setVisible(false);
60 connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
61 }
62
63 separatorAction = menuFile->addSeparator();
64 for (int i = 0; i < MaxRecentFiles; ++i)
65 menuFile->addAction(recentFileActions[i]);
66 menuFile->addSeparator();
67 menuFile->addAction(actionExit);
68
71 //modelMainThread.setBaseDirectory(curBaseDirectory);
72
73 // Status viewer....
74 statusView->setColumnCount(2);
75 statusView->setHeaderLabels(QStringList()<< tr ("Label") << tr ("Value"));
76 statusView->clear();
77 statusView->sortByColumn(0);
78 statusView->setFocus(); //????
79
80
81
82
83 /*
84 DONE: statusView should be implemented like this:
85
86 Model
87 -> year
88 -> total plots
89 -> rented plots
90 -> abandoned plots
91 Managers
92 -> Manager_farmer
93 -> number of agents
94 Agents
95 Agent_0
96 -> Type
97 -> ID
98 -> mould
99 -> owned plots
100 ...
101 Agent_1
102 -> Type
103 -> ID
104 -> mould
105 -> owned plots
106 ...
107 ...
108 */
109
110 qRegisterMetaType<string>("string"); // allows string objects to be thread-safely queued within signal-slots comunications
111 qRegisterMetaType<QString>("QString");
112 qRegisterMetaType< QVector<QString> >("QVector<QString>");
113
114
115 connect(actionRun, SIGNAL(triggered()), this, SLOT(startModelMainThread()));
116 connect(actionPause, SIGNAL(triggered()), this, SLOT(pauseOrResumeModelMainThread()));
117 connect(actionStop, SIGNAL(triggered()), this, SLOT(stopModelMainThread()));
118 connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
119 connect(actionSaveLog, SIGNAL(triggered()), this, SLOT(save()));
120 connect(actionSaveLogAs, SIGNAL(triggered()), this, SLOT(saveAs()));
121 connect(actionLoadConfiguration, SIGNAL(triggered()), this, SLOT(open()));
122 connect(actionHideDebugMsgs, SIGNAL(triggered(bool)), this, SLOT(hideDebugMsgs(bool)));
123 connect(actionAboutRegMAS, SIGNAL(triggered()), this, SLOT(about()));
124 connect(actionRegMASDocumentation, SIGNAL(triggered()), this, SLOT(showDocumentation()));
125 connect(actionFitMap, SIGNAL(triggered()), mapBox, SLOT(fitInWindow()));
126 connect(this, SIGNAL(resized()),mapBox, SLOT(fitInWindow()));
127 connect(viewResultsButton, SIGNAL(clicked()),this, SLOT(openResults()));
128
129 connect(&modelMainThread, SIGNAL(upgradeLogArea(const QString&)), this, SLOT(processLogArea(const QString&)));
130 connect(&modelMainThread, SIGNAL(addLayerToGui(QString, QString)), this, SLOT( addLayer(QString, QString)));
131 connect(layerSelector, SIGNAL(activated(int)), this, SLOT(switchToLayerFromLayerSelector(int)));
132 connect(&modelMainThread, SIGNAL(updatePixelToGui(QString, int, int, QColor)), this, SLOT (updatePixel(QString, int, int, QColor)));
133 connect(&modelMainThread, SIGNAL(updateImageToGui(QString, QImage)), this, SLOT (updateImage(QString, QImage)));
134 connect(&modelMainThread, SIGNAL(setOutputDirNameToGui(string)), this, SLOT(setOutputDirName(string)));
135 connect(&modelMainThread, SIGNAL(setGUIUnsavedStatus(bool)), this, SLOT(setUnsavedStatus(bool)));
136 connect(&modelMainThread, SIGNAL(sendScenarioOptionsToGUI(const QVector<QString> &)), this, SLOT( receiveScenarioOptions(const QVector<QString> &) ));
137
138 // Scenario selection widget...
140 connect(scenarioWidget->scenarioSelector, SIGNAL( activated(const QString&)), scenarioWidget, SLOT( close()));
141 connect(scenarioWidget->scenarioSelector, SIGNAL( activated(const QString&)), &modelMainThread, SLOT( retrieveScenarioNameFromGUI(const QString &)));
142 //connect(scenarioWidget, SIGNAL( selectedScenarioName(const QString&)), scenarioWidget, SLOT( close()));
143 //connect(scenarioWidget, SIGNAL( selectedScenarioName(const QString&)), &modelMainThread, SLOT( retrieveScenarioNameFromGUI(const QString &)));
144
145 // Model tree viewer...
146 connect(&modelMainThread, SIGNAL( treeViewerItemChangeValueToGui(string, string) ), this, SLOT( treeViewerItemChangeValue(string, string) ));
147 connect(&modelMainThread, SIGNAL( treeViewerItemRemoveToGui(string) ), this, SLOT( treeViewerItemRemove(string) ));
148 connect(&modelMainThread, SIGNAL( treeViewerAddItemToGui(string, string, string) ), this, SLOT( treeViewerAddItem(string, string, string) ));
149 connect(&modelMainThread, SIGNAL( fitInWindowToGui()), mapBox, SLOT(fitInWindow()));
150
151 connect(mapBox, SIGNAL( queryRequestOnPx(int, int, bool) ), &modelMainThread, SLOT ( checkQuery(int, int, bool) ) );
152 connect(&modelMainThread,SIGNAL(publishQueryResults(const QString&)), pxInfoArea, SLOT (setHtml(const QString&)));
153 connect(&modelMainThread,SIGNAL(activateTab(int)), tabWidget, SLOT (setCurrentIndex(int)));
154
155 connect(&modelMainThread, SIGNAL( resetGUIForNewSimulation() ), this, SLOT( resetGUIForNewSimulation() ));
156
157}
void stopModelMainThread()
void createStatusBar()
bool unsavedStatus
Definition MainWindow.h:110
void setCurrentLogFileName(const QString &fileName)
ScenarioSelectionWidget * scenarioWidget
Definition MainWindow.h:120
QString outputDirName
Definition MainWindow.h:111
ThreadManager modelMainThread
Definition MainWindow.h:107
void resized()
void treeViewerItemChangeValue(string itemID, string newValue)
Change value to an existing item in the Status Viewer.
void resetGUIForNewSimulation()
Reset the graphical elements for a new simulation // Send the request of getting the pixel info to th...
void treeViewerAddItem(string text, string itemID, string parentID)
e.g. manager_farmer_manager agents or agent_12345_ownedHa
void treeViewerItemRemove(string itemID)
void pauseOrResumeModelMainThread()
void readSettings()
QLabel * yearSBLabel
Status bar current year label.
Definition MainWindow.h:108
void openRecentFile()
void setOutputDirName(string outputDirName_h)
Definition MainWindow.h:66
void receiveScenarioOptions(const QVector< QString > &scenarios_h)
void setUnsavedStatus(bool unsavedStatus_h)
Definition MainWindow.h:65
bool debugMsgsEnable
Allow debug messages to be show in the logArea.
Definition MainWindow.h:119
void openResults()
bool saveAs()
QAction * separatorAction
Definition MainWindow.h:118
void updateImage(QString layerName_h, const QImage &image_h)
QString curLogFileName
Definition MainWindow.h:112
void addLayer(QString layerName_h, QString layerLabel_h)
void processLogArea(const QString &message_h)
void updatePixel(QString layerName_h, int x_h, int y_h, QColor color_h)
QString curModelFileName
Definition MainWindow.h:113
void showDocumentation()
QAction * recentFileActions[MaxRecentFiles]
Definition MainWindow.h:117
void startModelMainThread()
void hideDebugMsgs(bool hide)
QString curBaseDirectory
Definition MainWindow.h:114
QLabel * mainSBLabel
Status bar main label.
Definition MainWindow.h:109
void switchToLayerFromLayerSelector(int layerIndex_h)
void setInputFileName(QString inputFileName_h)
Here is the call graph for this function:

Member Function Documentation

◆ about

void about ( )
privateslot

Definition at line 570 of file MainWindow.cpp.

570 {
571 QMessageBox::about(this, tr("About FFSM"),
572 tr("<h2>FFSM</h2>"
573 "<p>Copyright &copy; 2012 Laboratoire d'Economie Forestière - LEF"
574 "<br/>"
575 "<p>FFSM is a flexible, spatially explicit, coupled resource and economic simulator of the Forest Sector, "
576 "designed for long-term simulations of effects of government policies "
577 "over different forest systems."
578 "<br>It is released under the GNU GPL licence."
579 "<p>For documentation and credits please refer to the project site:"
580 "<br><a href=\"http://www.ffsm-project.org\">http://www.ffsm-project.org</a>"
581 ));
582}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ addLayer()

void addLayer ( QString  layerName_h,
QString  layerLabel_h 
)

Perform all the operation needed when adding a new layer:

  • add a layer to mapBox;
  • add the layer to layerSelector;
  • (NOTNEEDED: add the layer to layerLegend); Not needed any longer, as legend was dropped in name of the Model Status Viewer

Definition at line 440 of file MainWindow.cpp.

440 {
441 static int counter =0;
442 mapBox->addLayer(layerName_h);
443 layerSelector->addItem(layerLabel_h,layerName_h);
444 // first layer added only. it is not needed as MapBox::addLayer() and QComboBox automatically switch to the new value if it is the first one :-))
445 //if (counter == 0) switchToLayer(layerName_h);
446 update();
447 counter ++;
448}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ closeEvent()

void closeEvent ( QCloseEvent *  event)
protected

Manage the event of closing the application.

Definition at line 181 of file MainWindow.cpp.

181 {
182 if (okToContinue()) {
185 modelMainThread.wait();
186 event->accept();
187 } else {
188 event->ignore();
189 }
190}
bool okToContinue()
void writeSettings()
Here is the call graph for this function:

◆ createStatusBar()

void createStatusBar ( )
private

Definition at line 160 of file MainWindow.cpp.

160 {
161 yearSBLabel = new QLabel(" 2000 ");
162 yearSBLabel->setAlignment(Qt::AlignHCenter);
163 yearSBLabel->setMinimumSize(yearSBLabel->sizeHint());
164
165 mainSBLabel = new QLabel;
166 mainSBLabel->setIndent(3);
167
168 statusBar()->addWidget(yearSBLabel);
169 statusBar()->addWidget(mainSBLabel, 1);
170
171 yearSBLabel->setText("0");
172 mainSBLabel->setText("Welcome to FFSM!");
173
174 connect(&modelMainThread, SIGNAL(upgradeYearSBLabelToGui(const QString&)), yearSBLabel, SLOT(setText(const QString&)));
175 connect(&modelMainThread, SIGNAL(upgradeMainSBLabelToGui(const QString&)), mainSBLabel, SLOT(setText(const QString&)));
176
177}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ currentModelFilenameChanged

void currentModelFilenameChanged ( QString  )
signal

◆ getModelFileName()

QString getModelFileName ( )
inline

Definition at line 61 of file MainWindow.h.

61{return curModelFileName;};

◆ hideDebugMsgs

void hideDebugMsgs ( bool  hide)
privateslot

Definition at line 564 of file MainWindow.cpp.

564 {
565 if(hide) debugMsgsEnable = false;
566 else debugMsgsEnable = true;
567}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ okToContinue()

bool okToContinue ( )
private

Definition at line 251 of file MainWindow.cpp.

251 {
252 if (modelMainThread.isRunning()) {
253 int t = QMessageBox::warning(
254 this, // parent
255 tr("FFSM"), // title
256 tr("The model is still running.\n" // message
257 "Do you want to stop it?"),
258 QMessageBox::Yes | QMessageBox::Default, // 1st button
259 QMessageBox::Cancel | QMessageBox::Escape // 3rd button
260 );
261 if (t == QMessageBox::Yes) {
263 modelMainThread.wait();
264 } else if (t == QMessageBox::Cancel) {
265 return false;
266 }
267 }
268
269 if (unsavedStatus) {
270 int r = QMessageBox::warning(
271 this, // parent
272 tr("FFSM"), // title
273 tr("The model log has not been saved.\n" // message
274 "Do you want to save it?"),
275 QMessageBox::Yes , // 1st button
276 QMessageBox::No | QMessageBox::Default, // 2nd button
277 QMessageBox::Cancel | QMessageBox::Escape // 3rd button
278 );
279 if (r == QMessageBox::Yes) {
280 return save();
281 } else if (r == QMessageBox::Cancel) {
282 return false;
283 }
284 }
285 return true;
286}

Referenced by closeEvent(), open(), and openRecentFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open

void open ( )
privateslot

Definition at line 289 of file MainWindow.cpp.

289 {
290 if (okToContinue()) {
291 QString fileName = QFileDialog::getOpenFileName(
292 this,
293 tr("Load model file.."),
294 "data/",
295 tr("OpenDocument Spreadsheet (*.ods)\n" "All files (*.*)")
296 );
297 if (!fileName.isEmpty()){
298 statusBar()->showMessage(tr("Loaded new FFSM model file"), 2000);
299 setCurrentModelFileName(fileName);
300 // getting the baseData path information...
301 QFileInfo info(fileName);
302 QString path;
303 path = info.absolutePath();
304 path = path+"/";
305 curBaseDirectory = path;
306 //modelMainThread.setBaseDirectory(curBaseDirectory);
307 }
308 }
309}
void setCurrentModelFileName(const QString &fileName)

Referenced by MainWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openRecentFile

void openRecentFile ( )
privateslot

Definition at line 319 of file MainWindow.cpp.

319 {
320 if (okToContinue()) {
321 QAction *action = qobject_cast<QAction *>(sender());
322 if (action){
323 curModelFileName=action->data().toString();
325 // getting the baseData path information...
326 QFileInfo info(curModelFileName);
327 QString path;
328 path = info.absolutePath();
329 path = path+"/";
330 curBaseDirectory = path;
331 //modelMainThread.setBaseDirectory(curBaseDirectory);
332 }
333 }
334}

Referenced by MainWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openResults

void openResults ( )
privateslot

Definition at line 680 of file MainWindow.cpp.

680 {
681 //QLabel *label = new QLabel("Hello World!");
682 //label->show();
683 //string aaa = curBaseDirectory.toStdString();
684 //cout << "curBaseDirectory " << aaa << endl;
685 //cout << "outputDirName: " << outputDirName.toStdString() << endl;
686 QUrl resultsUrl(curBaseDirectory+outputDirName+"results/results.ods", QUrl::TolerantMode);
687 QDesktopServices::openUrl(resultsUrl);
688
689}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ pauseOrResumeModelMainThread

void pauseOrResumeModelMainThread ( )
privateslot

Definition at line 416 of file MainWindow.cpp.

416 {
418}

Referenced by MainWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processLogArea()

void processLogArea ( const QString &  message_h)

Definition at line 552 of file MainWindow.cpp.

552 {
553 if(debugMsgsEnable){
554 logArea->append(message_h);
555 }
556 else {
557 if( ! message_h.startsWith("*DEBUG")){
558 logArea->append(message_h);
559 }
560 }
561}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ readSettings()

void readSettings ( )
private

Definition at line 312 of file MainWindow.cpp.

312 {
313 QSettings settings("LEF", "FFSM");
314 recentFiles = settings.value("recentFiles").toStringList();
316}
void updateRecentFileActions()
QStringList recentFiles
Definition MainWindow.h:115

Referenced by MainWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiveScenarioOptions()

void receiveScenarioOptions ( const QVector< QString > &  scenarios_h)

Definition at line 664 of file MainWindow.cpp.

664 {
665
666 //for(uint i=0;i<scenarios_h.size();i++){
667 // cout << scenarios_h.at(i).toStdString() << endl;
668 //} // stange.. it works like expected !!!!
669
671 scenarioWidget->show();
672 scenarioWidget->scenarioSelector->setFocus();
673 //scenarioWidget->scenarioSelector->grabMouse();
674 //scenarioWidget->scenarioSelector->grabKeyboard();
675
676
677}
void receiveScenarioOptions(const QVector< QString > &scenarios_h)

Referenced by MainWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetGUIForNewSimulation()

void resetGUIForNewSimulation ( )

Reset the graphical elements for a new simulation // Send the request of getting the pixel info to the main thread.

Definition at line 607 of file MainWindow.cpp.

607 {
608
609 static int simulationCounter = 0;
610 //reset map <string, QTreeWidgetItem*> svIndex and clean the tree widget
611 statusView->clear();
612 map<string, QTreeWidgetItem*>::iterator p;
613 //for(p=svIndex.begin(); p= svIndex.end(); p++){
614 //delete p->second; // no need because they are destroyed already from statusView->clear();
615 //}
616 svIndex.clear();
617
618 QTreeWidgetItem* svGeneralNode = new QTreeWidgetItem(statusView);
619 svIndex.insert(pair<string, QTreeWidgetItem*>("general", svGeneralNode));
620 svGeneralNode -> setText(0, "General");
621 QTreeWidgetItem* svYearItem = new QTreeWidgetItem(svGeneralNode);
622 svIndex.insert(pair<string, QTreeWidgetItem*>("general_year", svYearItem));
623 svYearItem->setText(0, "year");
624 svYearItem->setText(1, "0");
625 QTreeWidgetItem* svTotalPlotsItem = new QTreeWidgetItem(svGeneralNode);
626 svIndex.insert(pair<string, QTreeWidgetItem*>("general_total plots", svTotalPlotsItem));
627 svTotalPlotsItem->setText(0, "total plots");
628 svTotalPlotsItem->setText(1, "0");
629 QTreeWidgetItem* svTotalLandItem = new QTreeWidgetItem(svGeneralNode);
630 svIndex.insert(pair<string, QTreeWidgetItem*>("general_total land", svTotalLandItem));
631 svTotalLandItem->setText(0, "total land");
632 QTreeWidgetItem* svTotalAgrLandItem = new QTreeWidgetItem(svGeneralNode);
633 svIndex.insert(pair<string, QTreeWidgetItem*>("general_total agr land", svTotalAgrLandItem));
634 svTotalAgrLandItem->setText(0, "total agr land");
635 QTreeWidgetItem* svOwnedAgrLandItem = new QTreeWidgetItem(svGeneralNode);
636 svIndex.insert(pair<string, QTreeWidgetItem*>("general_owned agr land", svOwnedAgrLandItem));
637 svOwnedAgrLandItem->setText(0, "owned agr land");
638 QTreeWidgetItem* svRentedAgrLandItem = new QTreeWidgetItem(svGeneralNode);
639 svIndex.insert(pair<string, QTreeWidgetItem*>("general_rented agr land", svRentedAgrLandItem));
640 svRentedAgrLandItem->setText(0, "rented agr land");
641
642 QTreeWidgetItem* svManagersNode = new QTreeWidgetItem(statusView);
643 svIndex.insert(pair<string, QTreeWidgetItem*>("managers", svManagersNode));
644 svManagersNode->setText(0,"Managers");
645
646 QTreeWidgetItem* svAgentsNode = new QTreeWidgetItem(statusView);
647 svIndex.insert(pair<string, QTreeWidgetItem*>("agents", svAgentsNode));
648 svAgentsNode->setText(0,"Agents");
649
650 // reset layer selector
651 layerSelector->clear();
652 // reset pixel info area
653 pxInfoArea->setHtml("<i>Tip: Right click over a plot to retrieve its values across layers.</i>");
654 // reset log area
655 logArea->clear();
656 // reset map
657
658 if (simulationCounter) logArea->append("***WARNING: You are running more simulations from the GUI without closing/reopening it. It should works, but there are no guarantees. The best way is to run only one simulation from the GUI, eventually closing and opening FFSM again for further simulations.");
659 simulationCounter++;
660
661}
map< string, QTreeWidgetItem * > svIndex
Map containing the ID and the pointers to the status viewer.
Definition MainWindow.h:132

Referenced by MainWindow().

Here is the caller graph for this function:

◆ resized

void resized ( )
signal

Referenced by MainWindow(), and resizeEvent().

Here is the caller graph for this function:

◆ resizeEvent()

void resizeEvent ( QResizeEvent *  event)
protected

Manage the event of resizing the application.

Definition at line 193 of file MainWindow.cpp.

193 {
194 emit resized();
195}
Here is the call graph for this function:

◆ save

bool save ( )
privateslot

Definition at line 337 of file MainWindow.cpp.

337 {
338 if (curLogFileName.isEmpty()) {
339 return saveAs();
340 } else {
341 cerr <<(curLogFileName.toStdString())<<endl;
342 cerr <<(outputDirName.toStdString())<<endl;
344 }
345 unsavedStatus = false;
346 return true;
347}
bool saveLogFile(const QString &logFileName)

Referenced by MainWindow(), and okToContinue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveAs

bool saveAs ( )
privateslot

Definition at line 350 of file MainWindow.cpp.

350 {
351 QString logFileName = QFileDialog::getSaveFileName(
352 this,
353 tr("Save output log"),
355 tr("Log files (*.log)\n" "All files (*.*)")
356 );
357 if (logFileName.isEmpty())
358 return false;
359 return saveLogFile(logFileName);
360 unsavedStatus = false;
361 return true;
362}

Referenced by MainWindow(), and save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveLogFile()

bool saveLogFile ( const QString &  logFileName)

Definition at line 365 of file MainWindow.cpp.

365 {
366 QFile file(logFileName);
367 if (!file.open(QIODevice::WriteOnly)) {
368 QMessageBox::warning(this, tr("FFSM"),
369 tr("Cannot write log file file %1:\n%2.")
370 .arg(file.fileName())
371 .arg(file.errorString()));
372 return false;
373 }
374 //QString logAreaContent = logArea->toHtml();
375 QString logAreaContent = logArea->toPlainText(); // Also available "toHtml()"
376 QTextStream stream( &file );
377 stream << logAreaContent;
378 file.close();
379
380 setCurrentLogFileName(logFileName);
381 statusBar()->showMessage(tr("Log file saved"), 2000);
382 unsavedStatus = false;
383 return true;
384}

Referenced by save(), and saveAs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectedScenarioName

void selectedScenarioName ( const QString &  scenarioName_h)
signal

◆ setCurrentLogFileName()

void setCurrentLogFileName ( const QString &  fileName)

Definition at line 201 of file MainWindow.cpp.

201 {
202 curLogFileName = fileName;
203}

Referenced by MainWindow(), and saveLogFile().

Here is the caller graph for this function:

◆ setCurrentModelFileName()

void setCurrentModelFileName ( const QString &  fileName)

Definition at line 206 of file MainWindow.cpp.

206 {
207 curModelFileName = fileName;
208 //setWindowModified(false);
210
211 QString shownName = "Untitled";
212 if (!curModelFileName.isEmpty()) {
213 shownName = strippedName(curModelFileName);
214 recentFiles.removeAll(curModelFileName);
217 }
218 setWindowTitle(tr("%2 - [%1]").arg(shownName).arg(tr("FFSM - Forest Sector Simulator")));
219}
QString strippedName(const QString &fullFileName)

Referenced by open(), and openRecentFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setModelFileName()

void setModelFileName ( const QString  curModelFileName_h)
inline

Definition at line 62 of file MainWindow.h.

62{curModelFileName=curModelFileName_h;};

◆ setOutputDirName()

void setOutputDirName ( string  outputDirName_h)
inline

Definition at line 66 of file MainWindow.h.

66{outputDirName = outputDirName_h.c_str();};

Referenced by MainWindow().

Here is the caller graph for this function:

◆ setUnsavedStatus

void setUnsavedStatus ( bool  unsavedStatus_h)
inlineslot

Definition at line 65 of file MainWindow.h.

65{unsavedStatus = unsavedStatus_h;};

Referenced by MainWindow().

Here is the caller graph for this function:

◆ showDocumentation

void showDocumentation ( )
privateslot

Definition at line 585 of file MainWindow.cpp.

585 {
586 QMessageBox::question(this, tr("FFSM Documentation"), // QMessageBox::information or QMessageBox::question
587 tr("<h2>FFSM Documentation</h2>"
588 "<p align=\"justify\">FFSM documentation is organised in three main categories: "
589 "<p align=\"left\">(1) <b>official documentation</b> "
590 "(comprising the <i>User Manual</i> and the <i>Reference Manual</i>); <br>(2) <b>contributed "
591 "documentation</b> (<i>wiki</i>);<br>(3) <b>community project</b> (<i>forum</i> and <i>mailing list</i>). "
592 "<p align=\"justify\">The documentation is located at "
593 "<a href=\"http://www.ffsm-project.org/doc\">http://www.ffsm-project.org/doc</a>"
594 "<p align=\"justify\">If you have chosen to instal a local copy of the documentation, "
595 "you can access it also from the <i>Start menu</i>-><i>Programs</i>-><i>FFSM</i> "
596 "(MS Windows) or directly from the following links (Linux):"
597 "<br><a href=\"doc/userManual/regmasUserManual.pdf\">User Manual</a> "
598 "&nbsp;-&nbsp;<a href=\"doc/referenceManual/html/index.html\">Reference Manual</a> "
599 "<p>Tips:"
600 "<br> - right click on a pixel to get its value across the layers;"
601 "<br> - use the mouse and its wheel over the map to zoom/scroll it;"
602 "</p>"
603 ));
604}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ startModelMainThread

void startModelMainThread ( )
privateslot

Definition at line 394 of file MainWindow.cpp.

394 {
395 if (modelMainThread.isRunning()) {
396 return ;
397 cout <<"It seems that the model is already running..."<<endl;
398 } else {
399 logArea->clear();
400 modelMainThread.start();
401 unsavedStatus=true;
402 }
403}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ stopModelMainThread

void stopModelMainThread ( )
privateslot

Definition at line 406 of file MainWindow.cpp.

406 {
407 if (! modelMainThread.isRunning()) {
408 return ;
409 } else {
411 modelMainThread.wait();
412 }
413}

Referenced by MainWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strippedName()

QString strippedName ( const QString &  fullFileName)

Definition at line 222 of file MainWindow.cpp.

222 {
223 return QFileInfo(fullFileName).fileName();
224}

Referenced by setCurrentModelFileName(), and updateRecentFileActions().

Here is the caller graph for this function:

◆ switchToLayer()

void switchToLayer ( QString  layerName_h)

Perform all the operation needed when switching layer:

  • call mapBox to switch its current layer;
  • call layerLegend to switch its layer); I don't think it is used anywhere, but any how.. it is here...

Definition at line 457 of file MainWindow.cpp.

457 {
458 mapBox->switchToLayer(layerName_h);
459 int index = mapBox->getLayerIndex(layerName_h);
460 layerSelector->setCurrentIndex(index);
461 update();
462}

◆ switchToLayerFromLayerSelector()

void switchToLayerFromLayerSelector ( int  layerIndex_h)

Definition at line 465 of file MainWindow.cpp.

465 {
466 QString layerName= layerSelector->itemData(layerIndex_h, Qt::UserRole ).toString();
467 mapBox->switchToLayer(layerName);
468 update();
469}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ treeViewerAddItem()

void treeViewerAddItem ( string  text,
string  itemID,
string  parentID 
)

e.g. manager_farmer_manager agents or agent_12345_ownedHa

Definition at line 528 of file MainWindow.cpp.

528 {
529 // searching for the parent item...
530 map<string, QTreeWidgetItem*>::iterator p;
531 QTreeWidgetItem *parentItem;
532
533 p=svIndex.find(parentID);
534 if(p != svIndex.end()){
535 parentItem = p->second;
536 QTreeWidgetItem *node = new QTreeWidgetItem(parentItem);
537 svIndex.insert(pair<string, QTreeWidgetItem*>(itemID, node));
538 node->setText(0, text.c_str());
539 }
540 else {
541 QString tempString;
542 QString tempString2 = itemID.c_str();
543 QString tempString3 = parentID.c_str();
544 tempString = "**** ERROR, Coud not add sub item "+tempString2+" to the Model Status Viewer. Parent item ("+tempString3+") doesn't found.";
545 logArea->append(tempString);
546 }
547
548}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ treeViewerItemChangeValue()

void treeViewerItemChangeValue ( string  itemID,
string  newValue 
)

Change value to an existing item in the Status Viewer.

Definition at line 485 of file MainWindow.cpp.

485 {
486
487 map<string, QTreeWidgetItem*>::iterator p;
488 p=svIndex.find(itemID);
489 if(p != svIndex.end())
490 p->second->setText(1,newValue.c_str());
491 else {
492 QString tempString;
493 QString tempString2 = itemID.c_str();
494 tempString = "**** ERROR, Coud not change value for item "+tempString2+" in the Model Status Viewer. Item doesn't found.";
495 logArea->append(tempString);
496 }
497 return;
498
499}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ treeViewerItemRemove()

void treeViewerItemRemove ( string  itemID)

Definition at line 502 of file MainWindow.cpp.

502 {
503 map<string, QTreeWidgetItem*>::iterator p;
504 p=svIndex.find(itemID);
505 if(p != svIndex.end()){
506 QTreeWidgetItem *parent = p->second->parent();
507 int index;
508 if (parent) {
509 index = parent->indexOfChild(p->second); //DONE: check if it works !!! While it should not ???? After 15 years of simulation agents should be deleted, but htey are still here in the tree.. mayme it is true it is NOT working!!! To be checken. 20071108: It works, it works.. agents are deleted when go out of the model
510 delete parent->takeChild(index);
511 svIndex.erase(p);
512 } else {
513 QString tempString = "**** ERROR, I will not delete a top level item in the Model Satus Viewer";
514 logArea->append(tempString);
515 }
516
517 }
518 else {
519 QString tempString;
520 QString tempString2 = itemID.c_str();
521 tempString = "**** ERROR, Coud not delete for item "+tempString2+" in the Model Status Viewer. Item doesn't found.";
522 //logArea->append(tempString); //20080111 lots of this errors when re-starting a simulation, so hidding them
523 }
524 return;
525}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ updateImage()

void updateImage ( QString  layerName_h,
const QImage &  image_h 
)

Definition at line 478 of file MainWindow.cpp.

478 {
479 mapBox->updateImage(layerName_h, image_h);
480 update();
481}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ updatePixel()

void updatePixel ( QString  layerName_h,
int  x_h,
int  y_h,
QColor  color_h 
)

Definition at line 472 of file MainWindow.cpp.

472 {
473 mapBox->updatePixel(layerName_h,x_h,y_h,color_h.rgb());
474 update();
475}

Referenced by MainWindow().

Here is the caller graph for this function:

◆ updateRecentFileActions()

void updateRecentFileActions ( )
private

Definition at line 227 of file MainWindow.cpp.

227 {
228 QMutableStringListIterator i(recentFiles);
229 while (i.hasNext()) {
230 if (!QFile::exists(i.next()))
231 i.remove();
232 }
233
234 for (int j = 0; j < MaxRecentFiles; ++j) {
235 if (j < recentFiles.count()) {
236 QString text = tr("&%1 %2")
237 .arg(j + 1)
238 .arg(strippedName(recentFiles.at(j)));
239 //cerr <<text.toStdString()<<endl;
240 recentFileActions[j]->setText(text);
241 recentFileActions[j]->setData(recentFiles.at(j));
242 recentFileActions[j]->setVisible(true);
243 } else {
244 recentFileActions[j]->setVisible(false);
245 }
246 }
247 separatorAction->setVisible(!recentFiles.isEmpty());
248}

Referenced by readSettings(), and setCurrentModelFileName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeSettings()

void writeSettings ( )
private

Definition at line 386 of file MainWindow.cpp.

386 {
387 QSettings settings("LEF", "FFSM");
388 settings.setValue("recentFiles", recentFiles);
389}

Referenced by closeEvent().

Here is the caller graph for this function:

Member Data Documentation

◆ curBaseDirectory

QString curBaseDirectory
private

Definition at line 114 of file MainWindow.h.

Referenced by MainWindow(), open(), openRecentFile(), and openResults().

◆ curLogFileName

QString curLogFileName
private

Definition at line 112 of file MainWindow.h.

Referenced by MainWindow(), save(), and setCurrentLogFileName().

◆ curModelFileName

QString curModelFileName
private

◆ debugMsgsEnable

bool debugMsgsEnable
private

Allow debug messages to be show in the logArea.

Definition at line 119 of file MainWindow.h.

Referenced by hideDebugMsgs(), MainWindow(), and processLogArea().

◆ mainSBLabel

QLabel* mainSBLabel
private

Status bar main label.

Definition at line 109 of file MainWindow.h.

Referenced by createStatusBar(), and MainWindow().

◆ modelMainThread

◆ outputDirName

QString outputDirName
private

Definition at line 111 of file MainWindow.h.

Referenced by MainWindow(), openResults(), save(), saveAs(), and setOutputDirName().

◆ recentFileActions

QAction* recentFileActions[MaxRecentFiles]
private

Definition at line 117 of file MainWindow.h.

Referenced by MainWindow(), and updateRecentFileActions().

◆ recentFiles

QStringList recentFiles
private

◆ scenarioWidget

ScenarioSelectionWidget* scenarioWidget
private

Definition at line 120 of file MainWindow.h.

Referenced by MainWindow(), and receiveScenarioOptions().

◆ separatorAction

QAction* separatorAction
private

Definition at line 118 of file MainWindow.h.

Referenced by MainWindow(), and updateRecentFileActions().

◆ svIndex

map<string, QTreeWidgetItem*> svIndex
private

Map containing the ID and the pointers to the status viewer.

Ids are based on the name of the item:

  • general
  • general_{name}
  • managers
  • manager_{managerID}
  • manager_{managerID}_{name}
  • agents
  • agent_{agentUniqueID}
  • agent_{agentUniqueID}_{name}

Definition at line 132 of file MainWindow.h.

Referenced by resetGUIForNewSimulation(), treeViewerAddItem(), treeViewerItemChangeValue(), and treeViewerItemRemove().

◆ unsavedStatus

bool unsavedStatus
private

◆ yearSBLabel

QLabel* yearSBLabel
private

Status bar current year label.

Definition at line 108 of file MainWindow.h.

Referenced by createStatusBar(), and MainWindow().


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