Skip to content

Commit c8f0c2a

Browse files
committed
feat(qt): add lifecycle and vote-aware sorting in proposal list
1 parent c1f97d6 commit c8f0c2a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/qt/proposalmodel.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,24 @@ QVariant ProposalModel::data(const QModelIndex& index, int role) const
234234
{
235235
// Edit role is used for sorting, so return the raw values where possible
236236
switch (index.column()) {
237-
case Column::STATUS:
238-
return static_cast<int>(proposal->status(isFundable));
237+
case Column::STATUS: {
238+
// Two-level sort: status group (passing before failing), then
239+
// vote margin within each group (winning by most sorts first).
240+
// Clamp to 16 bits so the value stays within its group window
241+
// and doesn't bleed into an adjacent group's key range.
242+
const int deficit{std::clamp(nAbsVoteReq - proposal->getAbsoluteYesCount(), -32768, 32767)};
243+
switch (proposal->status(isFundable)) {
244+
case ProposalStatus::Funded: return (0 << 16) + deficit;
245+
case ProposalStatus::Passing: return (1 << 16) + deficit;
246+
case ProposalStatus::Unfunded: return (2 << 16) + deficit;
247+
case ProposalStatus::Voting: return (3 << 16) + deficit;
248+
case ProposalStatus::Confirming: return (4 << 16) + deficit;
249+
case ProposalStatus::Pending: return (5 << 16) + deficit;
250+
case ProposalStatus::Failing: return (6 << 16) + deficit;
251+
case ProposalStatus::Lapsed: return (7 << 16) + deficit;
252+
} // no default case, so the compiler can warn about missing cases
253+
return 0;
254+
}
239255
case Column::HASH:
240256
return proposal->hash();
241257
case Column::TITLE:
@@ -417,7 +433,8 @@ void ProposalModel::setVotingParams(int newAbsVoteReq)
417433
// column. Emit signal to force recalculation.
418434
this->nAbsVoteReq = newAbsVoteReq;
419435
if (!m_data.empty()) {
420-
Q_EMIT dataChanged(createIndex(0, Column::VOTING_STATUS), createIndex(rowCount() - 1, Column::VOTING_STATUS));
436+
// STATUS also embeds nAbsVoteReq in its sort key, so both columns need invalidating
437+
Q_EMIT dataChanged(createIndex(0, Column::STATUS), createIndex(rowCount() - 1, Column::VOTING_STATUS));
421438
}
422439
}
423440

0 commit comments

Comments
 (0)