From e9370ccf83f6c808323af3ae52e857ab8b28a7b3 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Mon, 12 Oct 2015 16:38:42 +0200 Subject: [PATCH] Gerrit: Add ProgressIndicator Show a nice spinner while waiting for data from Gerrit. Change-Id: Ia35d7408e6a65126d40e8cff5278a442f4b5c760 Reviewed-by: Tobias Hunger --- src/plugins/git/gerrit/gerritdialog.cpp | 28 +++++++++++++++++++++++++ src/plugins/git/gerrit/gerritdialog.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/src/plugins/git/gerrit/gerritdialog.cpp b/src/plugins/git/gerrit/gerritdialog.cpp index 75fd293344a..05c94204be8 100644 --- a/src/plugins/git/gerrit/gerritdialog.cpp +++ b/src/plugins/git/gerrit/gerritdialog.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -122,6 +123,18 @@ GerritDialog::GerritDialog(const QSharedPointer &p, m_treeView->setSortingEnabled(true); m_treeView->setActivationMode(Utils::DoubleClickActivation); + connect(&m_progressIndicatorTimer, &QTimer::timeout, + [this]() { setProgressIndicatorVisible(true); }); + m_progressIndicatorTimer.setSingleShot(true); + m_progressIndicatorTimer.setInterval(50); // don't show progress for < 50ms tasks + + m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Large, + m_treeView); + m_progressIndicator->attachToWidget(m_treeView->viewport()); + m_progressIndicator->hide(); + + connect(m_model, &GerritModel::stateChanged, this, &GerritDialog::manageProgressIndicator); + QItemSelectionModel *selectionModel = m_treeView->selectionModel(); connect(selectionModel, &QItemSelectionModel::currentChanged, this, &GerritDialog::slotCurrentChanged); @@ -251,6 +264,16 @@ void GerritDialog::slotRefresh() m_treeView->sortByColumn(-1); } +void GerritDialog::manageProgressIndicator() +{ + if (m_model->state() == GerritModel::Running) { + m_progressIndicatorTimer.start(); + } else { + m_progressIndicatorTimer.stop(); + setProgressIndicatorVisible(false); + } +} + QModelIndex GerritDialog::currentIndex() const { const QModelIndex index = m_treeView->selectionModel()->currentIndex(); @@ -292,5 +315,10 @@ void GerritDialog::fetchFinished() m_checkoutButton->setToolTip(QString()); } +void GerritDialog::setProgressIndicatorVisible(bool v) +{ + m_progressIndicator->setVisible(v); +} + } // namespace Internal } // namespace Gerrit diff --git a/src/plugins/git/gerrit/gerritdialog.h b/src/plugins/git/gerrit/gerritdialog.h index e5e49c3b67d..7958f103a9e 100644 --- a/src/plugins/git/gerrit/gerritdialog.h +++ b/src/plugins/git/gerrit/gerritdialog.h @@ -35,6 +35,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QTreeView; @@ -50,6 +51,7 @@ QT_END_NAMESPACE namespace Utils { class FancyLineEdit; +class ProgressIndicator; class TreeView; } @@ -88,7 +90,10 @@ private slots: void slotFetchCheckout(); void slotRefresh(); + void manageProgressIndicator(); + private: + void setProgressIndicatorVisible(bool v); QModelIndex currentIndex() const; QPushButton *addActionButton(const QString &text, const std::function &buttonSlot); void updateCompletions(const QString &query); @@ -109,6 +114,8 @@ private: QPushButton *m_checkoutButton; QPushButton *m_refreshButton; QLabel *m_repositoryChooserLabel; + Utils::ProgressIndicator *m_progressIndicator; + QTimer m_progressIndicatorTimer; bool m_fetchRunning; };