[Uml-devel] branches/work/soc-umbrello/umbrello

Andi Fischer andi.fischer at hispeed.ch
Wed Jan 18 20:19:09 UTC 2012


SVN commit 1274549 by fischer:

Changes taken from trunk applied.

 M  +0 -1      clipboard/idchangelog.cpp  
 M  +1 -1      clipboard/umlclipboard.cpp  
 M  +1 -1      codeimport/kdevcppparser/parser.cpp  
 M  +75 -20    codeimpwizard/codeimpstatuspage.cpp  
 M  +11 -3     codeimpwizard/codeimpstatuspage.h  
 M  +24 -12    codeimpwizard/codeimpthread.cpp  
 M  +6 -4      codeimpwizard/codeimpthread.h  


--- branches/work/soc-umbrello/umbrello/clipboard/idchangelog.cpp #1274548:1274549
@@ -90,7 +90,6 @@
     uint pos = 0;
     if (!findIDChange(OldID, NewID, pos)) {
         pos = m_LogArray.size();
-        m_LogArray.resize(pos + 1);
         m_LogArray.setPoint(pos, NewID, OldID);
     } else {
         m_LogArray.setPoint(pos, NewID, OldID);
--- branches/work/soc-umbrello/umbrello/clipboard/umlclipboard.cpp #1274548:1274549
@@ -367,7 +367,7 @@
             uDebug() << "adjusting lvitem(" << ID2STR(oldID)
                 << ") to new UMLObject(" << ID2STR(newID) << ")";
             childItem->setUMLObject(newObj);
-            childItem->setText(0, newObj->name());
+            childItem->setText(newObj->name());
         } else {
             uDebug() << "no UMLObject found for lvitem " << ID2STR(newID);
         }
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/parser.cpp #1274548:1274549
@@ -423,7 +423,7 @@
 
     // catch first comment
     Position ps = m_tokenIt->getStartPosition();
