Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

TrapperDoc Class Reference

TrapperDoc provides a document object for a document-view model. More...

#include <trapperdoc.h>

List of all members.

Public Slots

void updateAllViews (TrapperView *sender)

Public Member Functions

 TrapperDoc (DbEnv *dbenv)
 ~TrapperDoc ()
void addView (TrapperView *view)
void removeView (TrapperView *view)
void changedViewList ()
TrapperViewfirstView ()
bool isLastView ()
bool canCloseFrame (TrapperView *pFrame)
void setModified (bool _m=true)
bool isModified ()
void deleteContents ()
bool newDocument ()
void closeDocument ()
bool openDocument (const QString &dirname, const char *format=0)
bool saveDocument (const QString &filename, const char *format=0)
void setPathName (const QString &name)
const QString & pathName () const
void setTitle (const QString &title)
const QString & title () const
void saveExport (ostream &stream)
bool import (QDomElement &elem)
void importChromat (const QString &dirname)
void importMates (const QString &filename)
void importPhd (const QString &dirname)
std::vector< std::string > all_readnames ()
void openDbs ()
void closeDbs ()
TrDbfindTrDb (string)
void changedAlgoList ()
void addAlgorithm (Algo *)
void removeAlgorithm (Algo *)
QString getStatistics ()

Private Attributes

bool modified
QString m_title
QString m_filename
QList< TrapperView > * pViewList
QList< Algo > * pAlgoList
TrDbMap trDbMap
QString m_contigDir
DbEnv * dbenv

Friends

class TrapperView


Detailed Description

TrapperDoc provides a document object for a document-view model.

The TrapperDoc class provides a document object that can be used in conjunction with the classes TrapperApp and TrapperView to create a document-view model for MDI (Multiple Document Interface) Qt 2.1 applications based on QApplication and QMainWindow as main classes and QWorkspace as MDI manager widget. Thereby, the document object is created by the TrapperApp instance (and kept in a document list) and contains the document structure with the according methods for manipulating the document data by TrapperView objects. Also, TrapperDoc contains the methods for serialization of the document data from and to files.

Author:
Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
Version:
KDevelop version 1.1 code generation

Definition at line 56 of file trapperdoc.h.


Constructor & Destructor Documentation

TrapperDoc::TrapperDoc DbEnv *  dbenv  ) 
 

Constructor for the fileclass of the application

Definition at line 43 of file trapperdoc.cpp.

References pAlgoList, pViewList, and setModified().

00043                                     : dbenv( dbenv_ )
00044 {
00045     qDebug("in TrapperDoc::TrapperDoc()");
00046     pViewList = new QList<TrapperView>;
00047 //     pViewList->setAutoDelete(false);
00048     pViewList->setAutoDelete(true);
00049     pAlgoList = new QList<Algo>;
00050     pAlgoList->setAutoDelete(false);
00051     setModified(true );
00052 }

TrapperDoc::~TrapperDoc  ) 
 

Destructor for the fileclass of the application

Definition at line 54 of file trapperdoc.cpp.

References closeDbs(), pAlgoList, and pViewList.

00055 {
00056   cerr<<"closing doc"<<endl;
00057   delete pViewList;
00058   delete pAlgoList;
00059   closeDbs();
00060 }


Member Function Documentation

void TrapperDoc::addAlgorithm Algo  ) 
 

adds an algorithm to the document which represents the document contents.

Definition at line 68 of file trapperdoc.cpp.

References changedAlgoList(), and pAlgoList.

Referenced by TrapperView::runAlgo().

00069 {
00070     pAlgoList->append(algo);
00071     changedAlgoList();
00072 }

void TrapperDoc::addView TrapperView view  ) 
 

adds a view to the document which represents the document contents. Usually this is your main view.

Definition at line 62 of file trapperdoc.cpp.

References changedViewList(), and pViewList.

Referenced by TrapperApp::createClient().

00063 {
00064     pViewList->append(view);
00065     changedViewList();
00066 }

vector< string > TrapperDoc::all_readnames  ) 
 

Helper function for importing

Definition at line 636 of file trapperdoc.cpp.

References Database::SecondaryIterator< T >::answer(), Database::SecondaryIterator< T >::first(), ReadData::name(), and Database::SecondaryIterator< T >::next().

Referenced by importChromat(), importMates(), and importPhd().

00637 {
00638   vector<string> names;
00639 
00640   Database::SecondaryIterator<ReadData> name_it( "name", this, "ReadData" );
00641   assert(name_it.first() == 0);
00642   string name;
00643   
00644   do {
00645     name = name_it.answer()->name().c_str();
00646     names.push_back(name);//Have to use c_str() due to some straaange bug...
00647   }while( name_it.next() == 0 );
00648   
00649   return names;
00650   
00651 }

