forked from qt-creator/qt-creator
QmlProfiler: Preserve statistics sorting order across model reloads
Task-number: QTCREATORBUG-19660 Change-Id: I19e20cbeddf91790a4aec056a438e97c96f57735 Reviewed-by: Robert Loehning <robert.loehning@qt.io>
This commit is contained in:
@@ -47,6 +47,28 @@
|
|||||||
namespace QmlProfiler {
|
namespace QmlProfiler {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
const int DEFAULT_SORT_COLUMN = 2;
|
||||||
|
|
||||||
|
struct SortPreserver {
|
||||||
|
SortPreserver(Utils::TreeView *view) : view(view)
|
||||||
|
{
|
||||||
|
const QHeaderView *header = view->header();
|
||||||
|
column = header->sortIndicatorSection();
|
||||||
|
order = header->sortIndicatorOrder();
|
||||||
|
view->setSortingEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SortPreserver()
|
||||||
|
{
|
||||||
|
view->setSortingEnabled(true);
|
||||||
|
view->sortByColumn(column, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
int column;
|
||||||
|
Qt::SortOrder order;
|
||||||
|
Utils::TreeView *view;
|
||||||
|
};
|
||||||
|
|
||||||
struct Colors {
|
struct Colors {
|
||||||
Colors () : noteBackground(QColor("orange")), defaultBackground(QColor("white")) {}
|
Colors () : noteBackground(QColor("orange")), defaultBackground(QColor("white")) {}
|
||||||
QColor noteBackground;
|
QColor noteBackground;
|
||||||
@@ -374,7 +396,6 @@ public:
|
|||||||
QList<bool> m_fieldShown;
|
QList<bool> m_fieldShown;
|
||||||
QHash<int, int> m_columnIndex; // maps field enum to column index
|
QHash<int, int> m_columnIndex; // maps field enum to column index
|
||||||
bool m_showExtendedStatistics;
|
bool m_showExtendedStatistics;
|
||||||
int m_firstNumericColumn;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainView(
|
QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainView(
|
||||||
@@ -384,8 +405,6 @@ QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainView(
|
|||||||
setViewDefaults(this);
|
setViewDefaults(this);
|
||||||
setObjectName(QLatin1String("QmlProfilerEventsTable"));
|
setObjectName(QLatin1String("QmlProfilerEventsTable"));
|
||||||
|
|
||||||
setSortingEnabled(false);
|
|
||||||
|
|
||||||
d->m_model = new QStandardItemModel(this);
|
d->m_model = new QStandardItemModel(this);
|
||||||
d->m_model->setSortRole(SortRole);
|
d->m_model->setSortRole(SortRole);
|
||||||
setModel(d->m_model);
|
setModel(d->m_model);
|
||||||
@@ -396,7 +415,6 @@ QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainView(
|
|||||||
this, &QmlProfilerStatisticsMainView::buildModel);
|
this, &QmlProfilerStatisticsMainView::buildModel);
|
||||||
connect(d->model, &QmlProfilerStatisticsModel::notesAvailable,
|
connect(d->model, &QmlProfilerStatisticsModel::notesAvailable,
|
||||||
this, &QmlProfilerStatisticsMainView::updateNotes);
|
this, &QmlProfilerStatisticsMainView::updateNotes);
|
||||||
d->m_firstNumericColumn = 0;
|
|
||||||
d->m_showExtendedStatistics = false;
|
d->m_showExtendedStatistics = false;
|
||||||
|
|
||||||
setFieldViewable(Name, true);
|
setFieldViewable(Name, true);
|
||||||
@@ -412,6 +430,9 @@ QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainView(
|
|||||||
setFieldViewable(MedianTime, true);
|
setFieldViewable(MedianTime, true);
|
||||||
setFieldViewable(Details, true);
|
setFieldViewable(Details, true);
|
||||||
|
|
||||||
|
setSortingEnabled(true);
|
||||||
|
sortByColumn(DEFAULT_SORT_COLUMN, Qt::DescendingOrder);
|
||||||
|
|
||||||
buildModel();
|
buildModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,18 +459,15 @@ void QmlProfilerStatisticsMainView::setFieldViewable(Fields field, bool show)
|
|||||||
void QmlProfilerStatisticsMainView::setHeaderLabels()
|
void QmlProfilerStatisticsMainView::setHeaderLabels()
|
||||||
{
|
{
|
||||||
int fieldIndex = 0;
|
int fieldIndex = 0;
|
||||||
d->m_firstNumericColumn = 0;
|
|
||||||
|
|
||||||
d->m_columnIndex.clear();
|
d->m_columnIndex.clear();
|
||||||
if (d->m_fieldShown[Name]) {
|
if (d->m_fieldShown[Name]) {
|
||||||
d->m_columnIndex[Name] = fieldIndex;
|
d->m_columnIndex[Name] = fieldIndex;
|
||||||
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(displayHeader(Location)));
|
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(displayHeader(Location)));
|
||||||
d->m_firstNumericColumn++;
|
|
||||||
}
|
}
|
||||||
if (d->m_fieldShown[Type]) {
|
if (d->m_fieldShown[Type]) {
|
||||||
d->m_columnIndex[Type] = fieldIndex;
|
d->m_columnIndex[Type] = fieldIndex;
|
||||||
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(displayHeader(Type)));
|
d->m_model->setHeaderData(fieldIndex++, Qt::Horizontal, QVariant(displayHeader(Type)));
|
||||||
d->m_firstNumericColumn++;
|
|
||||||
}
|
}
|
||||||
if (d->m_fieldShown[TimeInPercent]) {
|
if (d->m_fieldShown[TimeInPercent]) {
|
||||||
d->m_columnIndex[TimeInPercent] = fieldIndex;
|
d->m_columnIndex[TimeInPercent] = fieldIndex;
|
||||||
@@ -521,11 +539,10 @@ bool QmlProfilerStatisticsMainView::showExtendedStatistics() const
|
|||||||
|
|
||||||
void QmlProfilerStatisticsMainView::clear()
|
void QmlProfilerStatisticsMainView::clear()
|
||||||
{
|
{
|
||||||
|
SortPreserver sorter(this);
|
||||||
d->m_model->clear();
|
d->m_model->clear();
|
||||||
d->m_model->setColumnCount(d->getFieldCount());
|
d->m_model->setColumnCount(d->getFieldCount());
|
||||||
|
|
||||||
setHeaderLabels();
|
setHeaderLabels();
|
||||||
setSortingEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainViewPrivate::getFieldCount()
|
int QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainViewPrivate::getFieldCount()
|
||||||
@@ -540,12 +557,13 @@ int QmlProfilerStatisticsMainView::QmlProfilerStatisticsMainViewPrivate::getFiel
|
|||||||
void QmlProfilerStatisticsMainView::buildModel()
|
void QmlProfilerStatisticsMainView::buildModel()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
parseModel();
|
|
||||||
setShowExtendedStatistics(d->m_showExtendedStatistics);
|
|
||||||
|
|
||||||
setRootIsDecorated(false);
|
{
|
||||||
setSortingEnabled(true);
|
SortPreserver sorter(this);
|
||||||
sortByColumn(d->m_firstNumericColumn,Qt::DescendingOrder);
|
parseModel();
|
||||||
|
setShowExtendedStatistics(d->m_showExtendedStatistics);
|
||||||
|
setRootIsDecorated(false);
|
||||||
|
}
|
||||||
|
|
||||||
expandAll();
|
expandAll();
|
||||||
if (d->m_fieldShown[Name])
|
if (d->m_fieldShown[Name])
|
||||||
@@ -839,7 +857,6 @@ QmlProfilerStatisticsRelativesView::QmlProfilerStatisticsRelativesView(
|
|||||||
Utils::TreeView(parent), d(new QmlProfilerStatisticsRelativesViewPrivate(this))
|
Utils::TreeView(parent), d(new QmlProfilerStatisticsRelativesViewPrivate(this))
|
||||||
{
|
{
|
||||||
setViewDefaults(this);
|
setViewDefaults(this);
|
||||||
setSortingEnabled(false);
|
|
||||||
d->model = model;
|
d->model = model;
|
||||||
QStandardItemModel *itemModel = new QStandardItemModel(this);
|
QStandardItemModel *itemModel = new QStandardItemModel(this);
|
||||||
itemModel->setSortRole(SortRole);
|
itemModel->setSortRole(SortRole);
|
||||||
@@ -847,6 +864,9 @@ QmlProfilerStatisticsRelativesView::QmlProfilerStatisticsRelativesView(
|
|||||||
setRootIsDecorated(false);
|
setRootIsDecorated(false);
|
||||||
updateHeader();
|
updateHeader();
|
||||||
|
|
||||||
|
setSortingEnabled(true);
|
||||||
|
sortByColumn(DEFAULT_SORT_COLUMN, Qt::DescendingOrder);
|
||||||
|
|
||||||
connect(this, &QAbstractItemView::activated,
|
connect(this, &QAbstractItemView::activated,
|
||||||
this, &QmlProfilerStatisticsRelativesView::jumpToItem);
|
this, &QmlProfilerStatisticsRelativesView::jumpToItem);
|
||||||
|
|
||||||
@@ -862,12 +882,11 @@ QmlProfilerStatisticsRelativesView::~QmlProfilerStatisticsRelativesView()
|
|||||||
|
|
||||||
void QmlProfilerStatisticsRelativesView::displayType(int typeIndex)
|
void QmlProfilerStatisticsRelativesView::displayType(int typeIndex)
|
||||||
{
|
{
|
||||||
|
SortPreserver sorter(this);
|
||||||
rebuildTree(d->model->getData(typeIndex));
|
rebuildTree(d->model->getData(typeIndex));
|
||||||
|
|
||||||
updateHeader();
|
updateHeader();
|
||||||
resizeColumnToContents(0);
|
resizeColumnToContents(0);
|
||||||
setSortingEnabled(true);
|
|
||||||
sortByColumn(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerStatisticsRelativesView::rebuildTree(
|
void QmlProfilerStatisticsRelativesView::rebuildTree(
|
||||||
@@ -929,6 +948,7 @@ void QmlProfilerStatisticsRelativesView::rebuildTree(
|
|||||||
void QmlProfilerStatisticsRelativesView::clear()
|
void QmlProfilerStatisticsRelativesView::clear()
|
||||||
{
|
{
|
||||||
if (treeModel()) {
|
if (treeModel()) {
|
||||||
|
SortPreserver sorter(this);
|
||||||
treeModel()->clear();
|
treeModel()->clear();
|
||||||
updateHeader();
|
updateHeader();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user