QVariant JobTrackerModel::data(const QModelIndex & idx, int role) const { // top level items are sessions if ( !idx.parent().isValid() ) { if ( role == Qt::DisplayRole ) { if( idx.column() == 0 ) { assert(d->tracker.sessions().size() > idx.row()); return d->tracker.sessions().at(idx.row()); } } } else // not top level, so a job or subjob { const int id = idx.internalId(); const JobInfo info = d->tracker.info( id ); if ( role == Qt::DisplayRole ) { if ( idx.column() == 0 ) return info.id; if ( idx.column() == 1 ) return QString(KGlobal::locale()->formatTime( info.timestamp.time(), true ) + QString::fromLatin1( ".%1" ).arg( info.timestamp.time().msec(), 3, 10, QLatin1Char('0') ) ); if ( idx.column() == 2 ) return info.type; if ( idx.column() == 3 ) return info.stateAsString(); } else if ( role == Qt::ForegroundRole ) { if ( info.state == JobInfo::Failed ) return Qt::red; } else if ( role == Qt::BackgroundColorRole ) { return d->currentColor; } else if ( role == Qt::FontRole ) { if ( info.state == JobInfo::Running ) { QFont f; f.setBold( true ); return f; } } else if ( role == Qt::ToolTipRole ) { if ( info.state == JobInfo::Failed ) return info.error; } } return QVariant(); }
QVariant StatesEditorModel::data(const QModelIndex &index, int role) const { if (index.parent().isValid() || index.column() != 0 || m_statesEditorView.isNull() || !m_statesEditorView->hasModelNodeForInternalId(index.internalId())) return QVariant(); ModelNode stateNode; if (index.internalId() > 0) stateNode = m_statesEditorView->modelNodeForInternalId(index.internalId()); switch (role) { case StateNameRole: { if (index.row() == 0) { return QString(tr("base state", "Implicit default state")); } else { if (stateNode.hasVariantProperty("name")) { return stateNode.variantProperty("name").value(); } else { return QVariant(); } } } case StateImageSourceRole: { static int randomNumber = 0; randomNumber++; if (index.row() == 0) { return QString("image://qmldesigner_stateseditor/baseState-%1").arg(randomNumber); } else { return QString("image://qmldesigner_stateseditor/%1-%2").arg(index.internalId()).arg(randomNumber); } } case NodeId : return index.internalId(); } return QVariant(); }
QModelIndex QvisPluginManagerAttributesDataModel::parent(const QModelIndex &index) const { if(!index.isValid()) return QModelIndex(); TreeItem childItem((int)index.internalId()); TreeItem parentItem(childItem.parent()); if(parentItem == TreeItem(-1)) return QModelIndex(); return createIndex(parentItem.row(), 0, (int)parentItem.index); }
QModelIndex PlayersList::parent(const QModelIndex & index) const { if (!index.isValid()) return QModelIndex(); quint32 parentRow = (quint32)(index.internalId() & NoParent); if (parentRow == NoParent || parentRow >= (quint32)m_playersList.size()) { return QModelIndex(); } return QAbstractItemModel::createIndex(parentRow, 0, NoParent); }
QModelIndex BtMiniModuleTextModel::index(int row, int column, const QModelIndex &parent) const { Q_D(const BtMiniModuleTextModel); switch(d->indexDepth(parent)) { case 0: return createIndex(row, column, row); case 1: return createIndex(row, column, (void*)&d->_lists[parent.internalId()]); } return QModelIndex(); }
bool VariablesModel::hasChildren(const QModelIndex &parent) const { if (parent.column() > 0) return false; QMutexLocker lock(mMutex); VarTreeItem *parentItem; if(!parent.isValid()) parentItem = mLocals; else parentItem = mItems->value(parent.internalId(), 0); if(!parentItem) return false; return parentItem->childCount() > 0; }
QModelIndex JobTrackerModel::parent(const QModelIndex & idx) const { if ( !idx.isValid() ) return QModelIndex(); const int parentid = d->tracker.parentId( idx.internalId() ); if ( parentid == -1 ) return QModelIndex(); // top level session const int row = d->rowForParentId( parentid ); if ( row >= 0 ) { return createIndex( row, 0, parentid ); } else { return QModelIndex(); } }
void ModelMoveCommand::doCommand() { QModelIndex srcParent = findIndex( m_rowNumbers ); QModelIndex destParent = findIndex( m_destRowNumbers ); if ( !emitPreSignal( srcParent, m_startRow, m_endRow, destParent, m_destRow ) ) { return; } for ( int column = 0; column < m_numCols; ++column ) { const QList<qint64> l = m_model->m_childItems.value( srcParent.internalId() )[column].mid( m_startRow, m_endRow - m_startRow + 1 ); for ( int i = m_startRow; i <= m_endRow ; i++ ) { m_model->m_childItems[srcParent.internalId()][column].removeAt( m_startRow ); } int d; if ( m_destRow < m_startRow ) d = m_destRow; else { if ( srcParent == destParent ) d = m_destRow - ( m_endRow - m_startRow + 1 ); else d = m_destRow - ( m_endRow - m_startRow ) + 1; } for ( const qint64 id : l ) { m_model->m_childItems[destParent.internalId()][column].insert( d++, id ); } } emitPostSignal(); }
void KateBuildView::writeSessionConfig(KConfigGroup& cg) { m_targetsUi->targetsModel.deleteTargetSet(i18n("Project Plugin Targets")); QList<TargetModel::TargetSet> targets = m_targetsUi->targetsModel.targetSets(); cg.writeEntry("NumTargets", targets.size()); for (int i=0; i<targets.size(); i++) { cg.writeEntry(QStringLiteral("%1 Target").arg(i), targets[i].name); cg.writeEntry(QStringLiteral("%1 BuildPath").arg(i), targets[i].workDir); QStringList cmdNames; for (int j=0; j<targets[i].commands.count(); j++) { const QString& cmdName = targets[i].commands[j].first; const QString& buildCmd = targets[i].commands[j].second; cmdNames << cmdName; cg.writeEntry(QStringLiteral("%1 BuildCmd %2").arg(i).arg(cmdName), buildCmd); } cg.writeEntry(QStringLiteral("%1 Target Names").arg(i), cmdNames); cg.writeEntry(QStringLiteral("%1 Target Default").arg(i), targets[i].defaultCmd); } int setRow = 0; int set = 0; QModelIndex ind = m_targetsUi->targetsView->currentIndex(); if (ind.internalId() == TargetModel::InvalidIndex) { set = ind.row(); } else { set = ind.internalId(); setRow = ind.row(); } if (setRow < 0) setRow = 0; cg.writeEntry(QStringLiteral("Active Target Index"), set); cg.writeEntry(QStringLiteral("Active Target Command"), setRow); slotAddProjectTarget(); }
QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex &parent) const { // if (column != 0) // return QModelIndex(); if ( column < 0 || row < 0 ) return QModelIndex(); QList<QList<qint64> > childIdColumns = m_childItems.value(parent.internalId()); const qint64 grandParent = findParentId(parent.internalId()); if (grandParent >= 0) { QList<QList<qint64> > parentTable = m_childItems.value(grandParent); if (parent.column() >= parentTable.size()) qFatal("%s: parent.column() must be less than parentTable.size()", Q_FUNC_INFO); QList<qint64> parentSiblings = parentTable.at(parent.column()); if (parent.row() >= parentSiblings.size()) qFatal("%s: parent.row() must be less than parentSiblings.size()", Q_FUNC_INFO); } if (childIdColumns.size() == 0) return QModelIndex(); if (column >= childIdColumns.size()) return QModelIndex(); QList<qint64> rowIds = childIdColumns.at(column); if ( row >= rowIds.size()) return QModelIndex(); qint64 id = rowIds.at(row); return createIndex(row, column, reinterpret_cast<void *>(id)); }
QVariant PlayersList::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.column() != 0) return QVariant(); Person * person; int row = index.row(); if (row < 0) return QVariant(); quint32 parentRow = (quint32)(index.internalId() & NoParent); if (parentRow == NoParent) { if (row >= m_playersList.size()) return QVariant(); Player * player = m_playersList.at(row); person = player; if (role == Qt::BackgroundRole && player->isGM()) { QPalette pal = qApp->palette(); return QVariant(pal.color(QPalette::Active,QPalette::Button)); } } else { if (parentRow >= (quint32)m_playersList.size()) return QVariant(); Player * player = m_playersList.at(parentRow); if (row >= player->getCharactersCount()) return QVariant(); person = player->getCharacterByIndex(row); } switch (role) { case Qt::DisplayRole: case Qt::EditRole: return QVariant(person->name()); case Qt::DecorationRole: return QVariant(person->color()); case IdentifierRole: return QVariant(person->uuid()); } return QVariant(); }
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const { qint32 parentId; if( parent.isValid() ) parentId = parent.internalId(); else parentId = 0; int nPtr; int ret = m_queryItem->index(row, parentId, nPtr).toInt(); if( ret == 1 ) return createIndex(row, column, nPtr); return QModelIndex(); }
QModelIndex PackageModel::index( int row, int column, const QModelIndex &parent ) const { if (!parent.isValid()) // root { if ( row > rootItems.count() ) return QModelIndex(); unsigned int internalId = makeId( row, 0, INVALID_PARENT ); return createIndex( row, 0, internalId ); } else { unsigned int parentId = getRow( parent.internalId() ); return createIndex( row, column, makeId( row, column, parentId )); } }
QVariant SectionDataModel::data(const QModelIndex &index, int role) const { if (!m_model || !m_sectionRole) return QVariant(); if (index.parent().isValid()) { if (index.internalId() >= m_sectionMap.length()) return QVariant(); if (index.row() >= m_sectionMap[index.internalId()].entries.length()) return QVariant(); QModelIndex childIndex = m_sectionMap[index.internalId()].entries[index.row()]; return m_model->data(childIndex, role); } else { if (index.row() >= m_sectionMap.length()) return QVariant(); if (role == m_sectionRole || role == Qt::DisplayRole) return m_sectionMap[index.row()].section; else return QVariant(); } }
/****************************************************************************** CheckDirModel::data ******************************************************************************/ QVariant CheckDirModel::data( const QModelIndex& index, int role) const { if (role == Qt::CheckStateRole) { int id = index.internalId(); return m_checkTable.contains(id) ? m_checkTable.value(id) : Qt::Checked; } else { return QDirModel::data(index, role); } }
bool AMScanSetModel::setData ( const QModelIndex & index, const QVariant & value, int role ) { // invalid index... don't do anything if(!index.isValid()) return false; // editing a (valid) scan? if(index.internalId() == -1 && index.row() < scans_.count()) { AMScan* scan = scans_.at(index.row()); Q_UNUSED(scan) switch(role) { // no editable roles for editing scans (for now...) default: return false; } }
QVariant TextDocumentStructureModel::data(const QModelIndex &index, int role) const { if (! m_textDocument || ! index.isValid()) { return QVariant(); } Q_ASSERT(index.internalId() < uint(m_nodeDataTable.count())); const NodeData &nodeData = m_nodeDataTable.at(index.internalId()); switch (role) { case Qt::DisplayRole: { if (nodeData.type == NodeData::Frame) { QTextFrame* frame = nodeData.frame; return QLatin1String(frame->metaObject()->className()); } // else should be a block return QLatin1String("Block"); } } return QVariant(); }
/*! \internal \reimp Calculate and return an index for the parent of \a index. */ QModelIndex PackageModel::parent( const QModelIndex &index ) const { if (!index.isValid()) return QModelIndex(); int thisId = index.internalId(); unsigned int thisParent = getParent( thisId ); if ( thisParent == INVALID_PARENT ) { return QModelIndex(); } unsigned int internalId = makeId( thisParent, 0, INVALID_PARENT ); return createIndex( thisParent, 0, internalId ); }
int PlayersList::rowCount(const QModelIndex & index) const { if (!index.isValid()) { return m_playersList.size(); } quint32 parentRow = (quint32)(index.internalId() & NoParent); int row = index.row(); if (parentRow != NoParent || row < 0 || row >= m_playersList.size()) { return 0; } return m_playersList.at(row)->getCharactersCount(); }
bool CollectionModel::setData( const QModelIndex & index, const QVariant & value, int role ) { Q_D( CollectionModel ); if ( index.column() == 0 && role == Qt::EditRole ) { // rename collection Collection col = d->collections.value( index.internalId() ); if ( !col.isValid() || value.toString().isEmpty() ) { return false; } col.setName( value.toString() ); CollectionModifyJob *job = new CollectionModifyJob( col, d->session ); connect( job, SIGNAL(result(KJob*)), SLOT(editDone(KJob*)) ); return true; } return QAbstractItemModel::setData( index, value, role ); }
Qt::ItemFlags ItemsModel::flags(const QModelIndex &index) const { if (!index.isValid()) return 0; Qt::ItemFlags flags = QAbstractItemModel::flags(index); if ( index.column() == 0 && index.internalId() == 0) { const ItemLocation &location = search_.GetTabLocation(index); flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; if (!bo_manager_.GetRefreshLocked(location)) { flags |= Qt::ItemIsUserCheckable; } } return flags; }
QModelIndex SensorBrowserModel::index ( int row, int column, const QModelIndex & parent) const { //virtual if(column != 0) return QModelIndex(); QList<int> ids; if(!parent.isValid()) { ids = mHostInfoMap.keys(); } else { ids = mTreeMap.value(parent.internalId()); } if( row >= ids.size() || row< 0) { return QModelIndex(); } QModelIndex index = createIndex(row, column, ids[row]); Q_ASSERT(index.isValid()); return index; }
QModelIndex SidebarModel::index(int row, int column, const QModelIndex &parent) const { // The model tree has two levels: // Sections // Section specific pages // The leaf item ID is the section number (section row() + 1) if(parent.isValid()) { if(parent.internalId()==0) return createIndex(row, column, parent.row()+1); } else { return createIndex(row, column, quintptr(0)); } return QModelIndex(); }
int VariablesModel::rowCount(const QModelIndex &parent) const { QMutexLocker lock(mMutex); int rows = 0; VarTreeItem *parentItem; if (parent.column() <= 0) { if (!parent.isValid()) parentItem = mLocals; else parentItem = mItems->value(parent.internalId(), 0); if(parentItem) rows = parentItem->childCount(); } return rows; }
void WatchHandler::expandChildren(const QModelIndex &idx) { if (m_inChange || m_completeSet.isEmpty()) { //qDebug() << "WATCHHANDLER: EXPAND IGNORED" << idx; return; } int index = idx.internalId(); if (index == 0) return; QTC_ASSERT(index >= 0, qDebug() << toString() << index; return); QTC_ASSERT(index < m_completeSet.size(), qDebug() << toString() << index; return); const WatchData &display = m_displaySet.at(index); QTC_ASSERT(index >= 0, qDebug() << toString() << index; return); QTC_ASSERT(index < m_completeSet.size(), qDebug() << toString() << index; return); const WatchData &complete = m_completeSet.at(index); MODEL_DEBUG("\n\nEXPAND" << display.iname); if (display.iname.isEmpty()) { // This should not happen but the view seems to send spurious // "expand()" signals folr the root item from time to time. // Try to handle that gracfully. //MODEL_DEBUG(toString()); qDebug() << "FIXME: expandChildren, no data " << display.iname << "found" << idx; //rebuildModel(); return; } //qDebug() << " ... NODE: " << display.toString() // << complete.childIndex.size() << complete.childCount; if (m_expandedINames.contains(display.iname)) return; // This is a performance hack and not strictly necessary. // Remove it if there are troubles when expanding nodes. if (0 && complete.childCount > 0 && complete.childIndex.size() > 0) { MODEL_DEBUG("SKIP FETCHING CHILDREN"); return; } WatchData data = takeData(display.iname); // remove previous data m_expandedINames.insert(data.iname); if (data.iname.contains('.')) // not for top-level items data.setChildrenNeeded(); insertData(data); emit watchModelUpdateRequested(); }
void CameraPropertyModelDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const { switch(index.internalId()) { case CameraPropertyModel::CAMERANAME: { QLineEdit *lineEdit=static_cast<QLineEdit*>(editor); QString value=lineEdit->text(); model->setData(index,value,Qt::EditRole); return; } break; case CameraPropertyModel::FOV: case CameraPropertyModel::FARPLANE: case CameraPropertyModel::NEARPLANE: case CameraPropertyModel::FROMX: case CameraPropertyModel::FROMY: case CameraPropertyModel::FROMZ: case CameraPropertyModel::TOX: case CameraPropertyModel::TOY: case CameraPropertyModel::TOZ: case CameraPropertyModel::UPX: case CameraPropertyModel::UPY: case CameraPropertyModel::UPZ: case CameraPropertyModel::SCALE: { QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->interpretText(); int value = spinBox->value(); model->setData(index, value, Qt::EditRole); return; } break; case CameraPropertyModel::ISSHOWINFO: case CameraPropertyModel::ISDRAW: { QCheckBox *checkBox=static_cast<QCheckBox*>(editor); bool value=checkBox->isChecked(); model->setData(index,value,Qt::EditRole); return; } break; } return QStyledItemDelegate::setModelData(editor,model,index); }
void DockerStylesComboModel::createMapping() { Q_ASSERT(m_sourceModel); if (!m_sourceModel || !m_styleManager) { return; } m_proxyToSource.clear(); m_sourceToProxy.clear(); m_unusedStyles.clear(); m_usedStyles.clear(); m_usedStylesId.clear(); QVector<int> usedStyles; if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) { usedStyles = m_styleManager->usedCharacterStyles(); } else { usedStyles = m_styleManager->usedParagraphStyles(); } // The order of the styles is already correctly given by the source model. // Therefor it is not needed to resort the styles again here. The source model // makes sure to have the NoneStyleId as first style and the styles after // that are ordered by name. for (int i = 0; i < m_sourceModel->rowCount(QModelIndex()); ++i) { QModelIndex index = m_sourceModel->index(i, 0, QModelIndex()); int id = (int)index.internalId(); if (id == StylesModel::NoneStyleId || usedStyles.contains(id)) { m_usedStylesId.append(id); m_usedStyles.append(i); } else { m_unusedStyles.append(i); } } if (!m_usedStyles.isEmpty()) { m_proxyToSource << UsedStyleId << m_usedStyles; } if (!m_unusedStyles.isEmpty()) { m_proxyToSource << UnusedStyleId << m_unusedStyles; //UsedStyleId and UnusedStyleId will be detected as title (in index method) and will be treated accordingly } m_sourceToProxy.fill(-1, m_sourceModel->rowCount((QModelIndex()))); for (int i = 0; i < m_proxyToSource.count(); ++i) { if (m_proxyToSource.at(i) >= 0) { //we do not need to map to the titles m_sourceToProxy[m_proxyToSource.at(i)] = i; } } }
void taskinfodlg::onCategoryBoxChange(int index) { qDebug()<<__FUNCTION__ << index<< this->mCatView->currentIndex()<<this->mCatView->currentIndex().data(); // QString cat; QModelIndex cidx = this->mCatView->currentIndex(); this->mCatId = cidx.internalId(); // cat = uiwin.tid_g_le_cb_category->itemText(index); // cat = QString("C:\\") + cat; // uiwin.tid_g_cb_save_to->setItemText(index, cat); // uiwin.tid_g_cb_save_to->setCurrentIndex(index); QModelIndex pathIndex = this->mCatModel->index(cidx.row(), ng::cats::path, cidx.parent()); this->uiwin.tid_g_cb_save_to->setEditText(pathIndex.data().toString()); this->uiwin.tid_g_cb_save_to->setToolTip(pathIndex.data().toString()); }
void ValidParentStylesProxyModel::createMapping() { if (!m_styleManager || !m_sourceModel) { return; } m_sourceToProxy.clear(); m_proxyToSource.clear(); for(int i = 0; i < m_sourceModel->rowCount(QModelIndex()); ++i) { QModelIndex index = m_sourceModel->index(i, 0, QModelIndex()); int id = (int)index.internalId(); KoParagraphStyle *paragraphStyle = m_styleManager->paragraphStyle(id); if (paragraphStyle) { bool ok = true; KoParagraphStyle *testStyle = paragraphStyle; while (testStyle && ok) { ok = testStyle->styleId() != m_currentChildStyleId; testStyle = testStyle->parentStyle(); } if (!ok) { continue; //we cannot inherit ourself even indirectly through the parent chain } m_proxyToSource.append(i); //the style is ok for parenting } else { KoCharacterStyle *characterStyle = m_styleManager->characterStyle(id); if (characterStyle) { bool ok = true; KoCharacterStyle *testStyle = characterStyle; while (testStyle && ok) { ok = testStyle->styleId() != m_currentChildStyleId; testStyle = testStyle->parentStyle(); } if (!ok) { continue; //we cannot inherit ourself even indirectly through the parent chain } m_proxyToSource.append(i); //the style is ok for parenting } } } m_sourceToProxy.fill(-1, m_sourceModel->rowCount(QModelIndex())); for(int i = 0; i < m_proxyToSource.count(); ++i) { m_sourceToProxy[m_proxyToSource.at(i)] = i; } }
int qtSDLTreeModel::rowCount(const QModelIndex& parent) const { if(parent.isValid()) { SDLModelIndex myParent = indices[parent.internalId()]; switch(myParent.type) { case kSDR: return myParent.ptr.sdr->getNumVars(); case kVar: return myParent.ptr.sv->getCount(); case kVal: return 0; default: return 0; } }else{ return 1; // only one root } }