bool TrapperDoc::canCloseFrame TrapperView pFrame  ) 
 

This method gets called when the user is about to close a frame window. It checks, if more than one view is connected to the document (then the frame can be closed), if pFrame is the last view and the document is modified, the user gets asked if he wants to save the document.

Definition at line 232 of file trapperdoc.cpp.

References isLastView(), isModified(), pathName(), saveDocument(), and title().

Referenced by TrapperApp::eventFilter().

00233 {
00234     if(!isLastView())
00235         return true;
00236 
00237     bool ret=false;
00238     if(isModified())
00239     {
00240         QString saveName;
00241         switch(QMessageBox::information(pFrame, title(), tr("The current file has been modified.\n"
00242                                         "Do you want to save it?"),QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel ))
00243         {
00244         case QMessageBox::Yes:
00245             if(title().contains(tr("Untitled")))
00246             {
00247                 saveName=QFileDialog::getSaveFileName(0, 0, pFrame);
00248                 if(saveName.isEmpty())
00249                     return false;
00250             }
00251             else
00252                 saveName=pathName();
00253 
00254             if(!saveDocument(saveName))
00255             {
00256                 switch(QMessageBox::critical(pFrame, tr("I/O Error !"), tr("Could not save the current document !\n"
00257                                              "Close anyway ?"),QMessageBox::Yes ,QMessageBox::No))
00258 
00259                 {
00260                 case QMessageBox::Yes:
00261                     ret=true;
00262                 case QMessageBox::No:
00263                     ret=false;
00264                 }
00265             }
00266             else
00267                 ret=true;
00268             break;
00269         case QMessageBox::No:
00270             ret=true;
00271             break;
00272         case QMessageBox::Cancel:
00273         default:
00274             ret=false;
00275             break;
00276         }
00277     }
00278     else
00279         ret=true;
00280 
00281     return ret;
00282 }

void TrapperDoc::changedAlgoList  ) 
 

gets called if a algorithm is removed or added

Definition at line 115 of file trapperdoc.cpp.

Referenced by addAlgorithm(), and removeAlgorithm().

00116 {
00117 }

void TrapperDoc::changedViewList  ) 
 

gets called if a view is removed or added

Definition at line 94 of file trapperdoc.cpp.

References m_title, TrapperView::mode(), and pViewList.

Referenced by addView(), removeView(), TrapperApp::slotFileSaveAs(), and TrapperView::slotSwitchToMode().

00095 {
00096 
00097     TrapperView *w;
00098     if((int)pViewList->count() == 1)
00099     {
00100         w=pViewList->first();
00101         QString mode = w->mode();
00102         w->setCaption(QString(m_title+" mode=%2").arg(mode));
00103     }
00104     else
00105     {
00106         int i;
00107         for( i=1,w=pViewList->first(); w!=0; i++, w=pViewList->next())
00108         {
00109             QString mode = w->mode();
00110             w->setCaption(QString(m_title+" :%1 mode=%2").arg(i).arg(mode));
00111         }
00112     }
00113 }

void TrapperDoc::closeDbs  ) 
 

Definition at line 705 of file trapperdoc.cpp.

References trDbMap.

Referenced by ~TrapperDoc().

00706 {
00707 
00708   TrDbMap::iterator it;
00709   it = trDbMap.begin();
00710 
00711   while (it != trDbMap.end()) {
00712     Q_CHECK_PTR( it->second );
00713     it->second->close();
00714     delete it->second;
00715     ++it;
00716   }
00717   trDbMap.clear();
00718 }

void TrapperDoc::closeDocument  ) 
 

closes the acutal document

Definition at line 154 of file trapperdoc.cpp.

References isLastView(), and pViewList.

Referenced by TrapperApp::slotFileClose().

00155 {
00156   cerr<<"closeDocument()"<<endl;
00157   TrapperView *w;
00158   if(!isLastView()) {
00159     for(w=pViewList->first(); w!=0; w=pViewList->next()) {
00160       if(!w->close())
00161         break;
00162     }
00163   }
00164   if(isLastView()) {
00165     w = pViewList->first();
00166     w->close();
00167   }
00168 }

void TrapperDoc::deleteContents  ) 
 

deletes the document's contents

Definition at line 224 of file trapperdoc.cpp.

Referenced by removeAlgorithm(), and removeView().

00225 {
00226     /////////////////////////////////////////////////
00227     // TODO: Add implementation to delete the document contents
00228     /////////////////////////////////////////////////
00229 
00230 }

TrDb * TrapperDoc::findTrDb string   ) 
 

Definition at line 687 of file trapperdoc.cpp.

References m_contigDir, and trDbMap.

