FFSM++  1.1.0
French Forest Sector Model ++
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. More...
 
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. More...
 
void treeViewerItemRemove (string itemID)
 
void treeViewerAddItem (string text, string itemID, string parentID)
 e.g. manager_farmer_manager agents or agent_12345_ownedHa More...
 
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. More...
 
void receiveScenarioOptions (const QVector< QString > &scenarios_h)
 

Protected Member Functions

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

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. More...
 
QLabel * mainSBLabel
 Status bar main label. More...
 
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. More...
 
ScenarioSelectionWidgetscenarioWidget
 
map< string, QTreeWidgetItem * > svIndex
 Map containing the ID and the pointers to the status viewer. More...
 

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
private
Enumerator
MaxRecentFiles 

Definition at line 116 of file MainWindow.h.

Constructor & Destructor Documentation

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/";
54  curLogFileName ="";
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 
69  readSettings();
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 createStatusBar()
Definition: MainWindow.cpp:160
void openRecentFile()
Definition: MainWindow.cpp:319
bool save()
Definition: MainWindow.cpp:337
void startModelMainThread()
Definition: MainWindow.cpp:394
void hideDebugMsgs(bool hide)
Definition: MainWindow.cpp:564
void setCurrentLogFileName(const QString &fileName)
Definition: MainWindow.cpp:201
QString curBaseDirectory
Definition: MainWindow.h:114
void stopModelMainThread()
Definition: MainWindow.cpp:406
QString curLogFileName
Definition: MainWindow.h:112
void setUnsavedStatus(bool unsavedStatus_h)
Definition: MainWindow.h:65
void pauseOrResumeModelMainThread()
Definition: MainWindow.cpp:416
void open()
Definition: MainWindow.cpp:289
bool unsavedStatus
Definition: MainWindow.h:110
bool saveAs()
Definition: MainWindow.cpp:350
void updatePixel(QString layerName_h, int x_h, int y_h, QColor color_h)
Definition: MainWindow.cpp:472
void treeViewerItemRemove(string itemID)
Definition: MainWindow.cpp:502
void about()
Definition: MainWindow.cpp:570
void resized()
QAction * separatorAction
Definition: MainWindow.h:118
QLabel * yearSBLabel
Status bar current year label.
Definition: MainWindow.h:108
void treeViewerAddItem(string text, string itemID, string parentID)
e.g. manager_farmer_manager agents or agent_12345_ownedHa
Definition: MainWindow.cpp:528
bool debugMsgsEnable
Allow debug messages to be show in the logArea.
Definition: MainWindow.h:119
void readSettings()
Definition: MainWindow.cpp:312
QString curModelFileName
Definition: MainWindow.h:113
void setInputFileName(QString inputFileName_h)
QAction * recentFileActions[MaxRecentFiles]
Definition: MainWindow.h:117
void setOutputDirName(string outputDirName_h)
Definition: MainWindow.h:66
void openResults()
Definition: MainWindow.cpp:680
QLabel * mainSBLabel
Status bar main label.
Definition: MainWindow.h:109
void processLogArea(const QString &message_h)
Definition: MainWindow.cpp:552
void resetGUIForNewSimulation()
Reset the graphical elements for a new simulation // Send the request of getting the pixel info to th...
Definition: MainWindow.cpp:607
void updateImage(QString layerName_h, const QImage &image_h)
Definition: MainWindow.cpp:478
void treeViewerItemChangeValue(string itemID, string newValue)
Change value to an existing item in the Status Viewer.
Definition: MainWindow.cpp:485
void showDocumentation()
Definition: MainWindow.cpp:585
void receiveScenarioOptions(const QVector< QString > &scenarios_h)
Definition: MainWindow.cpp:664
QString outputDirName
Definition: MainWindow.h:111
void switchToLayerFromLayerSelector(int layerIndex_h)
Definition: MainWindow.cpp:465
void addLayer(QString layerName_h, QString layerLabel_h)
Definition: MainWindow.cpp:440
ScenarioSelectionWidget * scenarioWidget
Definition: MainWindow.h:120
ThreadManager modelMainThread
Definition: MainWindow.h:107

