コード例 #1
0
/*!
 Returns appropiate model's data
 \param modelIndex model index
 \param role which data role to return
 \retval models data as QVariant
 */
QVariant CaItemModelPrivate::data(const QModelIndex &modelIndex,
                                  int role) const
{
    CACLIENTTEST_FUNC_ENTRY("CaItemModelPrivate::data");
    QVariant variant;
    QSharedPointer<CaEntry> pEntry = entry(modelIndex);
    if (!pEntry.isNull()) {
        switch (role) {
        case Qt::DisplayRole:
            variant = displayRole(pEntry.data());
            break;
        case Qt::DecorationRole:
            variant = QVariant(HbIcon(pEntry->makeIcon(mSize)));
            break;
        case CaItemModel::IdRole:
            variant = QVariant(pEntry->id());
            break;
        case CaItemModel::TypeRole:
            variant = QVariant(pEntry->entryTypeName());
            break;
        case CaItemModel::FlagsRole:
            variant = qVariantFromValue(pEntry->flags());
            break;
        case CaItemModel::TextRole:
            variant = QVariant(pEntry->text());
            break;
        case CaItemModel::DescriptionRole:
            variant = QVariant(pEntry->description());
            break;            
        case CaItemModel::FullTextRole:
            variant = QVariant(pEntry->text() + QString(" ") + pEntry->description());
            break;
        case CaItemModel::UninstalRole:
            variant = QVariant(
                pEntry->attribute(UNINSTALL_PROGRESS_APPLICATION_ATTRIBUTE_NAME).toInt());
            break;
        case CaItemModel::CollectionTitleRole:
            if (!pEntry->attribute(COLLECTION_TITLE_NAME).isNull()) {
                variant = QVariant(
                        HbParameterLengthLimiter(pEntry->attribute(COLLECTION_TITLE_NAME))
                        .arg(this->rowCount()).arg(pEntry->text()));
            }
            else {
                variant = QVariant(pEntry->text());
            }
            break;
            
        default:
            variant = QVariant(QVariant::Invalid);
        }
    }
    CACLIENTTEST_FUNC_EXIT("CaItemModelPrivate::data");
    return variant;
}
コード例 #2
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();
}
コード例 #3
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();
}
コード例 #4
0
ファイル: RemoteDirModel.cpp プロジェクト: MrKID/RetroShare
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();
}