sublime
document.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "document.h"
00020
00021 #include <kdebug.h>
00022
00023 #include "view.h"
00024 #include "controller.h"
00025
00026 namespace Sublime {
00027
00028
00029
00030 struct DocumentPrivate {
00031 DocumentPrivate(Document *doc): m_document(doc) {}
00032
00033 void removeView(QObject *obj)
00034 {
00035 views.removeAll(reinterpret_cast<Sublime::View*>(obj));
00036 emit m_document->viewNumberChanged(m_document);
00037
00038 if (views.count() == 0)
00039 {
00040 emit m_document->aboutToDelete(m_document);
00041 m_document->deleteLater();
00042 }
00043 }
00044
00045 Controller *controller;
00046 QList<View*> views;
00047
00048 Document *m_document;
00049 };
00050
00051
00052
00053
00054
00055 Document::Document(const QString &title, Controller *controller)
00056 :QObject(controller), d( new DocumentPrivate(this) )
00057 {
00058 setObjectName(title);
00059 d->controller = controller;
00060 d->controller->addDocument(this);
00061 connect(this, SIGNAL(destroyed(QObject*)), d->controller, SLOT(removeDocument(QObject*)));
00062 }
00063
00064 Document::~Document()
00065 {
00066 delete d;
00067 }
00068
00069 Controller *Document::controller() const
00070 {
00071 return d->controller;
00072 }
00073
00074 View *Document::createView()
00075 {
00076 View *view = newView(this);
00077 connect(view, SIGNAL(destroyed(QObject*)), this, SLOT(removeView(QObject*)));
00078 d->views.append(view);
00079 return view;
00080 }
00081
00082 const QList<View*> &Document::views() const
00083 {
00084 return d->views;
00085 }
00086
00087 QString Document::title() const
00088 {
00089 return objectName();
00090 }
00091
00092 void Document::setTitle(const QString& newTitle)
00093 {
00094 setObjectName(newTitle);
00095 emit titleChanged(this);
00096 }
00097
00098 View *Document::newView(Document *doc)
00099 {
00100 emit viewNumberChanged(this);
00101 return new View(doc);
00102 }
00103
00104 }
00105
00106 #include "document.moc"