Referenced by Database::Creator< T >::Creator(), Database::PrimaryIterator< T >::PrimaryIterator(), Database::SecondaryIterator< T >::SecondaryIterator(), and TrapperApp::slotFileFlush().

00688 {
00689     TrDb * trdb = NULL;
00690     TrDbMap::iterator it;
00691     it = trDbMap.find( generalDataName );
00692     if (it != trDbMap.end())
00693     {
00694         trdb = it->second;
00695     }
00696     else
00697     {
00698         cerr << "TrDb for generalData type=\""
00699         << generalDataName << "\" and contig=\""
00700         << m_contigDir << "\" not found" << endl;
00701     }
00702     return trdb;
00703 }

TrapperView* TrapperDoc::firstView  )  [inline]
 

returns the first view instance

Definition at line 75 of file trapperdoc.h.

References pViewList.

Referenced by TrapperApp::eventFilter(), and TrapperApp::openDocumentFile().

00076   {
00077     return pViewList->first();
00078   };

QString TrapperDoc::getStatistics  ) 
 

shows berkeley db statistics about underlying databases

Definition at line 720 of file trapperdoc.cpp.

References trDbMap.

Referenced by TrapperApp::slotShowStatistics().

00721 {
00722     QString res;
00723     TrDbMap::iterator it;
00724     it = trDbMap.begin();
00725     while (it != trDbMap.end())
00726     {
00727         Q_CHECK_PTR( it->second );
00728         res += it->second->statistics();
00729         ++it;
00730     }
00731     return res;
00732 }

bool TrapperDoc::import QDomElement &  elem  ) 
 

imports data from file with filename. I believe QDom holds the entire dom tree in ram. This could be a limiting factor for large xml files. To fix that, this function might be enhanced to use "QXmlReader" to find a record and then letting that record be put in a dom tree.

Definition at line 332 of file trapperdoc.cpp.

References Database::Creator< T >::create(), Database::Creator< T >::data(), and GeneralData::readDom().

Referenced by TrapperApp::slotImport().

00333 {
00334   QDomNode node2 = elem1.firstChild();
00335   
00336   while ( !node2.isNull() )
00337     {
00338       if ( node2.isElement() )
00339         {
00340           QString generalDataName = node2.nodeName();
00341           QDomElement elem2 = node2.toElement();
00342           
00343           Database::Creator<GeneralData> creator( this, generalDataName.ascii() );
00344           
00345           QDomNode node3 = elem2.firstChild();
00346           
00347           while ( !node3.isNull() )
00348             {
00349               if ( node3.isElement() && node3.nodeName() == "record" )
00350                 {
00351                   QDomElement elem3 = node3.toElement();
00352                   
00353                   creator.data()->readDom( elem3 );
00354                   creator.create( true );
00355                 }
00356               node3 = node3.nextSibling();
00357             }
00358         }
00359       node2 = node2.nextSibling();
00360     }
00361   return true;
00362 }

void TrapperDoc::importChromat const QString &  dirname  ) 
 

Imports chromatogram data

Definition at line 364 of file trapperdoc.cpp.

References all_readnames(), Database::SecondaryIterator< T >::answer(), ChromatData::cagt_vec, GeneralData::copy(), Database::Creator< T >::create(), Database::Creator< T >::data(), GeneralData::getRecno(), Database::SecondaryIterator< T >::key(), Database::SecondaryIterator< T >::set(), ChromatParser::set_result_array(), ReadData::setName(), FeatureData::setReadRecno(), and ReadData::strand().

