QVariant PeerTableModel::data(const QModelIndex &index, int role) const { if(!index.isValid()) return QVariant(); CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer()); if (role == Qt::DisplayRole) { switch(index.column()) { case NetNodeId: return (qint64)rec->nodeStats.nodeid; case Address: return QString::fromStdString(rec->nodeStats.addrName); case Subversion: return QString::fromStdString(rec->nodeStats.cleanSubVer); case Ping: return GUIUtil::formatPingTime(rec->nodeStats.dMinPing); case Sent: return GUIUtil::formatBytes(rec->nodeStats.nSendBytes); case Received: return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes); } } else if (role == Qt::TextAlignmentRole) { switch (index.column()) { case Ping: case Sent: case Received: return QVariant(Qt::AlignRight | Qt::AlignVCenter); default: return QVariant(); } } return QVariant(); }
QVariant FavoriteHubModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.column() > columnCount(QModelIndex())) return QVariant(); FavoriteHubItem *item = static_cast<FavoriteHubItem*>(index.internalPointer()); switch(role) { case Qt::DecorationRole: // icon break; case Qt::DisplayRole: if (index.column() == COLUMN_HUB_AUTOCONNECT) break; else if (index.column() != COLUMN_HUB_PASSWORD) return item->data(index.column()); else return QString("******"); break; case Qt::TextAlignmentRole: break; case Qt::ForegroundRole: break; case Qt::ToolTipRole: break; case Qt::CheckStateRole: if (index.column() == COLUMN_HUB_AUTOCONNECT) return item->data(COLUMN_HUB_AUTOCONNECT); break; } return QVariant(); }
int RCommandStackModel::rowCount (const QModelIndex& parent) const { RK_ASSERT (listeners); RK_TRACE (RBACKEND); if (!parent.isValid ()) return 1; RCommandBase* index_data = static_cast<RCommandBase*> (parent.internalPointer ()); RK_ASSERT (index_data); if (index_data->commandPointer ()) { RCommandStack *substack = RCommandStack::stackForCommand (index_data->commandPointer ())->sub_stack; if (substack) { if (substack->parent_command == index_data) { RK_ASSERT (parent.row () == 0); return 1; } } return 0; } if (index_data->chainPointer ()) { return (index_data->chainPointer ()->commands.size ()); } RK_ASSERT (false); return 0; }
QVariant AspectTreeModel::data(const QModelIndex &index, int role) const{ if (!index.isValid()) return QVariant(); AbstractAspect *aspect = static_cast<AbstractAspect*>(index.internalPointer()); switch(role) { case Qt::DisplayRole: case Qt::EditRole: switch(index.column()) { case 0: return aspect->name(); case 1: return aspect->metaObject()->className(); case 2: return aspect->creationTime().toString(); case 3: return aspect->comment().replace('\n', ' ').simplified(); default: return QVariant(); } case Qt::ToolTipRole: if (aspect->comment().isEmpty()) return aspect->name(); else return aspect->name() + ", " + aspect->comment(); case Qt::DecorationRole: return index.column() == 0 ? aspect->icon() : QIcon(); case ContextMenuRole: return QVariant::fromValue(static_cast<QWidget*>(aspect->createContextMenu())); case Qt::ForegroundRole:{ const WorksheetElement* we = qobject_cast<WorksheetElement*>(aspect); if (we){ if (!we->isVisible()) return QVariant( QApplication::palette().color(QPalette::Disabled,QPalette::Text ) ); } return QVariant( QApplication::palette().color(QPalette::Active,QPalette::Text ) ); } default: return QVariant(); } }
QModelIndex QtSessionTreeModel::findIndexForSessionName(QString fullsessname) const { QStringList dirname = fullsessname.split(QUTTY_SESSION_NAME_SPLIT); QModelIndex par; QModelIndex ch; for(auto it = dirname.begin(); it != dirname.end(); it++) { bool isfound = false; for(int r = 0; r < rowCount(par); r++) { ch = index(r, 0, par); if (!ch.isValid()) continue; QtSessionTreeItem *chitem = static_cast<QtSessionTreeItem*>(ch.internalPointer()); if (chitem->getSessionName() == *it) { par = ch; isfound = true; break; } } if (!isfound) { return QModelIndex(); } } return ch; }
QModelIndex GpodderServiceModel::parent( const QModelIndex &index ) const { if( !index.isValid() ) return QModelIndex(); GpodderTreeItem *childItem = static_cast<GpodderTreeItem *>( index.internalPointer() ); if( childItem == 0 || childItem->isRoot() ) return QModelIndex(); GpodderTreeItem *parentItem = childItem->parent(); if( parentItem == 0 ) return QModelIndex(); int childIndex; if( parentItem->isRoot() ) return QModelIndex(); else childIndex = parentItem->parent()->children().indexOf( parentItem ); return createIndex( childIndex, 0, parentItem ); }
QVariant StorageTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); StorageTreeItem *item = static_cast<StorageTreeItem*>(index.internalPointer()); if ( role == Qt::CheckStateRole && item->isCheckable() ) return item->checkState(); if (role == Qt::DisplayRole) return item->data(index.column(), role); if (role == Qt::FontRole) return item->font(); if (role == Qt::EditRole) return item->data(index.column(),role); if (role == Qt::DecorationRole) return item->icon(); return QVariant(); }
QVariant ExtraTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); QXmlTreeNode *item = static_cast<QXmlTreeNode*>(index.internalPointer()); switch(role) { case Qt::ToolTipRole: return item->property("__ToolTip"); case Qt::StatusTipRole: return item->property("__StatusTip"); case Qt::DisplayRole: case Qt::EditRole: { QGameEntityNode* node = qobject_cast<QGameEntityNode*>(item); if( node ) { switch( index.column() ) { case 0: return node->name(); case 1: return item->xmlNode().tagName(); case 2: return node->ID(); } } else return item->xmlNode().tagName(); } case Qt::CheckStateRole: if( index.column() == 0 && item->property("Enabled").isValid() ) return item->property("Enabled").toBool() ? Qt::Checked : Qt::Unchecked; default: return QVariant(); }; }
QModelIndex TableListModel::index(int row,int column,const QModelIndex &parent) const { TreeViewItem *parentItem; if(!parent.isValid()) { parentItem = rootItem; } else { parentItem = static_cast<TreeViewItem *>(parent.internalPointer()); } TreeViewItem *childItem = parentItem->child(row); if(childItem) { return createIndex(row,column,childItem); } else { return QModelIndex(); } }
int ContactModel::rowCount(const QModelIndex &parent) const { // qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<parent; int cnt = 0; int row; int gid; ContactInfoNode *pnode = NULL; ContactInfoNode *cnode = NULL; if (!parent.isValid()) { cnt = this->mContacts.count(); // qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<parent<<cnt; if (cnt == 0 && this->m_dretr->lazy_flag == 0) { this->m_dretr->lazy_flag = 1; this->m_dretr->getGroupList(); } } else { row = parent.row(); pnode = static_cast<ContactInfoNode*>(parent.internalPointer()); if (pnode->ntype == 0) { // pnode = this->mContacts.at(row); cnt = pnode->childs.count(); // qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<parent<<cnt; ////////// if (cnt == 0 && pnode->lazy_flag == 0) { pnode->lazy_flag = 1; this->m_dretr->getContactsByGroupId(pnode->gid); } } else { cnt = 0; } } // qDebug()<<__FILE__<<__LINE__<<__FUNCTION__<<parent<<cnt; return cnt; }
void TodoNote::taskChanged(const QModelIndex& proxy_index) { extra_widget->setVisible(proxy_index.isValid()); if(!proxy_index.isValid()) return; mapper->setRootIndex(proxy_index.parent()); mapper->setCurrentModelIndex(proxy_index); QModelIndex index = proxy_model->mapToSource(proxy_index); Task* task = static_cast<Task*>(index.internalPointer()); // disconnect(dt_date_limit, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(noteDateLimitChanged(QDateTime))); disconnect(cb_date_limit, SIGNAL(toggled(bool)), this, SLOT(noteLimitChanged(bool))); dt_date_limit->setDateTime(task->dateLimit()); cb_date_limit->setChecked(task->limited()); connect(dt_date_limit, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(noteDateLimitChanged(QDateTime))); connect(cb_date_limit, SIGNAL(toggled(bool)), this, SLOT(noteLimitChanged(bool))); // bool task_done = task->done(); lb_date_1->setVisible(task_done); lb_date_stop->setVisible(task_done); cb_date_limit->setHidden(task_done); dt_date_limit->setHidden(task_done); dt_date_limit->setEnabled(task->limited()); }
QVariant ProcModel::data( const QModelIndex &index, int role /*= Qt::DisplayRole*/ ) const { // 判断下标是否合法 if (!index.isValid()) return QVariant(); if (role != Qt::DisplayRole) return QVariant(); ProcessInfoEntry *_item = static_cast<ProcessInfoEntry *>(index.internalPointer()); switch (index.column()) { case PROC_NAME: return _item->proc_name_; case PROC_ID: return _item->proc_id_; case THREAD_COUNT: return _item->thread_count_; case PRIORITY_BASE: return proc_base_pri(_item->priority_base_); case PARENT_PROC_ID: return _item->parent_proc_id_; case PROC_PATH: return _item->proc_path_; case USAGE_COUNT: return _item->usage_count_; case BLOCK_SIZE: return _item->block_size_; default: break; } return QVariant(); }
QVariant DbStructureModel::data(const QModelIndex& index, int role) const { if(!index.isValid()) return QVariant(); // Get the item the index points at QTreeWidgetItem* item = static_cast<QTreeWidgetItem*>(index.internalPointer()); // Depending on the role either return the text or the icon switch(role) { case Qt::DisplayRole: // For the display role and the browsable branch of the tree we want to show the column name including the schema name if necessary (i.e. // for schemata != "main"). For the normal structure branch of the tree we don't want to add the schema name because it's already obvious from // the position of the item in the tree. if(index.column() == ColumnName && item->parent() == browsablesRootItem) return sqlb::ObjectIdentifier(item->text(ColumnSchema), item->text(ColumnName)).toDisplayString(); else return Settings::getValue("db", "hideschemalinebreaks").toBool() ? item->text(index.column()).replace("\n", " ").simplified() : item->text(index.column()); case Qt::EditRole: return item->text(index.column()); case Qt::ToolTipRole: { // Show the original text but limited, when it's supposed to be shown in a tooltip QString text = item->text(index.column()); if (text.length() > 512) { text.truncate(509); text.append("..."); } return text; } case Qt::DecorationRole: return item->icon(index.column()); default: return QVariant(); } }
QModelIndex ViewTreeModel::index(int row, int column, const QModelIndex& parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } ViewTreeItem* parentItem = nullptr; if (!parent.isValid()) { parentItem = d->rootItem.data(); } else { parentItem = static_cast<ViewTreeItem*>(parent.internalPointer()); } ViewTreeItem* childItem = parentItem->childItem(row); if (childItem) { return createIndex(row, column, childItem); } return QModelIndex(); }
QModelIndex Lua::LuaGraphTreeModel::index( int row, int column, const QModelIndex& parent ) const { if ( !hasIndex( row, column, parent ) ) { return QModelIndex(); } LuaGraphTreeItem* parentItem; if ( !parent.isValid() ) { parentItem = rootItem; } else { parentItem = static_cast<LuaGraphTreeItem*>( parent.internalPointer() ); } LuaGraphTreeItem* childItem = parentItem->child( row ); if ( childItem ) { return createIndex( row, column, childItem ); } else { return QModelIndex(); } }
QVariant TorrentContentModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer()); if ((index.column() == 0) && (role == Qt::DecorationRole)) { if (item->itemType() == TorrentContentModelItem::FolderType) return getDirectoryIcon(); else return getFileIcon(); } if ((index.column() == 0) && (role == Qt::CheckStateRole)) { if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED) return Qt::Unchecked; if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::MIXED) return Qt::PartiallyChecked; return Qt::Checked; } if (role != Qt::DisplayRole) return QVariant(); return item->data(index.column()); }
QModelIndex TreeModel::index(int row, int column, const QModelIndex &p) const { const int c = columnCount(p); if(row < 0 || column < 0 || column >= c) return QModelIndex(); TreeItem *parentItem; if(p.isValid()) parentItem = static_cast<TreeItem *>(p.internalPointer()); else parentItem = m_root; if(!parentItem) return QModelIndex(); TreeItem *childItem = parentItem->child(row); if(childItem) return createIndex(row, column, childItem); else return QModelIndex(); }
QModelIndex Project_ItemModel::index(int row, int column, const QModelIndex &parent) const { /* if(!parent.isValid()) { return createIndex(0,0,rootItem_); } */ if (!hasIndex(row, column, parent)) return QModelIndex(); GsTL_item *parentItem; if (!parent.isValid()) parentItem = rootItem_; else parentItem = static_cast<GsTL_item*>(parent.internalPointer()); GsTL_item *childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem); else return QModelIndex(); }
//----------------------------------------------------------------------------- // Function: PortMapsTreeModel::parent() //----------------------------------------------------------------------------- QModelIndex PortMapsTreeModel::parent(QModelIndex const& child) const { if (!child.isValid() || child.column() > COLUMN_COUNT) { return QModelIndex(); } PortMapsTreeItem* childItem = static_cast<PortMapsTreeItem*>(child.internalPointer()); PortMapsTreeItem* parent = childItem->getParent(); if (parent == 0 || parent == root_) { return QModelIndex(); } int index = parent->getIndex(); if (index < 0) { return QModelIndex(); } return createIndex(index, 0, parent); }
QVariant ShVarModel::data(const QModelIndex &i_qIndex, int i_nRole) const { if (!i_qIndex.isValid()) { return QVariant(); } ShVarItem *item = static_cast<ShVarItem*>(i_qIndex.internalPointer()); switch (i_nRole) { case Qt::DisplayRole: return item->data(i_qIndex.column()); case Qt::TextColorRole: if (item->data(DF_CHANGED).toBool() == true) { return Qt::red; } else { return QVariant(); } case Qt::FontRole: // all inactive uniforms should never be made bold if (item->isUniform() && !item->isActiveUniform()) { return QVariant(); } if (item->isInScope()) { QFont f; f.setWeight(QFont::DemiBold); return f; } else { return QVariant(); } default: return QVariant(); } //return item->data(i_qIndex.column()); return QVariant(); }
bool DirModel::hasChildren(const QModelIndex &parent) const { // qDebug() << "DirModel::hasChildren parent:" << parent; // If we are invalid we are at the root level and always have some children. if(!parent.isValid()) { return true; } else { // Lookup the actual item. If it is a folder, set this to true. Otherwise false. ParentHelper* idx = static_cast<ParentHelper*>(parent.internalPointer()); if(!idx) { return false; } else { KDirectory* dir = d->m_lister->directory(idx->row); if(!dir) { return false; } if(parent.row() < dir->count()) { return dir->entries().at(parent.row()).isDir(); } } return false; } }
QVariant FileItemModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { return QVariant(); } if (role != Qt::DisplayRole) { return QVariant(); } StaticFile* file = static_cast<StaticFile*>(index.internalPointer()); switch (index.column()) { case 0: return QVariant(file->toString().get()); break; case 1: File realFile = file->getFile(); if (realFile.isDirectory()) { return tr("Directory"); } else { EntityOpenRequest req; req.setAttribute("type", "file"); req.setAttribute("file", QString(realFile.getPath().toString().get())); EntityHandler* handler = EntityManager::getInstance()->getEntityHandler(req); if (handler) { return handler->getFileFormatName(realFile); } else { return tr("Unrecognized File"); } } } return QVariant(); }
void AutoDJFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index) { //Save the model index so we can get it in the action slots... m_lastRightClickedIndex = index; TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); QString crateName = item->getLabel(); if (crateName.length() > 0) { // A crate was right-clicked. // Bring up the context menu. QMenu menu(NULL); menu.addAction(m_pRemoveCrateFromAutoDj); menu.exec(globalPos); } else { // The "Crates" tree-item was right-clicked. // Bring up the context menu. QMenu menu(NULL); QMenu crateMenu(NULL); crateMenu.setTitle(tr("Add Crate as Track Source")); QMap<QString,int> crateMap; m_crateDao.getAutoDjCrates(false, &crateMap); QMapIterator<QString,int> it(crateMap); while (it.hasNext()) { it.next(); // No leak because making the menu the parent means they will be // auto-deleted QAction* pAction = new QAction(it.key(), &crateMenu); crateMenu.addAction(pAction); m_crateMapper.setMapping(pAction, it.value()); connect(pAction, SIGNAL(triggered()), &m_crateMapper, SLOT(map())); } menu.addMenu(&crateMenu); menu.exec(globalPos); } }
QModelIndex FileItemModel::index(int row, int column, const QModelIndex& parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } if (parent.isValid()) { StaticFile* parentFile = static_cast<StaticFile*>(parent.internalPointer()); return createIndex(row, column, parentFile->getChild(row)); } else { StaticFile* rootFile = rootFiles[row]; return createIndex(row, column, rootFile); } /*StaticFile* parentFile; if (parent.isValid()) { parentFile = static_cast<StaticFile*>(parent.internalPointer()); } else { parentFile = rootFile; } return createIndex(row, column, parentFile->getChild(row));*/ }
QModelIndex SessionItemModel::parent(const QModelIndex& index) const { if (index.isValid() == true) { SessionItemWrapper* pWrapper = reinterpret_cast<SessionItemWrapper*>(index.internalPointer()); if (pWrapper != NULL) { // Get the parent data SessionItemWrapper* pParent = pWrapper->getParent(); if ((pParent != NULL) && (pParent != mpRootWrapper)) { // Get the parent row by iterating over the grandparent SessionItemWrapper* pGrandparent = pParent->getParent(); if (pGrandparent != NULL) { int row = -1; const vector<SessionItemWrapper*>& children = pGrandparent->getChildren(); for (vector<SessionItemWrapper*>::size_type i = 0; i < children.size(); ++i) { SessionItemWrapper* pCurrentWrapper = children[i]; if (pCurrentWrapper == pParent) { row = i; break; } } return createIndex(row, 0, pParent); } } } } return QModelIndex(); }
void CWorkspacePage::createPS() { QString fileName = QFileDialog::getSaveFileName(this, tr("Create new particle system file"), ".", tr("ps files (*.ps)")); if (!fileName.isEmpty()) { // TODO: create method particle editor createNewPS if (Modules::psEdit().getParticleWorkspace()->containsFile(NLMISC::CFile::getFilename(fileName.toUtf8().constData()))) { QMessageBox::critical(this, tr("NeL particle system editor"), tr("Failed to create new particle system"), QMessageBox::Ok); return; } CWorkspaceNode *node = Modules::psEdit().getParticleWorkspace()->addNode(NLMISC::CFile::getFilename(fileName.toUtf8().constData())); // should always succeed because we tested if file already exists nlassert(node); node->createEmptyPS(); try { node->savePS(); node->setModified(false); } catch (NLMISC::Exception &e) { QMessageBox::critical(this, tr("NeL particle system editor"), QString(e.what()), QMessageBox::Ok); return; } QModelIndex index = _treeModel->index(0, 0); _treeModel->insertRows(node, static_cast<CParticleTreeItem *>(index.internalPointer())->childCount(), index); } }
void ShortcutController::updateKey(const QModelIndex& index, const QKeySequence& keySequence) { if (!index.isValid()) { return; } const QModelIndex& parent = index.parent(); if (!parent.isValid()) { return; } ShortcutItem* item = itemAt(index); if (item->functions().first) { QKeySequence oldShortcut = item->shortcut(); if (!oldShortcut.isEmpty()) { m_heldKeys.take(oldShortcut); } if (!keySequence.isEmpty()) { m_heldKeys[keySequence] = item; } } item->setShortcut(keySequence); if (m_config) { m_config->setQtOption(item->name(), keySequence.toString(), KEY_SECTION); } emit dataChanged(createIndex(index.row(), 0, index.internalPointer()), createIndex(index.row(), 2, index.internalPointer())); }
void Region_weight_proxy_model_no_selection::begin_remove_proxy_rows(const QModelIndex & source_parent, int start, int end){ GsTL_object_item *item = static_cast<GsTL_object_item*>(source_parent.internalPointer()); // Check to see if the source parent is the property manager or the region manager if(item->parent() != grid_) return; if(item->item_name() == "Properties" ) { //The start end may not be continuous, so far we only delete them one at a time, potentially dangerous QModelIndex child_index = source_parent.child(start,0); GsTL_object_item *child_item = static_cast<GsTL_object_item*>(child_index.internalPointer()); int i = weight_names_.indexOf(child_item->item_name()); this->beginRemoveRows(QModelIndex(),region_names_.size()+i,region_names_.size() + i + start - end); for(int j=i ; j<= i + start - end ; ++j ) { weight_names_.removeAt(j); } } else if(item->item_name() == "Regions" ) { this->beginRemoveRows(QModelIndex(),start,end); for(int j=start ; j<= end ; ++j ) { region_names_.removeAt(j+1); } } }
// --- void VSWSCReleasesDataListTree::mouseReleaseEvent (QMouseEvent* evnt) { QModelIndexList selected = selectedIndexes (); QModelIndexList::iterator i = selected.begin (); // The action is only allowed with just one item...first? if (i == selected.end ()) { QTreeView::mouseReleaseEvent (evnt); // None has been selected, then it is sent to the parent... return; } // When a button is released, // then depending on the button one or other thing is done... QModelIndex index = *i; VSWSCReleasesDataListModel::Item* item = static_cast <VSWSCReleasesDataListModel::Item*> (index.internalPointer ()); evnt -> accept(); // But in any case, the event is consideres as just treated... if (item -> type () == 2) // Button works just only for releases... { switch (evnt -> button ()) { // Left button implies to select a release // and to access to the detailt data of it... case Qt::LeftButton: QTreeView::mouseReleaseEvent (evnt); // Default treatement just in case... emit (releaseSelectedSignal (item -> parent () -> value (), item -> value ())); // ...the data in the right siode has to change... break; // Any other behaviour... default: QTreeView::mouseReleaseEvent (evnt); // Default treatement just in case... break; // Nothing to do...Option not possible, just to perfect code!. } } }
bool AbstractAlbumModel::hasChildren(const QModelIndex& parent) const { if (parent.isValid()) { Album* const a = static_cast<Album*>(parent.internalPointer()); return a->firstChild(); } else { if (!d->rootAlbum) { return false; } if (d->rootBehavior == IncludeRootAlbum) { return 1; } else { return d->rootAlbum->firstChild(); } } }