void Grid_proxy_model_no_selection::end_insert_proxy_rows(const QModelIndex & source_parent, int start, int end){ GsTL_object_item *item = static_cast<GsTL_object_item*>(source_parent.internalPointer()); if(item != grid_manager_) return; //Add the grid into the list // Check if an item that is currently selected is removed // set the selection to None in that case for(int i = start; i<= end; ++i) { item = static_cast<GsTL_object_item*>(source_parent.child(i,0).internalPointer()); grid_names_.insert(i+1,item->item_name()); grid_types_.insert(i+1,item->item_type()); } this->endInsertRows(); }
QModelIndexList searchLeafs(const QModelIndex& curentIndex) const { QModelIndexList res; if(curentIndex.isValid()) { int childCount=curentIndex.model()->columnCount(curentIndex); if(childCount) { for(int i=0; i<childCount; ++i) res+=searchLeafs(curentIndex.child(0, i)); } else { res.push_back(curentIndex); } } return res; }
int HbDataFormPrivate::childCount(const QModelIndex &index) const { Q_Q(const HbDataForm); int itemCount = 0; int rowCount = 0; if(!index.isValid()) { return 0; } if (q->isExpanded(index)) { rowCount = index.model()->rowCount(index); } itemCount += rowCount; for (int row = 0; row < rowCount; ++row) { itemCount += childCount(index.child(row, 0)); } return itemCount; }
void EditorViewMViface::rowsMoved(QModelIndex const &sourceParent, int sourceStart, int sourceEnd, QModelIndex const &destinationParent, int destinationRow) { Q_UNUSED(sourceParent); Q_UNUSED(sourceStart); Q_UNUSED(sourceEnd); Q_ASSERT(sourceStart == sourceEnd); QPersistentModelIndex movedElementIndex = destinationParent.child(destinationRow, 0); Q_ASSERT(movedElementIndex.isValid()); Element *movedElement = item(movedElementIndex); if (movedElement == NULL) { // no element on the scene, forget about it return; } movedElement->updateData(); }
bool QgsVectorLayerAndAttributeModel::setData( const QModelIndex &index, const QVariant &value, int role ) { if ( index.column() == 0 && role == Qt::CheckStateRole ) { int i = 0; for ( i = 0; ; i++ ) { QModelIndex child = index.child( i, 0 ); if ( !child.isValid() ) break; setData( child, value, role ); } if ( i == 0 ) { if ( value.toInt() == Qt::Checked ) mCheckedLeafs.insert( index ); else if ( value.toInt() == Qt::Unchecked ) mCheckedLeafs.remove( index ); else Q_ASSERT( "expected checked or unchecked" ); emit dataChanged( QModelIndex(), index ); } return true; } if ( index.column() == 1 ) { if ( role != Qt::EditRole ) return false; QgsVectorLayer *vl = vectorLayer( index ); if ( vl ) { mAttributeIdx[ vl ] = value.toInt(); return true; } } return QgsLayerTreeModel::setData( index, value, role ); }
static QModelIndex nextIndex( const QModelIndex& idx ) { if ( !idx.isValid() ) return QModelIndex(); const QAbstractItemModel* const model = idx.model(); assert( model ); if ( model->hasChildren( idx ) ) return idx.child( 0, idx.column() ); QModelIndex i = idx; while ( true ) { if ( !i.isValid() ) return i; const int siblings = model->rowCount( i.parent() ); if ( i.row() + 1 < siblings ) return i.sibling( i.row() + 1, i.column() ); i = i.parent(); } }
int KateCompletionTree::columnTextViewportPosition(int column) const { int ret = columnViewportPosition(column); QModelIndex i = model()->index(0, column, QModelIndex()); QModelIndex base = model()->index(0, 0, QModelIndex()); //If it's just a group header, use the first child if (base.isValid() && model()->rowCount(base)) { i = base.child(0, column); } if (i.isValid()) { QIcon icon = i.data(Qt::DecorationRole).value<QIcon>(); if (!icon.isNull()) { ret += icon.actualSize(sizeHintForIndex(i)).width(); } } return ret; }
bool FileBrowser::DeleteFile(const QModelIndex &index, int &deleteConfirmed,bool &skipErrors) { if(!index.isValid()) return false; bool allChildrenDeleted=true; //delete children first if(model->isDir(index)) { int nbChildren = model->rowCount(index); QList<QPersistentModelIndex>listIdx; for(int i=0;i<nbChildren; i++) { listIdx << index.child(i,0); } foreach(QPersistentModelIndex idx, listIdx) { if(!DeleteFile(idx,deleteConfirmed,skipErrors)) allChildrenDeleted=false; } }
QModelIndex spCollapseArray::numCollapser( NifModel * nif, QModelIndex &iNumElem, QModelIndex &iArray ) { if ( iNumElem.isValid() && iArray.isValid() ) { QVector<qint32> links; for ( int r = 0; r < nif->rowCount( iArray ); r++ ) { qint32 l = nif->getLink( iArray.child( r, 0 ) ); if ( l >= 0 ) links.append( l ); } if ( links.count() < nif->rowCount( iArray ) ) { nif->set<int>( iNumElem, links.count() ); nif->updateArray( iArray ); nif->setLinkArray( iArray, links ); } } return iArray; }
QModelIndex TreeViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const { if (wrapped) *wrapped = false; QAbstractItemModel *model = d->m_view->model(); // pathological if (!idx.isValid()) return model->index(0, 0); // same parent has more columns, go to next column if (idx.column() + 1 < model->columnCount(idx.parent())) return model->index(idx.row(), idx.column() + 1, idx.parent()); // tree views have their children attached to first column // make sure we are at first column QModelIndex current = model->index(idx.row(), 0, idx.parent()); // check for children if (model->rowCount(current) > 0) { return current.child(0, 0); } // no more children, go up and look for parent with more children QModelIndex nextIndex; while (!nextIndex.isValid()) { int row = current.row(); current = current.parent(); if (row + 1 < model->rowCount(current)) { // Same parent has another child nextIndex = model->index(row + 1, 0, current); } else { // go up one parent if (!current.isValid()) { // we start from the beginning if (wrapped) *wrapped = true; nextIndex = model->index(0, 0); } } } return nextIndex; }
void ProjectSelectionPage::typeChanged(const QModelIndex& idx) { if (!idx.model()) { qCDebug(PLUGIN_APPWIZARD) << "Index with no model"; return; } int children = idx.model()->rowCount(idx); ui->templateType->setVisible(children); ui->templateType->setEnabled(children > 1); if (children) { ui->templateType->setModel(m_templatesModel); ui->templateType->setRootModelIndex(idx); ui->templateType->setCurrentIndex(0); itemChanged(idx.child(0, 0)); } else { itemChanged(idx); } }
void TemplateSelectionPagePrivate::currentTemplateChanged(const QModelIndex& index) { // delete preview tabs if (!index.isValid() || index.child(0, 0).isValid()) { // invalid or has child assistant->setValid(assistant->currentPage(), false); ui->previewLabel->setVisible(false); ui->tabWidget->setVisible(false); } else { selectedTemplate = model->data(index, TemplatesModel::DescriptionFileRole).toString(); assistant->setValid(assistant->currentPage(), true); previewTemplate(selectedTemplate); ui->previewLabel->setVisible(true); ui->tabWidget->setVisible(true); ui->previewLabel->setText(i18nc("%1: template comment", "<b>Preview:</b> %1", index.data(TemplatesModel::CommentRole).toString())); } }
QModelIndex layers_tree_model::index_for_node (layers_tree_node *node) const { std::stack<int> indexes; while (node->parent != nullptr) { indexes.push (node->node_number); node = node->parent; } QModelIndex curIndex = index (indexes.top (), 0); indexes.pop (); while (!indexes.empty ()) { curIndex = curIndex.child (indexes.top (), 0); indexes.pop (); } return curIndex; }
/*! * \param name Name of server * \param server Server details * \param network Network name (optional * * Changes server details of specified server.\n * If network isn't specified, this applies to servers without parents. */ void ServerModel::setServer(QString name, QString server, QString network) { QStandardItem *parent; if (network.length() == 0) network = "NONE"; if (network == "NONE") parent = invisibleRootItem(); else parent = itemFromIndex( netmap.value(network) ); QModelIndex parentIdx = indexFromItem(parent); // Parent index QModelIndex current; // Item's index if (network != "NONE") { for (int r = 0 ;; r++) { QModelIndex idx = parentIdx.child(r, 0); if (! idx.isValid()) return; // No relevant child found, stop. if (idx.data().toString() == name) { current = idx; break; } } } else { current = nonemap.value(name); } int row = current.row(); QModelIndex nameIndex = index(row, 0, current.parent()); QModelIndex serverIndex = index(row, 1, current.parent()); QStandardItem *serverItem = itemFromIndex(serverIndex); serverItem->setText(server); hostmap.insert(server, nameIndex); }
BoneWeights::BoneWeights( const NifModel * nif, const QModelIndex & index, int b, int vcnt ) { trans = Transform( nif, index ); center = nif->get<Vector3>( index, "Center" ); radius = nif->get<float>( index, "Radius" ); bone = b; QModelIndex idxWeights = nif->getIndex( index, "Vertex Weights" ); if ( idxWeights.isValid() ) { for ( int c = 0; c < nif->rowCount( idxWeights ); c++ ) { QModelIndex idx = idxWeights.child( c, 0 ); weights.append( VertexWeight( nif->get<int>( idx, "Index" ), nif->get<float>( idx, "Weight" ) ) ); } } else // create artificial ones, TODO: should they weight nothing* instead? for ( int c = 0; c < vcnt; c++ ) weights.append( VertexWeight( c, 1.0f ) ); }
static PyObject *meth_QModelIndex_child(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { int a0; int a1; QModelIndex *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "Bii", &sipSelf, sipType_QModelIndex, &sipCpp, &a0, &a1)) { QModelIndex *sipRes; Py_BEGIN_ALLOW_THREADS sipRes = new QModelIndex(sipCpp->child(a0,a1)); Py_END_ALLOW_THREADS return sipConvertFromNewType(sipRes,sipType_QModelIndex,NULL); } }
void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set<std::string>& exp, const std::set<std::string> &sel) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; #endif if(sel.find(local_path) != sel.end()) ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); if(exp.find(local_path) != exp.end()) { #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "re expanding index " << local_path << std::endl; #endif ui.dirTreeView->setExpanded(index,true) ; for(int row=0;row<ui.dirTreeView->model()->rowCount(index);++row) recursRestoreExpandedItems(index.child(row,0),local_path,exp,sel) ; } }
void NTagView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const { if (!index.child(0,0).isValid()) return; painter->save(); if (isExpanded(index)) { int offset = rect.width()-expandedImage->width()-1; painter->drawImage(offset, rect.y(),*expandedImage); } else { int offset = rect.width()-collapsedImage->width()-1; painter->drawImage(offset, rect.y(),*collapsedImage); } painter->restore(); return; // if (index.data(Qt::UserRole).toString() == "root") { // return; // } // QTreeView::drawBranches(painter, rect, index); }
QModelIndex TreeViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const { if (wrapped) *wrapped = false; QAbstractItemModel *model = d->m_view->model(); // pathological if (!idx.isValid()) return model->index(0, 0); if (model->rowCount(idx) > 0) { // node with children return idx.child(0, 0); } // leaf node QModelIndex nextIndex; QModelIndex current = idx; while (!nextIndex.isValid()) { int row = current.row(); int column = current.column(); current = current.parent(); if (column + 1 < model->columnCount(current)) { nextIndex = model->index(row, column + 1, current); } else { if (row + 1 < model->rowCount(current)) { // Same parent has another child nextIndex = model->index(row + 1, 0, current); } else { // go up one parent if (!current.isValid()) { // we start from the beginning if (wrapped) *wrapped = true; nextIndex = model->index(0, 0); } } } } return nextIndex; }
QModelIndexList Reviews::retrieveAnnotations(const QModelIndex& idx) const { QModelIndexList ret; if ( idx.isValid() ) { if ( idx.model()->hasChildren( idx ) ) { int rowCount = idx.model()->rowCount( idx ); for ( int i = 0; i < rowCount; i++ ) { ret += retrieveAnnotations( idx.child( i, idx.column() ) ); } } else { ret += idx; } } return ret; }
void FolderProvider::onDirectoryReady(const QString &path) { QModelIndex idx = d->mFileSystemModel->index(d->mFileSystemModel->rootPath()); mFolderList.clear(); for (int i = 0; i < d->mFileSystemModel->rowCount(idx); i++) { QModelIndex child = idx.child(i, 0); /// qDebug() << Q_FUNC_INFO << d->mFileSystemModel->fileName(child) << endl; FolderItem *item = new FolderItem(QRectF(0.0, 0.0, 64, 64), 0); item->setFileName(d->mFileSystemModel->fileName(child)); item->setFileInfo((d->mFileSystemModel->fileInfo(child))); item->setFilePath(d->mFileSystemModel->filePath(child)); item->setIcon(d->mFileSystemModel->fileIcon(child)); mFolderList.append(item); connect(item, SIGNAL(clicked(FolderItem *)), this, SIGNAL(itemClicked(FolderItem *))); connect(item, SIGNAL(doubleClicked(FolderItem *)), this, SIGNAL(itemDoubleClicked(FolderItem *))); } Q_EMIT updated(); }
bool VirtualSystemSortProxyModel::filterAcceptsRow(int srcRow, const QModelIndex & srcParenIdx) const { /* By default enable all, we will explicitly filter out below */ if (srcParenIdx.isValid()) { QModelIndex i = srcParenIdx.child(srcRow, 0); if (i.isValid()) { ModelItem *item = static_cast<ModelItem*>(i.internalPointer()); /* We filter hardware types only */ if (item->type() == HardwareType) { HardwareItem *hwItem = static_cast<HardwareItem*>(item); /* The license type shouldn't be displayed */ if (m_filterList.contains(hwItem->m_type)) return false; } } } return true; }
void MainWindow::cycleChannel(bool cycleDown) { QModelIndex selectedChannelIndex = ui->treeView->selectionModel()->currentIndex(); // going to assume if it's not selected, they're at the first one if (!selectedChannelIndex.isValid()) { selectedChannelIndex = ui->treeView->model()->index(0,0); } QModelIndex nextChannel; if (cycleDown) { nextChannel = ui->treeView->indexBelow(selectedChannelIndex); if (!nextChannel.isValid()) { nextChannel = ui->treeView->model()->index(0,0); } } else { nextChannel = ui->treeView->indexAbove(selectedChannelIndex); if (!nextChannel.isValid()) { int lastRowIndex = ui->treeView->model()->rowCount() - 1; QModelIndex lastServer = ui->treeView->model()->index(lastRowIndex,0); if (lastServer.model()->hasChildren()) { int lastChildRowIndex = lastServer.model()->rowCount(lastServer) - 1; nextChannel = lastServer.child(lastChildRowIndex, 0); } else { nextChannel = lastServer; } } } this->selectItem(nextChannel); ui->treeView->setCurrentIndex(nextChannel); }
bool CLModel::TryDropContact (const QMimeData *mime, int row, const QModelIndex& parent) { if (!mime->hasFormat (CLEntryFormat)) return false; if (parent.data (Core::CLREntryType).value<Core::CLEntryType> () != Core::CLETAccount) return false; QObject *accObj = parent.data (Core::CLRAccountObject).value<QObject*> (); IAccount *acc = qobject_cast<IAccount*> (accObj); if (!acc) return false; const QString& newGrp = parent.child (row, 0) .data (Core::CLREntryCategory).toString (); QDataStream stream (mime->data (CLEntryFormat)); while (!stream.atEnd ()) { QString id; QString oldGroup; stream >> id >> oldGroup; if (oldGroup == newGrp) continue; QObject *entryObj = Core::Instance ().GetEntry (id); ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj); if (!entry) continue; QStringList groups = entry->Groups (); groups.removeAll (oldGroup); groups << newGrp; entry->SetGroups (groups); } return true; }
FileDigger::FileDigger(MergedRepository *pRepository, QWidget *pParent) : KMainWindow(pParent) { setWindowIcon(KIcon(QLatin1String("chronometer"))); KToolBar *lAppToolBar = toolBar(); lAppToolBar->addAction(KStandardAction::quit(this, SLOT(close()), this)); QSplitter *lSplitter = new QSplitter(); mMergedVfsModel = new MergedVfsModel(pRepository, this); mMergedVfsView = new QTreeView(); mMergedVfsView->setHeaderHidden(true); mMergedVfsView->setSelectionMode(QAbstractItemView::SingleSelection); mMergedVfsView->setModel(mMergedVfsModel); lSplitter->addWidget(mMergedVfsView); connect(mMergedVfsView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateVersionModel(QModelIndex,QModelIndex))); mVersionView = new QListView(); mVersionView->setSelectionMode(QAbstractItemView::SingleSelection); mVersionModel = new VersionListModel(this); mVersionView->setModel(mVersionModel); VersionListDelegate *lVersionDelegate = new VersionListDelegate(mVersionView,this); mVersionView->setItemDelegate(lVersionDelegate); lSplitter->addWidget(mVersionView); connect(lVersionDelegate, SIGNAL(openRequested(QModelIndex)), SLOT(open(QModelIndex))); connect(lVersionDelegate, SIGNAL(restoreRequested(QModelIndex)), SLOT(restore(QModelIndex))); mMergedVfsView->setFocus(); //expand all levels from the top until the node has more than one child QModelIndex lIndex; forever { mMergedVfsView->expand(lIndex); if(mMergedVfsModel->rowCount(lIndex) == 1) { lIndex = mMergedVfsModel->index(0, 0, lIndex); } else { break; } } mMergedVfsView->selectionModel()->setCurrentIndex(lIndex.child(0,0), QItemSelectionModel::Select); setCentralWidget(lSplitter); }
void RxDev::openSpecFile(){ const QModelIndex index = ui->treeView_availableNodes->selectionModel()->currentIndex(); QModelIndex seekRoot = index; while(seekRoot.parent() != QModelIndex()) { seekRoot = seekRoot.parent(); } QString filePath = seekRoot.child(0,0).child(0,0).data(Qt::DisplayRole).toString(); //qDebug()<<filePath; SpecFileParser *specParser = new SpecFileParser; specParser->nodeParser(filePath); SpecFileEdit specFile(&specParser->node); //qDebug()<<QString::fromStdString(specParser->node.type); specFile.setWindowTitle("Specfile: "+seekRoot.data(Qt::DisplayRole).toString()); bool accept = specFile.exec(); if ((accept)){ QFile file; file.setFileName(filePath); file.open(QIODevice::WriteOnly | QIODevice::Text); if (file.isWritable()){ QString tempContens = specParser->writeSpecFile(&specParser->node); QTextStream text(&file); text<<tempContens; //qDebug()<<"subs "<<specFile.getSubscriptions(); file.close(); QMessageBox::information( this, "File written!", "The file "+filePath+" was updated\n", QMessageBox::Ok, 0 ); on_pushButton_refreshNodesOrComps_clicked(); } else QMessageBox::critical(this, "File is write protected!", "The file "+filePath+" could not get updated\n", QMessageBox::Ok, 0 ); // setType(nodeEdit.getType()); // setName(nodeEdit.getName()); // setArgs(nodeEdit.getArgs()); } // QDesktopServices::openUrl(QUrl::fromLocalFile( filePath)); }
bool ShortcutsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (filterRegExp().isEmpty()) return true; if (source_parent.isValid()) { QModelIndex index = source_parent.child(source_row, filterKeyColumn()); QString data = sourceModel()->data(index, filterRole()).toString(); return data.contains(filterRegExp()); } else { QModelIndex index = sourceModel()->index(source_row, filterKeyColumn()); for (int row = 0; row < sourceModel()->rowCount(index); row++) { if (filterAcceptsRow(row, index)) return true; } } return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); }
bool ContactListSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { if (filter.isEmpty() && !allowOnlineOnly) return true; Contact* contact = contactListModel->contactFromIndex(source_parent.child(source_row, 0)); if (!contact) return true; if (!allowOnlineOnly || contact->status().connected()) { if (filter.isEmpty()) return true; if (contact->nickname().contains(filter, Qt::CaseInsensitive) || QString::fromLatin1(contact->email()).contains(filter, Qt::CaseInsensitive)) return true; } return false; }
void RxDev::addCompFile(){ const QModelIndex index = ui->listView_availableComponents->selectionModel()->currentIndex(); QModelIndex seekRoot = index; while(seekRoot.parent() != QModelIndex()) { seekRoot = seekRoot.parent(); } QString filePath = seekRoot.child(0,0).data(Qt::DisplayRole).toString(); // qDebug()<<filePath; IncludeFileItem * newFile; newFile = new IncludeFileItem; connect(newFile,SIGNAL(expandItem(QString,GroupItem &)),this,SLOT(expandInclude(const QString &, GroupItem &))); newFile->setPos(findSpace(QPoint(0,55))); newFile->setLocation(findSpace(QPoint(0,55))); newFile->setColor(Qt::yellow); newFile->setFile(filePath); //if (newFile->getFileData()==true){ newFile->updateIncludeFileItem(); scene->addItem(newFile); //} }
void TestCFSM::printDir(const QString dirname, const int depth) { QTextStream console(stdout); QModelIndex index; QModelIndex dir; dir = _model.index(dirname); for(int i = 0; i < _model.rowCount(dir); i++) { index = dir.child(i, dir.column()); console << _model.data(index, Qt::CheckStateRole).toInt() << "\t"; // Add indents to show the directory structure. for(int j = 0; j < depth; j++) console << "\t"; console << _model.fileName(index) << endl; // Recursively print the subdirectory. if(_model.isDir(index)) { printDir(_model.filePath(index), depth + 1); } } }