00365 {
00366   //Get all readnames
00367   
00368   vector<string> names = all_readnames();
00369   
00370   //Parse files
00371 
00372   for( size_t i = 0; i < names.size(); i++ ) {
00373 
00374 
00375     vector<TrapperVector<Q_UINT32> > chromat_array;
00376     ChromatParser handler;
00377     handler.set_result_array( &chromat_array );
00378     QFile xmlFile( dirname + '/' + names[i] + ".xml" );
00379     QXmlInputSource source( &xmlFile );
00380     QXmlSimpleReader reader;
00381     reader.setContentHandler( &handler );
00382     if ( !reader.parse( source ) ) {
00383       cerr<<"Error, couldn't find chromatogram for "<<names[i]<<endl;
00384       continue;
00385     }
00386     //First, find recno of read
00387     Database::SecondaryIterator<ReadData> name_it( "name", this, "ReadData" );
00388     name_it.key()->setName( names[i] );
00389     if ( name_it.set() != 0 ) {
00390       cerr<<"Error, couldn't find "<<names[i]<<" in db"<<endl;
00391       continue;
00392     }
00393     //Second, find corresponding chromat feature data
00394     Database::SecondaryIterator<ChromatData>* chr_it = 
00395       new Database::SecondaryIterator<ChromatData>( "readRecno", this, "ChromatData" );
00396     
00397     chr_it->key()->setReadRecno( name_it.answer()->getRecno() );
00398     
00399     if ( chr_it->set() != 0 ) {
00400       cerr<<"Error, couldn't find recno "<<name_it.answer()->getRecno()<<" of read "<<names[i]<<endl;
00401       delete chr_it;
00402       continue;
00403     }
00404 
00405     //Create new data
00406     Database::Creator<ChromatData> creator( this, "ChromatData" );
00407     
00408     creator.data()->copy(chr_it->answer());
00409 
00410 //     creator.data()->setStartPos( chr_it->answer()->startPos() );
00411 //     creator.data()->setEndPos( chr_it->answer()->endPos() );
00412     
00413 //     creator.data()->setReadRecno( name_it.answer()->getRecno() );
00414     
00415     creator.data()->cagt_vec.clear();
00416     if ( name_it.answer()->strand() == "C" ) {
00417 
00418       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00419       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00420       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00421       creator.data()->cagt_vec.push_back(TrapperVector<Q_UINT32>());
00422 
00423       //Revcomp, must reverse the chromat and switch curves A->T, G->C
00424 //       creator.data()->cagt_vec[0].stlVector().clear();
00425 //       creator.data()->cagt_vec[0].stlVector().insert(creator.data()->cagt_vec[0].stlVector().begin(),
00426 //                                          chromat_array[3].stlVector().rbegin(), chromat_array[3].stlVector().rend());
00427 //       creator.data()->cagt_vec[1].stlVector().clear();
00428 //       creator.data()->cagt_vec[1].stlVector().insert(creator.data()->cagt_vec[1].stlVector().begin(),
00429 //                                          chromat_array[2].stlVector().rbegin(), chromat_array[2].stlVector().rend());
00430 //       creator.data()->cagt_vec[2].stlVector().clear();
00431 //       creator.data()->cagt_vec[2].stlVector().insert(creator.data()->cagt_vec[2].stlVector().begin(),
00432 //                                          chromat_array[1].stlVector().rbegin(), chromat_array[1].stlVector().rend());
00433 //       creator.data()->cagt_vec[3].stlVector().clear();
00434 //       creator.data()->cagt_vec[3].stlVector().insert(creator.data()->cagt_vec[3].stlVector().begin(),
00435 //                                          chromat_array[0].stlVector().rbegin(), chromat_array[0].stlVector().rend());
00436 
00437       creator.data()->cagt_vec[0].stlVector().clear();
00438       creator.data()->cagt_vec[0].stlVector().insert(creator.data()->cagt_vec[0].stlVector().begin(),
00439                                          chromat_array[2].stlVector().rbegin(), chromat_array[2].stlVector().rend());
00440       creator.data()->cagt_vec[1].stlVector().clear();
00441       creator.data()->cagt_vec[1].stlVector().insert(creator.data()->cagt_vec[1].stlVector().begin(),
00442                                          chromat_array[3].stlVector().rbegin(), chromat_array[3].stlVector().rend());
00443       creator.data()->cagt_vec[2].stlVector().clear();
00444       creator.data()->cagt_vec[2].stlVector().insert(creator.data()->cagt_vec[2].stlVector().begin(),
00445                                          chromat_array[0].stlVector().rbegin(), chromat_array[0].stlVector().rend());
00446       creator.data()->cagt_vec[3].stlVector().clear();
00447       creator.data()->cagt_vec[3].stlVector().insert(creator.data()->cagt_vec[3].stlVector().begin(),
00448                                          chromat_array[1].stlVector().rbegin(), chromat_array[1].stlVector().rend());
00449       
00450     }
00451     else {
00452     
00453 //       creator.data()->cagt_vec.push_back(chromat_array[0]);
00454 //       creator.data()->cagt_vec.push_back(chromat_array[1]);
00455 //       creator.data()->cagt_vec.push_back(chromat_array[2]);
00456 //       creator.data()->cagt_vec.push_back(chromat_array[3]);
00457       creator.data()->cagt_vec = chromat_array;
00458     }
00459     
00460     delete chr_it;
00461     
00462     creator.create(true);
00463   }
00464 
00465 
00466 }

void TrapperDoc::importMates const QString &  filename  ) 
 

Imports mate pair data

Definition at line 569 of file trapperdoc.cpp.

References all_readnames(), Database::SecondaryIterator< T >::answer(), GeneralData::copy(), Database::Creator< T >::create(), Database::Creator< T >::data(), Database::SecondaryIterator< T >::key(), MateParser::parse_line(), Database::SecondaryIterator< T >::set(), MateParser::set_file(), ReadData::setMate(), ReadData::setMateLength(), and ReadData::setName().

