From c6713d0876ce2d99f912151c9884477606909681 Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 17 Aug 2020 00:56:17 +0200 Subject: More UI work --- taglistmodel.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'taglistmodel.cpp') diff --git a/taglistmodel.cpp b/taglistmodel.cpp index d68fc57..435f5f1 100644 --- a/taglistmodel.cpp +++ b/taglistmodel.cpp @@ -17,10 +17,24 @@ int TagListModel::rowCount(const QModelIndex &parent) const return cached_tags.size(); } +bool collateTagNames(QString a, QString b) { + QRegularExpression name_re("^(\\d*)(.*?)(\\d*)$"); + auto res_a = name_re.match(a), res_b = name_re.match(b); + + if (res_a.captured(1).isEmpty() && !res_b.captured(1).isEmpty()) + return true; + + if (res_a.captured().toInt() < res_b.captured().toInt()) + return true; + /* FIXME TODO */ +} + void TagListModel::reloadTags() { + qDebug() << "TagListModel::reloadTags()"; beginResetModel(); cached_tags = backend.getAllTags(); + std::sort(cached_tags.begin(), cached_tags.end(), [](const Tag &a, const Tag &b) { return collateTagNames(a.name, b.name); }); endResetModel(); } @@ -47,6 +61,11 @@ QVariant TagListModel::headerData(int section, Qt::Orientation orientation, int return QString("Tag"); } +QModelIndex TagListModel::indexOf(const Tag &t) const +{ + return index(cached_tags.indexOf(t)); +} + Qt::ItemFlags TagListModel::flags(const QModelIndex &index) const { Q_UNUSED(index); -- cgit