1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_PROJECT_IMPL_H_
23 #define _U2_PROJECT_IMPL_H_
24 
25 #include <QMap>
26 
27 #include <U2Core/AppResources.h>
28 #include <U2Core/ProjectModel.h>
29 
30 namespace U2 {
31 
32 class FailedToLoadFormat;
33 class ServiceLock;
34 class SaveProjectTask;
35 class LoadProjectTask;
36 class MWMDIWindow;
37 
38 class ProjectImpl : public Project {
39     Q_OBJECT
40     friend class SaveProjectTask;
41     friend class LoadProjectTask;
42 
43 public:
44     ProjectImpl(const QString &_name, const QString &_url, const QList<Document *> &_docs = QList<Document *>(), const QList<GObjectViewState *> &_states = QList<GObjectViewState *>());
45     virtual ~ProjectImpl();
46 
getProjectName()47     virtual const QString &getProjectName() const {
48         return name;
49     }
50 
51     virtual void setProjectName(const QString &name);
52 
getProjectURL()53     virtual const QString &getProjectURL() const {
54         return url;
55     }
56 
57     virtual void setProjectURL(const QString &);
58 
getDocuments()59     virtual const QList<Document *> &getDocuments() const {
60         return docs;
61     }
62 
63     virtual void addDocument(Document *d);
64 
65     virtual void removeDocument(Document *d, bool autodelete = true);
66 
67     virtual bool lockResources(int sizeMB, const QString &url, QString &error);
68 
69     virtual Document *findDocumentByURL(const QString &url) const;
70 
findDocumentByURL(const GUrl & url)71     virtual Document *findDocumentByURL(const GUrl &url) const {
72         return findDocumentByURL(url.getURLString());
73     }
74 
getGObjectViewStates()75     virtual const QList<GObjectViewState *> &getGObjectViewStates() const {
76         return objectViewStates;
77     }
78 
79     virtual void addGObjectViewState(GObjectViewState *s);
80 
81     virtual void removeGObjectViewState(GObjectViewState *s);
82 
83     virtual void makeClean();
84 
getObjectIdCounter()85     quint64 getObjectIdCounter() const {
86         return idGen;
87     }
88 
setObjectIdCounter(quint64 c)89     void setObjectIdCounter(quint64 c) {
90         idGen = c;
91     }
92 
93     virtual void removeRelations(const QString &docUrl);
94 
95     virtual void updateDocInRelations(const QString &oldDocUrl, const QString &newDocUrl);
96 
97 private slots:
98     void sl_onStateModified(GObjectViewState *);
99     void sl_onObjectAdded(GObject *);
100     void sl_onObjectRemoved(GObject *o);
101     void sl_onObjectRenamed(const QString &oldName);
102     void sl_onObjectRelationChanged(const QList<GObjectRelation> &previousRelations);
103 
104     void sl_onMdiWindowAdded(MWMDIWindow *w);
105     void sl_onMdiWindowClosing(MWMDIWindow *w);
106     void sl_onViewRenamed(const QString &oldName);
107 
108 private:
109     void addState(GObjectViewState *s);
110     void updateObjectRelations(const GObjectReference &oldRef, const GObjectReference &newRef);
111     // returns number of reference fields updated
112     int updateReferenceFields(const QString &stateName, QVariantMap &map, const GObjectReference &from, const GObjectReference &to);
113     void updateGObjectViewStates(const QString &oldViewName, const QString &newViewName);
114     QString genNextObjectId();
115 
116     int idGen;
117 
118     QString name;
119     QString url;
120     QList<Document *> docs;
121 
122     QList<GObjectViewState *> objectViewStates;
123     AppResource *resourceTracker;
124     QMap<QString, qint64> resourceUsage;
125 
126     // Every implementation of Project Parser must be added as friend, to get access to addState
127     friend class ProjectParser00;
128     friend class ProjectParser10;
129 };
130 
131 }  // namespace U2
132 
133 #endif
134