00570 {
00571   //Get all readnames
00572   
00573   vector<string> names = all_readnames();
00574   
00575   //Parse file
00576   MateParser parser;
00577   parser.set_file(filename);
00578   
00579   string read_name, mate_name;
00580   size_t mate_length;
00581 
00582   while( parser.parse_line( read_name, mate_name, mate_length ) ) {
00583 
00584 
00585     //For each read:
00586     
00587     //Add mate data
00588     //NB, assumes that the same read name is present only once in each contig, might need to fix this
00589 
00590 
00591     Database::Creator<ReadData> creator( this, "ReadData" );
00592     
00593     //First, find recno of read with name read_name
00594     Database::SecondaryIterator<ReadData>* name_it =
00595       new Database::SecondaryIterator<ReadData>( "name", this, "ReadData" );
00596     name_it->key()->setName( read_name );
00597     if ( name_it->set() != 0 ) {
00598       delete name_it;
00599       continue;
00600     }
00601     
00602     creator.data()->copy( name_it->answer() );
00603     
00604     creator.data()->setMate( mate_name );
00605     creator.data()->setMateLength( mate_length );
00606     
00607     
00608     delete name_it;
00609     
00610     creator.create(true);
00611     
00612     //Same for mate
00613       
00614     //First, find recno of read with name mate_name
00615     name_it = new Database::SecondaryIterator<ReadData>( "name", this, "ReadData" );
00616     name_it->key()->setName( mate_name );
00617     if ( name_it->set() != 0 ) {
00618       delete name_it;
00619       continue;
00620     }
00621     creator.data()->copy( name_it->answer() );
00622     
00623     creator.data()->setMate( read_name );
00624     creator.data()->setMateLength( mate_length );
00625     
00626     
00627     delete name_it;
00628     
00629     creator.create(true);
00630     
00631   }
00632   
00633 }

void TrapperDoc::importPhd const QString &  dirname  ) 
 

Imports phd data

Definition at line 468 of file trapperdoc.cpp.

References all_readnames(), Database::SecondaryIterator< T >::answer(), ChromatData::cagt_vec, GeneralData::copy(), Database::Creator< T >::create(), Database::Creator< T >::data(), DnaStrData::dnaVector, FeatureData::endPos(), ChromatData::gap_vec, GeneralData::getRecno(), Database::SecondaryIterator< T >::key(), PhdParser::parse(), ChromatData::phd_vec, Database::SecondaryIterator< T >::set(), ReadData::setName(), FeatureData::setReadRecno(), TrapperVector< T >::size(), TrapperVector< T >::stlVector(), and ReadData::strand().

