Core::ProgressManager Class
class Core::ProgressManagerProgressManager 클래스는 Qt Creator 에서 작업을 실행하기 위한 사용자 인터페이스를 표시하는 데 사용됩니다. 더 보기...
| Header: | #include <coreplugin/progressmanager/progressmanager.h> |
| Inherits: | QObject |
공개 유형
| enum | ProgressFlag { KeepOnFinish, ShowInApplicationIcon } |
| flags | ProgressFlags |
공개 슬롯
| void | cancelTasks(Utils::Id type) |
신호
| void | allTasksFinished(Utils::Id type) |
| void | taskStarted(Utils::Id type) |
정적 공용 멤버
| Core::FutureProgress * | addTask(const QFuture<void> &future, const QString &title, Utils::Id type, Core::ProgressManager::ProgressFlags flags = {}) |
| Core::FutureProgress * | addTimedTask(const QFutureInterface<void> &futureInterface, const QString &title, Utils::Id type, std::chrono::seconds expectedDuration, Core::ProgressManager::ProgressFlags flags = {}) |
| Core::ProgressManager * | instance() |
| void | setApplicationLabel(const QString &text) |
상세 설명
진행 상황 관리자는 전달받은 작업의 진행 상황을 추적하고, Qt Creator 메인 창의 오른쪽 하단 모서리에 사용자에게 진행 상황 표시기를 보여줍니다. 또한 진행 상황 표시기를 통해 사용자는 작업을 취소할 수도 있습니다.
ProgressManager::instance() 함수를 통해 이 클래스의 단일 인스턴스를 얻을 수 있습니다.
작업 등록
ProgressManager API는 QtConcurrent 를 작업 정의의 기반으로 사용합니다. 작업은 다음과 같은 속성으로 구성됩니다:
| 속성 | 유형 | 설명 |
|---|---|---|
| 작업 추상화 | QFuture<void> | 작업의 상태를 보고하는 역할을 담당하는 작업을 나타내는 QFuture 객체입니다. 특정 작업에 대해 이 객체를 생성하는 코딩 패턴은 아래를 참조하십시오. |
| 제목 | QString | 작업 내용을 간략히 설명하는 제목입니다. 이 제목은 진행률 표시줄 위에 제목으로 표시됩니다. |
| 유형 | QString | 서로 관련이 있는 여러 태스크를 그룹화하는 데 사용되는 문자열 식별자입니다. 예를 들어, 모든 검색 작업은 동일한 유형 식별자를 사용합니다. |
| 플래그 | ProgressManager::ProgressFlags | 진행 바가 사용자에게 어떻게 표시되어야 하는지를 지정하는 추가 플래그입니다. |
작업을 등록하려면 ` QFuture<void> ` 객체를 생성하고 ` addTask()`를 호출합니다. 이 함수는 진행 바의 모양을 추가로 사용자 정의하는 데 사용할 수 있는 ` FutureProgress ` 객체를 반환합니다. 자세한 내용은 FutureProgress 문서를 참조하십시오.
다음에서는 태스크에 대한 QFuture<void> 객체를 생성하는 두 가지 일반적인 패턴에 대해 알아보겠습니다.
QtConcurrent를 사용하여 스레드 기반 작업 생성
첫 번째 방법은 QtConcurrent 를 직접 사용하여 다른 스레드에서 작업을 실제로 동시 실행하는 것입니다. QtConcurrent 에는 예를 들어 클래스 함수를 다른 스레드에서 실행하는 등 여러 가지 함수가 있습니다. Qt Creator 자체도 src/libs/utils/async.h 에 몇 가지 기능을 추가합니다. 동시 작업을 실행하는 QtConcurrent 함수는 QFuture 객체를 반환합니다. 이것이 바로 addTask() 함수에서 ProgressManager에 전달해야 할 객체입니다.
예를 들어 Core::ILocatorFilter 를 참고해 보세요. 로케이터 필터는 QFutureInterface 객체를 매개변수로 받는 refresh() 함수를 구현합니다. 이 함수들은 대략 다음과 같습니다:
void Filter::refresh(QFutureInterface<void> &future) { future.setProgressRange(0, MAX); ... while (!future.isCanceled()) { // Do a part of the long stuff ... future.setProgressValue(currentProgress); ... } }
다른 스레드에서 모든 필터의 새로고침 함수를 호출하는 실제 새로고침 코드는 다음과 같습니다:
QFuture<void> task = Utils::map(filters, &ILocatorFilter::refresh); Core::FutureProgress *progress = Core::ProgressManager::addTask(task, ::Core::Tr::tr("Indexing"), Locator::Constants::TASK_INDEX);
먼저, 모든 필터의 새로고침 함수를 호출하는 비동기 작업을 시작합니다. 그 후 반환된 QFuture 객체를 ProgressManager에 등록합니다.
스레드용 QtConcurrent 객체를 수동으로 생성하기
작업에 스레드를 생성하고 실행하는 자체적인 방법이 있다면, 필요한 객체를 직접 생성하고 시작/중지 상태를 보고해야 합니다.
// We are already running in a different thread here QFutureInterface<void> *progressObject = new QFutureInterface<void>; progressObject->setProgressRange(0, MAX); Core::ProgressManager::addTask(progressObject->future(), ::Core::Tr::tr("DoIt"), MYTASKTYPE); progressObject->reportStarted(); // Do something ... progressObject->setProgressValue(currentProgress); ... // We have done what we needed to do progressObject->reportFinished(); delete progressObject;
첫 번째 줄에서는 작업의 상태를 보고하는 수단이 될 QFutureInterface 객체를 생성합니다. 가장 먼저 보고하는 것은 진행률 값의 예상 범위입니다. QFutureInterface 객체를 위해 생성된 내부 QFuture 객체를 사용하여 ProgressManager에 작업을 등록합니다. 다음으로 작업이 시작되었음을 보고하고, 실제 작업을 수행하면서 QFutureInterface의 함수를 통해 정기적으로 진행 상황을 보고합니다. 시간이 오래 걸리는 작업이 완료된 후에는 QFutureInterface 객체를 통해 이를 보고하고, 그 후 객체를 삭제합니다.
진행 상태 표시 사용자 정의
addTask() 함수가 반환하는 FutureProgress 객체를 사용하여 진행률 표시줄 바로 아래에 표시할 사용자 정의 위젯을 설정할 수 있습니다. 또한 이 객체를 사용하여 사용자가 진행률 표시기를 클릭했을 때 알림을 받을 수도 있습니다.
멤버 유형 설명
enum ProgressManager::ProgressFlag
flags ProgressManager::ProgressFlags
동작에 대한 세부 사항을 지정하는 추가 플래그입니다. 작업의 기본값은 이러한 플래그가 하나도 설정되지 않은 상태입니다.
| 상수 | 값 | 설명 |
|---|---|---|
Core::ProgressManager::KeepOnFinish | 0x01 | 작업이 완료된 후에도 진행률 표시기가 계속 표시됩니다. |
Core::ProgressManager::ShowInApplicationIcon | 0x02 | 이를 지원하는 플랫폼(현재 Windows 7 및 macOS)에서는 이 작업의 진행률 표시기가 시스템 작업 표시줄이나 도크의 애플리케이션 아이콘에도 추가로 표시됩니다. |
ProgressFlags 유형은 QFlags<ProgressFlag>에 대한 typedef입니다. 이 유형은 ProgressFlag 값들의 OR 조합을 저장합니다.
멤버 함수 설명
[static] Core::FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QString &title, Utils::Id type, Core::ProgressManager::ProgressFlags flags = {})
QFuture 객체 future 가 지정한 작업에 대한 진행률 표시기를 표시합니다.
이 진행률 표시기는 지정된 title 와 진행률 막대를 함께 표시합니다. 작업의 type 는 다른 실행 중인 작업들과의 논리적 그룹을 지정합니다. flags 매개변수를 통해, 예를 들어 작업이 완료된 후에도 진행률 표시기가 계속 표시되도록 설정할 수 있습니다.
생성된 진행률 표시기를 나타내는 객체를 반환하며, 이 객체를 사용하여 추가로 사용자 정의할 수 있습니다. FutureProgress 객체의 수명은 ProgressManager 에 의해 관리되며, 다음 이벤트 루프 주기까지 또는 다음 addTask 호출 시까지만 유지된다는 것이 보장됩니다.
이 함수를 호출한 직후가 아닌 나중에 반환된 FutureProgress 를 사용하려면, 보호 함수를 사용해야 합니다(예: 반환된 객체를 QPointer 로 감싸고, 사용할 때마다 0인지 확인하는 방식).
[static] Core::FutureProgress *ProgressManager::addTimedTask(const QFutureInterface<void> &futureInterface, const QString &title, Utils::Id type, std::chrono::seconds expectedDuration, Core::ProgressManager::ProgressFlags flags = {})
futureInterface 라는 QFutureInterface 객체가 지정한 작업에 대한 진행률 표시기를 표시합니다. 이 진행률 표시기는 지정된 title 와 진행률 막대를 함께 보여줍니다. 진행률 표시기는 시간이 지남에 따라 단조롭게 증가하며, expectedDuration 에서 약 80%에 도달한 후 점점 더 느린 속도로 계속 증가합니다.
작업의 type 는 다른 실행 중인 작업들과의 논리적 그룹화를 지정합니다. flags 매개변수를 통해, 예를 들어 작업이 완료된 후에도 진행률 표시기를 계속 표시되도록 설정할 수 있습니다.
addTask항목도 참조하십시오 .
[signal] void ProgressManager::allTasksFinished(Utils::Id type)
type 의 모든 작업이 완료되면 전송됩니다.
[static slot] void ProgressManager::cancelTasks(Utils::Id type)
지정된 type 의 실행 중인 모든 작업의 중지를 예약합니다. 중지 기능은 실행 중인 작업이 실제로 QFuture::isCanceled 속성을 확인하는지에 따라 달라집니다.
[static] Core::ProgressManager *ProgressManager::instance()
단일 진행 상황 관리자 인스턴스를 반환합니다.
[static] void ProgressManager::setApplicationLabel(const QString &text)
지정된 ` text `을 시스템의 작업 표시줄이나 도크에 있는 애플리케이션 아이콘에 플랫폼에 따라 다른 방식으로 표시합니다. 이는 Windows 및 macOS에서 빌드 오류 수를 표시하는 데 사용됩니다.
[signal] void ProgressManager::taskStarted(Utils::Id type)
지정된 type 의 작업이 시작될 때마다 전송됩니다.
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.