Explorar o código

Refined progress value and text reporting.

Sascha Zelzer %!s(int64=12) %!d(string=hai) anos
pai
achega
e7f6b3e190

+ 10 - 4
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleProcessTask.cpp

@@ -95,9 +95,15 @@ void ctkCmdLineModuleProcessTask::run()
     this->reportException(ctkCmdLineModuleRunException(d->Location, process.exitCode(), process.errorString()));
   }
 
-  this->setProgressValue(1000);
-
-  //this->reportResult(result);
+  if (this->progressValue() == 1001)
+  {
+    // We got a "filter-end" progress report, potentially with a comment,
+    // so don't overwrite the comment in the progress text.
+    this->setProgressValue(1002);
+  }
+  else
+  {
+    this->setProgressValueAndText(1002, QObject::tr("Finished."));
+  }
   this->reportFinished();
-
 }

+ 17 - 13
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleProcessWatcher.cpp

@@ -35,12 +35,15 @@ ctkCmdLineModuleProcessWatcher::ctkCmdLineModuleProcessWatcher(QProcess& process
   : process(process), location(location), futureInterface(futureInterface), processXmlWatcher(&process),
     processPaused(false), progressValue(0)
 {
-  futureInterface.setProgressRange(0, 1000);
+  // The reported float value in the range [0.0,1.0] for the progress is scaled to [0,1000].
+  // Value 1001 is reserved for the last "filter-end" output, which is reported as a progress event.
+  // Value 1002 is reserved internally to report process termination.
+  futureInterface.setProgressRange(0, 1002);
 
   connect(&processXmlWatcher, SIGNAL(filterStarted(QString,QString)), SLOT(filterStarted(QString,QString)));
-  connect(&processXmlWatcher, SIGNAL(filterProgress(float)), SLOT(filterProgress(float)));
+  connect(&processXmlWatcher, SIGNAL(filterProgress(float,QString)), SLOT(filterProgress(float,QString)));
   connect(&processXmlWatcher, SIGNAL(filterResult(QString,QString)), SLOT(filterResult(QString,QString)));
-  connect(&processXmlWatcher, SIGNAL(filterFinished(QString)), SLOT(filterFinished(QString)));
+  connect(&processXmlWatcher, SIGNAL(filterFinished(QString,QString)), SLOT(filterFinished(QString,QString)));
   connect(&processXmlWatcher, SIGNAL(filterXmlError(QString)), SLOT(filterXmlError(QString)));
 
   connect(&processXmlWatcher, SIGNAL(outputDataAvailable(QByteArray)), SLOT(outputDataAvailable(QByteArray)));
@@ -62,14 +65,13 @@ ctkCmdLineModuleProcessWatcher::ctkCmdLineModuleProcessWatcher(QProcess& process
 //----------------------------------------------------------------------------
 void ctkCmdLineModuleProcessWatcher::filterStarted(const QString& name, const QString& comment)
 {
-  Q_UNUSED(comment)
-  futureInterface.setProgressValueAndText(incrementProgress(), name);
+  futureInterface.setProgressValueAndText(incrementProgress(), comment.isEmpty() ? tr("Starting") + name : comment);
 }
 
 //----------------------------------------------------------------------------
-void ctkCmdLineModuleProcessWatcher::filterProgress(float progress)
+void ctkCmdLineModuleProcessWatcher::filterProgress(float progress, const QString& comment)
 {
-  futureInterface.setProgressValue(updateProgress(progress));
+  futureInterface.setProgressValueAndText(updateProgress(progress), comment);
 }
 
 //----------------------------------------------------------------------------
@@ -79,9 +81,11 @@ void ctkCmdLineModuleProcessWatcher::filterResult(const QString &parameter, cons
 }
 
 //----------------------------------------------------------------------------
-void ctkCmdLineModuleProcessWatcher::filterFinished(const QString& name)
+void ctkCmdLineModuleProcessWatcher::filterFinished(const QString& name, const QString& comment)
 {
-  futureInterface.setProgressValueAndText(incrementProgress(), "Finished: " + name);
+  int progressValue = incrementProgress();
+  if (progressValue = 1000) progressValue = 1001;
+  futureInterface.setProgressValueAndText(progressValue, comment.isEmpty() ? tr("Finished ") + name : comment);
 }
 
 //----------------------------------------------------------------------------
@@ -149,16 +153,16 @@ int ctkCmdLineModuleProcessWatcher::updateProgress(float progress)
 {
   progressValue = static_cast<int>(progress * 1000.0f);
   // normalize the value to lie between 0 and 1000.
-  // 0 is reported when the process starts and 1000 is reserved for
-  // reporting completion + standard output text
+  // 0 is reported when the process starts and 1001 is reserved for
+  // reporting completion.
   if (progressValue < 1) progressValue = 1;
-  if (progressValue > 999) progressValue = 999;
+  if (progressValue > 1000) progressValue = 1000;
   return progressValue;
 }
 
 //----------------------------------------------------------------------------
 int ctkCmdLineModuleProcessWatcher::incrementProgress()
 {
-  if (++progressValue > 999) progressValue = 999;
+  if (++progressValue > 1000) progressValue = 1000;
   return progressValue;
 }

+ 2 - 2
Libs/CommandLineModules/Backend/LocalProcess/ctkCmdLineModuleProcessWatcher_p.h

@@ -50,9 +50,9 @@ public:
 protected Q_SLOTS:
 
   void filterStarted(const QString& name, const QString& comment);
-  void filterProgress(float progress);
+  void filterProgress(float progress, const QString &comment);
   void filterResult(const QString& parameter, const QString& value);
-  void filterFinished(const QString& name);
+  void filterFinished(const QString& name, const QString &comment);
 
   void filterXmlError(const QString& error);
 

+ 2 - 2
Libs/CommandLineModules/Core/Testing/Cpp/ctkCmdLineModuleSignalTester.cpp

@@ -63,12 +63,12 @@ void ctkCmdLineModuleSignalTester::filterStarted(const QString &/*name*/, const
   events.push_back("filter.started");
 }
 
-void ctkCmdLineModuleSignalTester::filterProgress(float /*progress*/)
+void ctkCmdLineModuleSignalTester::filterProgress(float /*progress*/, const QString &/*comment*/)
 {
   events.push_back("filter.progress");
 }
 
-void ctkCmdLineModuleSignalTester::filterFinished(const QString &/*name*/)
+void ctkCmdLineModuleSignalTester::filterFinished(const QString &/*name*/, const QString &/*comment*/)
 {
   events.push_back("filter.finished");
 }

+ 2 - 2
Libs/CommandLineModules/Core/Testing/Cpp/ctkCmdLineModuleSignalTester.h

@@ -47,8 +47,8 @@ public Q_SLOTS:
   virtual void moduleCanceled();
 
   virtual void filterStarted(const QString& name, const QString& comment);
-  virtual void filterProgress(float progress);
-  virtual void filterFinished(const QString& name);
+  virtual void filterProgress(float progress, const QString& comment);
+  virtual void filterFinished(const QString& name, const QString& comment);
   virtual void filterXmlError(const QString& error);
 
 private:

+ 8 - 8
Libs/CommandLineModules/Core/Testing/Cpp/ctkCmdLineModuleXmlProgressWatcherTest.cpp

@@ -58,15 +58,15 @@ public:
     }
   }
 
-  void filterProgress(float progress)
+  void filterProgress(float progress, const QString& comment)
   {
-    ctkCmdLineModuleSignalTester::filterProgress(progress);
+    ctkCmdLineModuleSignalTester::filterProgress(progress, comment);
     accumulatedProgress += progress;
   }
 
-  void filterFinished(const QString& name)
+  void filterFinished(const QString& name, const QString& comment)
   {
-    ctkCmdLineModuleSignalTester::filterFinished(name);
+    ctkCmdLineModuleSignalTester::filterFinished(name, comment);
     if (name != "My Filter")
     {
       error = "Filter name does not match \"My Filter\" (got \"" + name + "\")";
@@ -117,8 +117,8 @@ void ctkCmdLineModuleXmlProgressWatcherTester::testSignalsAndValues()
 
   SignalTester signalTester;
   signalTester.connect(&progressWatcher, SIGNAL(filterStarted(QString,QString)), &signalTester, SLOT(filterStarted(QString,QString)));
-  signalTester.connect(&progressWatcher, SIGNAL(filterProgress(float)), &signalTester, SLOT(filterProgress(float)));
-  signalTester.connect(&progressWatcher, SIGNAL(filterFinished(QString)), &signalTester, SLOT(filterFinished(QString)));
+  signalTester.connect(&progressWatcher, SIGNAL(filterProgress(float,QString)), &signalTester, SLOT(filterProgress(float,QString)));
+  signalTester.connect(&progressWatcher, SIGNAL(filterFinished(QString,QString)), &signalTester, SLOT(filterFinished(QString,QString)));
   signalTester.connect(&progressWatcher, SIGNAL(filterXmlError(QString)), &signalTester, SLOT(filterXmlError(QString)));
 
   buffer.write(filterStart);
@@ -170,8 +170,8 @@ void ctkCmdLineModuleXmlProgressWatcherTester::testMalformedXml()
 
   SignalTester signalTester;
   signalTester.connect(&progressWatcher, SIGNAL(filterStarted(QString,QString)), &signalTester, SLOT(filterStarted(QString,QString)));
-  signalTester.connect(&progressWatcher, SIGNAL(filterProgress(float)), &signalTester, SLOT(filterProgress(float)));
-  signalTester.connect(&progressWatcher, SIGNAL(filterFinished(QString)), &signalTester, SLOT(filterFinished(QString)));
+  signalTester.connect(&progressWatcher, SIGNAL(filterProgress(float,QString)), &signalTester, SLOT(filterProgress(float,QString)));
+  signalTester.connect(&progressWatcher, SIGNAL(filterFinished(QString,QString)), &signalTester, SLOT(filterFinished(QString,QString)));
   signalTester.connect(&progressWatcher, SIGNAL(filterXmlError(QString)), &signalTester, SLOT(filterXmlError(QString)));
 
   buffer.write(filterOutput);

+ 10 - 5
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlProgressWatcher.cpp

@@ -90,7 +90,8 @@ public:
           break;
         }
 
-        if (stack.size() == 2 && stack.front() == FILTER_START)
+        if (stack.size() == 2 &&
+            (stack.front() == FILTER_START || stack.front() == FILTER_END || stack.front() == FILTER_PROGRESS))
         {
           if (stack.back() == FILTER_NAME)
           {
@@ -135,8 +136,8 @@ public:
 
           if (name.compare(FILTER_START, Qt::CaseInsensitive) == 0)
           {
-            currentName.clear();
-            currentComment.clear();
+            currentName = QString();
+            currentComment = QString();
             currentProgress = 0;
           }
           else if (name.compare(FILTER_RESULT, Qt::CaseInsensitive) == 0)
@@ -170,10 +171,12 @@ public:
           if (name.compare(FILTER_START, Qt::CaseInsensitive) == 0)
           {
             emit q->filterStarted(currentName, currentComment);
+            currentComment = QString();
           }
           else if (name.compare(FILTER_PROGRESS, Qt::CaseInsensitive) == 0)
           {
-            emit q->filterProgress(currentProgress);
+            emit q->filterProgress(currentProgress, currentComment);
+            currentComment = QString();
           }
           else if (name.compare(FILTER_RESULT, Qt::CaseInsensitive) == 0)
           {
@@ -181,7 +184,9 @@ public:
           }
           else if (name.compare(FILTER_END, Qt::CaseInsensitive) == 0)
           {
-            emit q->filterFinished(currentName);
+            emit q->filterFinished(currentName, currentComment);
+            currentName = QString();
+            currentComment = QString();
           }
         }
         break;

+ 2 - 2
Libs/CommandLineModules/Core/ctkCmdLineModuleXmlProgressWatcher.h

@@ -49,9 +49,9 @@ public:
 Q_SIGNALS:
 
   void filterStarted(const QString& name, const QString& comment);
-  void filterProgress(float progress);
+  void filterProgress(float progress, const QString& comment);
   void filterResult(const QString& parameter, const QString& value);
-  void filterFinished(const QString& name);
+  void filterFinished(const QString& name, const QString& comment);
   void filterXmlError(const QString& error);
 
   void outputDataAvailable(const QByteArray& outputData);

+ 27 - 12
Libs/CommandLineModules/Testing/Cpp/ctkCmdLineModuleFutureTest.cpp

@@ -174,14 +174,14 @@ void ctkCmdLineModuleFutureTester::testStartFinish()
                   << "module.progressRangeChanged(0,0)"
                   << "module.progressValueChanged(0)"
 
-                  << "module.progressRangeChanged(0,1000)"
+                  << "module.progressRangeChanged(0,1002)"
 
                      // the test module always reports error data when starting
                   << "module.errorReady"
 
                      // the following two signals are send when the module reports "filter start"
                   << "module.progressValueChanged(1)"
-                  << "module.progressTextChanged(Test Filter)"
+                  << "module.progressTextChanged(Does nothing useful)"
 
                      // imageOutput result
                   << "module.resultReadyAt(0,1)"
@@ -191,8 +191,12 @@ void ctkCmdLineModuleFutureTester::testStartFinish()
                   << "module.resultReadyAt(1,2)"
                   << "module.resultReadyAt(1)"
 
+                     // <filter-end> progress value and text
+                  << "module.progressValueChanged(1001)"
+                  << "module.progressTextChanged(Finished successfully.)"
+
                      // the following signal is sent at the end to report completion
-                  << "module.progressValueChanged(1000)"
+                  << "module.progressValueChanged(1002)"
                   << "module.finished";
 
   ctkCmdLineModuleSignalTester signalTester;
@@ -221,20 +225,21 @@ void ctkCmdLineModuleFutureTester::testProgress()
                   << "module.progressRangeChanged(0,0)"
                   << "module.progressValueChanged(0)"
 
-                  << "module.progressRangeChanged(0,1000)"
+                  << "module.progressRangeChanged(0,1002)"
 
                      // the test module always reports error data when starting
                   << "module.errorReady"
 
                      // the following two signals are send when the module reports "filter start"
                   << "module.progressValueChanged(1)"
-                  << "module.progressTextChanged(Test Filter)"
+                  << "module.progressTextChanged(Does nothing useful)"
 
                      // the output data on the standard output channel
                   << "module.outputReady"
 
                      // this signal is send when the module reports progress for "output1"
-                  << "module.progressValueChanged(999)"
+                  << "module.progressValueChanged(1000)"
+                  << "module.progressTextChanged(Calculating output 2...)"
 
                      // first resultNumberOutput result
                   << "module.resultReadyAt(0,1)"
@@ -248,8 +253,12 @@ void ctkCmdLineModuleFutureTester::testProgress()
                   << "module.resultReadyAt(2,3)"
                   << "module.resultReadyAt(2)"
 
+                     // <filter-end> progress value and text
+                  << "module.progressValueChanged(1001)"
+                  << "module.progressTextChanged(Finished successfully.)"
+
                      // the following signal is sent at the end to report completion
-                  << "module.progressValueChanged(1000)"
+                  << "module.progressValueChanged(1002)"
                   << "module.finished";
 
   ctkCmdLineModuleSignalTester signalTester;
@@ -285,7 +294,7 @@ void ctkCmdLineModuleFutureTester::testPauseAndCancel()
   expectedSignals << "module.started"
                   << "module.progressRangeChanged(0,0)"
                   << "module.progressValueChanged(0)"
-                  << "module.progressRangeChanged(0,1000)"
+                  << "module.progressRangeChanged(0,1002)"
                   << "module.errorReady";
 
   if (future.canPause())
@@ -368,20 +377,21 @@ void ctkCmdLineModuleFutureTester::testOutput()
                   << "module.progressRangeChanged(0,0)"
                   << "module.progressValueChanged(0)"
 
-                  << "module.progressRangeChanged(0,1000)"
+                  << "module.progressRangeChanged(0,1002)"
 
                      // the test module always reports error data when starting
                   << "module.errorReady"
 
                      // the following two signals are send when the module reports "filter start"
                   << "module.progressValueChanged(1)"
-                  << "module.progressTextChanged(Test Filter)"
+                  << "module.progressTextChanged(Does nothing useful)"
 
                      // the output data on the standard output channel "Output 1"
                   << "module.outputReady"
 
                      // this signal is send when the module reports progress for "output1"
                   << "module.progressValueChanged(500)"
+                  << "module.progressTextChanged(Calculating output 2...)"
 
                      // first resultNumberOutput result
                   << "module.resultReadyAt(0,1)"
@@ -391,7 +401,8 @@ void ctkCmdLineModuleFutureTester::testOutput()
                   << "module.outputReady"
 
                      // this signal is send when the module reports progress for "output2"
-                  << "module.progressValueChanged(999)"
+                  << "module.progressValueChanged(1000)"
+                  << "module.progressTextChanged(Calculating output 3...)"
 
                      // second resultNumberOutput result
                   << "module.resultReadyAt(1,2)"
@@ -405,11 +416,15 @@ void ctkCmdLineModuleFutureTester::testOutput()
                   << "module.resultReadyAt(3,4)"
                   << "module.resultReadyAt(3)"
 
+                     // <filter-end> progress value and text
+                  << "module.progressValueChanged(1001)"
+                  << "module.progressTextChanged(Finished successfully.)"
+
                      // final error message
                   << "module.errorReady"
 
                      // the following signal is sent at the end to report completion
-                  << "module.progressValueChanged(1000)"
+                  << "module.progressValueChanged(1002)"
                   << "module.finished";
 
   QVERIFY(signalTester.checkSignals(expectedSignals));

+ 3 - 1
Libs/CommandLineModules/Testing/Modules/TestBed/ctkCmdLineModuleTestBed.cpp

@@ -170,7 +170,8 @@ int main(int argc, char* argv[])
       out << output << endl;
 
       // report progress
-      out << "<filter-progress>" << (i+1)*progressStep << "</filter-progress>" << endl;
+      out << "<filter-progress>" << (i+1)*progressStep
+          << "<filter-comment>Calculating output " << (i+2) << "...</filter-comment></filter-progress>" << endl;
       // report the current output number as a result
       out << "<filter-result name=\"resultNumberOutput\">" << (i+1) << "</filter-result>" << endl;
     }
@@ -199,6 +200,7 @@ int main(int argc, char* argv[])
   else
   {
     out << "Normal exit</filter-result>" << endl;
+    out << "<filter-end><filter-comment>Finished successfully.</filter-comment></filter-end>" << endl;
   }
 
   return exitCode;