Skip to content

Commit c2e7728

Browse files
committed
fix sorting order of location in caller callee view
add a new sfpm for SourceMapModel that implements lessThen to correctly sort the locations fixes: #466
1 parent 09a11b1 commit c2e7728

4 files changed

+46
-2
lines changed

src/models/callercalleemodel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class LocationCostModelImpl : public HashModel<Data::SourceLocationCostMap, Mode
265265
{
266266
if (role == SortRole) {
267267
if (column == Location) {
268-
return fileLine.toString();
268+
return QVariant::fromValue(fileLine);
269269
}
270270
column -= NUM_BASE_COLUMNS;
271271
if (column < m_totalCosts.numTypes()) {

src/models/callercalleeproxy.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "callercalleeproxy.h"
1010

11+
#include "callercalleemodel.h"
1112
#include "data.h"
1213

1314
namespace {
@@ -32,3 +33,21 @@ bool match(const QSortFilterProxyModel* proxy, const Data::FileLine& fileLine)
3233
return matchImpl(needle, fileLine.file);
3334
}
3435
}
36+
37+
SourceMapProxy::SourceMapProxy(QObject* parent)
38+
: CallerCalleeProxy<SourceMapModel>(parent)
39+
{
40+
}
41+
42+
SourceMapProxy::~SourceMapProxy() { }
43+
44+
bool SourceMapProxy::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
45+
{
46+
47+
if (source_left.column() == source_right.column() && source_left.column() == SourceMapModel::Location) {
48+
const auto left = source_left.data(SourceMapModel::SortRole).value<Data::FileLine>();
49+
const auto right = source_right.data(SourceMapModel::SortRole).value<Data::FileLine>();
50+
return left < right;
51+
}
52+
return QSortFilterProxyModel::lessThan(source_left, source_right);
53+
}

src/models/callercalleeproxy.h

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ bool match(const QSortFilterProxyModel* proxy, const Data::Symbol& symbol);
2020
bool match(const QSortFilterProxyModel* proxy, const Data::FileLine& fileLine);
2121
}
2222

23+
class SourceMapModel;
24+
2325
template<typename Model>
2426
class CallerCalleeProxy : public QSortFilterProxyModel
2527
{
@@ -46,3 +48,16 @@ class CallerCalleeProxy : public QSortFilterProxyModel
4648

4749
private:
4850
};
51+
52+
class SourceMapProxy : public CallerCalleeProxy<SourceMapModel>
53+
{
54+
Q_OBJECT
55+
public:
56+
SourceMapProxy(QObject* parent = nullptr);
57+
~SourceMapProxy();
58+
59+
protected:
60+
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
61+
62+
private:
63+
};

src/resultscallercalleepage.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@
3636
#endif
3737

3838
namespace {
39+
QSortFilterProxyModel* createProxy(SourceMapModel* model)
40+
{
41+
return new SourceMapProxy(model);
42+
}
43+
template<typename Model>
44+
QSortFilterProxyModel* createProxy(Model* model)
45+
{
46+
return new CallerCalleeProxy<Model>(model);
47+
}
48+
3949
template<typename Model>
4050
Model* setupModelAndProxyForView(QTreeView* view, CostContextMenu* contextMenu)
4151
{
4252
auto model = new Model(view);
43-
auto proxy = new CallerCalleeProxy<Model>(model);
53+
auto proxy = createProxy(model);
4454
proxy->setSourceModel(model);
4555
proxy->setSortRole(Model::SortRole);
4656
view->setModel(proxy);

0 commit comments

Comments
 (0)