Commit e9370ccf authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Gerrit: Add ProgressIndicator



Show a nice spinner while waiting for data from Gerrit.

Change-Id: Ia35d7408e6a65126d40e8cff5278a442f4b5c760
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 2a014eae
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/fancylineedit.h> #include <utils/fancylineedit.h>
#include <utils/itemviews.h> #include <utils/itemviews.h>
#include <utils/progressindicator.h>
#include <utils/theme/theme.h> #include <utils/theme/theme.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
...@@ -122,6 +123,18 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, ...@@ -122,6 +123,18 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
m_treeView->setSortingEnabled(true); m_treeView->setSortingEnabled(true);
m_treeView->setActivationMode(Utils::DoubleClickActivation); 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(); QItemSelectionModel *selectionModel = m_treeView->selectionModel();
connect(selectionModel, &QItemSelectionModel::currentChanged, connect(selectionModel, &QItemSelectionModel::currentChanged,
this, &GerritDialog::slotCurrentChanged); this, &GerritDialog::slotCurrentChanged);
...@@ -251,6 +264,16 @@ void GerritDialog::slotRefresh() ...@@ -251,6 +264,16 @@ void GerritDialog::slotRefresh()
m_treeView->sortByColumn(-1); 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 QModelIndex GerritDialog::currentIndex() const
{ {
const QModelIndex index = m_treeView->selectionModel()->currentIndex(); const QModelIndex index = m_treeView->selectionModel()->currentIndex();
...@@ -292,5 +315,10 @@ void GerritDialog::fetchFinished() ...@@ -292,5 +315,10 @@ void GerritDialog::fetchFinished()
m_checkoutButton->setToolTip(QString()); m_checkoutButton->setToolTip(QString());
} }
void GerritDialog::setProgressIndicatorVisible(bool v)
{
m_progressIndicator->setVisible(v);
}
} // namespace Internal } // namespace Internal
} // namespace Gerrit } // namespace Gerrit
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QDialog> #include <QDialog>
#include <QSharedPointer> #include <QSharedPointer>
#include <QTimer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTreeView; class QTreeView;
...@@ -50,6 +51,7 @@ QT_END_NAMESPACE ...@@ -50,6 +51,7 @@ QT_END_NAMESPACE
namespace Utils { namespace Utils {
class FancyLineEdit; class FancyLineEdit;
class ProgressIndicator;
class TreeView; class TreeView;
} }
...@@ -88,7 +90,10 @@ private slots: ...@@ -88,7 +90,10 @@ private slots:
void slotFetchCheckout(); void slotFetchCheckout();
void slotRefresh(); void slotRefresh();
void manageProgressIndicator();
private: private:
void setProgressIndicatorVisible(bool v);
QModelIndex currentIndex() const; QModelIndex currentIndex() const;
QPushButton *addActionButton(const QString &text, const std::function<void()> &buttonSlot); QPushButton *addActionButton(const QString &text, const std::function<void()> &buttonSlot);
void updateCompletions(const QString &query); void updateCompletions(const QString &query);
...@@ -109,6 +114,8 @@ private: ...@@ -109,6 +114,8 @@ private:
QPushButton *m_checkoutButton; QPushButton *m_checkoutButton;
QPushButton *m_refreshButton; QPushButton *m_refreshButton;
QLabel *m_repositoryChooserLabel; QLabel *m_repositoryChooserLabel;
Utils::ProgressIndicator *m_progressIndicator;
QTimer m_progressIndicatorTimer;
bool m_fetchRunning; bool m_fetchRunning;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment