From: Manuel Nickschas Date: Wed, 9 Apr 2008 18:28:21 +0000 (+0000) Subject: Prettified and correctly sortified user categories, closing BR #93. Translators can now X-Git-Tag: 0.2.0-beta1~69 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=9850247cc7533d35d71d202e32d9734197bb6f08 Prettified and correctly sortified user categories, closing BR #93. Translators can now add different strings for singular and plural. WARNING: make distclean is _mandatory_, else strange things WILL happen! --- diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index f1b1c73b..63ebf9af 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -465,24 +465,27 @@ QString NetworkItem::toolTip(int column) const { // TODO make this translateable depending on the number of users in a category // -> we can't set the real string here, because tr() needs to get the actual number as second param // -> tr("%n User(s)", n) needs to be used somewhere where we do know the user number n -const QList UserCategoryItem::categories = QList() - << UserCategoryItem::Category('q', tr("Owners")) - << UserCategoryItem::Category('a', tr("Admins")) - << UserCategoryItem::Category('o', tr("Operators")) - << UserCategoryItem::Category('h', tr("Half-Ops")) - << UserCategoryItem::Category('v', tr("Voiced")); + +const QList UserCategoryItem::categories = QList() << 'q' << 'a' << 'o' << 'h' << 'v'; UserCategoryItem::UserCategoryItem(int category, AbstractTreeItem *parent) - : PropertyMapItem(QStringList() << "categoryId", parent), + : PropertyMapItem(QStringList() << "categoryName", parent), _category(category) { + } -QString UserCategoryItem::categoryId() { - if(_category < categories.count()) - return categories[_category].displayString; - else - return tr("Users"); +// caching this makes no sense, since we display the user number dynamically +QString UserCategoryItem::categoryName() const { + int n = childCount(); + switch(_category) { + case 0: return tr("%n Owner(s)", 0, n); + case 1: return tr("%n Admin(s)", 0, n); + case 2: return tr("%n Operator(s)", 0, n); + case 3: return tr("%n Half-Op(s)", 0, n); + case 4: return tr("%n Voiced", 0, n); + default: return tr("%n User(s)", 0, n); + } } quint64 UserCategoryItem::id() const { @@ -502,7 +505,7 @@ bool UserCategoryItem::removeUser(IrcUser *ircUser) { int UserCategoryItem::categoryFromModes(const QString &modes) { for(int i = 0; i < categories.count(); i++) { - if(modes.contains(categories[i].mode)) + if(modes.contains(categories[i])) return i; } return categories.count(); @@ -510,6 +513,8 @@ int UserCategoryItem::categoryFromModes(const QString &modes) { QVariant UserCategoryItem::data(int column, int role) const { switch(role) { + case TreeModel::SortRole: + return _category; case NetworkModel::ItemActiveRole: return true; case NetworkModel::ItemTypeRole: diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index 861d07cf..dc010dd8 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -146,12 +146,12 @@ private: *****************************************/ class UserCategoryItem : public PropertyMapItem { Q_OBJECT - Q_PROPERTY(QString categoryId READ categoryId) + Q_PROPERTY(QString categoryName READ categoryName) public: UserCategoryItem(int category, AbstractTreeItem *parent); - QString categoryId(); + QString categoryName() const; virtual quint64 id() const; virtual QVariant data(int column, int role) const; @@ -163,13 +163,7 @@ public: private: int _category; - struct Category { - QChar mode; - QString displayString; - inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {}; - }; - - static const QList categories; + static const QList categories; }; /***************************************** @@ -208,7 +202,7 @@ class NetworkModel : public TreeModel { public: enum myRoles { - BufferTypeRole = Qt::UserRole, + BufferTypeRole = TreeModel::UserRole, ItemActiveRole, BufferActivityRole, BufferIdRole, diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index ace9d3d7..65310a62 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -247,6 +247,7 @@ QVariant PropertyMapItem::data(int column, int role) const { case Qt::ToolTipRole: return toolTip(column); case Qt::DisplayRole: + case TreeModel::SortRole: // fallthrough, since SortRole should default to DisplayRole return property(_propertyOrder[column].toAscii()); default: return QVariant(); diff --git a/src/client/treemodel.h b/src/client/treemodel.h index 3a1c144e..599956e2 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -133,6 +133,11 @@ class TreeModel : public QAbstractItemModel { Q_OBJECT public: + enum myRoles { + SortRole = Qt::UserRole, + UserRole + }; + TreeModel(const QList &, QObject *parent = 0); virtual ~TreeModel(); diff --git a/src/uisupport/nickviewfilter.cpp b/src/uisupport/nickviewfilter.cpp index e4955ac5..907034d7 100644 --- a/src/uisupport/nickviewfilter.cpp +++ b/src/uisupport/nickviewfilter.cpp @@ -36,6 +36,7 @@ NickViewFilter::NickViewFilter(const BufferId &bufferId, NetworkModel *parent) setSourceModel(parent); setDynamicSortFilter(true); setSortCaseSensitivity(Qt::CaseInsensitive); + setSortRole(TreeModel::SortRole); } QVariant NickViewFilter::data(const QModelIndex &index, int role) const {