[Fixed Bug 183625] Sorting of files in the commit dialog
ClosedPublic

Authored by apuzio on Jan 26 2016, 6:41 PM.

Details

Summary

This fixes Bug 183625
In the commit dialog files whern't sorted. They are showed using VcsFileCHangesModel. I overloaded operator < of VcsStatusInfoItem to sort them. The sorting rules are:

  1. versioned files before uneversioned
  2. alphabetically (by path)

Details:
Added possibility to access the state of file in VcsFileChangesModel (not used in the end)
Introduced enum ColumnsRoles in VcsFileChangesModel: { PathColumn = 0, StatusColumn = 1 } (not used in the end)
Overloaded operator < of VcsStatusInfoItem to compare according to the rules
Used QSortFilterProxyModel in patchreviewtoolview to sort the list of changed files

Test Plan

Manually testing revealed no problems.

Diff Detail

Repository
R33 KDevPlatform
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
apuzio updated this revision to Diff 2100.Jan 26 2016, 6:41 PM
apuzio retitled this revision from to [Fixed Bug 183625] Sorting of files in the commit dialog.
apuzio updated this object.
apuzio edited the test plan for this revision. (Show Details)
apuzio added a reviewer: kfunk.
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJan 26 2016, 6:41 PM
apuzio updated this revision to Diff 2101.Jan 26 2016, 6:46 PM

Style fixes

apuzio updated this object.Jan 26 2016, 6:48 PM
kfunk edited edge metadata.Jan 26 2016, 7:24 PM

Just lot of nitpicks. Good work!

plugins/patchreview/patchreviewtoolview.cpp
210

This looks quite expensive.

Try setting http://doc.qt.io/qt-5/qsortfilterproxymodel.html#dynamicSortFilter-prop to true in the proxy model

plugins/patchreview/patchreviewtoolview.h
102

Use more descriptive name, e.g. m_fileChangesProxyModel

vcs/models/vcsfilechangesmodel.cpp
122

return QVariant::fromValue(m_info.state()).

You will have to Q_DECLARE_METATYPE(VcsStatusInfo::State) in the header

vcs/models/vcsfilechangesmodel.h
71

Name enum Column { ... }

vcs/models/vcsfilechangessortproxymodel.cpp
29 ↗(On Diff #2101)

Please keep the argument names as in the base class: source_left and source_right. There here to disambiguate between source & proxy model indices.

36 ↗(On Diff #2101)

Simplify: source_left.data(VcsFileChangesModel::StateRole).toInt() should work

46 ↗(On Diff #2101)

Dito, see above.

49 ↗(On Diff #2101)

Style: return a < b

53 ↗(On Diff #2101)

Please add newline at EOF

vcs/models/vcsfilechangessortproxymodel.h
34 ↗(On Diff #2101)

Use QObject* parent = nullptr (same as baseclass)

35 ↗(On Diff #2101)

Add override

apuzio updated this revision to Diff 2106.Jan 26 2016, 8:42 PM
apuzio marked 11 inline comments as done.
apuzio edited edge metadata.

Fixed issues: m_fileSortedModel -> m_fileSortProxyModel, setDynamicSortFilter(true) instead of connect, VcsFileChangesModel::StateRole return VcsStatusInfo::State, ColumnsRoles -> Column,
rLeft -> source_left, rRight -> source_right, simplified VcsFileChangesSortProxyModel::lessThan, added overide, added = nullptr in constructor deffinition

kfunk added inline comments.Jan 26 2016, 8:51 PM
vcs/models/vcsfilechangessortproxymodel.cpp
31 ↗(On Diff #2106)

const auto ... (it's a VcsStatusInfo::State, not an int)

34 ↗(On Diff #2106)

Style: (a != b)

apuzio updated this revision to Diff 2107.Jan 26 2016, 8:54 PM

Fixed a problem: sort(0) -> sort(1)
Fixed style

apuzio marked 2 inline comments as done.Jan 26 2016, 8:54 PM
kfunk added a comment.Jan 26 2016, 9:09 PM

I think that's it then.

vcs/models/vcsfilechangessortproxymodel.cpp
39 ↗(On Diff #2107)

Nitpick remove newline.

40 ↗(On Diff #2107)

Ah, and that one was a misunderstanding. I still wanted you to use QString::localeAwareCompare; that was just a style nitpick earlier.

apuzio updated this revision to Diff 2108.Jan 26 2016, 9:12 PM
apuzio marked 2 inline comments as done.

Fixed style

apuzio updated this revision to Diff 2109.Jan 26 2016, 9:28 PM

Simplified the code. Overriding operator < instead of using a special class

apuzio updated this object.Jan 26 2016, 9:31 PM
kfunk requested changes to this revision.Jan 27 2016, 9:01 AM
kfunk edited edge metadata.
kfunk added inline comments.
vcs/models/vcsfilechangesmodel.cpp
127

See my comment from IRC:
[23:11:22] <kfunk> cytadela8|2: why the 'using'? why 'this->'? why no 'override'? :)

This revision now requires changes to proceed.Jan 27 2016, 9:01 AM
apuzio added inline comments.Jan 27 2016, 11:23 AM
vcs/models/vcsfilechangesmodel.cpp
127

@kfunk: override causes: error "marked override, but does not override"
using suppressed: "warning: virtual bool QStandardItem::operator<(const QStandardItem&) const was hidden"
this-> I will remove.
Unfortunately I haven't received your message probably due to a buggy android IRC client.

apuzio added inline comments.Jan 27 2016, 11:30 AM
vcs/models/vcsfilechangesmodel.cpp
127

Also I see now, I'm should change to bool operator < (const VcsStatusInfoItem & other) const

apuzio updated this revision to Diff 2115.Jan 27 2016, 11:32 AM
apuzio edited edge metadata.
apuzio marked an inline comment as done.

Added const. Removed unnecessery this->

kfunk added inline comments.Jan 27 2016, 10:08 PM
vcs/models/vcsfilechangesmodel.cpp
128

Still no override. If override does not work, then this means you didn't override the base class method properly => This feature will *not* work as expected.

I have it fixed locally. One question: How did you test that feature? I don't see unversioned files in the commit dialog at all(?)

apuzio added inline comments.Jan 28 2016, 9:12 PM
vcs/models/vcsfilechangesmodel.cpp
128

For git: you see the unversioned files only if you do a git add. I had done it through the right click on file menu. I added such unversioned files, that without sorting the paths are wrong, with sorting paths only an changed file is in between. I can send you a screenshot of the code behaving correctly after the change. If you really want I can add a screenshot before the change.

As for the `bool operator < (const VcsStatusInfoItem &):
I'm NOT overriding the operator actually. The original is bool operator < (const StandardItem&).
The code behaves correctly despite this. If I used bool operator < (const QStandardItem&) I would have to cast the other variable to VcsStatusInfoItem before using it. This would create a potential seg fault if the VcsStatusInfoItem would be compared for some reason to QStandardItem. I understand your concerns about this code not working potentially and I wasn't able to find any information in the QT5 docs.

This revision was automatically updated to reflect the committed changes.