Member Function Documentation

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 }
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 }
void closeEvent ( QCloseEvent *  event)
protected

Manage the event of closing the application.

Definition at line 181 of file MainWindow.cpp.

181  {
182  if (okToContinue()) {
183  writeSettings();
185  modelMainThread.wait();
186  event->accept();
187  } else {
188  event->ignore();
189  }
190 }
bool okToContinue()
Definition: MainWindow.cpp:251
void writeSettings()
Definition: MainWindow.cpp:386
ThreadManager modelMainThread
Definition: MainWindow.h:107
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 }
QLabel * yearSBLabel
Status bar current year label.
Definition: MainWindow.h:108
QLabel * mainSBLabel
Status bar main label.
Definition: MainWindow.h:109
ThreadManager modelMainThread
Definition: MainWindow.h:107
void currentModelFilenameChanged ( QString  )
signal
QString getModelFileName ( )
inline

Definition at line 61 of file MainWindow.h.

61 {return curModelFileName;};
QString curModelFileName
Definition: MainWindow.h:113
void hideDebugMsgs ( bool  hide)
privateslot

Definition at line 564 of file MainWindow.cpp.

564  {
565  if(hide) debugMsgsEnable = false;
566  else debugMsgsEnable = true;
567 }
bool debugMsgsEnable
Allow debug messages to be show in the logArea.
Definition: MainWindow.h:119
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 }
bool save()
Definition: MainWindow.cpp:337
bool unsavedStatus
Definition: MainWindow.h:110
ThreadManager modelMainThread
Definition: MainWindow.h:107
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 }
QString curBaseDirectory
Definition: MainWindow.h:114
bool okToContinue()
Definition: MainWindow.cpp:251
void setCurrentModelFileName(const QString &fileName)
Definition: MainWindow.cpp:206
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 }
QString curBaseDirectory
Definition: MainWindow.h:114
bool okToContinue()
Definition: MainWindow.cpp:251
QString curModelFileName
Definition: MainWindow.h:113
void setCurrentModelFileName(const QString &fileName)
Definition: MainWindow.cpp:206
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 }
QString curBaseDirectory
Definition: MainWindow.h:114
QString outputDirName
Definition: MainWindow.h:111
void pauseOrResumeModelMainThread ( )
privateslot

Definition at line 416 of file MainWindow.cpp.

416  {
418 }
ThreadManager modelMainThread
Definition: MainWindow.h:107
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 }
bool debugMsgsEnable
Allow debug messages to be show in the logArea.
Definition: MainWindow.h:119
void readSettings ( )
private

Definition at line 312 of file MainWindow.cpp.

312  {
313  QSettings settings("LEF", "FFSM");
314  recentFiles = settings.value("recentFiles").toStringList();
316 }
QStringList recentFiles
Definition: MainWindow.h:115
void updateRecentFileActions()
Definition: MainWindow.cpp:227
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)
ScenarioSelectionWidget * scenarioWidget
Definition: MainWindow.h:120
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
void resized ( )
signal
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 }
void resized()
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;
343  return saveLogFile(curLogFileName);
344  }
345  unsavedStatus = false;
346  return true;
347 }
QString curLogFileName
Definition: MainWindow.h:112
bool unsavedStatus
Definition: MainWindow.h:110
bool saveAs()
Definition: MainWindow.cpp:350
bool saveLogFile(const QString &logFileName)
Definition: MainWindow.cpp:365
QString outputDirName
Definition: MainWindow.h:111
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 }
bool unsavedStatus
Definition: MainWindow.h:110
bool saveLogFile(const QString &logFileName)
Definition: MainWindow.cpp:365
QString outputDirName
Definition: MainWindow.h:111
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 }
void setCurrentLogFileName(const QString &fileName)
Definition: MainWindow.cpp:201
bool unsavedStatus
Definition: MainWindow.h:110
void selectedScenarioName ( const QString &  scenarioName_h)
signal
void setCurrentLogFileName ( const QString &  fileName)

Definition at line 201 of file MainWindow.cpp.

