00001 /******************************************************************************* 00002 * * 00003 * Copyright (C) 2003 Erik Sjolund, (<html>Erik Sjölund</html>) * 00004 * Center for Genomics and Bioinformatics, * 00005 * Karolinska Institutet, * 00006 * Stockholm, * 00007 * Sweden * 00008 * * 00009 * Author: Erik Sjolund * 00010 * Email: erik.sjolund@adivo.se * 00011 * * 00012 ******************************************************************************* 00013 */ 00014 00015 #ifndef TRAPPERDOC_H 00016 #define TRAPPERDOC_H 00017 00018 #ifdef HAVE_CONFIG_H 00019 #include <config.h> 00020 #endif 00021 00022 // include files for QT 00023 #include <qobject.h> 00024 #include <qstring.h> 00025 #include <qlist.h> 00026 00027 #include <string> 00028 #include <map> 00029 #include <vector> 00030 #include <iosfwd> 00031 using namespace std; 00032 00033 class QDomElement; 00034 class TrDb; 00035 class DbEnv; 00036 typedef map<string, TrDb *> TrDbMap; 00037 00038 // forward declaration of the Trapper classes 00039 class TrapperView; 00040 class Algo; 00041 00042 00043 00044 /** \brief TrapperDoc provides a document object for a document-view model. 00045 * 00046 * The TrapperDoc class provides a document object that can be used in conjunction with the classes 00047 * TrapperApp and TrapperView to create a document-view model for MDI (Multiple Document Interface) 00048 * Qt 2.1 applications based on QApplication and QMainWindow as main classes and QWorkspace as MDI manager widget. 00049 * Thereby, the document object is created by the TrapperApp instance (and kept in a document list) and contains 00050 * the document structure with the according methods for manipulating the document 00051 * data by TrapperView objects. Also, TrapperDoc contains the methods for serialization of the document data 00052 * from and to files. 00053 * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. 00054 * @version KDevelop version 1.1 code generation 00055 */ 00056 class TrapperDoc : public QObject 00057 { 00058 Q_OBJECT 00059 00060 friend class TrapperView; 00061 00062 public: 00063 /** Constructor for the fileclass of the application */ 00064 TrapperDoc(DbEnv * dbenv); 00065 /** Destructor for the fileclass of the application */ 00066 ~TrapperDoc(); 00067 00068 /** adds a view to the document which represents the document contents. Usually this is your main view. */ 00069 void addView(TrapperView *view); 00070 /** removes a view from the list of currently connected views */ 00071 void removeView(TrapperView *view); 00072 /** gets called if a view is removed or added */ 00073 void changedViewList(); 00074 /** returns the first view instance */ 00075 TrapperView* firstView() 00076 { 00077 return pViewList->first(); 00078 }; 00079 /** returns true, if the requested view is the last view of the document */ 00080 bool isLastView(); 00081 /** This method gets called when the user is about to close a frame window. It checks, if more than one view 00082 * is connected to the document (then the frame can be closed), if pFrame is the last view and the document is 00083 * modified, the user gets asked if he wants to save the document. 00084 */ 00085 bool canCloseFrame(TrapperView* pFrame); 00086 /** sets the modified flag for the document after a modifying action on the view connected to the document.*/ 00087 void setModified(bool _m=true) 00088 { 00089 modified=_m; 00090 }; 00091 /** returns if the document is modified or not. Use this to determine if your document needs saving by the user on closing.*/ 00092 bool isModified() 00093 { 00094 return modified; 00095 }; 00096 /** deletes the document's contents */ 00097 void deleteContents(); 00098 /** initializes the document generally */ 00099 bool newDocument(); 00100 /** closes the acutal document */ 00101 void closeDocument(); 00102 /** loads the document by filename and format and emits the updateViews() signal */ 00103 00104 bool openDocument(const QString &dirname, const char* format = 0 ); 00105 00106 /** saves the document under filename and format.*/ 00107 bool saveDocument(const QString &filename, const char *format=0); 00108 /** sets the path to the file connected with the document */ 00109 void setPathName(const QString &name); 00110 /** returns the pathname of the current document file*/ 00111 const QString& pathName() const; 00112 00113 /** sets the filename of the document */ 00114 void setTitle(const QString &title); 00115 /** returns the title of the document */ 00116 const QString& title() const; 00117 /** exports the document to a stream.*/ 00118 void saveExport(ostream& stream); 00119 /** imports data from file with filename. 00120 I believe QDom holds the entire dom tree in ram. This could be a limiting factor for large xml files. 00121 To fix that, this function might be enhanced to use "QXmlReader" to find a record and then letting 00122 that record be put in a dom tree.*/ 00123 bool import(QDomElement & elem); 00124 /** Imports chromatogram data*/ 00125 void importChromat(const QString& dirname); 00126 /** Imports mate pair data*/ 00127 void importMates(const QString& filename); 00128 /** Imports phd data*/ 00129 void importPhd(const QString& dirname); 00130 /** Helper function for importing*/ 00131 std::vector<std::string> all_readnames(); 00132 00133 void openDbs(); 00134 void closeDbs(); 00135 TrDb * findTrDb( string ); 00136 /** gets called if a algorithm is removed or added */ 00137 00138 void changedAlgoList(); 00139 /** adds an algorithm to the document which represents the document contents. */ 00140 void addAlgorithm(Algo *); 00141 /** removes an algorithm from the list of currently connected algorithm */ 00142 void removeAlgorithm(Algo *); 00143 /** shows berkeley db statistics about underlying databases */ 00144 QString getStatistics(); 00145 00146 public slots: 00147 /** calls repaint() on all views connected to the document object and is called by the view by which the document has been changed. 00148 * As this view normally repaints itself, it is excluded from the paintEvent. 00149 */ 00150 void updateAllViews(TrapperView *sender); 00151 00152 private: 00153 /** the modified flag of the current document */ 00154 bool modified; 00155 QString m_title; 00156 QString m_filename; 00157 /** the list of the views currently connected to the document */ 00158 QList<TrapperView> *pViewList; 00159 QList<Algo> *pAlgoList; 00160 TrDbMap trDbMap; 00161 QString m_contigDir; 00162 DbEnv * dbenv; 00163 }; 00164 00165 #endif // TRAPPER2DOC_H