Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sorting order of location in caller callee view #468

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/models/callercalleemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class LocationCostModelImpl : public HashModel<Data::SourceLocationCostMap, Mode
{
if (role == SortRole) {
if (column == Location) {
return fileLine.toString();
return QVariant::fromValue(fileLine);
}
column -= NUM_BASE_COLUMNS;
if (column < m_totalCosts.numTypes()) {
Expand Down
18 changes: 18 additions & 0 deletions src/models/callercalleeproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "callercalleeproxy.h"

#include "callercalleemodel.h"
#include "data.h"

namespace {
Expand All @@ -32,3 +33,20 @@ bool match(const QSortFilterProxyModel* proxy, const Data::FileLine& fileLine)
return matchImpl(needle, fileLine.file);
}
}

SourceMapProxy::SourceMapProxy(QObject* parent)
: CallerCalleeProxy<SourceMapModel>(parent)
{
}

SourceMapProxy::~SourceMapProxy() = default;

bool SourceMapProxy::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
{
if (source_left.column() == source_right.column() && source_left.column() == SourceMapModel::Location) {
const auto left = source_left.data(SourceMapModel::SortRole).value<Data::FileLine>();
const auto right = source_right.data(SourceMapModel::SortRole).value<Data::FileLine>();
return left < right;
}
return QSortFilterProxyModel::lessThan(source_left, source_right);
}
13 changes: 12 additions & 1 deletion src/models/callercalleeproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ bool match(const QSortFilterProxyModel* proxy, const Data::Symbol& symbol);
bool match(const QSortFilterProxyModel* proxy, const Data::FileLine& fileLine);
}

class SourceMapModel;

template<typename Model>
class CallerCalleeProxy : public QSortFilterProxyModel
{
Expand All @@ -43,6 +45,15 @@ class CallerCalleeProxy : public QSortFilterProxyModel

return CallerCalleeProxyDetail::match(this, key);
}
};

class SourceMapProxy : public CallerCalleeProxy<SourceMapModel>
{
Q_OBJECT
public:
SourceMapProxy(QObject* parent = nullptr);
~SourceMapProxy();

private:
protected:
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
};
13 changes: 12 additions & 1 deletion src/resultscallercalleepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,22 @@
#endif

namespace {
QSortFilterProxyModel* createProxy(SourceMapModel* model)
{
return new SourceMapProxy(model);
}

template<typename Model>
lievenhey marked this conversation as resolved.
Show resolved Hide resolved
QSortFilterProxyModel* createProxy(Model* model)
{
return new CallerCalleeProxy<Model>(model);
}

template<typename Model>
Model* setupModelAndProxyForView(QTreeView* view, CostContextMenu* contextMenu)
{
auto model = new Model(view);
auto proxy = new CallerCalleeProxy<Model>(model);
auto proxy = createProxy(model);
proxy->setSourceModel(model);
proxy->setSortRole(Model::SortRole);
view->setModel(proxy);
Expand Down