00469 {
00470   //Get all readnames
00471   
00472   vector<string> names = all_readnames();
00473   
00474   //Parse files
00475 
00476   for( size_t i = 0; i < names.size(); i++ ) {
00477 
00478     TrapperVector<Q_UINT32> phd_array;
00479 
00480     PhdParser parser(dirname + '/' + names[i] + ".phd.1");
00481     phd_array = parser.parse();
00482     
00483     if ( phd_array.size() == 0 ) {
00484       cerr<<"Error, couldn't find phd file for "<<names[i]<<endl;
00485       continue;
00486     }
00487     //First, find recno of read
00488     Database::SecondaryIterator<ReadData> name_it( "name", this, "ReadData" );
00489     name_it.key()->setName( names[i] );
00490     if ( name_it.set() != 0 ) {
00491       cerr<<"Error, couldn't find "<<names[i]<<" in db"<<endl;
00492       continue;
00493     }
00494     //Second, find corresponding chromat feature data
00495     Database::SecondaryIterator<ChromatData>* chr_it = 
00496       new Database::SecondaryIterator<ChromatData>( "readRecno", this, "ChromatData" );
00497     
00498     chr_it->key()->setReadRecno( name_it.answer()->getRecno() );
00499     
00500     if ( chr_it->set() != 0 ) {
00501       cerr<<"Error, couldn't find recno "<<name_it.answer()->getRecno()<<" of read "<<names[i]<<endl;
00502       delete chr_it;
00503       continue;
00504     }
00505     if ( chr_it->answer()->cagt_vec[0].stlVector().size() == 0 ) {
00506       cerr<<"Chromat file for "<<names[i]<<" not imported, skipping phd file"<<endl;
00507       delete chr_it;
00508       continue;
00509     }
00510 
00511     //Create new data
00512     Database::Creator<ChromatData> creator( this, "ChromatData" );
00513 
00514     creator.data()->copy(chr_it->answer());
00515 
00516     if ( name_it.answer()->strand() == "C" ) {
00517       creator.data()->phd_vec.stlVector().clear();
00518       creator.data()->phd_vec.stlVector().insert(creator.data()->phd_vec.stlVector().begin(),
00519                                                  phd_array.stlVector().rbegin(), phd_array.stlVector().rend());
00520       for( size_t i = 0; i < creator.data()->phd_vec.stlVector().size(); i++ ) {
00521         creator.data()->phd_vec.stlVector()[i] = creator.data()->cagt_vec[0].stlVector().size() - 1 - creator.data()->phd_vec.stlVector()[i];
00522       }
00523     }
00524     else {
00525       
00526       creator.data()->phd_vec = phd_array;
00527     }
00528     
00529 
00530     delete chr_it;
00531 
00532     //TEMPORARY FIX OF THE GAP PROBLEM!!!
00533     Database::SecondaryIterator<DnaStrData>* dna_it = 
00534       new Database::SecondaryIterator<DnaStrData>( "readRecno", this, "DnaStrData" );
00535     dna_it->key()->setReadRecno( name_it.answer()->getRecno() );
00536     
00537     if ( dna_it->set() != 0 ) {
00538       cerr<<"Error, couldn't find recno "<<name_it.answer()->getRecno()<<" of read "<<names[i]<<endl;
00539       delete dna_it;
00540       continue;
00541     }
00542     creator.data()->gap_vec.stlVector().clear();
00543     size_t numgap(0);
00544     for( size_t i = 0; i < dna_it->answer()->dnaVector.size(); i++ ) {
00545       if (dna_it->answer()->dnaVector.stlVector()[i] == '*' ) {
00546         numgap++;
00547       }
00548       creator.data()->gap_vec.stlVector().push_back(numgap);
00549     }
00550 
00551     if ( creator.data()->gap_vec.stlVector().size() != creator.data()->endPos() + 1) {
00552       cerr<<"creator.data()->gap_vec.stlVector().size(): "<<
00553           creator.data()->gap_vec.stlVector().size()<<endl;
00554       cerr<<"creator.data()->endPos(): "<<creator.data()->endPos()<<endl;
00555     }
00556     
00557     assert( creator.data()->gap_vec.stlVector().size() == creator.data()->endPos() + 1 );
00558     delete dna_it;
00559     
00560     //END FIX!!!
00561     
00562     creator.create(true);
00563     
00564   }
00565   
00566 
00567 }

bool TrapperDoc::isLastView  ) 
 

returns true, if the requested view is the last view of the document

Definition at line 119 of file trapperdoc.cpp.

References pViewList.

Referenced by canCloseFrame(), and closeDocument().

00120 {
00121     return ((int) pViewList->count() == 1);
00122 }

bool TrapperDoc::isModified  )  [inline]
 

returns if the document is modified or not. Use this to determine if your document needs saving by the user on closing.

Definition at line 92 of file trapperdoc.h.

References modified.

Referenced by canCloseFrame().

00093   {
00094     return modified;
00095   };

bool TrapperDoc::newDocument  ) 
 

initializes the document generally

Definition at line 170 of file trapperdoc.cpp.

References modified.

Referenced by TrapperApp::open_docs_not_already_open(), and TrapperApp::openDocumentFile().

00171 {
00172     /////////////////////////////////////////////////
00173     // TODO: Add your document initialization code here
00174     /////////////////////////////////////////////////
00175     modified=false;
00176     return true;
00177 }

void TrapperDoc::openDbs  ) 
 

Definition at line 654 of file trapperdoc.cpp.

References dbenv, GeneralData::getIndexMap(), GeneralMaker::listRegistered(), m_contigDir, GeneralMaker::newData(), TrDb::open(), and trDbMap.

Referenced by openDocument().

00655 {
00656 
00657   list<string> alist = GeneralMaker::listRegistered();
00658 
00659   for (  list<string>::iterator  it = alist.begin(); it != alist.end(); ++it )
00660     {
00661       GeneralData * data = GeneralMaker::newData( *it );
00662       if ( data )
00663         {
00664           QString directoryName(  m_contigDir );
00665           directoryName += "/";
00666           directoryName += it->c_str() ;
00667           
00668           QDir dir;
00669           dir.mkdir( directoryName , true );
00670           
00671           TrDb * trdb = new TrDb( dbenv, directoryName.ascii() , data->getIndexMap() );
00672           trDbMap.insert( make_pair( it->c_str(), trdb ) );
00673           
00674 //           cerr << "trDbMap.insert( make_pair( it->c_str(), trdb ) ) ******* "
00675 //                << it->c_str() << " ***************** "
00676 //                << directoryName.ascii() << endl;
00677           
00678           delete data;
00679           trdb->open();
00680 
00681 //           cerr<<"trdb->primaryDb(): "<<trdb->primaryDb()<<endl;
00682         }
00683     }
00684 
00685 }