-    if (ps.line == 1 && ps.column == 1)
+    if (ps.line == 1 && ps.column == 1 && (*m_tokenIt) == Token_comment)
     {
         FileAST::Node ast = CreateNode<FileAST>();
         ast->setFileName(m_driver->currentFileName());
--- branches/work/soc-umbrello/umbrello/codeimpwizard/codeimpstatuspage.cpp #1274548:1274549
@@ -17,6 +17,10 @@
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
+
+// do not work because there are runtime errors reporting that
+// objects derived from QObject could not be called in a different thread
+// #define ENABLE_IMPORT_THREAD
 #include "codeimpstatuspage.h"
 
 // app includes
@@ -40,7 +44,8 @@
  */
 CodeImpStatusPage::CodeImpStatusPage(QWidget *parent)
   : QWizardPage(parent),
-    m_workDone(false)
+    m_workDone(false),
+    m_index(0)
 {
     setTitle(i18n("Status of Code Importing Progress"));
     setSubTitle(i18n("Press the button 'Start import' to start the code import.\nCheck the success state for every class."));
@@ -63,6 +68,9 @@
  */
 CodeImpStatusPage::~CodeImpStatusPage()
 {
+#ifdef ENABLE_IMPORT_THREAD
+    delete m_thread;
+#endif
 }
 
 /**
@@ -113,31 +121,58 @@
     setCommitPage(true);  //:TODO: disable back and cancel button ?
 
     UMLDoc* doc = UMLApp::app()->document();
+    doc->setLoading(true);
 
-    ui_textEditLogger->setHtml(i18n("<b>Code import of %1 files:</b><br>", m_files.size()));
+    ui_textEditLogger->setHtml(i18np("<b>Code import of 1 file:</b><br>", "<b>Code import of %1 files:</b><br>", m_files.size()));
+    m_index = 0;
+    m_workDone = false;
+#ifdef ENABLE_IMPORT_THREAD
+    m_thread = new QThread;
+    //connect(thread, SIGNAL(started()), this, SLOT(importCodeFile()));
+    connect(m_thread, SIGNAL(finished()), this, SLOT(importCodeFile()));
+    connect(m_thread, SIGNAL(terminated()), this, SLOT(importCodeStop()));
+#endif
+    importCodeFile();
+}
 
-    foreach (const QFileInfo& file, m_files) {
-        messageToLog(file.fileName(), i18n("importing file ..."));
-        CodeImpThread* worker = new CodeImpThread(file);
+void CodeImpStatusPage::importCodeFile()
+{
+    // all files done
+    if (m_index >= m_files.size()) {
+        messageToLog(m_file.fileName(), i18n("importing file ... DONE<br>"));
+        updateStatus(m_file.fileName(), i18n("Import Done"));
+        importCodeFinish();
+        return;
+    }
+    // at least one file done
+    else if (m_index > 0) {
+        messageToLog(m_file.fileName(), i18n("importing file ... DONE<br>"));
+        updateStatus(m_file.fileName(), i18n("Import Done"));
+    }
+
+    m_file = m_files.at(m_index++);
+    messageToLog(m_file.fileName(), i18n("importing file ..."));
+    CodeImpThread* worker = new CodeImpThread(m_file);
         connect(worker, SIGNAL(messageToWiz(QString,QString)), this, SLOT(updateStatus(QString,QString)));
         connect(worker, SIGNAL(messageToLog(QString,QString)), this, SLOT(messageToLog(QString,QString)));
         connect(worker, SIGNAL(messageToApp(QString)), this, SLOT(messageToApp(QString)));
-#if 0
-        worker->start();
-uDebug() << "****** starting task for " << file.fileName();
-        worker->wait();  //:TODO: better solution - not blocking
-uDebug() << "****** task done for " << file.fileName();
+#ifndef ENABLE_IMPORT_THREAD
+    connect(worker, SIGNAL(finished()), this, SLOT(importCodeFile()));
+    connect(worker, SIGNAL(aborted()), this, SLOT(importCodeStop()));
+    worker->run();
+    worker->deleteLater();
 #else
-        ClassImport *classImporter = ClassImport::createImporterByFileExt(file.fileName(), worker);
-        QString fileName = file.absoluteFilePath();
-        if (classImporter) {
-            classImporter->importFile(fileName);
-            delete classImporter;
-        }
+    worker->moveToThread(m_thread);
+    m_thread->start();
+    QMetaObject::invokeMethod(worker, "run", Qt::QueuedConnection);
+    // FIXME: when to delete worker and m_thread
 #endif
-        messageToLog(file.fileName(), i18n("importing file ... DONE<br>"));
-        updateStatus(file.fileName(), i18n("Import Done"));
+    uDebug() << "****** starting task for " << m_file.fileName();
     }
+
+void CodeImpStatusPage::importCodeFinish()
+{
+    UMLDoc* doc = UMLApp::app()->document();
     doc->setLoading(false);
     // Modification is set after the import is made, because the file was modified when adding the classes.
     // Allowing undo of the whole class importing. I think it eats a lot of memory.
@@ -147,6 +182,10 @@
     m_workDone = true;
     setFinalPage(true);
     emit completeChanged();
+#ifdef ENABLE_IMPORT_THREAD
+    delete m_thread;
+    m_thread = 0;
+#endif
 }
 
 /**
@@ -162,9 +201,25 @@
 /**
  * Slot for the stop button. Stops the code import.
  */
-void CodeImpStatusPage::importStop()
+void CodeImpStatusPage::importCodeStop()
 {
-    uDebug() << "TODO: Not yet implemented!";
+    messageToLog(m_file.fileName(), i18n("importing file ... stopped<br>"));
+    updateStatus(m_file.fileName(), i18n("Import stopped"));
+
+    UMLDoc* doc = UMLApp::app()->document();
+    doc->setLoading(false);
+    // Modification is set after the import is made, because the file was modified when adding the classes.
+    // Allowing undo of the whole class importing. I think it eats a lot of memory.
+    // Setting the modification, but without allowing undo.
+    doc->setModified(true);
+
+    m_workDone = true;
+    setFinalPage(true);
+    emit completeChanged();
+#ifdef ENABLE_IMPORT_THREAD
+    delete m_thread;
+    m_thread = 0;
+#endif
 }
 
 /**
--- branches/work/soc-umbrello/umbrello/codeimpwizard/codeimpstatuspage.h #1274548:1274549
@@ -33,6 +33,7 @@
 #include <QtGui/QHBoxLayout>
 #include <QtCore/QFileInfo>
 
+class QThread;
 /**
  * This class is used in the code importing wizard.
  * It represents the second page where files are listed and imported by parsing.
@@ -50,12 +51,19 @@
     bool isComplete() const;
 
 private:
-    QList<QFileInfo> m_files;
+    QList<QFileInfo> m_files; ///< list of files to import
     bool             m_workDone;
+    int              m_index; ///< index in m_files
+    QFileInfo        m_file; ///< current file
+#ifdef ENABLE_IMPORT_THREAD
+    QThread         *m_thread;
+#endif
 
 protected slots:
-    void importCode();
-    void importStop();
+    void importCode(); ///< start importing
+    void importCodeFile(); ///< import single file
+    void importCodeFinish(); ///< finish importing
+    void importCodeStop(); ///< cancel importing
     void updateStatus(const QString& file, const QString& text);
     void messageToLog(const QString& file, const QString& text);
     void messageToApp(const QString& text);
--- branches/work/soc-umbrello/umbrello/codeimpwizard/codeimpthread.cpp #1274548:1274549
@@ -24,17 +24,18 @@
 
 // kde includes
 #include <klocale.h>
+#include <kmessagebox.h>
 
 /**
  * Constructor.
  * @param fileNames   name of imported files
  */
 CodeImpThread::CodeImpThread(QFileInfo file, QObject* parent)
-  : //QThread(parent),
+  : QObject(parent),
     m_file(file)
 {
-    connect(this, SIGNAL(askQuestion(QString,QMessageBox::StandardButton*)),
-            this, SLOT(questionAsked(QString,QMessageBox::StandardButton*)));
+    connect(this, SIGNAL(askQuestion(QString,int)),
+            this, SLOT(questionAsked(QString,int)));
 }
 
 /**
@@ -51,33 +52,44 @@
 {
     ClassImport *classImporter = ClassImport::createImporterByFileExt(m_file.fileName(), this);
     QString fileName = m_file.absoluteFilePath();
+
     if (classImporter) {
         emit messageToLog(m_file.fileName(), "start import...");
         emit messageToWiz(m_file.fileName(), "started");
         emit messageToApp(i18n("Importing file: %1", fileName));
-        classImporter->importFile(fileName);
-        delete classImporter;
+        // FIXME: ClassImport still uses umldoc->writeToStatusBar for log writing
+
+        if (!classImporter->importFile(fileName)) {
+            emit messageToApp(i18nc("show failed on status bar", "Failed."));
+            emit messageToWiz(m_file.fileName(), "failed");
+            emit messageToLog(m_file.fileName(), "...import failed");
+            emit aborted();
+        }
+        else {
         emit messageToApp(i18nc("show Ready on status bar", "Ready."));
         emit messageToWiz(m_file.fileName(), "finished");
-        emit messageToLog(m_file.fileName(), "...stop import");
+            emit messageToLog(m_file.fileName(), "...import finished");
+            emit finished();
     }
+        delete classImporter;
+    }
     else {
         emit messageToWiz(m_file.fileName(), "aborted");
         emit messageToApp(i18n("No code importer for file: %1", fileName));
+        emit aborted();
     }
 }
 
 /**
  * Emit a signal to the main gui thread to show a question box.
  * @param question   the text of the question
- * @return   the code of the answer button
+ * @return   the code of the answer button @ref KMessageBox::ButtonCode
  */
 int CodeImpThread::emitAskQuestion(const QString& question)
 {
     int buttonCode = 0;
-    QMessageBox::StandardButton buttonCodeOld;
     //QMutexLocker locker(&m_mutex);
-    emit askQuestion(question, &buttonCodeOld);
+    emit askQuestion(question, buttonCode);
     //m_waitCondition.wait(&m_mutex);
     return buttonCode;
 }
@@ -95,11 +107,11 @@
 /**
  * Slot for signal askQuestion.
  * @param question   the question to ask
- * @param answer     the pressed answer button code
+ * @param answer     the pressed answer button code @ref KMessageBox::ButtonCode
  */
-void CodeImpThread::questionAsked(const QString& question, QMessageBox::StandardButton* answer)
+void CodeImpThread::questionAsked(const QString& question, int& answer)
 {
     //QMutexLocker locker(&m_mutex);
-    *answer = QMessageBox::question(0, "Question:", question, QMessageBox::Yes|QMessageBox::No);
+    answer = KMessageBox::questionYesNo(0, question, "Question code import:");
     //m_waitCondition.wakeOne();
 }
--- branches/work/soc-umbrello/umbrello/codeimpwizard/codeimpthread.h #1274548:1274549
@@ -24,7 +24,6 @@
 #include <QtCore/QMutex>
 #include <QtCore/QThread>
 #include <QtCore/QWaitCondition>
-#include <QtGui/QMessageBox>
 
 class ClassImport;
 
@@ -33,26 +32,29 @@
  * TODO: For a start it is only a QObject and is used to signals messages.
  * @author Andi Fischer
  */
-class CodeImpThread : public QObject //QThread
+class CodeImpThread : public QObject
 {
     Q_OBJECT
 public:
     explicit CodeImpThread(QFileInfo file, QObject* parent = 0);
     virtual ~CodeImpThread();
 
+public slots:
     virtual void run();
 
     int emitAskQuestion(const QString& question);
     void emitMessageToLog(const QString& file, const QString& text);
 
 signals:
-    void askQuestion(const QString& question, QMessageBox::StandardButton* answer);
+    void askQuestion(const QString& question, int& answer);
     void messageToWiz(const QString& file, const QString& text);
     void messageToLog(const QString& file, const QString& text);
     void messageToApp(const QString& text);
+    void finished();
+    void aborted();
 
 private slots:
-    void questionAsked(const QString& question, QMessageBox::StandardButton* answer);
+    void questionAsked(const QString& question, int& answer);
 
 private:
     QFileInfo         m_file;




More information about the umbrello-devel mailing list