Replace ListView by TreeView inside results pane

This removes the flickering of the view when adding too many items
in a short time frame. Additionally it is the first step towards
making the results a real tree for having a better overview and to
be able to reduce the output easier to what is wanted by the user.

Change-Id: Id515bf0f43c5037d956bdbf2818a5d6ef97c82dd
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-04-21 07:41:06 +02:00
parent c13c37f9f4
commit fcf8484eb2
3 changed files with 25 additions and 20 deletions

View File

@@ -46,6 +46,8 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
{ {
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
// make sure we paint the complete delegate instead of keeping an offset
opt.rect.adjust(-opt.rect.x(), 0, 0, 0);
painter->save(); painter->save();
QFontMetrics fm(opt.font); QFontMetrics fm(opt.font);
@@ -181,6 +183,8 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
// make sure opt.rect is initialized correctly - otherwise we might get a width of 0
opt.initFrom(opt.widget);
initStyleOption(&opt, index); initStyleOption(&opt, index);
const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(opt.widget); const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(opt.widget);

View File

@@ -72,21 +72,22 @@ TestResultsPane::TestResultsPane(QObject *parent) :
outputLayout->addWidget(m_summaryWidget); outputLayout->addWidget(m_summaryWidget);
m_listView = new Utils::ListView(m_outputWidget); m_treeView = new Utils::TreeView(m_outputWidget);
m_listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); m_treeView->setHeaderHidden(true);
m_treeView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_model = new TestResultModel(this); m_model = new TestResultModel(this);
m_filterModel = new TestResultFilterModel(m_model, this); m_filterModel = new TestResultFilterModel(m_model, this);
m_filterModel->setDynamicSortFilter(true); m_filterModel->setDynamicSortFilter(true);
m_listView->setModel(m_filterModel); m_treeView->setModel(m_filterModel);
TestResultDelegate *trd = new TestResultDelegate(this); TestResultDelegate *trd = new TestResultDelegate(this);
m_listView->setItemDelegate(trd); m_treeView->setItemDelegate(trd);
outputLayout->addWidget(m_listView); outputLayout->addWidget(m_treeView);
createToolButtons(); createToolButtons();
connect(m_listView, &Utils::ListView::activated, this, &TestResultsPane::onItemActivated); connect(m_treeView, &Utils::TreeView::activated, this, &TestResultsPane::onItemActivated);
connect(m_listView->selectionModel(), &QItemSelectionModel::currentChanged, connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged,
trd, &TestResultDelegate::currentChanged); trd, &TestResultDelegate::currentChanged);
connect(TestRunner::instance(), &TestRunner::testRunStarted, connect(TestRunner::instance(), &TestRunner::testRunStarted,
this, &TestResultsPane::onTestRunStarted); this, &TestResultsPane::onTestRunStarted);
@@ -96,23 +97,23 @@ TestResultsPane::TestResultsPane(QObject *parent) :
void TestResultsPane::createToolButtons() void TestResultsPane::createToolButtons()
{ {
m_runAll = new QToolButton(m_listView); m_runAll = new QToolButton(m_treeView);
m_runAll->setIcon(QIcon(QLatin1String(":/images/run.png"))); m_runAll->setIcon(QIcon(QLatin1String(":/images/run.png")));
m_runAll->setToolTip(tr("Run All Tests")); m_runAll->setToolTip(tr("Run All Tests"));
connect(m_runAll, &QToolButton::clicked, this, &TestResultsPane::onRunAllTriggered); connect(m_runAll, &QToolButton::clicked, this, &TestResultsPane::onRunAllTriggered);
m_runSelected = new QToolButton(m_listView); m_runSelected = new QToolButton(m_treeView);
m_runSelected->setIcon(QIcon(QLatin1String(":/images/runselected.png"))); m_runSelected->setIcon(QIcon(QLatin1String(":/images/runselected.png")));
m_runSelected->setToolTip(tr("Run Selected Tests")); m_runSelected->setToolTip(tr("Run Selected Tests"));
connect(m_runSelected, &QToolButton::clicked, this, &TestResultsPane::onRunSelectedTriggered); connect(m_runSelected, &QToolButton::clicked, this, &TestResultsPane::onRunSelectedTriggered);
m_stopTestRun = new QToolButton(m_listView); m_stopTestRun = new QToolButton(m_treeView);
m_stopTestRun->setIcon(QIcon(QLatin1String(":/images/stop.png"))); m_stopTestRun->setIcon(QIcon(QLatin1String(":/images/stop.png")));
m_stopTestRun->setToolTip(tr("Stop Test Run")); m_stopTestRun->setToolTip(tr("Stop Test Run"));
m_stopTestRun->setEnabled(false); m_stopTestRun->setEnabled(false);
connect(m_stopTestRun, &QToolButton::clicked, TestRunner::instance(), &TestRunner::requestStopTestRun); connect(m_stopTestRun, &QToolButton::clicked, TestRunner::instance(), &TestRunner::requestStopTestRun);
m_filterButton = new QToolButton(m_listView); m_filterButton = new QToolButton(m_treeView);
m_filterButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER))); m_filterButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
m_filterButton->setToolTip(tr("Filter Test Results")); m_filterButton->setToolTip(tr("Filter Test Results"));
m_filterButton->setProperty("noArrow", true); m_filterButton->setProperty("noArrow", true);
@@ -135,14 +136,14 @@ TestResultsPane *TestResultsPane::instance()
TestResultsPane::~TestResultsPane() TestResultsPane::~TestResultsPane()
{ {
delete m_listView; delete m_treeView;
m_instance = 0; m_instance = 0;
} }
void TestResultsPane::addTestResult(const TestResult &result) void TestResultsPane::addTestResult(const TestResult &result)
{ {
m_model->addTestResult(result); m_model->addTestResult(result);
if (!m_listView->isVisible()) if (!m_treeView->isVisible())
popup(Core::IOutputPane::NoModeSwitch); popup(Core::IOutputPane::NoModeSwitch);
flash(); flash();
navigateStateChanged(); navigateStateChanged();
@@ -205,7 +206,7 @@ void TestResultsPane::setFocus()
bool TestResultsPane::hasFocus() const bool TestResultsPane::hasFocus() const
{ {
return m_listView->hasFocus(); return m_treeView->hasFocus();
} }
bool TestResultsPane::canFocus() const bool TestResultsPane::canFocus() const
@@ -233,7 +234,7 @@ void TestResultsPane::goToNext()
if (!canNext()) if (!canNext())
return; return;
QModelIndex currentIndex = m_listView->currentIndex(); QModelIndex currentIndex = m_treeView->currentIndex();
if (currentIndex.isValid()) { if (currentIndex.isValid()) {
int row = currentIndex.row() + 1; int row = currentIndex.row() + 1;
if (row == m_filterModel->rowCount(QModelIndex())) if (row == m_filterModel->rowCount(QModelIndex()))
@@ -242,7 +243,7 @@ void TestResultsPane::goToNext()
} else { } else {
currentIndex = m_filterModel->index(0, 0, QModelIndex()); currentIndex = m_filterModel->index(0, 0, QModelIndex());
} }
m_listView->setCurrentIndex(currentIndex); m_treeView->setCurrentIndex(currentIndex);
onItemActivated(currentIndex); onItemActivated(currentIndex);
} }
@@ -251,7 +252,7 @@ void TestResultsPane::goToPrev()
if (!canPrevious()) if (!canPrevious())
return; return;
QModelIndex currentIndex = m_listView->currentIndex(); QModelIndex currentIndex = m_treeView->currentIndex();
if (currentIndex.isValid()) { if (currentIndex.isValid()) {
int row = currentIndex.row() - 1; int row = currentIndex.row() - 1;
if (row < 0) if (row < 0)
@@ -260,7 +261,7 @@ void TestResultsPane::goToPrev()
} else { } else {
currentIndex = m_filterModel->index(m_filterModel->rowCount(QModelIndex()) - 1, 0, QModelIndex()); currentIndex = m_filterModel->index(m_filterModel->rowCount(QModelIndex()) - 1, 0, QModelIndex());
} }
m_listView->setCurrentIndex(currentIndex); m_treeView->setCurrentIndex(currentIndex);
onItemActivated(currentIndex); onItemActivated(currentIndex);
} }

View File

@@ -36,7 +36,7 @@ class IContext;
} }
namespace Utils { namespace Utils {
class ListView; class TreeView;
} }
namespace Autotest { namespace Autotest {
@@ -93,7 +93,7 @@ private:
QWidget *m_outputWidget; QWidget *m_outputWidget;
QFrame *m_summaryWidget; QFrame *m_summaryWidget;
QLabel *m_summaryLabel; QLabel *m_summaryLabel;
Utils::ListView *m_listView; Utils::TreeView *m_treeView;
TestResultModel *m_model; TestResultModel *m_model;
TestResultFilterModel *m_filterModel; TestResultFilterModel *m_filterModel;
Core::IContext *m_context; Core::IContext *m_context;