201  {
202  curLogFileName = fileName;
203 }
QString curLogFileName
Definition: MainWindow.h:112
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);
215  recentFiles.prepend(curModelFileName);
217  }
218  setWindowTitle(tr("%2 - [%1]").arg(shownName).arg(tr("FFSM - Forest Sector Simulator")));
219 }
QStringList recentFiles
Definition: MainWindow.h:115
QString strippedName(const QString &fullFileName)
Definition: MainWindow.cpp:222
QString curModelFileName
Definition: MainWindow.h:113
void setInputFileName(QString inputFileName_h)
void updateRecentFileActions()
Definition: MainWindow.cpp:227
ThreadManager modelMainThread
Definition: MainWindow.h:107
void setModelFileName ( const QString  curModelFileName_h)
inline

Definition at line 62 of file MainWindow.h.

62 {curModelFileName=curModelFileName_h;};
QString curModelFileName
Definition: MainWindow.h:113
void setOutputDirName ( string  outputDirName_h)
inline

Definition at line 66 of file MainWindow.h.

66 {outputDirName = outputDirName_h.c_str();};
QString outputDirName
Definition: MainWindow.h:111

Here is the call graph for this function:

void setUnsavedStatus ( bool  unsavedStatus_h)
inlineslot

Definition at line 65 of file MainWindow.h.

65 {unsavedStatus = unsavedStatus_h;};
bool unsavedStatus
Definition: MainWindow.h:110
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 }
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 }
bool unsavedStatus
Definition: MainWindow.h:110
ThreadManager modelMainThread
Definition: MainWindow.h:107
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 }
ThreadManager modelMainThread
Definition: MainWindow.h:107
QString strippedName ( const QString &  fullFileName)

Definition at line 222 of file MainWindow.cpp.

222  {
223  return QFileInfo(fullFileName).fileName();
224 }
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 }
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 }
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 }
def text(cat, text_h)
map< string, QTreeWidgetItem * > svIndex
Map containing the ID and the pointers to the status viewer.
Definition: MainWindow.h:132
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 }
map< string, QTreeWidgetItem * > svIndex
Map containing the ID and the pointers to the status viewer.
Definition: MainWindow.h:132
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 }
map< string, QTreeWidgetItem * > svIndex
Map containing the ID and the pointers to the status viewer.
Definition: MainWindow.h:132
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 }
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 }
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 }
QStringList recentFiles
Definition: MainWindow.h:115
def text(cat, text_h)
QString strippedName(const QString &fullFileName)
Definition: MainWindow.cpp:222
QAction * separatorAction
Definition: MainWindow.h:118
QAction * recentFileActions[MaxRecentFiles]
Definition: MainWindow.h:117

Here is the call graph for this function:

void writeSettings ( )
private

Definition at line 386 of file MainWindow.cpp.

386  {
387  QSettings settings("LEF", "FFSM");
388  settings.setValue("recentFiles", recentFiles);
389 }
QStringList recentFiles
Definition: MainWindow.h:115

Member Data Documentation

QString curBaseDirectory
private

Definition at line 114 of file MainWindow.h.

QString curLogFileName
private

Definition at line 112 of file MainWindow.h.

QString curModelFileName
private

Definition at line 113 of file MainWindow.h.

bool debugMsgsEnable
private

Allow debug messages to be show in the logArea.

Definition at line 119 of file MainWindow.h.

QLabel* mainSBLabel
private

Status bar main label.

Definition at line 109 of file MainWindow.h.

ThreadManager modelMainThread
private

Definition at line 107 of file MainWindow.h.

QString outputDirName
private

Definition at line 111 of file MainWindow.h.

QAction* recentFileActions[MaxRecentFiles]
private

Definition at line 117 of file MainWindow.h.

QStringList recentFiles
private

Definition at line 115 of file MainWindow.h.

ScenarioSelectionWidget* scenarioWidget
private

Definition at line 120 of file MainWindow.h.

QAction* separatorAction
private

Definition at line 118 of file MainWindow.h.

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.

bool unsavedStatus
private

Definition at line 110 of file MainWindow.h.

QLabel* yearSBLabel
private

Status bar current year label.

Definition at line 108 of file MainWindow.h.


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