QVariant CueSheetModel::data(const QModelIndex &index, int role) const { QMutexLocker lock(&m_mutex); if(role == Qt::DisplayRole) { CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer()); if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(item)) { switch(index.column()) { case 0: return tr("File %1").arg(QString().sprintf("%02d", index.row() + 1)).append(" "); break; case 1: return QFileInfo(filePtr->fileName()).fileName(); break; default: return QVariant(); break; } } else if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(item)) { switch(index.column()) { case 0: return tr("Track %1").arg(QString().sprintf("%02d", trackPtr->trackNo())).append(" "); break; case 1: if(!trackPtr->title().isEmpty() && !trackPtr->performer().isEmpty()) { return QString("%1 - %2").arg(trackPtr->performer(), trackPtr->title()); } else if(!trackPtr->title().isEmpty()) { return QString("%1 - %2").arg(tr("Unknown Artist"), trackPtr->title()); } else if(!trackPtr->performer().isEmpty()) { return QString("%1 - %2").arg(trackPtr->performer(), tr("Unknown Title")); } else { return QString("%1 - %2").arg(tr("Unknown Artist"), tr("Unknown Title")); } break; case 2: return indexToString(trackPtr->startIndex()); break; case 3: return indexToString(trackPtr->duration()); break; default: return QVariant(); break; } } } else if(role == Qt::ToolTipRole) { CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer()); if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(item)) { return QDir::toNativeSeparators(filePtr->fileName()); } else if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(item)) { return QDir::toNativeSeparators(trackPtr->parent()->fileName()); } } else if(role == Qt::DecorationRole) { if(index.column() == 0) { CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer()); if(dynamic_cast<CueSheetFile*>(item)) { return m_fileIcon; } else if(dynamic_cast<CueSheetTrack*>(item)) { return m_trackIcon; } } } else if(role == Qt::FontRole) { QFont font("Monospace"); font.setStyleHint(QFont::TypeWriter); if((index.column() == 1)) { CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer()); font.setBold(dynamic_cast<CueSheetFile*>(item) != NULL); } return font; } else if(role == Qt::ForegroundRole) { if((index.column() == 1)) { CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer()); if(CueSheetFile *filePtr = dynamic_cast<CueSheetFile*>(item)) { return (QFileInfo(filePtr->fileName()).size() > 4) ? QColor("mediumblue") : QColor("darkred"); } } else if((index.column() == 3)) { CueSheetItem *item = reinterpret_cast<CueSheetItem*>(index.internalPointer()); if(CueSheetTrack *trackPtr = dynamic_cast<CueSheetTrack*>(item)) { if(trackPtr->duration() == std::numeric_limits<double>::infinity()) { return QColor("dimgrey"); } } } } return QVariant(); }
void GroupDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QRect r = option.rect; QFont font = painter->font(); QPen pen = painter->pen(); if (!index.parent().isValid()) { painter->setBrush(Qt::red); font.setPixelSize(14); font.setUnderline(false); painter->setFont(font); pen.setColor(grayFont); //painter->setBackground(Qt::gray); painter->fillRect(option.rect, grayBackground); if (index.column()==0) { //if (option.state & QStyle::State_Editing) QPixmap icon = tree->isExpanded(index) ? QPixmap(":/Images/Visitors/icon_minus.png") : QPixmap(":/Images/Visitors/icon_plus.png"); painter->drawPixmap(r.x() + 8, r.y() + 6, 16, 16, icon); } painter->setPen(pen); painter->setFont(font); painter->drawText(QPoint(r.x() + 32, r.y() + 18), index.data().toString()); } else { if (option.state & QStyle::State_MouseOver) { painter->fillRect(option.rect, grayBackground); } QVariant value = index.data(Qt::DecorationRole); int adjust = index.column()==0 ? 24 : 0; if (value.isValid() && value.type() == QVariant::Icon) { QIcon icon = value.value<QIcon>(); if (icon.availableSizes().count()>0) { int width = icon.availableSizes().at(0).width(); icon.paint(painter, r.x()+8 + adjust, r.y(), width, 28); adjust += width + 8; } } font.setPixelSize(12); if (index.column() == 0 || index.column() == 10) { font.setUnderline(true); pen.setColor(hyperlink); } else { font.setUnderline(false); pen.setColor(grayFont); } painter->setPen(pen); painter->setFont(font); QTextOption textOptions(Qt::AlignLeft); textOptions.setWrapMode(QTextOption::NoWrap); painter->drawText(r.adjusted(8 + adjust,6,0,0), index.data().toString(), textOptions); //painter->drawText(QPoint(r.x() + 32, r.y() + r.height()/2 + font.pixelSize()/2 - 1), index.data().toString(), o); } }
QVariant SGGeometryModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || !m_geometry || !index.internalPointer() || index.row() >= m_geometry->vertexCount() || index.column() >= m_geometry->attributeCount()) return QVariant(); if (role == Qt::DisplayRole) { const QSGGeometry::Attribute *attrInfo = m_geometry->attributes(); attrInfo += index.column(); switch (attrInfo->type) { case GL_BYTE: return toStringList<char>(index.internalPointer(), attrInfo->tupleSize).join(", "); case GL_UNSIGNED_BYTE: return toStringList<unsigned char>(index.internalPointer(), attrInfo->tupleSize).join(", "); case GL_UNSIGNED_SHORT: return toStringList<quint16>(index.internalPointer(), attrInfo->tupleSize).join(", "); case GL_SHORT: return toStringList<qint16>(index.internalPointer(), attrInfo->tupleSize).join(", "); case GL_INT: return toStringList<int>(index.internalPointer(), attrInfo->tupleSize).join(", "); case GL_UNSIGNED_INT: return toStringList<uint>(index.internalPointer(), attrInfo->tupleSize).join(", "); case GL_FLOAT: return toStringList<float>(index.internalPointer(), attrInfo->tupleSize).join(", "); #if GL_DOUBLE != GL_FLOAT case GL_DOUBLE: return toStringList<double>(index.internalPointer(), attrInfo->tupleSize).join(", "); #endif #ifndef QT_OPENGL_ES_2 case GL_2_BYTES: return "2Bytes"; case GL_3_BYTES: return "3Bytes"; case GL_4_BYTES: return "4Bytes"; #endif default: return QString("Unknown %1 byte data: 0x").arg(attrInfo->tupleSize).append(QByteArray((char*)index.internalPointer(), attrInfo->tupleSize).toHex()); } } else if (role == IsCoordinateRole) { const QSGGeometry::Attribute *attrInfo = m_geometry->attributes(); attrInfo += index.column(); return (bool)attrInfo->isVertexCoordinate; } else if (role == RenderRole) { const QSGGeometry::Attribute *attrInfo = m_geometry->attributes(); attrInfo += index.column(); switch (attrInfo->type) { case GL_BYTE: return toVariantList<char>(index.internalPointer(), attrInfo->tupleSize); case GL_UNSIGNED_BYTE: return toVariantList<unsigned char>(index.internalPointer(), attrInfo->tupleSize); case GL_UNSIGNED_SHORT: return toVariantList<quint16>(index.internalPointer(), attrInfo->tupleSize); case GL_SHORT: return toVariantList<qint16>(index.internalPointer(), attrInfo->tupleSize); case GL_INT: return toVariantList<int>(index.internalPointer(), attrInfo->tupleSize); case GL_UNSIGNED_INT: return toVariantList<uint>(index.internalPointer(), attrInfo->tupleSize); case GL_FLOAT: return toVariantList<float>(index.internalPointer(), attrInfo->tupleSize); #if GL_DOUBLE != GL_FLOAT case GL_DOUBLE: return toVariantList<double>(index.internalPointer(), attrInfo->tupleSize); #endif default: return QVariant(); } } return QVariant(); }
QVariant EH_SECT_rela::data( const QModelIndex &index, int role ) const { EH_index_t value; QString temp; uElf_Rela current_header = rela; if( !index.isValid() ) return QVariant(); if( (EH_index_t) index.row() >= nRelocs || (EH_index_t) index.column() >= eh_rela::fieldnum ) return QVariant(); if( is64bit ) current_header.rela64 += index.row(); else current_header.rela32 += index.row(); switch( role ) { case Qt::DisplayRole: switch( index.column() ) { case 0: value = is64bit ? current_header.rela64->r_offset : current_header.rela32->r_offset; temp = "0x" + QString::number( value, 16 ); break; case 1: value = is64bit ? (current_header.rela64->r_info)>>32 : (current_header.rela32->r_info)>>8; temp = "Sym# " + QString::number( value ); break; case 2: value = is64bit ? (current_header.rela64->r_info)&0xFFFFFFFF : (current_header.rela32->r_info)&0xFF; switch( value ) { case R_386_NONE: temp = "R_386_NONE"; break; case R_386_32: temp = "R_386_32"; break; case R_386_PC32: temp = "R_386_PC32"; break; case R_386_GOT32: temp = "R_386_GOT32"; break; case R_386_PLT32: temp = "R_386_PLT32"; break; case R_386_COPY: temp = "R_386_COPY"; break; case R_386_GLOB_DAT: temp = "R_386_GLOB_DAT"; break; case R_386_JMP_SLOT: temp = "R_386_JMP_SLOT"; break; case R_386_RELATIVE: temp = "R_386_RELATIVE"; break; case R_386_GOTOFF: temp = "R_386_GOTOFF"; break; case R_386_GOTPC: temp = "R_386_GOTPC"; break; case R_386_32PLT: temp = "R_386_32PLT"; break; case R_386_TLS_TPOFF: temp = "R_386_TLS_TPOFF"; break; case R_386_TLS_IE: temp = "R_386_TLS_IE"; break; case R_386_TLS_GOTIE: temp = "R_386_TLS_GOTIE"; break; case R_386_TLS_LE: temp = "R_386_TLS_LE"; break; case R_386_TLS_GD: temp = "R_386_TLS_GD"; break; case R_386_TLS_LDM: temp = "R_386_TLS_LDM"; break; case R_386_16: temp = "R_386_16"; break; case R_386_PC16: temp = "R_386_PC16"; break; case R_386_8: temp = "R_386_8"; break; case R_386_PC8: temp = "R_386_PC8"; break; case R_386_TLS_GD_32: temp = "R_386_TLS_GD_32"; break; case R_386_TLS_GD_PUSH: temp = "R_386_TLS_GD_PUSH"; break; case R_386_TLS_GD_CALL: temp = "R_386_TLS_GD_CALL"; break; case R_386_TLS_GD_POP: temp = "R_386_TLS_GD_POP"; break; case R_386_TLS_LDM_32: temp = "R_386_TLS_LDM_32"; break; case R_386_TLS_LDM_PUSH: temp = "R_386_TLS_LDM_PUSH"; break; case R_386_TLS_LDM_CALL: temp = "R_386_TLS_LDM_CALL"; break; case R_386_TLS_LDM_POP: temp = "R_386_TLS_LDM_POP"; break; case R_386_TLS_LDO_32: temp = "R_386_TLS_LDO_32"; break; case R_386_TLS_IE_32: temp = "R_386_TLS_IE_32"; break; case R_386_TLS_LE_32: temp = "R_386_TLS_LE_32"; break; case R_386_TLS_DTPMOD32: temp = "R_386_TLS_DTPMOD32"; break; case R_386_TLS_DTPOFF32: temp = "R_386_TLS_DTPOFF32"; break; case R_386_TLS_TPOFF32: temp = "R_386_TLS_TPOFF32"; break; case R_386_TLS_GOTDESC: temp = "R_386_TLS_GOTDESC"; break; case R_386_TLS_DESC_CALL: temp = "R_386_TLS_DESC_CALL"; break; case R_386_TLS_DESC: temp = "R_386_TLS_DESC"; break; case R_386_IRELATIVE: temp = "R_386_IRELATIVE"; break; default: temp = "<Unknown>"; break; } break; case 3: value = is64bit ? current_header.rela64->r_addend : current_header.rela32->r_addend; temp = "0x" + QString::number( value, 16 ); break; default: return QVariant(); break; } break; case Qt::ToolTipRole: case Qt::StatusTipRole: switch( index.column() ) { case 0: value = is64bit ? current_header.rela64->r_offset : current_header.rela32->r_offset; break; case 1: value = is64bit ? (current_header.rela64->r_info)>>32 : (current_header.rela32->r_info)>>8; break; case 2: value = is64bit ? (current_header.rela64->r_info)&0xFFFFFFFF : (current_header.rela32->r_info)&0xFF; break; case 3: value = is64bit ? current_header.rela64->r_addend : current_header.rela32->r_addend; default: return QVariant(); break; } temp = "0x" + QString::number( value, 16 ); break; default: return QVariant(); } return temp; }
QVariant UserListModel::data(const QModelIndex & index, int role) const { if (!index.isValid()) return QVariant(); UserListItem * item = static_cast<UserListItem*>(index.internalPointer()); if (!item) return QVariant(); switch (role){ case Qt::DisplayRole: { switch (index.column()) { case COLUMN_NICK: return item->getNick(); case COLUMN_COMMENT: return item->getComment(); case COLUMN_TAG: return item->getTag(); case COLUMN_CONN: return item->getConnection(); case COLUMN_EMAIL: return item->getEmail(); case COLUMN_SHARE: return WulforUtil::formatBytes(item->getShare()); case COLUMN_IP: return item->getIP(); } break; } case Qt::DecorationRole: { if (index.column() != COLUMN_NICK) break; return (*WU->getUserIcon(item->getUser(), item->isAway(), item->isOP(), item->getConnection())); break; } case Qt::ToolTipRole: { if (index.column() == COLUMN_SHARE) return QString::number(item->getShare()); else { QString ttip = "<b>" + headerData(COLUMN_NICK, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getNick() + "<br/>"; ttip += "<b>" + headerData(COLUMN_COMMENT, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getComment() + "<br/>"; ttip += "<b>" + headerData(COLUMN_EMAIL, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getEmail() + "<br/>"; ttip += "<b>" + headerData(COLUMN_IP, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getIP() + "<br/>"; ttip += "<b>" + headerData(COLUMN_SHARE, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + WulforUtil::formatBytes(item->getShare()) + "<br/>"; QString tag = item->getTag(); WulforUtil::getInstance()->textToHtml(tag, true); ttip += "<b>" + headerData(COLUMN_TAG, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + tag + "<br/>"; ttip += "<b>" + headerData(COLUMN_CONN, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getConnection() + "<br/>"; if (item->isOP()) ttip += tr("<b>Hub role</b>: Operator"); else ttip += tr("<b>Hub role</b>: User"); if (item->isFav()) ttip += tr("<br/><b>Favorite user</b>"); return ttip; } break; } case Qt::TextAlignmentRole: { if (index.column() == COLUMN_SHARE) return static_cast<int>(Qt::AlignRight | Qt::AlignVCenter); break; } case Qt::FontRole: { if (item->isFav() && WBGET(WB_CHAT_HIGHLIGHT_FAVS)) { QFont font; font.setBold(true); return font; } break; } } return QVariant(); }
void qtractorMidiEventItemDelegate::setModelData ( QWidget *pEditor, QAbstractItemModel *pModel, const QModelIndex& index ) const { const qtractorMidiEventListModel *pListModel = static_cast<const qtractorMidiEventListModel *> (pModel); qtractorMidiEvent *pEvent = pListModel->eventOfIndex(index); if (pEvent == NULL) return; qtractorMidiEditor *pMidiEditor = pListModel->editor(); if (pMidiEditor == NULL) return; #ifdef CONFIG_DEBUG qDebug("qtractorMidiEventItemDelegate::setModelData(%p, %p, %d, %d)", pEditor, pListModel, index.row(), index.column()); #endif qtractorTimeScale *pTimeScale = pMidiEditor->timeScale(); qtractorMidiEditCommand *pEditCommand = new qtractorMidiEditCommand(pMidiEditor->midiClip(), tr("edit %1").arg(pListModel->headerData( index.column(), Qt::Horizontal, Qt::DisplayRole) .toString().toLower())); switch (index.column()) { case 0: // Time. { qtractorTimeSpinBox *pTimeSpinBox = qobject_cast<qtractorTimeSpinBox *> (pEditor); if (pTimeSpinBox) { unsigned long iTime = pTimeScale->tickFromFrame(pTimeSpinBox->valueFromText()); if (iTime > pMidiEditor->timeOffset()) iTime -= pMidiEditor->timeOffset(); else iTime = 0; unsigned long iDuration = 0; if (pEvent->type() == qtractorMidiEvent::NOTEON) iDuration = pEvent->duration(); pEditCommand->resizeEventTime(pEvent, iTime, iDuration); } break; } case 2: // Name. { QComboBox *pComboBox = qobject_cast<QComboBox *> (pEditor); if (pComboBox) { const int iNote = pComboBox->currentIndex(); const unsigned long iTime = pEvent->time(); pEditCommand->moveEvent(pEvent, iNote, iTime); } break; } case 3: // Value. { QSpinBox *pSpinBox = qobject_cast<QSpinBox *> (pEditor); if (pSpinBox) { const int iValue = pSpinBox->value(); pEditCommand->resizeEventValue(pEvent, iValue); } break; } case 4: // Duration/Data. { qtractorTimeSpinBox *pTimeSpinBox = qobject_cast<qtractorTimeSpinBox *> (pEditor); if (pTimeSpinBox) { const unsigned long iTime = pEvent->time(); const unsigned long iDuration = pTimeScale->tickFromFrame(pTimeSpinBox->value()); pEditCommand->resizeEventTime(pEvent, iTime, iDuration); } break; } default: break; } // Do it. pMidiEditor->commands()->exec(pEditCommand); }
QVariant MessageLogWindowModel::data(const QModelIndex &index, int role) const { if (mpLog.get() == NULL || !index.isValid()) { return QVariant(); } const Subject* pSubject = reinterpret_cast<Subject*>(index.internalPointer()); const DynamicObject* pProperties = dynamic_cast<const DynamicObject*>(pSubject); if (pProperties != NULL) { if ((role == Qt::DisplayRole) || (role == Qt::ToolTipRole)) { const Message* pParent = mPropertyCache[pProperties]; const Step* pParentStep = dynamic_cast<const Step*>(pParent); // this is a property index unsigned int propertyNumber = index.row(); if (pParentStep != NULL) { propertyNumber -= pParentStep->size(); } if (propertyNumber < pProperties->getNumAttributes()) { vector<string> propertyNames; pProperties->getAttributeNames(propertyNames); string name = propertyNames[propertyNumber]; QString header(headerData(index.column(), Qt::Horizontal).toString()); if (header == "ID") { return QString::fromStdString(name); } else if (header == "Type") { string type; const DataVariant& attrValue = pProperties->getAttribute(name); if (attrValue.isValid()) { type = attrValue.getTypeName(); } return QString::fromStdString(type); } else if (header == "Message") { string value = pProperties->getAttribute(name).toDisplayString(); return QString::fromStdString(value); } } return QVariant(); } } else { const MessageImp* pMessageImp = dynamic_cast<const MessageImp*>(pSubject); if (pMessageImp == NULL) { return QVariant(); } switch (role) { case Qt::DisplayRole: case Qt::ToolTipRole: { QString header(headerData(index.column(), Qt::Horizontal).toString()); if ((header == "ID") && (role == Qt::DisplayRole)) { return QString::fromStdString(const_cast<MessageImp*>(pMessageImp)->getStringId()); } else if ((header == "Type") && (role == Qt::DisplayRole)) { if (dynamic_cast<const Step*>(pMessageImp) != NULL) { return QString("Step"); } else { return QString("Message"); } } else if (header == "Message") { return QString::fromStdString(pMessageImp->getAction()); } else if ((header == "Result") && (role == Qt::DisplayRole)) { const Step* pStep = dynamic_cast<const Step*>(pMessageImp); if (pStep != NULL) { switch (pStep->getResult()) { case Message::Success: return QString("Success"); case Message::Failure: return QString("Failure"); case Message::Abort: return QString("Aborted"); default: ; // blank } } } else if (header == "Reason") { const Step* pStep = dynamic_cast<const Step*>(pMessageImp); if ((pStep != NULL) && ((pStep->getResult() == Message::Abort) || (pStep->getResult() == Message::Failure))) { return QString::fromStdString(pStep->getFailureMessage()); } } else if (header == "Time Stamp") { string date; string time; pMessageImp->serializeDate(date, time); return QString::fromStdString(date) + " " + QString::fromStdString(time); } else if ((header == "Component") && (role == Qt::DisplayRole)) { return QString::fromStdString(pMessageImp->getComponent()); } else if ((header == "Key") && (role == Qt::DisplayRole)) { return QString::fromStdString(pMessageImp->getKey()); } break; } case Qt::BackgroundRole: { if (pMessageImp->getComponent().empty() || pMessageImp->getKey().empty()) { return QVariant(Qt::yellow); } const StepImp* pStepImp = dynamic_cast<const StepImp*>(pMessageImp); if ((pStepImp != NULL) && (pStepImp->getResult() == Message::Failure)) { return QVariant(Qt::red); } break; } case Qt::ForegroundRole: { const StepImp* pStepImp = dynamic_cast<const StepImp*>(pMessageImp); if ((pStepImp != NULL) && (pStepImp->getResult() == Message::Failure)) { return QVariant(Qt::white); } break; } default: ; // blank } } return QVariant(); }
QVariant BaseModel::data( const QModelIndex & index, int role ) const { NifItem * item = static_cast<NifItem*>( index.internalPointer() ); if ( ! ( index.isValid() && item && index.model() == this ) ) return QVariant(); int column = index.column(); if (role == NifSkopeDisplayRole) role = Qt::DisplayRole; switch ( role ) { case Qt::DisplayRole: { switch ( column ) { case NameCol: return item->name(); case TypeCol: return item->type(); case ValueCol: return item->value().toString(); case ArgCol: return item->arg(); case Arr1Col: return item->arr1(); case Arr2Col: return item->arr2(); case CondCol: return item->cond(); case Ver1Col: return ver2str( item->ver1() ); case Ver2Col: return ver2str( item->ver2() ); case VerCondCol: return item->vercond(); default: return QVariant(); } } case Qt::EditRole: { switch ( column ) { case NameCol: return item->name(); case TypeCol: return item->type(); case ValueCol: return item->value().toVariant(); case ArgCol: return item->arg(); case Arr1Col: return item->arr1(); case Arr2Col: return item->arr2(); case CondCol: return item->cond(); case Ver1Col: return ver2str( item->ver1() ); case Ver2Col: return ver2str( item->ver2() ); case VerCondCol: return item->vercond(); default: return QVariant(); } } case Qt::ToolTipRole: { QString tip; switch ( column ) { case ValueCol: { switch ( item->value().type() ) { case NifValue::tWord: case NifValue::tShort: { quint16 s = item->value().toCount(); return QString( "dec: %1<br>hex: 0x%2" ).arg( s ).arg( s, 4, 16, QChar( '0' ) ); } case NifValue::tBool: case NifValue::tInt: case NifValue::tUInt: { quint32 i = item->value().toCount(); return QString( "dec: %1<br>hex: 0x%2" ).arg( i ).arg( i, 8, 16, QChar( '0' ) ); } case NifValue::tFloat: { float f = item->value().toFloat(); quint32 i = item->value().toCount(); return QString( "float: %1<br>data: 0x%2" ).arg( f ).arg( i, 8, 16, QChar( '0' ) ); } case NifValue::tFlags: { quint16 f = item->value().toCount(); return QString( "dec: %1<br>hex: 0x%2<br>bin: 0b%3" ).arg( f ).arg( f, 4, 16, QChar( '0' ) ).arg( f, 16, 2, QChar( '0' ) ); } case NifValue::tVector3: return item->value().get<Vector3>().toHtml(); case NifValue::tMatrix: return item->value().get<Matrix>().toHtml(); case NifValue::tQuat: case NifValue::tQuatXYZW: return item->value().get<Quat>().toHtml(); case NifValue::tColor3: { Color3 c = item->value().get<Color3>(); return QString( "R %1<br>G %2<br>B %3" ).arg( c[0] ).arg( c[1] ).arg( c[2] ); } case NifValue::tColor4: { Color4 c = item->value().get<Color4>(); return QString( "R %1<br>G %2<br>B %3<br>A %4" ).arg( c[0] ).arg( c[1] ).arg( c[2] ).arg( c[3] ); } default: break; } } break; default: break; } } return QVariant(); case Qt::BackgroundColorRole: { if ( column == ValueCol && item->value().isColor() ) { return item->value().toColor(); } } return QVariant(); default: return QVariant(); } }
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(); }
bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, int role ) { if ( !QStandardItemModel::setData( idx, value, role ) ) return false; if ( idx.column() == dbtmType || idx.column() == dbtmSrid || idx.column() == dbtmPkCol ) { QGis::WkbType wkbType = ( QGis::WkbType ) idx.sibling( idx.row(), dbtmType ).data( Qt::UserRole + 2 ).toInt(); QString tip; if ( wkbType == QGis::WKBUnknown ) { tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) ); } else if ( wkbType != QGis::WKBNoGeometry ) { bool ok; int srid = idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok ); if ( !ok || srid == INT_MIN ) tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) ); } QStringList pkCols = idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toStringList(); if ( tip.isEmpty() && !pkCols.isEmpty() ) { QSet<QString> s0( idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 2 ).toStringList().toSet() ); QSet<QString> s1( pkCols.toSet() ); if ( s0.intersect( s1 ).isEmpty() ) tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) ); } for ( int i = 0; i < dbtmColumns; i++ ) { QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) ); if ( tip.isEmpty() ) { if ( i == dbtmSchema ) { item->setData( QVariant(), Qt::DecorationRole ); } item->setFlags( item->flags() | Qt::ItemIsSelectable ); item->setToolTip( "" ); } else { item->setFlags( item->flags() & ~Qt::ItemIsSelectable ); if ( i == dbtmSchema ) item->setData( QgsApplication::getThemeIcon( "/mIconWarn.png" ), Qt::DecorationRole ); if ( i == dbtmSchema || i == dbtmTable || i == dbtmGeomCol ) { item->setFlags( item->flags() ); item->setToolTip( tip ); } } } } return true; }
QVariant RawModel::data(const QModelIndex &index, int role) const { if(role != Qt::DisplayRole && role != Qt::BackgroundRole) return QVariant(); if (index.isValid()) { //******** first column (chname) ******** if(index.column()==0 && role == Qt::DisplayRole) return QVariant(m_chInfolist[index.row()].ch_name); //******** second column (data plot) ******** if(index.column()==1) { QVariant v; switch(role) { case Qt::DisplayRole: { //form RowVectorPair of pointer and length of RowVector QPair<const double*,qint32> rowVectorPair; //pack all adjacent (after reload) RowVectorPairs into a QList QList<RowVectorPair> listRowVectorPair; for(qint16 i=0; i < m_data.size(); ++i) { //if channel is not filtered or background Processing pending... if(!m_assignedOperators.contains(index.row()) || (m_bProcessing && m_bReloadBefore && i==0) || (m_bProcessing && !m_bReloadBefore && i==m_data.size()-1)) { rowVectorPair.first = m_data[i].data() + index.row()*m_data[i].cols(); rowVectorPair.second = m_data[i].cols(); } else { //if channel IS filtered rowVectorPair.first = m_procData[i].data() + index.row()*m_procData[i].cols(); rowVectorPair.second = m_procData[i].cols(); } listRowVectorPair.append(rowVectorPair); } v.setValue(listRowVectorPair); return v; break; } case Qt::BackgroundRole: { if(m_fiffInfo.bads.contains(m_chInfolist[index.row()].ch_name)) { QBrush brush; brush.setStyle(Qt::SolidPattern); // qDebug() << m_chInfolist[index.row()].ch_name << "is marked as bad, index:" << index.row(); brush.setColor(Qt::red); return QVariant(brush); } else return QVariant(); break; } } // end role switch } // end column check } // end index.valid() check return QVariant(); }
QVariant PacketListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); PacketListRecord *record = static_cast<PacketListRecord*>(index.internalPointer()); if (!record) return QVariant(); frame_data *fdata = record->getFdata(); if (!fdata) return QVariant(); switch (role) { case Qt::FontRole: return wsApp->monospaceFont(); // case Qt::TextAlignmentRole: case Qt::BackgroundRole: const color_t *color; if (fdata->flags.ignored) { color = &prefs.gui_ignored_bg; } else if (fdata->flags.marked) { color = &prefs.gui_marked_bg; } else if (fdata->color_filter) { const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter; color = &color_filter->bg_color; } else { return QVariant(); } // g_log(NULL, G_LOG_LEVEL_DEBUG, "i: %d m: %d cf: %p bg: %d %d %d", fdata->flags.ignored, fdata->flags.marked, fdata->color_filter, color->red, color->green, color->blue); return QColor(color->red >> 8, color->green >> 8, color->blue >> 8); case Qt::ForegroundRole: if (fdata->flags.ignored) { color = &prefs.gui_ignored_fg; } else if (fdata->flags.marked) { color = &prefs.gui_marked_fg; } else if (fdata->color_filter) { const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter; color = &color_filter->fg_color; } else { return QVariant(); } return QColor(color->red >> 8, color->green >> 8, color->blue >> 8); case Qt::DisplayRole: // Fall through break; default: return QVariant(); } int col_num = index.column(); // g_log(NULL, G_LOG_LEVEL_DEBUG, "showing col %d", col_num); if (!cap_file_ || col_num > cap_file_->cinfo.num_cols) return QVariant(); epan_dissect_t edt; column_info *cinfo; gboolean create_proto_tree; struct wtap_pkthdr phdr; /* Packet header */ guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */ gboolean dissect_columns = TRUE; // XXX - Currently only a placeholder if (dissect_columns && cap_file_) cinfo = &cap_file_->cinfo; else cinfo = NULL; if (!cap_file_ || !cf_read_frame_r(cap_file_, fdata, &phdr, pd)) { /* * Error reading the frame. * * Don't set the color filter for now (we might want * to colorize it in some fashion to warn that the * row couldn't be filled in or colorized), and * set the columns to placeholder values, except * for the Info column, where we'll put in an * error message. */ if (dissect_columns) { col_fill_in_error(cinfo, fdata, FALSE, FALSE /* fill_fd_columns */); // for(gint col = 0; col < cinfo->num_cols; ++col) { // /* Skip columns based on frame_data because we already store those. */ // if (!col_based_on_frame_data(cinfo, col)) // packet_list_change_record(packet_list, record->physical_pos, col, cinfo); // } // record->columnized = TRUE; } if (enable_color_) { fdata->color_filter = NULL; // record->colorized = TRUE; } return QVariant(); /* error reading the frame */ } create_proto_tree = (color_filters_used() && enable_color_) || (have_custom_cols(cinfo) && dissect_columns); epan_dissect_init(&edt, create_proto_tree, FALSE /* proto_tree_visible */); if (enable_color_) color_filters_prime_edt(&edt); if (dissect_columns) col_custom_prime_edt(&edt, cinfo); epan_dissect_run(&edt, &phdr, pd, fdata, cinfo); if (enable_color_) fdata->color_filter = color_filters_colorize_packet(&edt); if (dissect_columns) { /* "Stringify" non frame_data vals */ epan_dissect_fill_in_columns(&edt, FALSE, FALSE /* fill_fd_columns */); // for(col = 0; col < cinfo->num_cols; ++col) { // /* Skip columns based on frame_data because we already store those. */ // if (!col_based_on_frame_data(cinfo, col)) // packet_list_change_record(packet_list, record->physical_pos, col, cinfo); // } // g_log(NULL, G_LOG_LEVEL_DEBUG, "d_c %d: %s", col_num, cinfo->col_data[col_num]); } // if (dissect_columns) // record->columnized = TRUE; // if (enable_color_) // record->colorized = TRUE; epan_dissect_cleanup(&edt); return record->data(col_num, cinfo); }
void ShVarModel::unsetItemWatched(const QModelIndex & i_qIndex) { QStack<QModelIndex> stack; ShVarItem *item = NULL; if (i_qIndex.isValid()) { stack.push(m_qWatchProxy->mapToSource(i_qIndex)); while (!stack.isEmpty()) { QModelIndex idx = stack.pop(); item = static_cast<ShVarItem*>(idx.internalPointer()); if (item != NULL) { item->setData(DF_WATCHED, false); if (item->childCount() > 0) { /* Item is root or inner node. */ for (int i = 0; i < item->childCount(); i++) { // TODO: There is possible a more elegant solution to // get indices of the children, but I am no Qt expert // and this seems to work somehow. stack.push(idx.child(i, idx.column())); } } else { /* Item is leaf node. */ if (item->getPixelBoxPointer() != NULL) { PixelBox *fb = item->getPixelBoxPointer(); item->setPixelBoxPointer(NULL); delete fb; } if (item->getCurrentPointer() != NULL) { VertexBox *vb = item->getCurrentPointer(); item->setCurrentPointer(NULL); delete vb; } if (item->getVertexBoxPointer() != NULL) { VertexBox *vb = item->getVertexBoxPointer(); item->setVertexBoxPointer(NULL); delete vb; } /* end if (item->childCount() > 0) */ m_qWatchListItems.removeAll(item); } /* end if (item->childCount() > 0) */ } /* if (item != NULL) */ } /* end while (!stack.isEmpty()) */ /* 'item' should now be the item associated with 'i_qIndex'. */ /* * Remove parent recursively when all children have left the watch list. * This must not be done for child nodes of 'item' as (i) these are * guaranteed to be removed be the iterative tree traversal above and * (ii) too many nodes will be removed if doing so because because the * tree is reorganised as nodes are removed and the indices of removed * nodes are reused under certain circumstances. */ if (item != NULL) { unsetRecursiveWatched(item); } /* used to update the whole tree, * it seems just emiting the signal is not enough for qt 4.2.2 */ m_qWatchProxy->setFilterRegExp(QRegExp("(true|1)")); } /* end if (i_qIndex.isValid()) */ }
// TODO margin void FileListItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { FileListItem *item = static_cast<FileListItem*>( index.internalPointer() ); QColor backgroundColor; painter->save(); QStyleOptionViewItem _option = option; bool isConverting = false; bool isFailed = false; if( item ) { switch( item->state ) { case FileListItem::WaitingForConversion: break; case FileListItem::Ripping: isConverting = true; break; case FileListItem::Converting: isConverting = true; break; case FileListItem::ApplyingReplayGain: isConverting = true; break; case FileListItem::WaitingForAlbumGain: break; case FileListItem::ApplyingAlbumGain: isConverting = true; break; case FileListItem::Stopped: switch( item->returnCode ) { case FileListItem::Succeeded: break; case FileListItem::SucceededWithProblems: break; case FileListItem::StoppedByUser: break; case FileListItem::BackendNeedsConfiguration: isFailed = true; break; case FileListItem::DiscFull: isFailed = true; break; case FileListItem::Skipped: break; case FileListItem::Failed: isFailed = true; break; } break; } } if( isConverting ) { if( option.state & QStyle::State_Selected ) { backgroundColor = QColor(215,102,102); // hsv: 0, 134, 215 } else { backgroundColor = QColor(255,234,234); // hsv: 0, 21, 255 } } else if( isFailed ) { if( option.state & QStyle::State_Selected ) { backgroundColor = QColor(235,154, 49); // hsv: 34, 202, 235 } else { backgroundColor = QColor(255,204,156); // hsv: 29, 99, 255 } } else { if( option.state & QStyle::State_Selected ) { backgroundColor = option.palette.highlight().color(); } else { backgroundColor = option.palette.base().color(); } } painter->fillRect( option.rect, backgroundColor ); int m_left, m_top, m_right, m_bottom; item->treeWidget()->getContentsMargins( &m_left, &m_top, &m_right, &m_bottom ); //QRect m_rect = QRect( option.rect.x()+m_left, option.rect.y()+m_top, option.rect.width()-m_left-m_right, option.rect.height()-m_top-m_bottom ); QRect m_rect = QRect( option.rect.x()+m_left, option.rect.y(), option.rect.width()-m_left-m_right, option.rect.height() ); if( index.column() == 1 || index.column() == 2 ) { QRect textRect = painter->boundingRect( QRect(), Qt::AlignLeft|Qt::TextSingleLine, item->text(index.column()) ); if ( textRect.width() < m_rect.width() ) { painter->drawText( m_rect, Qt::TextSingleLine|Qt::TextExpandTabs, item->text(index.column()) ); } else { //textRect = painter->boundingRect( QRect(), Qt::AlignLeft, "... " ); painter->drawText( m_rect, Qt::AlignRight|Qt::TextSingleLine|Qt::TextExpandTabs, item->text(index.column()) ); QLinearGradient linearGrad( QPoint(m_rect.x(),0), QPoint(m_rect.x()+15,0) ); linearGrad.setColorAt( 0, backgroundColor ); backgroundColor.setAlpha( 0 ); linearGrad.setColorAt( 1, backgroundColor ); painter->fillRect( m_rect.x(), m_rect.y(), 15, m_rect.height(), linearGrad ); } } else { painter->drawText( m_rect, Qt::TextSingleLine|Qt::TextExpandTabs, item->text(index.column()) ); } //QItemDelegate::paint( painter, _option, index ); painter->restore(); // int progress = (index.row() != 0 ? 100 / index.row() : 0); // // // draw your cool progress bar here // QStyleOptionProgressBar opt; // opt.rect = option.rect; // opt.minimum = 0; // opt.maximum = 100; // opt.progress = progress; // opt.text = QString("%1%").arg(progress); // opt.textVisible = true; // QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, 0); // maybe even let default implementation draw list item contents? // QItemDelegate::paint(painter, option, index); }
QString qtractorMidiEventListModel::itemDisplay ( const QModelIndex& index ) const { // qDebug("itemDisplay(%d, %d)", index.row(), index.column()); const QString sDashes(2, '-'); qtractorMidiEvent *pEvent = eventOfIndex(index); if (pEvent) { switch (index.column()) { case 0: // Time. return (m_pEditor->timeScale())->textFromTick( m_iTimeOffset + pEvent->time()); case 1: // Type. switch (pEvent->type()) { case qtractorMidiEvent::NOTEON: return tr("Note On (%1)").arg(pEvent->note()); case qtractorMidiEvent::NOTEOFF: return tr("Note Off (%1)").arg(pEvent->note()); case qtractorMidiEvent::KEYPRESS: return tr("Key Press (%1)").arg(pEvent->note()); case qtractorMidiEvent::CONTROLLER: return tr("Controller (%1)").arg(pEvent->controller()); case qtractorMidiEvent::CONTROL14: return tr("Control 14 (%1)").arg(pEvent->controller()); case qtractorMidiEvent::REGPARAM: return tr("RPN (%1)").arg(pEvent->param()); case qtractorMidiEvent::NONREGPARAM: return tr("NRPN (%1)").arg(pEvent->param()); case qtractorMidiEvent::PGMCHANGE: return tr("Pgm Change"); case qtractorMidiEvent::CHANPRESS: return tr("Chan Press"); case qtractorMidiEvent::PITCHBEND: return tr("Pitch Bend"); case qtractorMidiEvent::SYSEX: return tr("SysEx"); case qtractorMidiEvent::META: return tr("Meta (%1)").arg(int(pEvent->type())); default: break; } return tr("Unknown (%1)").arg(int(pEvent->type())); case 2: // Name. switch (pEvent->type()) { case qtractorMidiEvent::NOTEON: case qtractorMidiEvent::NOTEOFF: case qtractorMidiEvent::KEYPRESS: return m_pEditor->noteName(pEvent->note()); case qtractorMidiEvent::CONTROLLER: return m_pEditor->controllerName(pEvent->controller()); case qtractorMidiEvent::REGPARAM: return m_pEditor->rpnNames().value(pEvent->param()); case qtractorMidiEvent::NONREGPARAM: return m_pEditor->nrpnNames().value(pEvent->param()); case qtractorMidiEvent::CONTROL14: return m_pEditor->control14Name(pEvent->controller()); default: break; } break; case 3: // Value. switch (pEvent->type()) { case qtractorMidiEvent::NOTEON: case qtractorMidiEvent::NOTEOFF: case qtractorMidiEvent::KEYPRESS: return QString::number(pEvent->velocity()); case qtractorMidiEvent::CONTROLLER: case qtractorMidiEvent::REGPARAM: case qtractorMidiEvent::NONREGPARAM: case qtractorMidiEvent::CONTROL14: case qtractorMidiEvent::PGMCHANGE: case qtractorMidiEvent::CHANPRESS: return QString::number(pEvent->value()); case qtractorMidiEvent::PITCHBEND: return QString::number(pEvent->pitchBend()); case qtractorMidiEvent::SYSEX: return QString::number(pEvent->sysex_len()); default: break; } break; case 4: // Duration/Data switch (pEvent->type()) { case qtractorMidiEvent::NOTEON: return (m_pEditor->timeScale())->textFromTick( m_iTimeOffset + pEvent->time(), true, pEvent->duration()); case qtractorMidiEvent::SYSEX: { QString sText; unsigned char *data = pEvent->sysex(); unsigned short len = pEvent->sysex_len(); sText += '{'; sText += ' '; for (unsigned short i = 0; i < len; ++i) sText += QString().sprintf("%02x ", data[i]); sText += '}'; return sText; } default: break; } break; } } return sDashes; }
QVariant HistoryModel::data(const QModelIndex &index, int role) const { HistoryItem* item = itemFromIndex(index); if (index.row() < 0 || !item) { return QVariant(); } if (item->isTopLevel()) { switch (role) { case IsTopLevelRole: return true; case TimestampStartRole: return item->startTimestamp(); case TimestampEndRole: return item->endTimestamp(); case Qt::DisplayRole: case Qt::EditRole: return index.column() == 0 ? item->title : QVariant(); case Qt::DecorationRole: return index.column() == 0 ? QIcon::fromTheme(QSL("view-calendar"), QIcon(":/icons/menu/history_entry.svg")) : QVariant(); } return QVariant(); } const HistoryEntry entry = item->historyEntry; switch (role) { case IdRole: return entry.id; case TitleRole: return entry.title; case UrlRole: return entry.url; case UrlStringRole: return entry.urlString; case IconRole: return item->icon(); case IsTopLevelRole: return false; case TimestampStartRole: return -1; case TimestampEndRole: return -1; case Qt::ToolTipRole: if (index.column() == 0) { return QString("%1\n%2").arg(entry.title, entry.urlString); } case Qt::DisplayRole: case Qt::EditRole: switch (index.column()) { case 0: return entry.title; case 1: return entry.urlString; case 2: return dateTimeToString(entry.date); case 3: return entry.count; } break; case Qt::DecorationRole: if (index.column() == 0) { return item->icon().isNull() ? IconProvider::emptyWebIcon() : item->icon(); } } return QVariant(); }
void qtractorMidiEventItemDelegate::setEditorData ( QWidget *pEditor, const QModelIndex& index ) const { const qtractorMidiEventListModel *pListModel = static_cast<const qtractorMidiEventListModel *> (index.model()); qtractorMidiEvent *pEvent = pListModel->eventOfIndex(index); if (pEvent == NULL) return; qtractorMidiEditor *pMidiEditor = pListModel->editor(); if (pMidiEditor == NULL) return; #ifdef CONFIG_DEBUG qDebug("qtractorMidiEventItemDelegate::setEditorData(%p, %p, %d, %d)", pEditor, pListModel, index.row(), index.column()); #endif qtractorTimeScale *pTimeScale = pMidiEditor->timeScale(); switch (index.column()) { case 0: // Time. { qtractorTimeSpinBox *pTimeSpinBox = qobject_cast<qtractorTimeSpinBox *> (pEditor); if (pTimeSpinBox) { pTimeSpinBox->setValue(pTimeScale->frameFromTick( pMidiEditor->timeOffset() + pEvent->time())); } break; } case 2: // Name. { QComboBox *pComboBox = qobject_cast<QComboBox *> (pEditor); if (pComboBox) pComboBox->setCurrentIndex(int(pEvent->note())); break; } case 3: // Value. { QSpinBox *pSpinBox = qobject_cast<QSpinBox *> (pEditor); if (pSpinBox) { if (pEvent->type() == qtractorMidiEvent::PITCHBEND) pSpinBox->setValue(pEvent->pitchBend()); else pSpinBox->setValue(pEvent->value()); } break; } case 4: // Duration/Data. { qtractorTimeSpinBox *pTimeSpinBox = qobject_cast<qtractorTimeSpinBox *> (pEditor); if (pTimeSpinBox) { pTimeSpinBox->setValue( pTimeScale->frameFromTick(pEvent->duration())); } break; } default: break; } }
QVariant QgsCategorizedSymbolRendererModel::data( const QModelIndex &index, int role ) const { if ( !index.isValid() || !mRenderer ) return QVariant(); const QgsRendererCategory category = mRenderer->categories().value( index.row() ); switch ( role ) { case Qt::CheckStateRole: { if ( index.column() == 0 ) { return category.renderState() ? Qt::Checked : Qt::Unchecked; } break; } case Qt::DisplayRole: case Qt::ToolTipRole: { switch ( index.column() ) { case 1: { if ( category.value().type() == QVariant::List ) { QStringList res; const QVariantList list = category.value().toList(); res.reserve( list.size() ); for ( const QVariant &v : list ) res << v.toString(); if ( role == Qt::DisplayRole ) return res.join( ';' ); else // tooltip return res.join( '\n' ); } else if ( !category.value().isValid() || category.value().isNull() || category.value().toString().isEmpty() ) { return tr( "all other values" ); } else { return category.value().toString(); } } case 2: return category.label(); } break; } case Qt::FontRole: { if ( index.column() == 1 && category.value().type() != QVariant::List && ( !category.value().isValid() || category.value().isNull() || category.value().toString().isEmpty() ) ) { QFont italicFont; italicFont.setItalic( true ); return italicFont; } return QVariant(); } case Qt::DecorationRole: { if ( index.column() == 0 && category.symbol() ) { const int iconSize = QgsGuiUtils::scaleIconSize( 16 ); return QgsSymbolLayerUtils::symbolPreviewIcon( category.symbol(), QSize( iconSize, iconSize ) ); } break; } case Qt::ForegroundRole: { QBrush brush( qApp->palette().color( QPalette::Text ), Qt::SolidPattern ); if ( index.column() == 1 && ( category.value().type() == QVariant::List || !category.value().isValid() || category.value().isNull() || category.value().toString().isEmpty() ) ) { QColor fadedTextColor = brush.color(); fadedTextColor.setAlpha( 128 ); brush.setColor( fadedTextColor ); } return brush; } case Qt::TextAlignmentRole: { return ( index.column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft; } case Qt::EditRole: { switch ( index.column() ) { case 1: { if ( category.value().type() == QVariant::List ) { QStringList res; const QVariantList list = category.value().toList(); res.reserve( list.size() ); for ( const QVariant &v : list ) res << v.toString(); return res.join( ';' ); } else { return category.value(); } } case 2: return category.label(); } break; } } return QVariant(); }
QModelIndex MessageLogWindowModel::parent(const QModelIndex &index) const { if (mpLog.get() == NULL || !index.isValid()) { return QModelIndex(); } const Subject* pSubject = reinterpret_cast<Subject*>(index.internalPointer()); if (pSubject == NULL) { return QModelIndex(); } // find the parent const Message* pParent = NULL; const DynamicObject* pProperties = dynamic_cast<const DynamicObject*>(pSubject); if (pProperties != NULL) { // this is a property index pParent = mPropertyCache[pProperties]; } else { const MessageImp* pMessageImp = dynamic_cast<const MessageImp*>(pSubject); if (pMessageImp != NULL) { pParent = pMessageImp->getParent(); } } // locate the row number const MessageImp* pParentImp = dynamic_cast<const MessageImp*>(pParent); if (pParentImp == NULL) { return QModelIndex(); } int parentRow = 0; const Step* pGrandParent = pParentImp->getParent(); if (pGrandParent != NULL) { for (Step::const_iterator gpIter = pGrandParent->begin(); gpIter != pGrandParent->end(); ++gpIter) { if (*gpIter == pParent) { break; } parentRow++; } } else { for (MessageLog::const_iterator lIter = mpLog->begin(); lIter != mpLog->end(); ++lIter) { if (*lIter == pParent) { break; } parentRow++; } } return createIndex(parentRow, index.column(), const_cast<Subject*>(static_cast<const Subject*>(pParent))); }
bool CommandDataModel::setData(const QModelIndex &index, const QVariant &value, int role) { const bool isNormalRow = index.row() < mCommands.size(); bool isModified = false; bool shouldAppend = false; Command command; if (isNormalRow) { // Get the command as it exists already command = mCommands[index.row()]; // Modify the command based on the passed date switch (role) { case Qt::EditRole: { const QString text = value.toString(); if (!text.isEmpty()) { if (index.column() == NameColumn) { command.name = value.toString(); isModified = true; } else if (index.column() == CommandColumn) { command.command = value.toString(); isModified = true; } } } case Qt::CheckStateRole: if (index.column() == EnabledColumn) { command.isEnabled = value.toInt() > 0; isModified = true; } } } else { // If final row was edited, insert the new command if (role == Qt::EditRole && index.column() == NameColumn) { command.name = value.toString(); if (!command.name.isEmpty() && command.name != tr("<new command>")) { isModified = true; shouldAppend = true; } } } if (isModified) { // Write the modified command to our cache if (shouldAppend) mCommands.push_back(command); else mCommands[index.row()] = command; // Reset if there could be new rows or reordering, else emit dataChanged if (shouldAppend || index.column() == NameColumn) { beginResetModel(); endResetModel(); } else { emit dataChanged(index, index); } } return isModified; }
QVariant IgnoreListModel::data(const QModelIndex &index, int role) const { if(!_modelReady) return QVariant(); if(!index.isValid() || index.row() >= rowCount() || index.column() >= columnCount()) return QVariant(); switch(role) { case Qt::ToolTipRole: switch(index.column()) { /* case 0: return "<b>Type:</b><br />" "<i><u>BySender:</u></i><br />" "The ignore rule is matched against the <i>[email protected]</i> sender-string.<br />" "<i><u>ByMessage:</u></i><br />" "The ignore rule is matched against the message content."; case 1: return "<b>Strictness:</b><br />" "<i><u>Dynamic:</u></i><br />" "Messages are hidden but still get stored in the database.<br />Deactivate or delete an ignore rule to show the messages again<br />" "<i><u>Permanent:</u></i><br />" "Messages are never stored or shown anywhere."; */ case 0: return tr("<b>Enable / Disable:</b><br />" "Only enabled rules are filtered.<br />" "For dynamic rules, disabling actually shows the filtered messages again"); case 2: return tr("<b>Ignore rule:</b><br />" "Depending on the type of the rule, the text is matched against either:<br /><br />" "- <u>the message content:</u><br />" "<i>Example:<i><br />" " \"*foobar*\" matches any text containing the word \"foobar\"<br /><br />" "- <u>the sender string <i>[email protected]<i></u><br />" "<i>Example:</i><br />" " \"*@foobar.com\" matches any sender from host foobar.com<br />" " \"stupid!.+\" (RegEx) matches any sender with nickname \"stupid\" from any host<br />"); default: return QVariant(); } case Qt::DisplayRole: switch(index.column()) { case 1: if(ignoreListManager()[index.row()].type == IgnoreListManager::SenderIgnore) return tr("By Sender"); else return tr("By Message"); } case Qt::EditRole: switch(index.column()) { case 0: return ignoreListManager()[index.row()].isActive; case 1: return ignoreListManager()[index.row()].type; case 2: return ignoreListManager()[index.row()].ignoreRule; default: return QVariant(); } default: return QVariant(); } }
bool Model::hasChildren(const QModelIndex &parent) const { if (parent.isValid() && parent.column() != 0) return false; return rc > 0 && cc > 0; }
EH_FieldInfo EH_SECT_rela::GetFieldInfo( QModelIndex &index ) const { EH_FieldInfo fi = {0,0}; if( !index.isValid() ) return fi; if( (EH_index_t) index.row() >= nRelocs || (EH_index_t)index.column() >= eh_rela::fieldnum ) return fi; if( is64bit ) { fi.start = hdr.shdr64->sh_offset; fi.start += sizeof(Elf64_Rela)*index.row(); } else { fi.start = hdr.shdr32->sh_offset; fi.start += sizeof(Elf32_Rela)*index.row(); } switch( index.column() ) { case 0: if( is64bit ) { fi.start += offsetof( Elf64_Rela, r_offset ); fi.size = sizeof( Elf64_Rela::r_offset ); } else { fi.start += offsetof( Elf32_Rela, r_offset ); fi.size = sizeof( Elf32_Rela::r_offset ); } break; case 1: case 2: if( is64bit ) { fi.start += offsetof( Elf64_Rela, r_info ); fi.size = sizeof( Elf64_Rela::r_info ); } else { fi.start += offsetof( Elf32_Rela, r_info ); fi.size = sizeof( Elf32_Rela::r_info ); } break; case 3: if( is64bit ) { fi.start += offsetof( Elf64_Rela, r_addend ); fi.size = sizeof( Elf64_Rela::r_addend ); } else { fi.start += offsetof( Elf32_Rela, r_addend ); fi.size = sizeof( Elf32_Rela::r_addend ); } break; } return fi; }
int Model::rowCount(const QModelIndex &parent) const { return (parent.isValid() && parent.column() != 0) ? 0 : rc; }
void SWGISBrowser::itemClicked(const QModelIndex &index) { this->m_Index = index; QgsDataItem *item = this->m_Model->dataItem(index); if(!item) return; bool paramEnable = false; bool metaEnable = false; bool previewEnable = false; bool attributesEnable = false; this->m_DirtyAttributes = true; this->m_DirtyMetadata = true; this->m_DirtyPreview = true; this->setLayer(nullptr); QList<QgsMapCanvasLayer> noLayers; ui->mapCanvas->setLayerSet(noLayers); ui->metaTextBrowser->clear(); if(this->m_ParamWidget) { ui->paramLayout->removeWidget(this->m_ParamWidget); this->m_ParamWidget->hide(); delete this->m_ParamWidget; this->m_ParamWidget = nullptr; } QgsMapLayerRegistry::instance()->removeAllMapLayers(); this->m_Layer = nullptr; this->m_ParamWidget = item->paramWidget(); if(this->m_ParamWidget) { ui->paramLayout->addWidget(this->m_ParamWidget); this->m_ParamWidget->show(); paramEnable = true; } QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*> (this->m_Model->dataItem(index)); if(layerItem) { bool res = this->layerClicked(layerItem); if(res) { metaEnable = true; previewEnable = true; if(this->m_Layer->type() == QgsMapLayer::VectorLayer) attributesEnable = true; } } else ui->action_Set_Projection->setEnabled(false); this->updateCurrentTab(); int selected = -1; if(this->m_LastTab.contains(item->metaObject()->className())) selected = this->m_LastTab[item->metaObject()->className()]; ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->paramTab),paramEnable); ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->metaDataTab),metaEnable); ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->PreviewTab),previewEnable); ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->attributesTab),attributesEnable); if(selected > 0) { QgsDebugMsg(QString(" set tab %1 %2").arg(item->metaObject()->className()).arg(item->name())); ui->tabWidget->setCurrentIndex(selected); } QgsDebugMsg( QString( "clicked: %1 %2 %3" ).arg( index.row() ).arg( index.column() ).arg( item->name() ) ); }
void ModelResource::query(Orchid::Request* request, const QModelIndex& index) { if(!index.isValid()) return; if(!request->open(QIODevice::ReadWrite)) return; QTextStream stream(request); stream << "<h1>" << index.data().toString() << "</h1>\n" << "Parent: \"" << index.parent().data().toString() << "\"<br/>\nRow: " << index.row() << "<nr/>\nColumn: " << index.column() << "<br/>\n" << "Second-column: " << index.model()->index(index.row(), 1, index.parent()).data().toString(); }
bool CurveNameList::setData (const QModelIndex &index, const QVariant &value, int role) { LOG4CPP_INFO_S ((*mainCat)) << "CurveNameList::setData" << " indexRow=" << index.row () << " indexCol=" << index.column () << " indexValid=" << (index.isValid() ? "valid" : "invalid") << " valueValid=" << (value.isValid () ? "valid" : "invalid") << " value=" << value.toString().toLatin1().data() << " role=" << roleAsString (role).toLatin1 ().data (); bool success = false; if (index.isValid()) { // Process the new entry int row = index.row (); if (row < m_modelCurvesEntries.count ()) { // Variable 'row' points to an empty entry (created by insertRows) so we populate it here success = true; QString before = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE); if (!value.isValid () && (role == Qt::EditRole)) { // Remove the entry m_modelCurvesEntries.removeAt (row); } else { // Modify the entry CurveNameListEntry curvesEntry (m_modelCurvesEntries [row]); // Retrieve entry if (index.column () == 0) { if (role == Qt::EditRole) { // Does new curve name meet the requirements if (curveNameIsAcceptable (value.toString (), row)) { curvesEntry.setCurveNameCurrent (value.toString ()); m_modelCurvesEntries [row] = curvesEntry.toString (); // Save update entry } else { success = false; } } else if ((role == Qt::DisplayRole) || (curveNameIsAcceptable (value.toString(), row))) { // Above we skipped curve name uniqueness check for Qt::DisplayRole since that role is used when dragging // curve from one place to another, since for a short time the new curve name will coexist // with the old curve name (until the old entry is removed) if (rowIsUnpopulated (row)) { success = true; curvesEntry.setCurveNameCurrent (value.toString ()); curvesEntry.setNumPoints (0); m_modelCurvesEntries [row] = curvesEntry.toString (); // Save update entry tryToRemoveOriginalCopy (index, value, role); } else { success = false; } } } else if (index.column () == 1) { curvesEntry.setCurveNameOriginal (value.toString ()); m_modelCurvesEntries [row] = curvesEntry.toString (); // Save update entry } else if (index.column () == 2) { curvesEntry.setNumPoints (value.toInt ()); m_modelCurvesEntries [row] = curvesEntry.toString (); // Save update entry } else { ENGAUGE_ASSERT (false); } if (success) { emit dataChanged (index, index); } QString after = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE); LOG4CPP_INFO_S ((*mainCat)) << "CurveNameList::setData setting" << " before=" << before.toLatin1().data() << " after=" << after.toLatin1().data(); } } } return success; }
QVariant UserTreeModel::data( const QModelIndex& index, int role ) const { if (role == Qt::FontRole) { if(UserGroupList::getInstance()->getIgnore(m_userList[index.row()].name)) { QFont font; font.setStrikeOut(true); return font; } return QVariant(); } if (role == Qt::BackgroundRole) { QColor c = UserGroupList::getInstance()->getUserColor(m_userList[index.row()].name); if (c.isValid()) { return c; } return QVariant(); } if ( role == Qt::UserRole ) { QVariant a; a.setValue<User>( m_userList[index.row()] ); return a; } switch ( index.column() ) { case 0: //status if ( role == Qt::DecorationRole || role == Qt::ToolTipRole ) { User u = m_userList[index.row()]; QString tip; QStringList fileNameParts; if ( u.userState.isBot() ) { fileNameParts << "bot"; tip = tr("Bot "); } else if ( u.userState.isModerator() ) { fileNameParts << "chanop"; tip = tr("Moderator "); } else { tip = tr("Player "); } if ( u.userState.isAway() ) { fileNameParts << "away"; tip.append(tr("is away")); } else if ( u.userState.isIngame() ) { fileNameParts << "ingame"; tip.append(tr("is in game")); } else if ( u.joinedBattleId != -1 ) { fileNameParts << "broom"; tip.append(tr("is in battle room")); } else tip.append(tr("is available")); //tip.arg("aaa").arg("bbb"); if ( role == Qt::DecorationRole ) return QIcon( QString( P("icons/%1.xpm") ).arg( fileNameParts.join( "_" ) ) ); return tip; } break; case 1: //flags if ( role == Qt::DecorationRole ) { QString filename = QString( P("flags/%1.xpm") ).arg( m_userList[index.row()].countryCode ); return QIcon( filename ); } if ( role == Qt::ToolTipRole ) { QString c = tldlist.TLDMap->value( m_userList[index.row()].countryCode ); if ( c != "" ) return c; else return m_userList[index.row()].countryCode; } break; case 2: //rank if ( role == Qt::DecorationRole ) { int rank = m_userList[index.row()].userState.getRank(); if ( rank > 6 ) return QVariant(); return QIcon( QString( P("icons/rank%1-icon.png") ).arg( rank ) ); } if ( role == Qt::ToolTipRole ) { switch ( m_userList[index.row()].userState.getRank() ) { case 0: return tr("1/7 Newbie"); case 1: return tr("2/7 Beginner"); case 2: return tr("3/7 Average"); case 3: return tr("4/7 Above average"); case 4: return tr("5/7 Experienced"); case 5: return tr("6/7 Highly experienced"); case 6: return tr("7/7 Veteran"); } return tr("no rank set"); } break; case 3: //username if ( role == Qt::DisplayRole ) return m_userList[index.row()].name; if ( role == Qt::DecorationRole && m_userList[index.row()].founder) return QIcon(P("icons/host.xpm")); break; } return QVariant(); }
QVariant PartitionModel::data( const QModelIndex& index, int role ) const { Partition* partition = partitionForIndex( index ); if ( !partition ) return QVariant(); switch ( role ) { case Qt::DisplayRole: { int col = index.column(); if ( col == NameColumn ) { if ( KPMHelpers::isPartitionFreeSpace( partition ) ) return tr( "Free Space" ); else { return KPMHelpers::isPartitionNew( partition ) ? tr( "New partition" ) : partition->partitionPath(); } } if ( col == FileSystemColumn ) return KPMHelpers::prettyNameForFileSystemType( partition->fileSystem().type() ); if ( col == MountPointColumn ) return PartitionInfo::mountPoint( partition ); if ( col == SizeColumn ) { qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); return KFormat().formatByteSize( size ); } cDebug() << "Unknown column" << col; return QVariant(); } case Qt::DecorationRole: if ( index.column() == NameColumn ) return ColorUtils::colorForPartition( partition ); else return QVariant(); case SizeRole: return ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); case IsFreeSpaceRole: return KPMHelpers::isPartitionFreeSpace( partition ); case IsPartitionNewRole: return KPMHelpers::isPartitionNew( partition ); case FileSystemLabelRole: if ( partition->fileSystem().supportGetLabel() != FileSystem::cmdSupportNone && !partition->fileSystem().label().isEmpty() ) return partition->fileSystem().label(); return QVariant(); case FileSystemTypeRole: return partition->fileSystem().type(); case PartitionPathRole: return partition->partitionPath(); case PartitionPtrRole: return qVariantFromValue( (void*)partition ); // Osprober roles: case OsproberNameRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) if ( osproberEntry.path == partition->partitionPath() ) return osproberEntry.prettyName; return QVariant(); case OsproberPathRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) if ( osproberEntry.path == partition->partitionPath() ) return osproberEntry.path; return QVariant(); case OsproberCanBeResizedRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) if ( osproberEntry.path == partition->partitionPath() ) return osproberEntry.canBeResized; return QVariant(); case OsproberRawLineRole: foreach ( const OsproberEntry& osproberEntry, m_osproberEntries ) if ( osproberEntry.path == partition->partitionPath() ) return osproberEntry.line; return QVariant(); // end Osprober roles. default: return QVariant(); } }
//virtual int SensorBrowserModel::rowCount ( const QModelIndex & parent ) const { if(!parent.isValid()) return mHostInfoMap.size(); if(parent.column() != 0) return 0; return mTreeMap.value(parent.internalId()).size(); }