Gerrit: Add ProgressIndicator

Show a nice spinner while waiting for data from Gerrit.

Change-Id: Ia35d7408e6a65126d40e8cff5278a442f4b5c760
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-10-12 16:38:42 +02:00
parent 2a014eaee6
commit e9370ccf83
2 changed files with 35 additions and 0 deletions

View File

@@ -35,6 +35,7 @@
#include <utils/qtcassert.h>
#include <utils/fancylineedit.h>
#include <utils/itemviews.h>
#include <utils/progressindicator.h>
#include <utils/theme/theme.h>
#include <coreplugin/icore.h>
@@ -122,6 +123,18 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &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