00001 #include "threadDocument.h" 00002 #include "graphDocument.h" 00003 #include <QMutex> 00004 #include <KDebug> 00005 #include <KLocale> 00006 #include <QWaitCondition> 00007 00008 ThreadDocument::ThreadDocument( QWaitCondition& docCondition, QMutex& mutex, QObject* parent ): 00009 QThread( parent ), 00010 _docCondition( docCondition ), _mutex( mutex ) 00011 { 00012 _graphDocument = 0; 00013 // _loading = false; 00014 // _name = i18n("Untitled0"); 00015 } 00016 00017 ThreadDocument::~ThreadDocument() 00018 { 00019 } 00020 00021 00022 void ThreadDocument::releaseDocument() 00023 { 00024 if( _graphDocument ) 00025 _graphDocument->deleteLater(); 00026 _graphDocument = 0; 00027 } 00028 00029 void ThreadDocument::createEmptyDocument() 00030 { 00031 releaseDocument(); 00032 _graphDocument = new GraphDocument( i18n( "Untitled" ), 800, 600 ); 00033 _docCondition.wakeAll(); 00034 kDebug() << "Waking All"; 00035 } 00036 00037 void ThreadDocument::loadDocument( const QString& name ) 00038 { 00039 createEmptyDocument(); 00040 if( name.isEmpty() ) 00041 { 00042 _graphDocument->addGraph( i18n( "Untitled0" ) ); 00043 } 00044 else 00045 { 00046 _graphDocument->loadFromInternalFormat( name ); 00047 } 00048 _docCondition.wakeAll(); 00049 } 00050 00051 void ThreadDocument::setGraphDocument( GraphDocument* doc ) 00052 { 00053 releaseDocument(); 00054 _graphDocument = doc; 00055 doc->moveToThread( this ); 00056 _docCondition.wakeAll(); 00057 } 00058 00059 void ThreadDocument::run() 00060 { 00061 loadDocument(); 00062 exec(); 00063 }