Polka::Identity PolkaAllItemModel::identity( const QModelIndex &index ) { return model()->allIdentities().at( index.row() ); }
Qt::ItemFlags TileHeadModel::flags (const QModelIndex & index) const { if(!index.isValid()) return Qt::ItemIsEnabled; return QAbstractListModel::flags(index) | Qt::ItemIsEditable; }
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))); }
int QgsGraduatedSymbolRendererV2Model::rowCount( const QModelIndex &parent ) const { if ( parent.column() > 0 || !mRenderer ) return 0; return mRenderer->ranges().size(); }
AccountId CoreAccountSettingsPage::selectedAccount() const { QModelIndex index = ui.accountView->currentIndex(); if(!index.isValid()) return 0; return index.data(CoreAccountModel::AccountIdRole).value<AccountId>(); }
void PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); if ( option.state & QStyle::State_Selected && option.state & QStyle::State_Active ) { opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); } painter->save(); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( opt.palette.color( QPalette::Text ) ); QTextOption to; to.setAlignment( Qt::AlignCenter ); QFont font = opt.font; font.setPixelSize( 10 ); QFont boldFont = font; boldFont.setBold( true ); boldFont.setPixelSize( 11 ); QFont figFont = boldFont; figFont.setPixelSize( 10 ); QPixmap icon; RecentlyPlayedPlaylistsModel::PlaylistTypes type = (RecentlyPlayedPlaylistsModel::PlaylistTypes)index.data( RecentlyPlayedPlaylistsModel::PlaylistTypeRole ).toInt(); if( type == RecentlyPlayedPlaylistsModel::StaticPlaylist ) icon = m_playlistIcon; else if( type == RecentlyPlayedPlaylistsModel::AutoPlaylist ) icon = m_autoIcon; else if( type == RecentlyPlayedPlaylistsModel::Station ) icon = m_stationIcon; QRect pixmapRect = option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 ); icon = icon.scaled( pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); painter->drawPixmap( pixmapRect, icon ); if ( type != RecentlyPlayedPlaylistsModel::Station ) { painter->save(); painter->setFont( figFont ); QString tracks = index.data( RecentlyPlayedPlaylistsModel::TrackCountRole ).toString(); int width = painter->fontMetrics().width( tracks ); // int bottomEdge = pixmapRect // right edge 10px past right edge of pixmapRect // bottom edge flush with bottom of pixmap QRect rect( pixmapRect.right() - width , 0, width - 8, 0 ); rect.adjust( -2, 0, 0, 0 ); rect.setTop( pixmapRect.bottom() - painter->fontMetrics().height() - 1 ); rect.setBottom( pixmapRect.bottom() + 1 ); QColor figColor( "#464b55" ); painter->setPen( figColor ); painter->setBrush( figColor ); TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, rect ); painter->restore(); } QPixmap avatar = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( Source::FancyStyle ); if ( avatar.isNull() ) avatar = m_defaultAvatar; QRect r( option.rect.width() - avatar.width() - 10, option.rect.top() + option.rect.height()/2 - avatar.height()/2, avatar.width(), avatar.height() ); painter->drawPixmap( r, avatar ); painter->setFont( font ); QString author = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->friendlyName(); if ( author.indexOf( '@' ) > 0 ) author = author.mid( 0, author.indexOf( '@' ) ); const int w = painter->fontMetrics().width( author ) + 2; QRect avatarNameRect( opt.rect.width() - 10 - w, r.bottom(), w, opt.rect.bottom() - r.bottom() ); painter->drawText( avatarNameRect, author, QTextOption( Qt::AlignCenter ) ); const int leftEdge = opt.rect.width() - qMin( avatarNameRect.left(), r.left() ); QString descText; if ( type == RecentlyPlayedPlaylistsModel::Station ) { descText = index.data( RecentlyPlayedPlaylistsModel::DynamicPlaylistRole ).value< Tomahawk::dynplaylist_ptr >()->generator()->sentenceSummary(); } else { descText = index.data( RecentlyPlayedPlaylistsModel::ArtistRole ).toString(); } QColor c = painter->pen().color(); if ( !( option.state & QStyle::State_Selected && option.state & QStyle::State_Active ) ) { painter->setPen( QColor( Qt::gray ).darker() ); } QRect rectText = option.rect.adjusted( 66, 20, -leftEdge - 10, -8 ); #ifdef Q_WS_MAC rectText.adjust( 0, 1, 0, 0 ); #elif defined Q_WS_WIN rectText.adjust( 0, 2, 0, 0 ); #endif painter->drawText( rectText, descText ); painter->setPen( c ); painter->setFont( font ); painter->setFont( boldFont ); painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() ); painter->restore(); }
Qt::ItemFlags PeerTableModel::flags(const QModelIndex &index) const { if (!index.isValid()) return 0; Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled; return retval; }
void ValidatedDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { qobject_cast<QLineEdit*>(editor)->setText(index.data().toString()); }
void QgsWFSSourceSelect::buildQuery( const QModelIndex& index ) { if ( !index.isValid() ) { return; } const QString typeName = index.sibling( index.row(), MODEL_IDX_NAME ).data().toString(); //get available fields for wfs layer QgsWFSConnection connection( cmbConnections->currentText() ); QgsWFSDataSourceURI uri( connection.uri().uri() ); uri.setTypeName( typeName ); QgsWFSProvider p( uri.uri(), mCaps ); if ( !p.isValid() ) { QMessageBox* box = new QMessageBox( QMessageBox::Critical, tr( "Server exception" ), tr( "DescribeFeatureType failed" ), QMessageBox::Ok, this ); box->setAttribute( Qt::WA_DeleteOnClose ); box->setModal( true ); box->setObjectName( "WFSFeatureTypeErrorBox" ); if ( !property( "hideDialogs" ).toBool() ) box->open(); return; } QModelIndex filterIndex = index.sibling( index.row(), MODEL_IDX_SQL ); QString sql( filterIndex.data().toString() ); QString displayedTypeName( typeName ); if ( !mCaps.setAmbiguousUnprefixedTypename.contains( QgsWFSUtils::removeNamespacePrefix( typeName ) ) ) displayedTypeName = QgsWFSUtils::removeNamespacePrefix( typeName ); QString allSql( "SELECT * FROM " + QgsSQLStatement::quotedIdentifierIfNeeded( displayedTypeName ) ); if ( sql.isEmpty() ) { sql = allSql; } QgsSQLComposerDialog* d = new QgsSQLComposerDialog( this ); QgsWFSValidatorCallback* validatorCbk = new QgsWFSValidatorCallback( d, uri, allSql, mCaps ); d->setSQLValidatorCallback( validatorCbk ); QgsWFSTableSelectedCallback* tableSelectedCbk = new QgsWFSTableSelectedCallback( d, uri, mCaps ); d->setTableSelectedCallback( tableSelectedCbk ); const bool bSupportJoins = mCaps.featureTypes.size() > 1 && mCaps.supportsJoins; d->setSupportMultipleTables( bSupportJoins, QgsSQLStatement::quotedIdentifierIfNeeded( displayedTypeName ) ); QMap< QString, QString > mapTypenameToTitle; Q_FOREACH ( const QgsWFSCapabilities::FeatureType f, mCaps.featureTypes ) mapTypenameToTitle[f.name] = f.title; QList< QgsSQLComposerDialog::PairNameTitle > tablenames; tablenames << QgsSQLComposerDialog::PairNameTitle( QgsSQLStatement::quotedIdentifierIfNeeded( displayedTypeName ), mapTypenameToTitle[typeName] ); if ( bSupportJoins ) { for ( int i = 0; i < mModel->rowCount(); i++ ) { const QString iterTypename = mModel->index( i, MODEL_IDX_NAME ).data().toString(); if ( iterTypename != typeName ) { QString displayedIterTypename( iterTypename ); QString unprefixedIterTypename( QgsWFSUtils::removeNamespacePrefix( iterTypename ) ); if ( !mCaps.setAmbiguousUnprefixedTypename.contains( unprefixedIterTypename ) ) displayedIterTypename = unprefixedIterTypename; tablenames << QgsSQLComposerDialog::PairNameTitle( QgsSQLStatement::quotedIdentifierIfNeeded( displayedIterTypename ), mapTypenameToTitle[iterTypename] ); } } } d->addTableNames( tablenames ); QList< QgsSQLComposerDialog::Function> functionList; Q_FOREACH ( const QgsWFSCapabilities::Function& f, mCaps.functionList ) { QgsSQLComposerDialog::Function dialogF; dialogF.name = f.name; dialogF.returnType = f.returnType; dialogF.minArgs = f.minArgs; dialogF.maxArgs = f.maxArgs; Q_FOREACH ( const QgsWFSCapabilities::Argument& arg, f.argumentList ) { dialogF.argumentList << QgsSQLComposerDialog::Argument( arg.name, arg.type ); } functionList << dialogF; } d->addFunctions( functionList ); QList< QgsSQLComposerDialog::Function> spatialPredicateList; Q_FOREACH ( const QgsWFSCapabilities::Function& f, mCaps.spatialPredicatesList ) { QgsSQLComposerDialog::Function dialogF; dialogF.name = f.name; dialogF.returnType = f.returnType; dialogF.minArgs = f.minArgs; dialogF.maxArgs = f.maxArgs; Q_FOREACH ( const QgsWFSCapabilities::Argument& arg, f.argumentList ) { dialogF.argumentList << QgsSQLComposerDialog::Argument( arg.name, arg.type ); } spatialPredicateList << dialogF; } d->addSpatialPredicates( spatialPredicateList ); QList< QgsSQLComposerDialog::PairNameType> fieldList; QString fieldNamePrefix; if ( bSupportJoins ) { fieldNamePrefix = QgsSQLStatement::quotedIdentifierIfNeeded( displayedTypeName ) + "."; } Q_FOREACH ( const QgsField& field, p.fields().toList() ) { QString fieldName( fieldNamePrefix + QgsSQLStatement::quotedIdentifierIfNeeded( field.name() ) ); fieldList << QgsSQLComposerDialog::PairNameType( fieldName, field.typeName() ); } if ( !p.geometryAttribute().isEmpty() ) { QString fieldName( fieldNamePrefix + QgsSQLStatement::quotedIdentifierIfNeeded( p.geometryAttribute() ) ); fieldList << QgsSQLComposerDialog::PairNameType( fieldName, "geometry" ); } fieldList << QgsSQLComposerDialog::PairNameType( fieldNamePrefix + "*", "" ); d->addColumnNames( fieldList, QgsSQLStatement::quotedIdentifierIfNeeded( displayedTypeName ) ); d->setSql( sql ); mSQLIndex = index; mSQLComposerDialog = d; // For testability, do not use exec() if ( property( "hideDialogs" ).toBool() ) { d->setAttribute( Qt::WA_DeleteOnClose ); d->setModal( true ); d->open(); connect( d, SIGNAL( accepted() ), this, SLOT( updateSql() ) ); } else { // But we need to use exec() for real GUI, otherwise it does not look // right on Mac if ( d->exec() ) { updateSql(); } delete d; } }
void UberDelegate::paint_cell(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const { QModelIndex model_idx = idx; if (m_proxy) model_idx = m_proxy->mapToSource(idx); COLUMN_TYPE type = static_cast<COLUMN_TYPE>(model_idx.data(DwarfModel::DR_COL_TYPE).toInt()); QRect adjusted = opt.rect.adjusted(cell_padding, cell_padding, (cell_padding * -2) - 1, (cell_padding * -2) - 1); switch (type) { case CT_SKILL: { short rating = model_idx.data(DwarfModel::DR_RATING).toInt(); QColor bg = paint_bg(adjusted, false, p, opt, idx); paint_skill(adjusted, rating, bg, p, opt, idx); paint_grid(adjusted, false, p, opt, idx); } break; case CT_LABOR: { bool agg = model_idx.data(DwarfModel::DR_IS_AGGREGATE).toBool(); if (m_model->current_grouping() == DwarfModel::GB_NOTHING || !agg) { paint_labor(adjusted, p, opt, idx); } else { if (draw_aggregates) paint_aggregate(adjusted, p, opt, idx); } } break; case CT_HAPPINESS: { paint_bg(adjusted, false, p, opt, idx); p->save(); p->fillRect(adjusted, model_idx.data(Qt::BackgroundColorRole).value<QColor>()); p->restore(); paint_grid(adjusted, false, p, opt, idx); } break; case CT_IDLE: { paint_bg(adjusted, false, p, opt, idx); QIcon icon = idx.data(Qt::DecorationRole).value<QIcon>(); QPixmap pixmap = icon.pixmap(adjusted.size()); p->save(); p->drawPixmap(adjusted, pixmap); p->restore(); paint_grid(adjusted, false, p, opt, idx); } break; case CT_TRAIT: case CT_ATTRIBUTE: { paint_bg(adjusted, false, p, opt, idx); p->save(); p->drawText(adjusted, Qt::AlignCenter, model_idx.data(Qt::DisplayRole).toString()); p->restore(); paint_grid(adjusted, false, p, opt, idx); } break; case CT_MILITARY_PREFERENCE: { bool agg = model_idx.data(DwarfModel::DR_IS_AGGREGATE).toBool(); if (m_model->current_grouping() == DwarfModel::GB_NOTHING || !agg) { paint_pref(adjusted, p, opt, idx); } else { if (draw_aggregates) paint_aggregate(adjusted, p, opt, idx); } } break; case CT_DEFAULT: case CT_SPACER: default: paint_bg(adjusted, false, p, opt, idx); //QStyledItemDelegate::paint(p, opt, idx); if (opt.state & QStyle::State_Selected) { p->save(); p->setPen(color_guides); p->drawLine(opt.rect.topLeft(), opt.rect.topRight()); p->drawLine(opt.rect.bottomLeft(), opt.rect.bottomRight()); p->restore(); } break; } }
QSize UberDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &idx) const { if (idx.column() == 0) return QStyledItemDelegate::sizeHint(opt, idx); return QSize(cell_size, cell_size); }
QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const { switch (role) { case Qt::DisplayRole: case Qt::EditRole: break; // Retrieve the actual value default: return QVariant(); // ignore } QString event = m_settings->events().value(index.row()); const EventDescription description = parseEvent(event); switch (index.column()) { case ColumnEventType: { if (role == Qt::DisplayRole) { if (description.eventType == EventTypeInvalid) return QVariant(); auto meta = QMetaEnum::fromType<EventType>(); return QString::fromLatin1(meta.valueToKey(description.eventType)) .mid(static_cast<int>(strlen("EventType"))).toLower(); } return description.eventType; } case ColumnSubType: { switch (description.eventType) { case EventTypeHardware: case EventTypeSoftware: case EventTypeCache: if (role == Qt::DisplayRole) return subTypeString(description.eventType, description.subType); return description.subType; case EventTypeRaw: if (role == Qt::DisplayRole) return QString("r%1").arg(description.numericEvent, 3, 16, QLatin1Char('0')); else return description.numericEvent; case EventTypeBreakpoint: if (role == Qt::DisplayRole) return QString("0x%1").arg(description.numericEvent, 16, 16, QLatin1Char('0')); else return description.numericEvent; case EventTypeCustom: return description.customEvent; default: return QVariant(); } } case ColumnOperation: if (role == Qt::DisplayRole) { if (description.eventType == EventTypeBreakpoint) { QString result; if (description.operation & OperationLoad) result += 'r'; if (description.operation & OperationStore) result += 'w'; if (description.operation & OperationExecute) result += 'x'; return result; } if (description.eventType == EventTypeCache) { if (description.operation == OperationInvalid) return QVariant(); auto meta = QMetaEnum::fromType<Operation>(); return QString::fromLatin1(meta.valueToKey(description.operation)).mid( static_cast<int>(strlen("Operation"))).toLower(); } return QVariant(); } return description.operation; case ColumnResult: if (role == Qt::DisplayRole) { if (description.result == ResultInvalid) return QVariant(); auto meta = QMetaEnum::fromType<Result>(); return QString::fromLatin1(meta.valueToKey(description.result)).mid( static_cast<int>(strlen("Result"))).toLower(); } return description.result; default: return QVariant(); } }
int PerfConfigEventsModel::columnCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : ColumnInvalid; }
int PerfConfigEventsModel::rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : m_settings->events().length(); }
// Implement of dropEvent so dropMimeData gets called void FavoritesView::dropEvent(QDropEvent *event) { QTreeView::dropEvent(event); const QMimeData* data = event->mimeData(); QModelIndex droppedIndex = indexAt( event->pos() ); if (!droppedIndex.isValid()) return; int row = droppedIndex.row(); qint32 lid = 0; if (data->hasFormat("application/x-nixnote-tag")) { QByteArray d = data->data("application/x-nixnote-tag"); lid = d.trimmed().toInt(); addRecord(lid, FavoritesRecord::Tag, row); } if (data->hasFormat("application/x-nixnote-note")) { QByteArray d = data->data("application/x-nixnote-note"); lid = d.trimmed().toInt(); addRecord(lid, FavoritesRecord::Note, row); } if (data->hasFormat("application/x-nixnote-search")) { QByteArray d = data->data("application/x-nixnote-search"); lid = d.trimmed().toInt(); addRecord(lid, FavoritesRecord::Search, row); } if (data->hasFormat("application/x-nixnote-favorite")) { QByteArray d = data->data("application/x-nixnote-favorite"); lid = d.trimmed().toInt(); FavoritesTable ftable(global.db); FavoritesRecord rec; if (ftable.get(rec,lid)) { ftable.expunge(lid); rec.order = row; ftable.insert(rec); } } if (data->hasFormat("application/x-nixnote-notebook")) { QString d = data->data("application/x-nixnote-notebook"); int pos = d.indexOf("/"); if (pos == -1) return; int type = d.mid(0,pos).toInt(); d = d.mid(pos+1); pos = d.indexOf("/"); if (pos == -1) return; lid= d.mid(0,pos).toInt(); QString stack = d.mid(pos+1); FavoritesRecord::FavoritesRecordType rectype = FavoritesRecord::LocalNotebook; switch (type) { case NNotebookViewItem::Local : rectype = FavoritesRecord::LocalNotebook; break; case NNotebookViewItem::Synchronized : rectype = FavoritesRecord::SynchronizedNotebook; break; case NNotebookViewItem::LinkedStack : rectype = FavoritesRecord::LinkedStack; break; case NNotebookViewItem::Conflict : rectype = FavoritesRecord::ConflictNotebook; break; case NNotebookViewItem::Stack : rectype = FavoritesRecord::NotebookStack; break; case NNotebookViewItem::Shared: rectype = FavoritesRecord::SharedNotebook; break; case NNotebookViewItem::Linked : rectype = FavoritesRecord::LinkedNotebook; break; } if (lid > 0) addRecord(lid, rectype, row); else { FavoritesTable table(global.db); FavoritesRecord record; record.type = rectype; record.target= stack; record.lid = 0; record.order = row; record.parent = 0; qint32 newLid = table.insert(record); QList<qint32> lids; NotebookTable ntable(global.db); ntable.findByStack(lids, stack); for (int i=0; i<lids.size(); i++) { Notebook book; if (ntable.get(book, lids[i])) { FavoritesRecord rec; rec.parent = newLid; if (book.name.isSet()) rec.displayName = book.name; rec.type = FavoritesRecord::SynchronizedNotebook; if (ntable.isLocal(lids[i])) rec.type = FavoritesRecord::LocalNotebook; LinkedNotebookTable ltable(global.db); if (ltable.exists(lids[i])) rec.type = FavoritesRecord::LinkedNotebook; SharedNotebookTable stable(global.db); if (stable.exists(lids[i])) rec.type = FavoritesRecord::SharedNotebook; rec.target = lids[i]; rec.order = 1; table.add(rec); } } } } rebuildFavoritesTreeNeeded = true; this->loadData(); }
QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu() { QMenu* menu = new QMenu; QgsLayerTreeViewDefaultActions* actions = mView->defaultActions(); QModelIndex idx = mView->currentIndex(); if ( !idx.isValid() ) { // global menu menu->addAction( actions->actionAddGroup( menu ) ); menu->addAction( QgsApplication::getThemeIcon( "/mActionExpandTree.svg" ), tr( "&Expand All" ), mView, SLOT( expandAll() ) ); menu->addAction( QgsApplication::getThemeIcon( "/mActionCollapseTree.svg" ), tr( "&Collapse All" ), mView, SLOT( collapseAll() ) ); // TODO: update drawing order } else if ( QgsLayerTreeNode* node = mView->layerTreeModel()->index2node( idx ) ) { // layer or group selected if ( QgsLayerTree::isGroup( node ) ) { menu->addAction( actions->actionZoomToGroup( mCanvas, menu ) ); menu->addAction( QgsApplication::getThemeIcon( "/mActionRemoveLayer.svg" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) ); menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Group CRS" ), QgisApp::instance(), SLOT( legendGroupSetCRS() ) ); menu->addAction( actions->actionRenameGroupOrLayer( menu ) ); menu->addAction( actions->actionMutuallyExclusiveGroup( menu ) ); if ( mView->selectedNodes( true ).count() >= 2 ) menu->addAction( actions->actionGroupSelected( menu ) ); menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) ); menu->addAction( actions->actionAddGroup( menu ) ); } else if ( QgsLayerTree::isLayer( node ) ) { QgsMapLayer *layer = QgsLayerTree::toLayer( node )->layer(); QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer ); QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ); menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) ); menu->addAction( actions->actionShowInOverview( menu ) ); if ( rlayer ) { menu->addAction( QgsApplication::getThemeIcon( "/mActionZoomActual.svg" ), tr( "&Zoom to Native Resolution (100%)" ), QgisApp::instance(), SLOT( legendLayerZoomNative() ) ); if ( rlayer->rasterType() != QgsRasterLayer::Palette ) menu->addAction( tr( "&Stretch Using Current Extent" ), QgisApp::instance(), SLOT( legendLayerStretchUsingCurrentExtent() ) ); } menu->addAction( QgsApplication::getThemeIcon( "/mActionRemoveLayer.svg" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) ); // duplicate layer QAction* duplicateLayersAction = menu->addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) ); if ( !vlayer || vlayer->geometryType() != QGis::NoGeometry ) { // set layer scale visibility menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) ); // set layer crs menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) ); // assign layer crs to project menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) ); } // style-related actions if ( layer && mView->selectedLayerNodes().count() == 1 ) { QMenu *menuStyleManager = new QMenu( tr( "Styles" ) ); QgisApp *app = QgisApp::instance(); menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) ); if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) ) { menuStyleManager->addAction( tr( "Paste Style" ), app, SLOT( pasteStyle() ) ); } menuStyleManager->addSeparator(); QgsMapLayerStyleGuiUtils::instance()->addStyleManagerActions( menuStyleManager, layer ); menu->addMenu( menuStyleManager ); } menu->addSeparator(); if ( vlayer ) { QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing(); QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits(); QAction *allEditsAction = QgisApp::instance()->actionAllEdits(); // attribute table menu->addAction( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ), tr( "&Open Attribute Table" ), QgisApp::instance(), SLOT( attributeTable() ) ); // allow editing int cap = vlayer->dataProvider()->capabilities(); if ( cap & QgsVectorDataProvider::EditingCapabilities ) { if ( toggleEditingAction ) { menu->addAction( toggleEditingAction ); toggleEditingAction->setChecked( vlayer->isEditable() ); } if ( saveLayerEditsAction && vlayer->isModified() ) { menu->addAction( saveLayerEditsAction ); } } if ( allEditsAction->isEnabled() ) menu->addAction( allEditsAction ); // disable duplication of memory layers if ( vlayer->storageType() == "Memory storage" && mView->selectedLayerNodes().count() == 1 ) duplicateLayersAction->setEnabled( false ); // save as vector file menu->addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsFile() ) ); menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) ); if ( vlayer->dataProvider()->supportsSubsetString() ) { QAction *action = menu->addAction( tr( "&Filter..." ), QgisApp::instance(), SLOT( layerSubsetString() ) ); action->setEnabled( !vlayer->isEditable() ); } menu->addAction( actions->actionShowFeatureCount( menu ) ); menu->addSeparator(); } else if ( rlayer ) { menu->addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsRasterFile() ) ); menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) ); } else if ( layer && layer->type() == QgsMapLayer::PluginLayer && mView->selectedLayerNodes().count() == 1 ) { // disable duplication of plugin layers duplicateLayersAction->setEnabled( false ); } addCustomLayerActions( menu, layer ); if ( layer && QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() ) menu->addAction( tr( "&Properties" ), QgisApp::instance(), SLOT( layerProperties() ) ); if ( node->parent() != mView->layerTreeModel()->rootGroup() ) menu->addAction( actions->actionMakeTopLevel( menu ) ); menu->addAction( actions->actionRenameGroupOrLayer( menu ) ); if ( mView->selectedNodes( true ).count() >= 2 ) menu->addAction( actions->actionGroupSelected( menu ) ); } } else { // symbology item? } return menu; }
void queryTable::onClicked(QModelIndex index) { qDebug() << model->list.at(index.row())->PatientName; }
QModelIndex DesktopAccessModel::index(int row, int column, const QModelIndex & parent/* = QModelIndex()*/) const { if(!parent.isValid() && row<m_entries.size()) return createIndex(row, column); return QModelIndex(); }
/*override*/ void FilesGDelegate::paint(QPainter* pPainter, const QStyleOptionViewItem& option, const QModelIndex& index) const { // adapted from Trolltech's Pixelator (GPL V2 or V3) http://doc.trolltech.com/4.3/itemviews-pixelator.html int nCol (index.column()); if (0 == nCol) { return QItemDelegate::paint(pPainter, option, index); } //int nRow (index.row()); double r ((index.model()->data(index, Qt::DisplayRole).toString() == "" ? 0 : (CELL_HEIGHT - 0)/5)); pPainter->save(); pPainter->setRenderHint(QPainter::Antialiasing, true); pPainter->setPen(Qt::NoPen); const Note* pNote (m_pCommonData->getUniqueNotes().getFlt(nCol - 1)); bool bSel (0 != (QStyle::State_Selected & option.state)); bool bCrt (0 != (QStyle::State_HasFocus & option.state)); bool bActive (0 != (QStyle::State_Active & option.state)); // "active" is true if the parent window has keyboard focus /*QColor colSev (getNoteColor(*pNote)); //ttt2 perhaps try to derive all these colors from the global pallette (e.g. option.palette.highlight(), option.palette.highlightedText(), ...) QColor colBkg (colSev); QColor colFg (option.palette.color(QPalette::Active, QPalette::Highlight)); //ttt3 not necessarily "Active" //QColor colFg (Qt::black); //ttt3 not necessarily "Active" if (colFg.green() >= 160 && colFg.red() >= 160) { colFg = QColor(0, 0, 0); } if (bSel) { QColor c (colBkg); colBkg = colFg; colFg = c; }*/ //ttt2 perhaps try to derive all these colors from the global pallette (e.g. option.palette.highlight(), option.palette.highlightedText(), ...) QColor colNote; double dGradStart, dGradEnd; m_pCommonData->getNoteColor(*pNote, m_pCommonData->getUniqueNotes().getFltVec(), colNote, dGradStart, dGradEnd); QColor colSel (option.palette.color(QPalette::Active, QPalette::Highlight)); //ttt3 not necessarily "Active" //qDebug("gr %f %f", dGradStart, dGradEnd); QColor colFg, colBkg; colBkg = bSel ? colSel : colNote; if (colSel.green() >= 160 && colSel.red() >= 160) { // for better contrast we use something dark if the "highlight" color is light //colFg = QColor(0, 0, 0); colFg = option.palette.color(QPalette::Active, QPalette::HighlightedText); } else { colFg = bSel ? colNote : colSel; } //colBkg = QColor(220, 255, 230); QLinearGradient grad (option.rect.x(), 0, option.rect.x() + option.rect.width(), 0); /*switch(nCol % 4) { case 0: grad.setColorAt(0, colBkg.lighter(120)); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg.darker(120)); break; case 1: grad.setColorAt(0, colBkg.lighter(120)); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg); break; case 2: grad.setColorAt(0, colBkg); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg); break; case 3: grad.setColorAt(0, colBkg); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg.darker(120)); break; }*/ /* switch(nCol % 4) { case 0: configureGradient(grad, colBkg, 0, 1); break; case 1: configureGradient(grad, colBkg, 0, 0.33); break; case 2: configureGradient(grad, colBkg, 0.33, 0.67); break; case 3: configureGradient(grad, colBkg, 0.67, 1); break; } */ configureGradient(grad, colBkg, dGradStart, dGradEnd); //pPainter->fillRect(option.rect, colBkg); pPainter->fillRect(option.rect, grad); if (0 != r) { pPainter->setBrush(QBrush(colFg)); pPainter->drawEllipse( QRectF(option.rect.x() + option.rect.width()/2.0 - r, option.rect.y() + option.rect.height()/2.0 - r, 2*r, 2*r)); } if (bCrt && bActive) { pPainter->setRenderHint(QPainter::Antialiasing, false); const int ADJ (0); QRect r (option.rect); r.adjust(ADJ, ADJ, -ADJ - 1, -ADJ - 1); pPainter->setBrush(QBrush(Qt::NoBrush)); QPen pen (pPainter->pen()); pen.setStyle(Qt::DotLine); //pen.setColor(Qt::black); pen.setColor(colFg); pPainter->setPen(pen); pPainter->drawRect(r); } pPainter->restore(); }
QVariant CQJsonModel:: data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { if (jsonMatch_ != "") { if (! index.isValid()) return QVariant(); CJson::ValueP value = jsonValues_[index.row()]; if (index.column() >= 0 && index.column() < int(value->numValues())) return value->indexValue(index.column())->to_string().c_str(); return QVariant(); } //--- if (isHierarchical()) { if (! index.isValid()) return QVariant(); CJson::Value *value = static_cast<CJson::Value *>(index.internalPointer()); assert(value); CJson::Object *valueObj = value->cast<CJson::Object>(); assert(valueObj); CJson::ValueP columnValue; std::string name = hierColumns_[index.column()].toStdString(); if (! valueObj->getNamedValue(name, columnValue)) return QVariant(); return columnValue->to_string().c_str(); } else { CJson::Value *value = static_cast<CJson::Value *>(index.internalPointer()); if (! value) value = jsonValue_.get(); if (index.column() == 0) return parentName(value); if (index.column() != 1) return QVariant(); if (value->isObject()) { if (isFlat()) { CJson::Object *obj = value->cast<CJson::Object>(); return obj->to_string().c_str(); } return ""; } else if (value->isArray()) { if (isFlat()) { CJson::Array *array = value->cast<CJson::Array>(); return array->to_string().c_str(); } return ""; } else { return value->to_string().c_str(); } } } return QVariant(); }
void CSVWorld::TableSubView::rowActivated (const QModelIndex& index) { focusId (mTable->getUniversalId (index.row())); }
// get child of parent QModelIndex CQJsonModel:: index(int row, int column, const QModelIndex &parent) const { if (isHierarchical()) { // at root if (! parent.isValid()) return createIndex(0, column, jsonValue_.get()); CJson::Value *parentValue = static_cast<CJson::Value *>(parent.internalPointer()); assert(parentValue); CJson::Object *parentObj = parentValue->cast<CJson::Object>(); assert(parentObj); // parent must be non-root CJson::ValueP value; // if hierarchical then return child object if (parentObj->getNamedValue(hierName_.toStdString(), value)) { CJson::Array *childArray = value->cast<CJson::Array>(); CJson::ValueP childValue = childArray->at(row); return createIndex(row, column, childValue.get()); } else { return QModelIndex(); } } else { // get parent row CJson::Value *parentValue = static_cast<CJson::Value *>(parent.internalPointer()); if (! parentValue) parentValue = jsonValue_.get(); //if (! parentValue) // return createIndex(row, column, jsonValue_); if (parentValue->isObject()) { CJson::Object *obj = parentValue->cast<CJson::Object>(); if (row < 0 || row >= int(obj->nameValueMap().size())) return QModelIndex(); std::string name; CJson::ValueP value; if (! obj->indexNameValue(row, name, value)) return QModelIndex(); return createIndex(row, column, value.get()); } else if (parentValue->isArray()) { CJson::Array *array = parentValue->cast<CJson::Array>(); if (row < 0 || row >= int(array->size())) return QModelIndex(); return createIndex(row, column, array->at(row).get()); } else return QModelIndex(); } }
void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); painter->save(); switch(index.column()) { case TorrentModel::TR_AMOUNT_DOWNLOADED: case TorrentModel::TR_AMOUNT_UPLOADED: case TorrentModel::TR_AMOUNT_DOWNLOADED_SESSION: case TorrentModel::TR_AMOUNT_UPLOADED_SESSION: case TorrentModel::TR_AMOUNT_LEFT: case TorrentModel::TR_COMPLETED: case TorrentModel::TR_SIZE: case TorrentModel::TR_TOTAL_SIZE: { QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; } case TorrentModel::TR_ETA: { QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong())); break; } case TorrentModel::TR_SEEDS: case TorrentModel::TR_PEERS: { QString display = QString::number(index.data().toLongLong()); qlonglong total = index.data(Qt::UserRole).toLongLong(); if (total > 0) { // Scrape was successful, we have total values display += " ("+QString::number(total)+")"; } QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; } case TorrentModel::TR_STATUS: { const int state = index.data().toInt(); QString display; switch(state) { case BitTorrent::TorrentState::Downloading: display = tr("Downloading"); break; case BitTorrent::TorrentState::StalledDownloading: display = tr("Stalled", "Torrent is waiting for download to begin"); break; case BitTorrent::TorrentState::DownloadingMetadata: display = tr("Downloading metadata", "used when loading a magnet link"); break; case BitTorrent::TorrentState::ForcedDownloading: display = tr("[F] Downloading", "used when the torrent is forced started. You probably shouldn't translate the F."); break; case BitTorrent::TorrentState::Allocating: display = tr("Allocating", "qBittorrent is allocating the files on disk"); break; case BitTorrent::TorrentState::Uploading: case BitTorrent::TorrentState::StalledUploading: display = tr("Seeding", "Torrent is complete and in upload-only mode"); break; case BitTorrent::TorrentState::ForcedUploading: display = tr("[F] Seeding", "used when the torrent is forced started. You probably shouldn't translate the F."); break; case BitTorrent::TorrentState::QueuedDownloading: case BitTorrent::TorrentState::QueuedUploading: display = tr("Queued", "i.e. torrent is queued"); break; case BitTorrent::TorrentState::CheckingDownloading: case BitTorrent::TorrentState::CheckingUploading: display = tr("Checking", "Torrent local data is being checked"); break; case BitTorrent::TorrentState::QueuedForChecking: display = tr("Queued for checking", "i.e. torrent is queued for hash checking"); break; case BitTorrent::TorrentState::CheckingResumeData: display = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents."); break; case BitTorrent::TorrentState::PausedDownloading: display = tr("Paused"); break; case BitTorrent::TorrentState::PausedUploading: display = tr("Completed"); break; case BitTorrent::TorrentState::Error: display = tr("Missing Files"); break; default: display = ""; } QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, display); break; } case TorrentModel::TR_UPSPEED: case TorrentModel::TR_DLSPEED: { QItemDelegate::drawBackground(painter, opt, index); const qulonglong speed = index.data().toULongLong(); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed)+tr("/s", "/second (.i.e per second)")); break; } case TorrentModel::TR_UPLIMIT: case TorrentModel::TR_DLLIMIT: { QItemDelegate::drawBackground(painter, opt, index); const qlonglong limit = index.data().toLongLong(); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::String::fromDouble(limit/1024., 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)") : QString::fromUtf8(C_INFINITY)); break; } case TorrentModel::TR_TIME_ELAPSED: { QItemDelegate::drawBackground(painter, opt, index); QString txt = Utils::Misc::userFriendlyDuration(index.data().toLongLong()); qlonglong seeding_time = index.data(Qt::UserRole).toLongLong(); if (seeding_time > 0) txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(Utils::Misc::userFriendlyDuration(seeding_time))+")"; QItemDelegate::drawDisplay(painter, opt, opt.rect, txt); break; } case TorrentModel::TR_ADD_DATE: case TorrentModel::TR_SEED_DATE: QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, index.data().toDateTime().toLocalTime().toString(Qt::DefaultLocaleShortDate)); break; case TorrentModel::TR_RATIO_LIMIT: case TorrentModel::TR_RATIO: { QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; const qreal ratio = index.data().toDouble(); QItemDelegate::drawDisplay(painter, opt, opt.rect, ((ratio == -1) || (ratio > BitTorrent::TorrentHandle::MAX_RATIO)) ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2)); break; } case TorrentModel::TR_PRIORITY: { const int priority = index.data().toInt(); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; if (priority > 0) QItemDelegate::paint(painter, opt, index); else { QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, opt.rect, "*"); } break; } case TorrentModel::TR_PROGRESS: { QStyleOptionProgressBarV2 newopt; qreal progress = index.data().toDouble()*100.; newopt.rect = opt.rect; newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); newopt.progress = (int)progress; newopt.maximum = 100; newopt.minimum = 0; newopt.state |= QStyle::State_Enabled; newopt.textVisible = true; #ifndef Q_OS_WIN QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); #else // XXX: To avoid having the progress text on the right of the bar #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) QPlastiqueStyle st; #else QProxyStyle st("fusion"); #endif st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif break; } case TorrentModel::TR_LAST_ACTIVITY: { QString elapsedString; long long elapsed = index.data().toLongLong(); QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; if (elapsed == 0) // Show '< 1m ago' when elapsed time is 0 elapsed = 1; if (elapsed < 0) elapsedString = Utils::Misc::userFriendlyDuration(elapsed); else elapsedString = tr("%1 ago", "e.g.: 1h 20m ago").arg(Utils::Misc::userFriendlyDuration(elapsed)); QItemDelegate::drawDisplay(painter, opt, option.rect, elapsedString); break; } default: QItemDelegate::paint(painter, option, index); } painter->restore(); }
// get parent of child QModelIndex CQJsonModel:: parent(const QModelIndex &index) const { if (! index.isValid()) return QModelIndex(); if (isHierarchical()) { CJson::Value *childValue = static_cast<CJson::Value *>(index.internalPointer()); assert(childValue); CJson::Object *childObj = childValue->cast<CJson::Object>(); assert(childObj); if (! childObj->parent()) return QModelIndex(); // get parent object CJson::Array *parentArray = childObj->parent()->cast<CJson::Array>(); assert(parentArray); CJson::Object *parentObj = parentArray->parent()->cast<CJson::Object>(); assert(parentObj); if (! parentObj->parent()) return createIndex(0, 0, jsonValue_.get()); // get parent, parent object CJson::Array *parentParentArray = parentObj->parent()->cast<CJson::Array>(); assert(parentParentArray); CJson::Object *parentParentObj = parentParentArray->parent()->cast<CJson::Object>(); assert(parentParentObj); // find index of parentObj in parentParentArray for (uint i = 0; i < parentParentArray->size(); ++i) { if (parentParentArray->at(i).get() == parentObj) return createIndex(i, 0, parentObj); } // always non-leaf parent return createIndex(0, 0, parentObj); } else { CJson::Value *childValue = static_cast<CJson::Value *>(index.internalPointer()); if (! childValue) return QModelIndex(); CJson::Value *parentValue = childValue->parent(); if (! parentValue) return QModelIndex(); if (parentValue == jsonValue_.get()) return createIndex(0, 0, jsonValue_.get()); CJson::Value *parentParentValue = parentValue->parent(); if (! parentParentValue) return createIndex(0, 0, jsonValue_.get()); if (parentParentValue->isObject()) { CJson::Object *obj = parentParentValue->cast<CJson::Object>(); for (size_t i = 0; i < obj->nameValueMap().size(); ++i) { std::string name; CJson::ValueP value; if (obj->indexNameValue(i, name, value) && value.get() == parentValue) return createIndex(i, 0, parentValue); } } else if (parentParentValue->isArray()) { CJson::Array *array = parentParentValue->cast<CJson::Array>(); for (size_t i = 0; i < array->size(); ++i) { if (array->at(i).get() == parentValue) return createIndex(i, 0, parentValue); } } return QModelIndex(); } }
void CoreAccountSettingsPage::setSelectedAccount(AccountId accId) { QModelIndex index = filteredModel()->mapFromSource(model()->accountIndex(accId)); if(index.isValid()) ui.accountView->setCurrentIndex(index); }
Qt::ItemFlags HuboDataModel::flags(const QModelIndex& index) const { if (!index.isValid()) { return 0; } return Qt::ItemIsEnabled | Qt::ItemIsSelectable; }
void QScriptDebuggerLocalsWidgetPrivate::_q_expandIndex(const QModelIndex &index) { if (view->model() == index.model()) view->expand(proxy->mapFromSource(index)); }
void PlayerListWidget::removeSlot() { QModelIndex i = ui.tableView->currentIndex(); PlayerListModel *m = (PlayerListModel*)ui.tableView->model(); m->removeRows(i.row(), 1); }
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); } if (pMessageImp->getResult() == Message::Failure) { return QVariant(Qt::red); } break; } case Qt::ForegroundRole: { if (pMessageImp->getResult() == Message::Failure) { return QVariant(Qt::white); } break; } default: ; // blank } } return QVariant(); }
Polka::Identity PolkaAllItemModel::getIdentityData( const QModelIndex &index ) const { return model()->allIdentities().at( index.row() ); }