Esempio n. 1
0
int ImageSortSettings::compare(const ImageInfo& left, const ImageInfo& right, SortRole role) const
{
    switch (role)
    {
        case SortByFileName:
            return naturalCompare(left.name(), right.name(), currentSortOrder, sortCaseSensitivity);
        case SortByFilePath:
            return naturalCompare(left.filePath(), right.filePath(), currentSortOrder, sortCaseSensitivity);
        case SortByFileSize:
            return compareByOrder(left.fileSize(), right.fileSize(), currentSortOrder);
        case SortByModificationDate:
            return compareByOrder(left.modDateTime(), right.modDateTime(), currentSortOrder);
        case SortByCreationDate:
            return compareByOrder(left.dateTime(), right.dateTime(), currentSortOrder);
        case SortByRating:
            // I have the feeling that inverting the sort order for rating is the natural order
            return - compareByOrder(left.rating(), right.rating(), currentSortOrder);
        case SortByImageSize:
        {
            QSize leftSize = left.dimensions();
            QSize rightSize = right.dimensions();
            int leftPixels = leftSize.width() * leftSize.height();
            int rightPixels = rightSize.width() * rightSize.height();
            return compareByOrder(leftPixels, rightPixels, currentSortOrder);
        }
        default:
            return 1;
    }
}
Esempio n. 2
0
int ShowfotoItemSortSettings::compareCategories(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const
{
    switch (categorizationMode)
    {
        case NoCategories:
        case CategoryByFolder:
            return naturalCompare(left.folder, right.folder, currentCategorizationSortOrder, categorizationCaseSensitivity);
        case CategoryByFormat:
            return naturalCompare(left.mime, right.mime, currentCategorizationSortOrder, categorizationCaseSensitivity);
        default:
            return 0;
    }
}
Esempio n. 3
0
int ImageSortSettings::compareCategories(const ImageInfo& left, const ImageInfo& right) const
{
    switch (categorizationMode)
    {
        case NoCategories:
        case OneCategory:
            return 0;
        case CategoryByAlbum:
        {
            int leftAlbum = left.albumId();
            int rightAlbum = right.albumId();

            // return comparation result
            if (leftAlbum == rightAlbum)
            {
                return 0;
            }
            else if (lessThanByOrder(leftAlbum, rightAlbum, currentCategorizationSortOrder))
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }
        case CategoryByFormat:
        {
            return naturalCompare(left.format(), right.format(),
                                  currentCategorizationSortOrder, categorizationCaseSensitivity);
        }
        default:
            return 0;
    }
}
Esempio n. 4
0
bool ImageSortSettings::lessThan(const QVariant& left, const QVariant& right) const
{
    if (left.type() != right.type())
    {
        return false;
    }

    switch (left.type())
    {
        case QVariant::Int:
            return compareByOrder(left.toInt(), right.toInt(), currentSortOrder);
        case QVariant::UInt:
            return compareByOrder(left.toUInt(), right.toUInt(), currentSortOrder);
        case QVariant::LongLong:
            return compareByOrder(left.toLongLong(), right.toLongLong(), currentSortOrder);
        case QVariant::ULongLong:
            return compareByOrder(left.toULongLong(), right.toULongLong(), currentSortOrder);
        case QVariant::Double:
            return compareByOrder(left.toDouble(), right.toDouble(), currentSortOrder);
        case QVariant::Date:
            return compareByOrder(left.toDate(), right.toDate(), currentSortOrder);
        case QVariant::DateTime:
            return compareByOrder(left.toDateTime(), right.toDateTime(), currentSortOrder);
        case QVariant::Time:
            return compareByOrder(left.toTime(), right.toTime(), currentSortOrder);
        case QVariant::Rect:
        case QVariant::RectF:
        {
            QRectF rectLeft  = left.toRectF();
            QRectF rectRight = right.toRectF();
            int result;

            if ((result = compareByOrder(rectLeft.top(), rectRight.top(), currentSortOrder)) != 0)
            {
                return result < 0;
            }

            if ((result = compareByOrder(rectLeft.left(), rectRight.left(), currentSortOrder)) != 0)
            {
                return result < 0;
            }

            QSizeF sizeLeft = rectLeft.size(), sizeRight = rectRight.size();

            if ((result = compareByOrder(sizeLeft.width()*sizeLeft.height(), sizeRight.width()*sizeRight.height(), currentSortOrder)) != 0)
            {
                return result < 0;
            }
            // FIXME: fall through?? If not, add "break" here
        }
        default:
            return naturalCompare(left.toString(), right.toString(), currentSortOrder, sortCaseSensitivity);
    }
}
int CamItemSortSettings::compare(const CamItemInfo& left, const CamItemInfo& right, SortRole role) const
{
    switch (role)
    {
        case SortByFileName:
            return naturalCompare(left.name, right.name, currentSortOrder, sortCaseSensitivity);
        case SortByFilePath:
            return naturalCompare(left.url().toLocalFile(), right.url().toLocalFile(), currentSortOrder, sortCaseSensitivity);
        case SortByFileSize:
            return compareByOrder(left.size, right.size, currentSortOrder);
            //FIXME: Change it to creation date instead of modification date.
        case SortByCreationDate:
            return compareByOrder(left.ctime, right.ctime, currentSortOrder);
        case SortByRating:
            return compareByOrder(left.rating, right.rating, currentSortOrder);
        case SortByDownloadState:
            return compareByOrder(left.downloaded, right.downloaded, currentSortOrder);
        default:
            return 1;
    }
}
bool DBFRedactorSortFilterProxyModel::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
{
	for (int i = 0, size = m_sortedColumns.size(); i < size; i++) {
		const QVariant& leftData = sourceModel()->index(left.row(), m_sortedColumns.at(i).first).data(Qt::DisplayRole);
		const QVariant& rightData = sourceModel()->index(right.row(), m_sortedColumns.at(i).first).data(Qt::DisplayRole);
		const Qt::SortOrder order = m_sortedColumns.at(i).second;

		if (leftData == rightData)
			continue;

		switch (leftData.type()) {
			case QVariant::Bool:
				return (leftData.toBool() < rightData.toBool()) ^ order;
				break;
			case QVariant::Int:
				return (leftData.toInt() < rightData.toInt()) ^ order;
				break;
			case QVariant::UInt:
				return (leftData.toUInt() < rightData.toUInt()) ^ order;
				break;
			case QVariant::LongLong:
				return (leftData.toLongLong() < rightData.toLongLong()) ^ order;
				break;
			case QVariant::ULongLong:
				return (leftData.toULongLong() < rightData.toULongLong()) ^ order;
				break;
			case QVariant::Double:
				return (leftData.toDouble() < rightData.toDouble()) ^ order;
				break;
			case QVariant::Char:
				return (leftData.toChar() < rightData.toChar()) ^ order;
				break;
			case QVariant::Date:
				return (leftData.toDate() < rightData.toDate()) ^ order;
				break;
			case QVariant::Time:
				return (leftData.toTime() < rightData.toTime()) ^ order;
				break;
			case QVariant::DateTime:
				return (leftData.toDateTime() < rightData.toDateTime()) ^ order;
				break;
			case QVariant::String:
				return (naturalCompare(leftData.toString(), rightData.toString()) < 0) ^ order;
				break;
		}
	}
	return false;
}
Esempio n. 7
0
int ShowfotoItemSortSettings::compare(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right, SortRole role) const
{
    switch (role)
    {
        case SortByFileName:
            return naturalCompare(left.name, right.name, currentSortOrder, sortCaseSensitivity);
        case SortByFileSize:
            return compareByOrder(left.size, right.size, currentSortOrder);
            //FIXME: Change it to creation date instead of modification date.
            //TODO : complete the needed functions
        case SortByCreationDate:
            return compareByOrder(left.ctime, right.ctime, currentSortOrder);
        default:
            return 1;
    }
}
Esempio n. 8
0
bool DkUtils::compLogicQString(const QString & lhs, const QString & rhs) {

	return naturalCompare(lhs, rhs, Qt::CaseInsensitive);
}
Esempio n. 9
0
 virtual bool sort(const entry &lhs, const entry &rhs)
 {
     return naturalCompare(lhs.second, rhs.second) < 0;
 }
Esempio n. 10
0
bool naturalSortGreaterThanCS( const QString &left, const QString &right )
{
    return (naturalCompare( left, right, Qt::CaseSensitive ) > 0);
}
Esempio n. 11
0
bool naturalSortLessThanCI( const QString &left, const QString &right )
{
    return (naturalCompare( left, right, Qt::CaseInsensitive ) < 0);
}