bool
KernelSortFilterProxyModel::lessThan( const QModelIndex& left,
                                      const QModelIndex& right ) const
{
    QVariant leftData = sourceModel()->data( left, sortRole() );
    QVariant rightData = sourceModel()->data( right, sortRole() );

    if ( sortRole() == KernelModel::VersionRole )
    {
        int leftMajor = sourceModel()->data( left, KernelModel::MajorVersionRole ).toInt();
        int rightMajor = sourceModel()->data( right, KernelModel::MajorVersionRole ).toInt();
        int leftMinor = sourceModel()->data( left, KernelModel::MinorVersionRole ).toInt();
        int rightMinor = sourceModel()->data( right, KernelModel::MinorVersionRole ).toInt();

        if ( leftMajor == rightMajor )
        {
            if ( leftMinor < rightMinor )
                return true;
            else
                return false;
        }
        else
        {
            if ( leftMajor < rightMajor )
                return true;
            else
                return false;
        }
    }
    else
        return QString::localeAwareCompare( leftData.toString(), rightData.toString() ) < 0;
}
bool ChangelogSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right ) const
{
	QVariant leftData = sourceModel()->data(left, sortRole());
	QVariant rightData = sourceModel()->data(right, sortRole());

	if (!leftData.canConvert<ChangelogEntry>() || !rightData.canConvert<ChangelogEntry>())
	{
		return QSortFilterProxyModel::lessThan(left, right);
	}
	return leftData.value<ChangelogEntry>() < rightData.value<ChangelogEntry>();
}
Ejemplo n.º 3
0
QList<QPair<int, QVariant> > KStandardItemModel::groups() const
{
    QList<QPair<int, QVariant> > groups;

    const QByteArray role = sortRole().isEmpty() ? "group" : sortRole();
    bool isFirstGroupValue = true;
    QString groupValue;
    const int maxIndex = count() - 1;
    for (int i = 0; i <= maxIndex; ++i) {
        const QString newGroupValue = m_items.at(i)->dataValue(role).toString();
        if (newGroupValue != groupValue || isFirstGroupValue) {
            groupValue = newGroupValue;
            groups.append(QPair<int, QVariant>(i, newGroupValue));
            isFirstGroupValue = false;
        }
    }

    return groups;
}
Ejemplo n.º 4
0
bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
                                       const QModelIndex &right) const
{
    QVariant leftData = sourceModel()->data(left,sortRole());
    QVariant rightData = sourceModel()->data(right,sortRole());

    if (leftData.type() == QVariant::DateTime) {
        return leftData.toDateTime() < rightData.toDateTime();
    }
    else if (leftData.type() == QVariant::Double) {
        return leftData.toDouble() < rightData.toDouble();
    }
    else if (leftData.type() == QVariant::String) {
        return QString::localeAwareCompare(leftData.toString(), rightData.toString()) < 0;
    }
    else {
        return false;
    }
}
int QSortFilterProxyModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractProxyModel::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 20)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 20;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QRegExp*>(_v) = filterRegExp(); break;
        case 1: *reinterpret_cast< int*>(_v) = filterKeyColumn(); break;
        case 2: *reinterpret_cast< bool*>(_v) = dynamicSortFilter(); break;
        case 3: *reinterpret_cast< Qt::CaseSensitivity*>(_v) = filterCaseSensitivity(); break;
        case 4: *reinterpret_cast< Qt::CaseSensitivity*>(_v) = sortCaseSensitivity(); break;
        case 5: *reinterpret_cast< bool*>(_v) = isSortLocaleAware(); break;
        case 6: *reinterpret_cast< int*>(_v) = sortRole(); break;
        case 7: *reinterpret_cast< int*>(_v) = filterRole(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setFilterRegExp(*reinterpret_cast< QRegExp*>(_v)); break;
        case 1: setFilterKeyColumn(*reinterpret_cast< int*>(_v)); break;
        case 2: setDynamicSortFilter(*reinterpret_cast< bool*>(_v)); break;
        case 3: setFilterCaseSensitivity(*reinterpret_cast< Qt::CaseSensitivity*>(_v)); break;
        case 4: setSortCaseSensitivity(*reinterpret_cast< Qt::CaseSensitivity*>(_v)); break;
        case 5: setSortLocaleAware(*reinterpret_cast< bool*>(_v)); break;
        case 6: setSortRole(*reinterpret_cast< int*>(_v)); break;
        case 7: setFilterRole(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Ejemplo n.º 6
0
int QStandardItemModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractItemModel::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 2)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
    else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0:
            *reinterpret_cast< int*>(_v) = sortRole();
            break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0:
            setSortRole(*reinterpret_cast< int*>(_v));
            break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 1;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Ejemplo n.º 7
0
QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
{
#ifdef RDM_DEBUG
	std::cerr << "RetroshareDirModel::data(): " << index.internalPointer();
	std::cerr << ": ";
	std::cerr << std::endl;
#endif

	if (!index.isValid())
		return QVariant();

	/* get the data from the index */
	void *ref = index.internalPointer();
	int coln = index.column();

	DirDetails details;
	FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;

	if (!requestDirDetails(ref, details, flags))
		return QVariant();

	if (role == RetroshareDirModel::FileNameRole) /* end of FileNameRole */
		return QString::fromUtf8(details.name.c_str());

	if (role == Qt::TextColorRole)
	{
		if(details.min_age > ageIndicator)
			return Qt::gray ;
		else
			return Qt::black ;
	} /* end of TextColorRole */


	if(role == Qt::DecorationRole)
		return decorationRole(details,coln) ;

	/*****************
	  Qt::EditRole
	  Qt::ToolTipRole
	  Qt::StatusTipRole
	  Qt::WhatsThisRole
	  Qt::SizeHintRole
	 ****************/

	if (role == Qt::SizeHintRole)
	{       
		return QSize(18, 18);     
	} /* end of SizeHintRole */ 

	if (role == Qt::TextAlignmentRole)
	{
		if(coln == 1)
		{
			return int( Qt::AlignRight | Qt::AlignVCenter);
		}
		return QVariant();
	} /* end of TextAlignmentRole */

	if (role == Qt::DisplayRole)
		return displayRole(details,coln) ;

	if (role == SortRole)
		return sortRole(index,details,coln) ;

	return QVariant();
}
Ejemplo n.º 8
0
QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
{
#ifdef RDM_DEBUG
	std::cerr << "RetroshareDirModel::data(): " << index.internalPointer();
	std::cerr << ": ";
	std::cerr << std::endl;
#endif

	if (!index.isValid())
		return QVariant();

	/* get the data from the index */
	void *ref = index.internalPointer();
	int coln = index.column();

	const DirDetails *details = requestDirDetails(ref, RemoteMode);

	if (!details)
		return QVariant();

	if (role == RetroshareDirModel::FileNameRole) /* end of FileNameRole */
		return QString::fromUtf8(details->name.c_str());

	if (role == Qt::TextColorRole)
	{
		if(details->min_age > ageIndicator)
			return QVariant(QColor(Qt::gray)) ;
		else
			return QVariant() ; // standard
	} /* end of TextColorRole */


	if(role == Qt::DecorationRole)
		return decorationRole(*details,coln) ;

	/*****************
	  Qt::EditRole
	  Qt::ToolTipRole
	  Qt::StatusTipRole
	  Qt::WhatsThisRole
	  Qt::SizeHintRole
	 ****************/

	if (role == Qt::SizeHintRole)
	{       
		return QSize(18, 18);     
	} /* end of SizeHintRole */ 

	if (role == Qt::TextAlignmentRole)
	{
		if(coln == 1)
		{
			return int( Qt::AlignRight | Qt::AlignVCenter);
		}
		return QVariant();
	} /* end of TextAlignmentRole */

	if (role == Qt::DisplayRole)
		return displayRole(*details,coln) ;

	if (role == SortRole)
		return sortRole(index,*details,coln) ;

	return QVariant();
}
Ejemplo n.º 9
0
QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
{
#ifdef RDM_DEBUG
	std::cerr << "RetroshareDirModel::data(): " << index.internalPointer();
	std::cerr << ": ";
	std::cerr << std::endl;
#endif

	if (!index.isValid())
		return QVariant();

	/* get the data from the index */
	void *ref = index.internalPointer();
	int coln = index.column();

	const DirDetails *details = requestDirDetails(ref, RemoteMode);

	if (!details)
		return QVariant();

	if (role == RetroshareDirModel::FileNameRole) /* end of FileNameRole */
		return QString::fromUtf8(details->name.c_str());

	if (role == Qt::TextColorRole)
	{
		if(details->min_age > ageIndicator)
			return QVariant(QColor(Qt::gray)) ;
        else if(RemoteMode)
        {
            FileInfo info;
            QVariant local_file_color = QVariant(QColor(Qt::red));
            if(rsFiles->alreadyHaveFile(details->hash, info))
                return local_file_color;

            std::list<RsFileHash> downloads;
            rsFiles->FileDownloads(downloads);
            if(std::find(downloads.begin(), downloads.end(), details->hash) != downloads.end())
                return local_file_color;
            else
                return QVariant();
        }
		else
			return QVariant() ; // standard
	} /* end of TextColorRole */


	if(role == Qt::DecorationRole)
		return decorationRole(*details,coln) ;

	/*****************
	  Qt::EditRole
	  Qt::ToolTipRole
	  Qt::StatusTipRole
	  Qt::WhatsThisRole
	  Qt::SizeHintRole
	 ****************/

	if (role == Qt::SizeHintRole)
	{       
		return QVariant(); // Use standard
	} /* end of SizeHintRole */ 

	if (role == Qt::TextAlignmentRole)
	{
		if(coln == 1)
		{
			return int( Qt::AlignRight | Qt::AlignVCenter);
		}
		return QVariant();
	} /* end of TextAlignmentRole */

	if (role == Qt::DisplayRole)
		return displayRole(*details,coln) ;

	if (role == SortRole)
		return sortRole(index,*details,coln) ;

	return QVariant();
}