bool TrapperDoc::openDocument const QString &  dirname,
const char *  format = 0
 

loads the document by filename and format and emits the updateViews() signal

Definition at line 179 of file trapperdoc.cpp.

References m_contigDir, m_title, modified, and openDbs().

Referenced by TrapperApp::open_docs_not_already_open(), TrapperApp::openDocumentFile(), TrapperApp::slotImport(), and TrapperParser::startElement().

00180 {
00181   cerr<<"openDocument() "<<endl;
00182   m_contigDir=dirname;
00183   QDir dir( m_contigDir );
00184   
00185   if ( !dir.exists() ) {
00186     QDir dir2;
00187     if ( !dir2.mkdir( m_contigDir, true ) ) {
00188       // oops, still doesn't exist
00189       cerr << "creating new dir failed, dir name=" << m_contigDir << endl;
00190       exit(1);
00191       
00192       
00193     }
00194   }
00195   /////////////////////////////////////////////////
00196   // TODO: Add your document opening code here
00197   /////////////////////////////////////////////////
00198   modified=false;
00199   m_title=dirname;
00200   
00201   openDbs();
00202   return true;
00203 }

const QString & TrapperDoc::pathName  )  const
 

returns the pathname of the current document file

Definition at line 139 of file trapperdoc.cpp.

References m_contigDir.

Referenced by canCloseFrame(), TrapperApp::open_docs_not_already_open(), TrapperApp::openDocumentFile(), saveExport(), TrapperApp::slotFileFlush(), and TrapperApp::slotFileSave().

00140 {
00141     return m_contigDir;
00142 }

void TrapperDoc::removeAlgorithm Algo  ) 
 

removes an algorithm from the list of currently connected algorithm

Definition at line 84 of file trapperdoc.cpp.

References changedAlgoList(), deleteContents(), pAlgoList, and pViewList.

Referenced by TrapperView::runAlgo().

00085 {
00086     pAlgoList->remove
00087     (algo);
00088     if(!pViewList->isEmpty() || !pAlgoList->isEmpty() )
00089         changedAlgoList();
00090     else
00091         deleteContents();
00092 }

void TrapperDoc::removeView TrapperView view  ) 
 

removes a view from the list of currently connected views

Definition at line 74 of file trapperdoc.cpp.

References changedViewList(), deleteContents(), pAlgoList, and pViewList.

Referenced by TrapperApp::eventFilter().

00075 {
00076     pViewList->remove
00077     (view);
00078     if(!pViewList->isEmpty() || !pAlgoList->isEmpty() )
00079         changedViewList();
00080     else
00081         deleteContents();
00082 }

bool TrapperDoc::saveDocument const QString &  filename,
const char *  format = 0
 

saves the document under filename and format.

Definition at line 205 of file trapperdoc.cpp.

References m_contigDir, m_title, and modified.

Referenced by canCloseFrame(), TrapperApp::slotFileSave(), and TrapperApp::slotFileSaveAs().

00206 {
00207     /* we are using the berkeley db so changes are automatically changed in the files
00208        after the commit of the transaction.
00209        Here we might instead have some change of m_contigdir, to move the contig dir to
00210        another name to reflect the change of a "sandbox" contig to a regular contig. 
00211     */
00212     return false;
00213 
00214     /////////////////////////////////////////////////
00215     // TODO: Add your document saving code here
00216     /////////////////////////////////////////////////
00217 
00218     modified=false;
00219     m_contigDir=filename;
00220     m_title=filename;
00221     return true;
00222 }

void TrapperDoc::saveExport ostream &  stream  ) 
 

exports the document to a stream.

Definition at line 284 of file trapperdoc.cpp.

References Database::SecondaryIterator< T >::answer(), Database::PrimaryIterator< T >::answer(), Database::PrimaryIterator< T >::first(), GeneralData::getRecno(), Database::SecondaryIterator< T >::key(), GeneralMaker::listRegistered(), Database::PrimaryIterator< T >::next(), Database::SecondaryIterator< T >::nextdup(), pathName(), Database::SecondaryIterator< T >::set(), FeatureData::setReadRecno(), FeatureData::writeXml(), and ReadData::writeXml().

