ctkCmdLineModuleProcessTask.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCMDLINEMODULEPROCESSTASK_H
  16. #define CTKCMDLINEMODULEPROCESSTASK_H
  17. #include "ctkCmdLineModuleXmlProgressWatcher.h"
  18. #include "ctkCmdLineModuleFutureInterface.h"
  19. #include <QObject>
  20. #include <QRunnable>
  21. #include <QStringList>
  22. #include <QBuffer>
  23. #include <QFutureWatcher>
  24. #include <QTimer>
  25. class QProcess;
  26. class ctkCmdLineModuleProcessTask : public ctkCmdLineModuleFutureInterface, public QRunnable
  27. {
  28. public:
  29. ctkCmdLineModuleProcessTask(const QString& location, const QStringList& args);
  30. ~ctkCmdLineModuleProcessTask();
  31. ctkCmdLineModuleFuture start();
  32. void run();
  33. private:
  34. const QString location;
  35. const QStringList args;
  36. };
  37. class ctkCmdLineModuleProcessWatcher : public QObject
  38. {
  39. Q_OBJECT
  40. public:
  41. ctkCmdLineModuleProcessWatcher(QProcess& process, const QString& location,
  42. ctkCmdLineModuleFutureInterface& futureInterface);
  43. protected Q_SLOTS:
  44. void filterStarted(const QString& name, const QString& comment);
  45. void filterProgress(float progress);
  46. void filterFinished(const QString& name);
  47. void filterXmlError(const QString& error);
  48. void pauseProcess();
  49. void resumeProcess();
  50. void cancelProcess();
  51. private:
  52. int updateProgress(float progress);
  53. int incrementProgress();
  54. QProcess& process;
  55. QString location;
  56. ctkCmdLineModuleFutureInterface& futureInterface;
  57. ctkCmdLineModuleXmlProgressWatcher processXmlWatcher;
  58. QFutureWatcher<ctkCmdLineModuleResult> futureWatcher;
  59. QTimer pollPauseTimer;
  60. bool processPaused;
  61. int progressValue;
  62. };
  63. #endif // CTKCMDLINEMODULEPROCESSTASK_H