SciDAVis  1.D4
AbstractAspect.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : AbstractAspect.h
3  Project : SciDAVis
4  --------------------------------------------------------------------
5  Copyright : (C) 2007 by Knut Franke, Tilman Benkert
6  Email (use @ for *) : knut.franke*gmx.de, thzs*gmx.net
7  Description : Base class for all persistent objects in a Project.
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef ABSTRACT_ASPECT_H
30 #define ABSTRACT_ASPECT_H
31 
32 #include <QObject>
33 #include <QDateTime>
34 
35 class AspectPrivate;
36 class Project;
37 class QUndoStack;
38 class QString;
39 class QDateTime;
40 class QUndoCommand;
41 class QIcon;
42 class QMenu;
43 namespace future{
44 class Folder;
45 }
46 class XmlStreamReader;
47 #ifdef Q_OS_MAC32
48 // A hack in Qt 4.4 and later forces us to include QXmlStream* headers on MacOS instead of simple
49 // forward declarations. See
50 // http://lists.trolltech.com/qt-interest/2008-07/thread00798-0.html
51 #include <QXmlStreamWriter>
52 #else
53 class QXmlStreamWriter;
54 #endif
55 class QAction;
56 
58 
85 class AbstractAspect : public QObject
86 {
87  Q_OBJECT
88 
89  public:
90  class Private;
91  friend class Private;
92 
93  AbstractAspect(const QString &name);
94  virtual ~AbstractAspect();
95 
97  AbstractAspect * parentAspect() const;
99 
104 
107  bool isDescendantOf(AbstractAspect *other);
108 
114 
122  void removeChild(AbstractAspect* child, bool detach=false);
124 
129  void removeChild(int index);
131  AbstractAspect* child(int index) const;
133  int childCount() const;
135  int indexOfChild(const AbstractAspect * child) const;
137  int index() const { return parentAspect() ? parentAspect()->indexOfChild(this) : 0; }
139  void moveChild(int from, int to);
141  void reparentChild(AbstractAspect *new_parent, AbstractAspect *child, int d_new_index);
143  void reparentChild(AbstractAspect *new_parent, AbstractAspect *child);
145  QList<AbstractAspect *> descendantsThatInherit(const char *class_name);
147  virtual void removeAllChildAspects();
148 
150  virtual const Project *project() const { return parentAspect() ? parentAspect()->project() : 0; }
152  virtual Project *project() { return parentAspect() ? parentAspect()->project() : 0; }
154  virtual QString path() const { return parentAspect() ? parentAspect()->path() + "/" + name() : ""; }
155 
157  virtual QIcon icon() const;
159 
162  virtual QMenu *createContextMenu() const;
163 
164  QString name() const;
165  QString comment() const;
167 
170  QString captionSpec() const;
171  QDateTime creationTime() const;
172  QString caption() const;
173 
175 
176 
177 
182  virtual QUndoStack *undoStack() const { return parentAspect() ? parentAspect()->undoStack() : 0; }
184  void exec(QUndoCommand *command);
186  void beginMacro(const QString& text);
188  void endMacro();
190 
192  static QVariant global(const QString &key);
194  static void setGlobal(const QString &key, const QVariant &value);
196  static void setGlobalDefault(const QString &key, const QVariant &value);
197 
199 
200 
201  virtual void save(QXmlStreamWriter *) const {};
203 
217  virtual bool load(XmlStreamReader *) { return false; };
218  protected:
220 
223  bool readBasicAttributes(XmlStreamReader * reader);
225  void writeBasicAttributes(QXmlStreamWriter * writer) const;
227  void writeCommentElement(QXmlStreamWriter * writer) const;
229  bool readCommentElement(XmlStreamReader * reader);
231 
232  public slots:
233  void setName(const QString &value);
234  void setComment(const QString &value);
236 
248  void setCaptionSpec(const QString &value);
250  virtual void remove() { if(parentAspect()) parentAspect()->removeChild(parentAspect()->indexOfChild(this)); }
252  QString uniqueNameFor(const QString &current_name) const;
253 
254  public:
255  void importV0x0001XXCreationTime(const QString& str)
256  {
257  setCreationTime(QDateTime::fromString(str, Qt::LocalDate));
258  }
259 
260 
261  signals:
265  void aspectDescriptionChanged(const AbstractAspect *aspect);
267  void aspectAboutToBeAdded(const AbstractAspect *parent, int index);
269  void aspectAdded(const AbstractAspect *aspect);
271  void aspectAdded(const AbstractAspect *parent, int index);
273  void aspectAboutToBeRemoved(const AbstractAspect *aspect);
275  void aspectAboutToBeRemoved(const AbstractAspect *parent, int index);
277  void aspectRemoved(const AbstractAspect *parent, int index);
279  void statusInfo(const QString &text);
280 
281  protected:
283 
288  void setCreationTime(const QDateTime& time);
290 
294  virtual void completeAspectInsertion(AbstractAspect * aspect, int index) { Q_UNUSED(aspect); Q_UNUSED(index); }
296 
300  virtual void prepareAspectRemoval(AbstractAspect * aspect) { Q_UNUSED(aspect); }
302 
307  void info(const QString &text) { emit statusInfo(text); }
308 
309  private:
311 };
312 
313 #endif // ifndef ABSTRACT_ASPECT_H