00285 {
00286 
00287   //Ugly fix for strange behaviour...
00288   int offset(-1);
00289   if ( pathName()[pathName().length() -1] == '/' ) {
00290     --offset;
00291   }
00292   
00293   stream<<"<contig name=\""<<pathName().section('/', offset)<<"\">\n";
00294   
00295   Database::PrimaryIterator<ReadData> iter( this, "ReadData" );
00296 
00297   if ( iter.first() == 0 ) {
00298     do {
00299       //ReadData
00300       iter.answer()->writeXml(stream);
00301       //FeatureData
00302       
00303       list<string> alist = GeneralMaker::listRegistered();
00304       for ( list<string>::iterator  it = alist.begin(); it != alist.end(); ++it ) {
00305         if ( *it == "ReadData") {
00306           continue;
00307         }
00308         Database::SecondaryIterator<FeatureData> f_it( "readRecno", this, *it );
00309         
00310         f_it.key()->setReadRecno( iter.answer()->getRecno() );
00311         
00312         if ( f_it.set() == 0 ) {
00313           do {
00314             f_it.answer()->writeXml(stream);
00315             
00316           }while(f_it.nextdup() == 0);
00317         }
00318       }
00319       
00320       //End ReadData
00321       stream<<"</ReadData>\n";
00322         
00323     }while( iter.next() == 0 );
00324     
00325     
00326   }
00327   
00328   stream<<"</contig>\n";
00329   
00330 }

void TrapperDoc::setModified bool  _m = true  )  [inline]
 

sets the modified flag for the document after a modifying action on the view connected to the document.

Definition at line 87 of file trapperdoc.h.

References modified.

Referenced by TrapperDoc().

00088   {
00089     modified=_m;
00090   };

void TrapperDoc::setPathName const QString &  name  ) 
 

sets the path to the file connected with the document

Definition at line 133 of file trapperdoc.cpp.

References m_contigDir, and m_title.

00134 {
00135     m_contigDir=name;
00136     m_title=QFileInfo(name).fileName();
00137 }

void TrapperDoc::setTitle const QString &  title  ) 
 

sets the filename of the document

Definition at line 144 of file trapperdoc.cpp.

References m_title.

00145 {
00146     m_title=title;
00147 }

const QString & TrapperDoc::title  )  const
 

returns the title of the document

Definition at line 149 of file trapperdoc.cpp.

References m_title.

Referenced by canCloseFrame(), TrapperApp::slotFileSave(), SubsetAlgo::start(), ReadnamesAlgo::start(), and ConsAlgo::start().

00150 {
00151     return m_title;
00152 }

void TrapperDoc::updateAllViews TrapperView sender  )  [slot]
 

calls repaint() on all views connected to the document object and is called by the view by which the document has been changed. As this view normally repaints itself, it is excluded from the paintEvent.

Definition at line 124 of file trapperdoc.cpp.

References pViewList, and TrapperView::update().

00125 {
00126     TrapperView *w;
00127     for(w=pViewList->first(); w!=0; w=pViewList->next())
00128     {
00129         w->update(sender);
00130     }
00131 }


Friends And Related Function Documentation

friend class TrapperView [friend]
 

Definition at line 60 of file trapperdoc.h.


Member Data Documentation

DbEnv* TrapperDoc::dbenv [private]
 

Definition at line 162 of file trapperdoc.h.

Referenced by openDbs().

QString TrapperDoc::m_contigDir [private]
 

Definition at line 161 of file trapperdoc.h.

Referenced by findTrDb(), openDbs(), openDocument(), pathName(), saveDocument(), and setPathName().

QString TrapperDoc::m_filename [private]
 

Definition at line 156 of file trapperdoc.h.

QString TrapperDoc::m_title [private]
 

Definition at line 155 of file trapperdoc.h.

Referenced by changedViewList(), openDocument(), saveDocument(), setPathName(), setTitle(), and title().

bool TrapperDoc::modified [private]
 

the modified flag of the current document

Definition at line 154 of file trapperdoc.h.

Referenced by isModified(), newDocument(), openDocument(), saveDocument(), and setModified().

QList<Algo>* TrapperDoc::pAlgoList [private]
 

Definition at line 159 of file trapperdoc.h.

Referenced by addAlgorithm(), removeAlgorithm(), removeView(), TrapperDoc(), and ~TrapperDoc().

QList<TrapperView>* TrapperDoc::pViewList [private]
 

the list of the views currently connected to the document

Definition at line 158 of file trapperdoc.h.

Referenced by addView(), changedViewList(), closeDocument(), firstView(), isLastView(), removeAlgorithm(), removeView(), TrapperDoc(), updateAllViews(), and ~TrapperDoc().

TrDbMap TrapperDoc::trDbMap [private]
 

Definition at line 160 of file trapperdoc.h.

Referenced by closeDbs(), findTrDb(), getStatistics(), and openDbs().


The documentation for this class was generated from the following files:
Generated on Fri Mar 17 17:45:02 2006 for trapper by  doxygen 1.4.4