Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

omgexperimentprinter.cpp

Go to the documentation of this file.
00001  /***************************************************************************
00002  *   Copyright (C) 2005 by Tim Sutton   *
00003  *   tim@linfiniti.com   *
00004  *                                                                         *
00005  *   This program is free software{} you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation{} either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY{} without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program{} if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <omgexperimentprinter.h>
00022 #include <omgexperiment.h>
00023 #include <omgmodel.h>
00024 #include <omgui.h>
00025 #include <QDebug>
00026 #include <QCoreApplication>
00027 #include <QPrinter>
00028 #include <QTextDocument>
00029 #include <QVariant>
00030 #include <QUrl>
00031 #include <QMap>
00032 OmgExperimentPrinter::OmgExperimentPrinter() : QThread()
00033 {
00034 
00035 }
00036 OmgExperimentPrinter::~OmgExperimentPrinter()
00037 {
00038 
00039 }
00040 
00041 void OmgExperimentPrinter::run()
00042 {
00043   mMutex.lock();
00044   //create the text document with the report content
00045   //@TODO see if we cant stream directly out to the
00046   //print device
00047   QTextDocument myTextDocument;
00048   myTextDocument.setDefaultStyleSheet(Omgui::defaultStyleSheet());
00049   QString myReport;
00050   myReport += Omgui::getHtmlHeader();
00051   myReport += mpExperiment->toPrintHtml();
00052   
00053   // 
00054   // First get a list of all layersets, taxa and algs used
00055   // 
00056   QMap<QString,OmgAlgorithm> myAlgorithmMap;
00057   QMap<QString,OmgLayerSet> myLayerSetMap;
00058   QStringList myTaxonNameList;
00059   int myCount = mpExperiment->count();
00060   emit maximum(myCount);
00061   for (int i=0; i<myCount; i++)
00062   {
00063     OmgModel * mypModel=mpExperiment->getModel(i);
00064     if (mypModel==NULL)
00065     {
00066       continue;
00067     }
00068     
00069     //
00070     // Projection Layersets
00071     //
00072     
00073     QString myLayerSetName = mypModel->projectionLayerSet().name();
00074     if (!myLayerSetMap.contains(myLayerSetName))
00075     {
00076       myLayerSetMap.insert(myLayerSetName, mypModel->projectionLayerSet());
00077     }
00078 
00079     //
00080     // Algorithms
00081     //
00082     
00083     QString myAlgorithmName = mypModel->algorithm().name();
00084     if (!myAlgorithmMap.contains(myAlgorithmName))
00085     {
00086       myAlgorithmMap.insert(myAlgorithmName, mypModel->algorithm());
00087     }
00088     
00089     //
00090     // Taxa
00091     //
00092 
00093     QString myTaxonName = mypModel->taxonName();
00094     if (!myTaxonNameList.contains(myTaxonName))
00095     {
00096       myTaxonNameList << myTaxonName;
00097     }
00098   }
00099   qSort(myTaxonNameList.begin(), myTaxonNameList.end());
00100   //
00101   // Print thumbnail summary view by taxon
00102   //
00103   myReport += "<center><h2 style=\"page-break-before:always;\">" + tr("Overview of Model Projections by Taxon") + "</h2></center>";
00104   bool myPageBreakNeededFlag = false;
00105   QStringListIterator myTaxonNameIterator(myTaxonNameList);
00106   while (myTaxonNameIterator.hasNext())
00107   {
00108     QString myTaxonName = myTaxonNameIterator.next();
00109     //qDebug() << "Generating thumbnail list for: " << myTaxonName;
00110     if (myPageBreakNeededFlag)
00111     {
00112       myReport += "<center><h2 class=\"glossyBlue\" style=\"page-break-before:always;\">" + myTaxonName + "</h2></center>";
00113     }
00114     else
00115     {
00116       //first page break  is not needed
00117       myReport += "<center><h2 class=\"glossyBlue\">" + myTaxonName + "</h2></center>";
00118       myPageBreakNeededFlag = true;
00119     }
00120     myReport += mpExperiment->toTaxonSummaryHtml(myTaxonName);
00121   }
00122   //
00123   // Print thumbnail summary view by algorithm
00124   //
00125   /*
00126   QStringList myAlgorithmNameList = myAlgorithmMap.keys();
00127   qSort(myAlgorithmNameList.begin(), myAlgorithmNameList.end());
00128   QStringListIterator myIterator(myNameList);
00129   while (myIterator.hasNext())
00130   {
00131     QString myAlgorithmName = myIterator.next();
00132     myReport += mpExperiment->toAlgorithmSummaryHtml(myAlgorithmName);
00133   }
00134   */
00135   
00136   //
00137   // Print each layerst profile used in the experiment
00138   //
00139   //qSort(myLayerSetMap.begin(), myLayerSetMap.end());
00140   myReport += "<center><h2 style=\"page-break-before:always;\">" + tr("Summary of LayerSet Profiles") + "</h2>";
00141   myPageBreakNeededFlag = false;
00142   QMapIterator<QString,OmgLayerSet> myLayerSetIterator(myLayerSetMap);
00143   while (myLayerSetIterator.hasNext())
00144   {
00145     myLayerSetIterator.next();
00146     OmgLayerSet myLayerSet = myLayerSetIterator.value();
00147     if (myPageBreakNeededFlag)
00148     {
00149       myReport += "<h2 style=\"page-break-before:always;\"> </h2>";
00150     }
00151     else
00152     {
00153       //first page break  is not needed
00154       myPageBreakNeededFlag = true;
00155     }
00156     myReport += myLayerSet.toHtml();
00157   }
00158   
00159   //
00160   // Print each algorithm profile used in the experiment
00161   //
00162   //qSort(myAlgorithmMap.begin(), myAlgorithmMap.end());
00163   myReport += "<center><h2 style=\"page-break-before:always;\">" + tr("Summary of Algorithm Profiles") + "</h2></center>";
00164   myPageBreakNeededFlag = false;
00165   QMapIterator<QString,OmgAlgorithm> myAlgorithmtIterator(myAlgorithmMap);
00166   while (myAlgorithmtIterator.hasNext())
00167   {
00168     myAlgorithmtIterator.next();
00169     OmgAlgorithm myAlgorithm = myAlgorithmtIterator.value();
00170     if (myPageBreakNeededFlag)
00171     {
00172       myReport += "<h2 style=\"page-break-before:always;\"> </h2>";
00173     }
00174     else
00175     {
00176       //first page break  is not needed
00177       myPageBreakNeededFlag = true;
00178     }
00179     myReport += myAlgorithm.toHtml();
00180   }
00181   //
00182   // Print the detailed report for each model
00183   //
00184   myReport += "<center><h2 style=\"page-break-before:always;\">" + 
00185     tr("Detailed Model Reports") + "</h2></center>";
00186   myPageBreakNeededFlag = false;
00187   for (int i=0; i<myCount; i++)
00188   {
00189     OmgModel *  mypModel=mpExperiment->getModel(i);
00190     if (mypModel==NULL)
00191     {
00192       //emit logMessage("Model is null is NULL, skipping");
00193       continue;
00194     }
00195     if (myPageBreakNeededFlag)
00196     {
00197       myReport += "<h2 style=\"page-break-before:always;\"> </h2>";
00198     }
00199     else
00200     {
00201       //first page break  is not needed
00202       myPageBreakNeededFlag = true;
00203     }
00204     myReport += mypModel->toPrintHtml();  
00205     emit progress(i);
00206     QCoreApplication::processEvents();
00207   }
00208   myReport += Omgui::getHtmlFooter();
00209   myTextDocument.setHtml(myReport);
00210   myTextDocument.print(&mPrinter);
00211   emit progress(myCount);
00212   emit done();
00213   mMutex.unlock();
00214 }
00215 bool OmgExperimentPrinter::isRunning()
00216 {
00217  return mRunningFlag; 
00218 }
00220 void OmgExperimentPrinter::stop()
00221 {
00222 
00223 }
00224 
00225 void OmgExperimentPrinter::setPrinter(QPrinter &thePrinter)
00226 {
00227   mPrinter.setOutputFormat(thePrinter.outputFormat()) ;
00228   mPrinter.setOutputFileName(thePrinter.outputFileName()) ;
00229   mPrinter.setDocName("openModellerDesktopExperimentReport");
00230 }
00231 void OmgExperimentPrinter::setExperiment(OmgExperiment * thepExperiment)
00232 {
00233   mpExperiment = thepExperiment;
00234 }

Generated on Mon Apr 28 15:08:27 2008 for openModellerDesktop by  doxygen 1.4.1-20050210