ctkCmdLineModuleProcessTask.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. class QProcess;
  24. class ctkCmdLineModuleProcessTask : public QObject, public ctkCmdLineModuleFutureInterface, public QRunnable
  25. {
  26. Q_OBJECT
  27. public:
  28. ctkCmdLineModuleProcessTask(const QString& location, const QStringList& args);
  29. ~ctkCmdLineModuleProcessTask();
  30. ctkCmdLineModuleFuture start();
  31. void run();
  32. protected Q_SLOTS:
  33. void pollCancelState();
  34. private:
  35. QProcess* process;
  36. const QString location;
  37. const QStringList args;
  38. };
  39. class ctkCmdLineModuleProcessProgressWatcher : public QObject
  40. {
  41. Q_OBJECT
  42. public:
  43. ctkCmdLineModuleProcessProgressWatcher(QProcess& process, const QString& location,
  44. ctkCmdLineModuleFutureInterface& futureInterface);
  45. protected Q_SLOTS:
  46. void filterStarted(const QString& name, const QString& comment);
  47. void filterProgress(float progress);
  48. void filterFinished(const QString& name);
  49. void filterXmlError(const QString& error);
  50. private:
  51. int updateProgress(float progress);
  52. int incrementProgress();
  53. QProcess& process;
  54. QString location;
  55. ctkCmdLineModuleFutureInterface& futureInterface;
  56. ctkCmdLineModuleXmlProgressWatcher processXmlWatcher;
  57. int progressValue;
  58. };
  59. #endif // CTKCMDLINEMODULEPROCESSTASK_H