Small fixes, but that have an impact of how things are visualized.

* Move "not tagged" elements to the end. We sort the rest (when they have tags), but keep untagged elements (the category) at the end of the view, since the user had
"less" interest on them.

* Break the law again of "dirs first". If we have on a folder only a tagged file (and is a file) and the rest are folders, that file goes first, since it was tagged.

* If we are on the same category, dirs go first. Here we make them citizens of first class.

* Commas instead of spaces when building categories for tags, they make it more readable and less error-prone (we can have tags "a", "dog" and "a dog" as tags, right?, 
so spaces here make the thing a bit hard to distinguish, I have two tags "a", "dog", or the tag "a dog") ;)

* Return an empty string when the item is not tagged at the method tagsForIndex. This way we always show untagged items the latest ones very easily (without nasty string 
checks). We will let the categorizer put a fancy name for them, if the returned string was empty.

CCMAIL: peter.penz@gmx.at

svn path=/trunk/KDE/kdebase/apps/; revision=679097
This commit is contained in:
Rafael Fernández López 2007-06-23 00:43:20 +00:00
parent 743590a944
commit 126c14b3ba
2 changed files with 45 additions and 7 deletions

View file

@ -177,6 +177,10 @@ QString DolphinItemCategorizer::categoryForItem(const QModelIndex& index,
case DolphinView::SortByTags: {
retString = DolphinSortFilterProxyModel::tagsForIndex(index);
if (retString.isEmpty())
retString = i18n("Not yet tagged");
break;
}
#endif

View file

@ -176,6 +176,14 @@ bool DolphinSortFilterProxyModel::lessThanGeneralPurpose(const QModelIndex &left
return leftRating > rightRating;
}
case DolphinView::SortByTags: {
const QString leftTags = tagsForIndex(left);
const QString rightTags = tagsForIndex(right);
if (leftTags.isEmpty() && !rightTags.isEmpty())
return false;
else if (!leftTags.isEmpty() && rightTags.isEmpty())
return true;
return naturalCompare(tagsForIndex(left), tagsForIndex(right)) < 0;
}
#endif
@ -194,8 +202,9 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
const KFileItem* rightFileItem = dirModel->itemForIndex(right);
// If we are sorting by rating, folders and files are citizens of the same
// class
if (sortRole() != DolphinView::SortByRating)
// class. Same if we are sorting by tags.
if ((sortRole() != DolphinView::SortByRating) &&
(sortRole() != DolphinView::SortByTags))
{
// On our priority, folders go above regular files.
if (leftFileItem->isDir() && !rightFileItem->isDir()) {
@ -323,6 +332,11 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
if (leftRating == rightRating) {
// On our priority, folders go above regular files.
// This checks are needed (don't think it's the same doing it here
// than above). Here we make dirs citizens of first class because
// we know we are on the same category. On the check we do on the
// top of the method we don't know, so we remove that check when we
// are sorting by rating. (ereslibre)
if (leftFileItem->isDir() && !rightFileItem->isDir()) {
return true;
} else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
@ -338,7 +352,28 @@ bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
}
case DolphinView::SortByTags: {
return naturalCompare(tagsForIndex(left), tagsForIndex(right)) < 0;
const QString leftTags = tagsForIndex(left);
const QString rightTags = tagsForIndex(right);
if (leftTags == rightTags) {
// On our priority, folders go above regular files.
// This checks are needed (don't think it's the same doing it here
// than above). Here we make dirs citizens of first class because
// we know we are on the same category. On the check we do on the
// top of the method we don't know, so we remove that check when we
// are sorting by tags. (ereslibre)
if (leftFileItem->isDir() && !rightFileItem->isDir()) {
return true;
} else if (!leftFileItem->isDir() && rightFileItem->isDir()) {
return false;
}
return sortCaseSensitivity() ?
(naturalCompare(leftFileItem->name(), rightFileItem->name()) < 0) :
(naturalCompare(leftFileItem->name().toLower(), rightFileItem->name().toLower()) < 0);
}
return naturalCompare(leftTags, rightTags) < 0;
}
#endif
}
@ -384,12 +419,11 @@ QString DolphinSortFilterProxyModel::tagsForIndex(const QModelIndex& index)
foreach (const QString& str, stringList) {
tagsString += str;
tagsString += ' ';
tagsString += ", ";
}
}
if (tagsString.isEmpty()) {
tagsString = i18n("(no tags)");
if (!tagsString.isEmpty())
tagsString.resize(tagsString.size() - 2);
}
return tagsString;