Commit f4d90a82 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Revert to committerdate sorting when pattern is empty again

parent acacecc1
......@@ -46,10 +46,12 @@ protected:
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override
{
if (m_pattern.isEmpty()) {
return QSortFilterProxyModel::lessThan(sourceLeft, sourceRight);
const int l = sourceLeft.data(BranchesDialogModel::OriginalSorting).toInt();
const int r = sourceRight.data(BranchesDialogModel::OriginalSorting).toInt();
return l > r;
}
const int l = sourceLeft.data(WeightRole).toInt();
const int r = sourceRight.data(WeightRole).toInt();
const int l = sourceLeft.data(BranchesDialogModel::FuzzyScore).toInt();
const int r = sourceRight.data(BranchesDialogModel::FuzzyScore).toInt();
return l < r;
}
......@@ -61,15 +63,14 @@ protected:
int score = 0;
const auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
const QString string = idx.data(BranchesDialogModel::DisplayName).toString();
const QString string = idx.data().toString();
const bool res = kfts::fuzzy_match(m_pattern, string, score);
sourceModel()->setData(idx, score, WeightRole);
sourceModel()->setData(idx, score, BranchesDialogModel::FuzzyScore);
return res;
}
private:
QString m_pattern;
static constexpr int WeightRole = Qt::UserRole + 1;
};
class StyleDelegate : public QStyledItemDelegate
......@@ -87,25 +88,23 @@ public:
QTextDocument doc;
auto name = index.data(BranchesDialogModel::DisplayName).toString();
auto name = index.data().toString();
const QString nameColor = option.palette.color(QPalette::Link).name();
kfts::to_scored_fuzzy_matched_display_string(m_filterString, name, QStringLiteral("<b style=\"color:%1;\">").arg(nameColor), QStringLiteral("</b>"));
auto type = (GitUtils::RefType)index.data(BranchesDialogModel::RefType).toInt();
auto refType = (GitUtils::RefType)index.data(BranchesDialogModel::RefType).toInt();
auto itemType = (BranchesDialogModel::ItemType)index.data(BranchesDialogModel::ItemTypeRole).toInt();
using RefType = GitUtils::RefType;
const auto fontSz = option.font.pointSize();
name = QStringLiteral("<span style=\"font-size:%1pt;\">").arg(fontSz) + name + QStringLiteral("</span>");
if (type == RefType::Head) {
if (itemType == BranchesDialogModel::BranchItem && refType == RefType::Head) {
name.append(QStringLiteral(" &nbsp;<span style=\"color:gray; font-size:%1pt;\">local</span>").arg(fontSz - 1));
} else if (type == RefType::Remote) {
} else if (itemType == BranchesDialogModel::BranchItem && refType == RefType::Remote) {
name.append(QStringLiteral(" &nbsp;<span style=\"color:gray; font-size:%1pt;\">remote</span>").arg(fontSz - 1));
} /*else if (type == RefType::Tag) {
name.append(QStringLiteral(" &nbsp;<span style=\"color:gray; font-size:%1pt;\">tag at %2</span>").arg(fontSz));
} */
else {
Q_UNREACHABLE();
}
doc.setHtml(name);
doc.setDocumentMargin(2);
......
......@@ -35,7 +35,6 @@ public:
Q_SIGNAL void branchChanged(const QString &branch);
Q_SLOT void onCheckoutDone();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
......@@ -43,6 +42,11 @@ protected:
private Q_SLOTS:
void slotReturnPressed();
void reselectFirst();
void onCheckoutDone();
private:
void sendMessage(const QString& message, bool warn);
void createNewBranch(const QString& branch);
private:
QTreeView *m_treeView;
......
......@@ -36,12 +36,13 @@ QVariant BranchesDialogModel::data(const QModelIndex &idx, int role) const
return {};
}
const GitUtils::Branch &branch = m_modelEntries.at(idx.row());
if (role == Role::DisplayName || role == Qt::DisplayRole) {
const Branch &branch = m_modelEntries.at(idx.row());
if (role == Qt::DisplayRole) {
return branch.name;
} else if (role == Role::Score) {
} else if (role == Role::FuzzyScore) {
return branch.score;
} else if (role == Qt::DecorationRole) {
} else if (role == Role::OriginalSorting) {
return branch.dateSort;
static const auto branchIcon = QIcon(QStringLiteral(":/kxmlgui5/kateproject/sc-apps-git.svg"));
return branchIcon;
} else if (role == Role::CheckoutName) {
......
......@@ -18,8 +18,8 @@ class BranchesDialogModel : public QAbstractTableModel
Q_OBJECT
public:
enum Role {
Score = Qt::UserRole + 1,
DisplayName,
FuzzyScore = Qt::UserRole + 1,
OriginalSorting,
CheckoutName,
RefType,
};
......@@ -34,7 +34,7 @@ public:
if (!index.isValid()) {
return false;
}
if (role == Role::Score) {
if (role == Role::FuzzyScore) {
auto row = index.row();
m_modelEntries[row].score = value.toInt();
}
......
......@@ -21,7 +21,6 @@ struct Branch {
QString name;
QString remote;
RefType type;
int score; // used for scoring when filtering
};
struct CheckoutResult {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment