diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2016-11-22 13:32:29 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2016-11-23 12:17:11 +0000 |
commit | 4aae6b730fda6ca18c32682aa0ceb4474b2aa0e9 (patch) | |
tree | 7adb6f391a8ecaf5f928541eb968ed19a30c4535 /src/plugins/diffeditor | |
parent | 7f757884c5a04484820a97e592afae74beff95a9 (diff) | |
download | qt-creator-4aae6b730fda6ca18c32682aa0ceb4474b2aa0e9.tar.gz |
Show progress indicator while reloading diff
Change-Id: Ieefdb885682f01e0e1c8cec90f4769e832650a0c
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/diffeditor')
-rw-r--r-- | src/plugins/diffeditor/diffeditordocument.cpp | 2 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditordocument.h | 2 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorwidgetcontroller.cpp | 54 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorwidgetcontroller.h | 9 |
4 files changed, 67 insertions, 0 deletions
diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp index 5a4d575d9c..02f002565c 100644 --- a/src/plugins/diffeditor/diffeditordocument.cpp +++ b/src/plugins/diffeditor/diffeditordocument.cpp @@ -328,6 +328,7 @@ QString DiffEditorDocument::plainText() const void DiffEditorDocument::beginReload() { emit aboutToReload(); + m_isReloading = true; const bool blocked = blockSignals(true); setDiffFiles(QList<FileData>(), QString()); setDescription(QString()); @@ -336,6 +337,7 @@ void DiffEditorDocument::beginReload() void DiffEditorDocument::endReload(bool success) { + m_isReloading = false; emit reloadFinished(success); } diff --git a/src/plugins/diffeditor/diffeditordocument.h b/src/plugins/diffeditor/diffeditordocument.h index 18864711fe..5e0f677062 100644 --- a/src/plugins/diffeditor/diffeditordocument.h +++ b/src/plugins/diffeditor/diffeditordocument.h @@ -76,6 +76,7 @@ public: bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName) override; + bool isReloading() const { return m_isReloading; } QString plainText() const; @@ -101,6 +102,7 @@ private: int m_contextLineCount; bool m_isContextLineCountForced; bool m_ignoreWhitespace; + bool m_isReloading = false; friend class ::DiffEditor::DiffEditorController; }; diff --git a/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp b/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp index 3e30a0d820..decb179d21 100644 --- a/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp +++ b/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp @@ -38,6 +38,7 @@ #include <cpaster/codepasterservice.h> +#include <utils/progressindicator.h> #include <utils/qtcassert.h> #include <QDir> @@ -56,11 +57,64 @@ DiffEditorWidgetController::DiffEditorWidgetController(QWidget *diffEditorWidget : QObject(diffEditorWidget) , m_diffEditorWidget(diffEditorWidget) { + m_timer.setSingleShot(true); + m_timer.setInterval(100); + connect(&m_timer, &QTimer::timeout, this, &DiffEditorWidgetController::showProgress); } void DiffEditorWidgetController::setDocument(DiffEditorDocument *document) { + if (!m_progressIndicator) { + m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Large); + m_progressIndicator->attachToWidget(m_diffEditorWidget); + m_progressIndicator->hide(); + } + + if (m_document == document) + return; + + if (m_document) { + disconnect(m_document, &IDocument::aboutToReload, this, &DiffEditorWidgetController::scheduleShowProgress); + disconnect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress); + } + + const bool wasRunning = m_document && m_document->isReloading(); + m_document = document; + + if (m_document) { + connect(m_document, &IDocument::aboutToReload, this, &DiffEditorWidgetController::scheduleShowProgress); + connect(m_document, &IDocument::reloadFinished, this, &DiffEditorWidgetController::hideProgress); + } + + const bool isRunning = m_document && m_document->isReloading(); + + if (wasRunning == isRunning) + return; + + if (isRunning) + scheduleShowProgress(); + else + hideProgress(); +} + +void DiffEditorWidgetController::scheduleShowProgress() +{ + m_timer.start(); +} + +void DiffEditorWidgetController::showProgress() +{ + m_timer.stop(); + if (m_progressIndicator) + m_progressIndicator->show(); +} + +void DiffEditorWidgetController::hideProgress() +{ + m_timer.stop(); + if (m_progressIndicator) + m_progressIndicator->hide(); } void DiffEditorWidgetController::patch(bool revert) diff --git a/src/plugins/diffeditor/diffeditorwidgetcontroller.h b/src/plugins/diffeditor/diffeditorwidgetcontroller.h index 4c527ab9a5..b5655b5f99 100644 --- a/src/plugins/diffeditor/diffeditorwidgetcontroller.h +++ b/src/plugins/diffeditor/diffeditorwidgetcontroller.h @@ -29,11 +29,13 @@ #include <QObject> #include <QTextCharFormat> +#include <QTimer> QT_FORWARD_DECLARE_CLASS(QMenu) namespace Core { class IDocument; } namespace TextEditor { class FontSettings; } +namespace Utils { class ProgressIndicator; } namespace DiffEditor { @@ -74,12 +76,19 @@ private: bool setAndVerifyIndexes(QMenu *menu, int diffFileIndex, int chunkIndex); bool fileNamesAreDifferent() const; + void scheduleShowProgress(); + void showProgress(); + void hideProgress(); + QWidget *m_diffEditorWidget; DiffEditorDocument *m_document = nullptr; int m_contextMenuFileIndex = -1; int m_contextMenuChunkIndex = -1; + + Utils::ProgressIndicator *m_progressIndicator = nullptr; + QTimer m_timer; }; } // namespace Internal |