void QQInfoDlg::AddQQTroops(AccountInfo& accountInfo) { QStandardItem* group = new QStandardItem(Utils::stoq("群列表")); m_model->appendRow(group); int i = 0; for ( std::list<TroopInfo>::iterator it = accountInfo.troops.begin(); it != accountInfo.troops.end(); ++it, ++i ) { QStandardItem* item; item = new QStandardItem(Utils::utoq(it->troopName + "(" + it->troopUin + ")")); if ( !it->troopMemo.empty() ) item->setData(Utils::utoq(it->troopMemo), Qt::ToolTipRole); if ( accountInfo.chatMap.find(it->troopUin) != accountInfo.chatMap.end() ) item->setData(QBrush(QColor(255, 100, 100)), Qt::ForegroundRole); item->setData(Utils::utoq(it->troopUin), Qt::UserRole); group->setChild(i, item); } }
void QQInfoDlg::AddQQFriends(AccountInfo& accountInfo) { int i = 0; for ( std::map<std::string, FriendInfo>::iterator it = accountInfo.friends.begin(); it != accountInfo.friends.end(); ++it, ++i ) { QStandardItem* item; if ( (*it).second.remark.empty() ) item = new QStandardItem(Utils::utoq((*it).second.nickName + "(" + (*it).second.account + ")")); else item = new QStandardItem(Utils::utoq((*it).second.remark + "(" + (*it).second.account + ")")); if ( !(*it).second.signature.empty() ) item->setData(Utils::utoq((*it).second.signature), Qt::ToolTipRole); if ( accountInfo.chatMap.find((*it).second.account) != accountInfo.chatMap.end() ) item->setData(QBrush(QColor(255, 100, 100)), Qt::ForegroundRole); qDebug() << QString::fromUtf8((*it).second.groupName.c_str()); item->setData(Utils::utoq((*it).second.account), Qt::UserRole); QStandardItem* group = FindParent((*it).second.groupName); group->setChild(group->rowCount(), item); } }
void tst_QStandardItem::parent() { { QStandardItem item; QStandardItem *child = new QStandardItem; QCOMPARE(child->parent(), static_cast<QStandardItem*>(0)); item.setChild(0, 0, child); QCOMPARE(child->parent(), &item); QStandardItem *childOfChild = new QStandardItem; child->setChild(0, 0, childOfChild); QCOMPARE(childOfChild->parent(), child); } { QStandardItemModel model; QStandardItem *item = new QStandardItem; model.appendRow(item); // parent of a top-level item should be 0 QCOMPARE(item->parent(), static_cast<QStandardItem*>(0)); } }
void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo ) { setLayerSet( layerIds ); QStandardItem* currentItem = 0; QStandardItem* currentGroupItem = 0; int i = 0; QList< GroupLayerInfo >::const_iterator infoIt = groupInfo.constBegin(); for ( ; infoIt != groupInfo.constEnd() && i < invisibleRootItem()->rowCount(); ) { currentItem = invisibleRootItem()->child( i, 0 ); QString infoKey = infoIt->first; if ( infoKey.isNull() ) //a toplevel layer { ++i; } else //a group { currentGroupItem = addGroup( infoKey, i ); ++i; QList<QString> layerList = infoIt->second; QList<QString>::const_iterator groupLayerIt = layerList.constBegin(); for ( ; currentItem && ( groupLayerIt != layerList.constEnd() ); ++groupLayerIt ) { //check if current item is contained in this group QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( currentItem ); if ( !layerItem ) { return; //should never happen } //QString layerID = currentItem->data(Qt::UserRole + 2).toString(); QString layerID = layerItem->layerID(); if ( layerList.contains( layerID ) ) { takeRow( i ); currentGroupItem->setChild( currentGroupItem->rowCount(), 0, currentItem ); } else { ++i; } currentItem = invisibleRootItem()->child( i, 0 ); } } ++infoIt; } }
static void initStandardTreeModel(QStandardItemModel *model) { QStandardItem *item; item = new QStandardItem(QLatin1String("Row 1 Item")); model->insertRow(0, item); item = new QStandardItem(QLatin1String("Row 2 Item")); item->setCheckable(true); model->insertRow(1, item); QStandardItem *childItem = new QStandardItem(QLatin1String("Row 2 Child Item")); item->setChild(0, childItem); item = new QStandardItem(QLatin1String("Row 3 Item")); item->setIcon(QIcon()); model->insertRow(2, item); }
void QQInfoDlg::AddQQDiscusses(AccountInfo& accountInfo) { QStandardItem* group = new QStandardItem(Utils::stoq("讨论组列表")); m_model->appendRow(group); int i = 0; for ( std::list<DiscInfo>::iterator it = accountInfo.discusses.begin(); it != accountInfo.discusses.end(); ++it, ++i ) { QStandardItem* item; item = new QStandardItem(Utils::utoq(it->discussName + "(" + it->discussUin + ")")); item->setData(Utils::utoq(it->discussUin), Qt::UserRole); group->setChild(i, item); } }
void EditTOC::MoveLeft() { QModelIndex index = CheckSelection(0); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); QStandardItem *parent_item = item->parent(); // Can't indent above top level if (!parent_item) { return; } QStandardItem *grandparent_item = parent_item->parent(); if (!grandparent_item) { grandparent_item = m_TableOfContents->invisibleRootItem(); } // Make siblings following the entry into children int row = item->row() ; while (row + 1 < parent_item->rowCount()) { QList<QStandardItem *> row_items = parent_item->takeRow(row + 1); int row_count = item->rowCount(); item->setChild(row_count, 0, row_items[0]); item->setChild(row_count, 1, row_items[1]); } // Make item child of grandparent int parent_row = parent_item->row(); QList<QStandardItem *> row_items = parent_item->takeRow(row); grandparent_item->insertRow(parent_row + 1, row_items); // Reselect the item QModelIndex item_index = grandparent_item->child(parent_row + 1)->index(); ui.TOCTree->selectionModel()->clear(); ui.TOCTree->setCurrentIndex(item_index); ui.TOCTree->selectionModel()->select(item_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); ExpandChildren(grandparent_item->child(parent_row + 1)); }
otpFeature::otpFeature(QWidget *parent) { setupUi(this); otpFeature_icon.insert(QString("treeitem_project"),QIcon(":/images/treeitem_project.png")); otpFeature_icon.insert(QString("treeitem_folder"),QIcon(":/images/treeitem_folder.png")); QStringList title; title << QString("View Features") << QString("Information"); QStandardItemModel *otpFeatureModel = new QStandardItemModel; otpFeatureTreeView->setModel(otpFeatureModel); otpFeatureModel->setHorizontalHeaderLabels(title); otpFeatureTreeView->setHeaderHidden(false); QStandardItem *otpFeatureProject = new QStandardItem(otpFeature_icon.value("treeitem_project"),QString("OTP Server Component")); otpFeatureModel->appendRow(otpFeatureProject); otpFeatureModel->setItem(otpFeatureProject->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); QStandardItem *otpFeatureServer = new QStandardItem(otpFeature_icon.value("treeitem_project"),QString("OTP Support")); otpFeatureProject->appendRow(otpFeatureServer); otpFeatureProject->setChild(otpFeatureServer->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); QStandardItem *otpFeatureGridview = new QStandardItem(otpFeature_icon.value("treeitem_project"),QString("Gridview platform support")); otpFeatureProject->appendRow(otpFeatureGridview); otpFeatureProject->setChild(otpFeatureGridview->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); QStandardItem *otpFeature32bit = new QStandardItem(otpFeature_icon.value("treeitem_project"),QString("32-bit system enviroment")); otpFeatureProject->appendRow(otpFeature32bit); otpFeatureProject->setChild(otpFeature32bit->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); QStandardItem *otpFeatureRadius = new QStandardItem(otpFeature_icon.value("treeitem_folder"),QString("Radius support")); otpFeatureServer->appendRow(otpFeatureRadius); otpFeatureServer->setChild(otpFeatureRadius->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); QStandardItem *otpFeatureAdminTools = new QStandardItem(otpFeature_icon.value("treeitem_folder"),QString("Administration tools support")); otpFeatureServer->appendRow(otpFeatureAdminTools); otpFeatureServer->setChild(otpFeatureAdminTools->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); QStandardItem *otpFeatureHotStandby = new QStandardItem(otpFeature_icon.value("treeitem_folder"),QString("Hot-standby feature support")); otpFeatureServer->appendRow(otpFeatureHotStandby); otpFeatureServer->setChild(otpFeatureHotStandby->index().row(),1,new QStandardItem(QString("aaaaaaaaa"))); for(int i=0;i<otpFeatureModel->rowCount;i++){ otpFeatureTreeView->indexAt(QPoint(i,0)); } }
void OntologyClassView::onAddSiblingClass(){ if(!OBJECTLEVELMANAGER->count()) return; QModelIndex index = selectionModel()->currentIndex(); if(!index.isValid()) return; QStandardItemModel *omodel = qobject_cast<QStandardItemModel*>(model()); if(!omodel) return; ClassDescriptionDialog *pClassDescriptionDialog = new ClassDescriptionDialog(this); pClassDescriptionDialog->setParentClassId(omodel->data(index.parent()).toString()); if(pClassDescriptionDialog->exec() == QDialog::Rejected) return; QString classId = pClassDescriptionDialog->classId(); // if(omodel->insertRows(omodel->rowCount(index.parent()),1,index.parent())){ QStandardItem *pItem = new QStandardItem(); pItem->setData(classId,Qt::DisplayRole); pItem->setData(classId); QList<QStandardItem*> parentItemList = omodel->findItems(pClassDescriptionDialog->parentClassId(),Qt::MatchExactly | Qt::MatchRecursive); if(!parentItemList.isEmpty()) { QStandardItem *pParentItem = parentItemList.first(); pParentItem->setChild(pParentItem->rowCount(),pItem); }else omodel->setItem(omodel->rowCount(index.parent()),pItem); setCurrentIndex(omodel->index(omodel->rowCount(index.parent()),0,index.parent())); // } }
void Menu_Editor::entityBrowser_add(QString name, std::vector<int>* owners) { // Create / reuse row QStandardItem* item = model_entityBrowser->item(num_rows); // TRUE: Item doesn't exist, create new Item if(item == 0) { item = new QStandardItem(); model_entityBrowser->setItem(num_rows, item); } num_rows++; // Fill row with data int num_entities = 0; for(unsigned i=0; i<owners->size(); i++) { if(owners->at(i)!=0) { // Create data item QStandardItem* data = new QStandardItem(); item->setChild(num_entities, 0, data); model_entityBrowser->setData(data->index(), QVariant(owners->at(i))); // Increment index num_entities++; } } // Remove unused rows int excessRows = item->rowCount() - num_entities; if(excessRows>0) item->removeRows(num_entities, excessRows); // Set name item->setText("[" + QString::number(num_entities) + "] " + name); }
void Previlege::createModelPrevilege(){ QMap<int,QString> map = getBarInfo(); QMapIterator<int,QString> iterator(map); unsigned char column = 1; while(iterator.hasNext()){ iterator.next(); QStandardItem *item = new QStandardItem(tr("%1").arg(iterator.value())); if(iterator.value().compare(tr("来访登记管理")) == 0){ QMap<int,QString> btnMap = getBtnInfoByMenuId(iterator.key()); QMapIterator<int,QString> btnMapIterator(btnMap); column = 1; while(btnMapIterator.hasNext()){ btnMapIterator.next(); if(btnMapIterator.value().compare(tr("查看")) == 0) column = 1; else if(btnMapIterator.value().compare(tr("添加")) == 0) column = 2; else if(btnMapIterator.value().compare(tr("修改")) == 0) column = 3; else if(btnMapIterator.value().compare(tr("删除")) == 0) column = 4; else if(btnMapIterator.value().compare(tr("导出")) == 0) column = 5; else column = 6; QStandardItem *btn = new QStandardItem; btn->setCheckable(true); item->setChild(0,column,btn); ++column; } modelPrevilege->appendRow(item); } // else if(iterator.value().compare(tr("报表管理")) == 0){ // modelPrevilege->appendRow(item); // continue; // } else{ QMap<int,QString> menuMap = getMenuInfoByBarId(iterator.key()); QMapIterator<int,QString> menuIterator(menuMap); while(menuIterator.hasNext()){ menuIterator.next(); QStandardItem *menu = new QStandardItem(tr("%1").arg(menuIterator.value())); QMap<int,QString> btnMap = getBtnInfoByMenuId(menuIterator.key()); QMapIterator<int,QString> btnMapIterator(btnMap); column = 1; while(btnMapIterator.hasNext()){ btnMapIterator.next(); if(btnMapIterator.value().compare(tr("查看")) == 0) column = 1; else if(btnMapIterator.value().compare(tr("添加")) == 0) column = 2; else if(btnMapIterator.value().compare(tr("修改")) == 0) column = 3; else if(btnMapIterator.value().compare(tr("删除")) == 0) column = 4; else if(btnMapIterator.value().compare(tr("导出")) == 0) column = 5; else column = 6; QStandardItem *btn = new QStandardItem; btn->setCheckable(true); menu->setChild(0,column,btn); ++column; } item->appendRow(menu); } modelPrevilege->appendRow(item); } } qDebug()<<modelPrevilege->rowCount(); }
void Previlege::on_tableView_clicked(const QModelIndex &index) { modelPrevilege->removeRows(0,modelPrevilege->rowCount()); int roleId = modelRole->data(modelRole->index(index.row(),0)).toInt(); QList<int> menuIdList = getMenuIdListByRoleId(roleId); QMap<int,QString> map = getBarInfo(); QMapIterator<int,QString> iterator(map); unsigned char column = 1; while(iterator.hasNext()){ iterator.next(); QStandardItem *item = new QStandardItem(tr("%1").arg(iterator.value())); if(iterator.value().compare(tr("来访登记管理")) == 0){ QMap<int,QString> btnMap = getBtnInfoByMenuId(iterator.key()); QMapIterator<int,QString> btnMapIterator(btnMap); column = 1; while(btnMapIterator.hasNext()){ btnMapIterator.next(); if(btnMapIterator.value().compare(tr("查看")) == 0) column = 1; else if(btnMapIterator.value().compare(tr("添加")) == 0) column = 2; else if(btnMapIterator.value().compare(tr("修改")) == 0) column = 3; else if(btnMapIterator.value().compare(tr("删除")) == 0) column = 4; else if(btnMapIterator.value().compare(tr("导出")) == 0) column = 5; else column = 6; QStandardItem *btn = new QStandardItem; btn->setCheckable(true); if(menuIdList.contains(btnMapIterator.key())) btn->setCheckState(Qt::Checked); item->setChild(0,column,btn); ++column; } modelPrevilege->appendRow(item); } // else if(iterator.value().compare(tr("报表管理")) == 0){ // modelPrevilege->appendRow(item); // continue; // } else{ QMap<int,QString> menuMap = getMenuInfoByBarId(iterator.key()); QMapIterator<int,QString> menuIterator(menuMap); while(menuIterator.hasNext()){ menuIterator.next(); QStandardItem *menu = new QStandardItem(tr("%1").arg(menuIterator.value())); QMap<int,QString> btnMap = getBtnInfoByMenuId(menuIterator.key()); QMapIterator<int,QString> btnMapIterator(btnMap); column = 1; while(btnMapIterator.hasNext()){ btnMapIterator.next(); if(btnMapIterator.value().compare(tr("查看")) == 0) column = 1; else if(btnMapIterator.value().compare(tr("添加")) == 0) column = 2; else if(btnMapIterator.value().compare(tr("修改")) == 0) column = 3; else if(btnMapIterator.value().compare(tr("删除")) == 0) column = 4; else if(btnMapIterator.value().compare(tr("导出")) == 0) column = 5; else column = 6; QStandardItem *btn = new QStandardItem; btn->setCheckable(true); if(menuIdList.contains(btnMapIterator.key())) btn->setCheckState(Qt::Checked); menu->setChild(0,column,btn); ++column; } item->appendRow(menu); } modelPrevilege->appendRow(item); } } qDebug()<<modelPrevilege->rowCount(); ui->treeView->expandAll(); }
void CCustomer::fillFacesModel(const QModelIndex &index, QSqlQuery &stored) { modelFaces->insertRows(stored.numRowsAffected(), 0); #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(QCursor(QPixmap("data/picture/additionally/wait.png"))); #endif QString it; int ncols = stored.record().count(); int row(modelFaces->rowCount(index)); if (stored.record().field(stored.record().indexOf("grp_parent")).isValid()){ while(stored.next()){ if (stored.value(stored.record().indexOf("grp_parent")).toInt() == modelFaces->sibling(index.row(), 1, index).data().toInt()){ for (int i = 0; i != ncols; ++i){ it = stored.value(i).toString(); QStandardItem *item = new QStandardItem(it); if (i == stored.record().indexOf("grp_name")) item->setIcon(QIcon("data/picture/additionally/catalog.png")); if (i == stored.record().indexOf("grp_name")){ modelFaces->itemFromIndex(index)->setChild(row, 0, item); } else if (i == stored.record().indexOf("grp_code")){ modelFaces->itemFromIndex(index)->setChild(row, 1, item); } else if (i == stored.record().indexOf("grp_parent")){ modelFaces->itemFromIndex(index)->setChild(row, 2, item); } else if (i == stored.record().indexOf("grp_actual")){ modelFaces->itemFromIndex(index)->setChild(row, 3, item); } if (item) item->setChild(item->rowCount(), 0, new QStandardItem("Загрузка...")); } ++row; } } } else { while(stored.next()) { for (int i = 0; i != ncols; ++i){ it = stored.value(i).toString(); QStandardItem *item = new QStandardItem(it); if (i == stored.record().indexOf("par_name_first")) item->setIcon(QIcon("data/picture/additionally/customer.png")); if (i == stored.record().indexOf("par_name_first")){ modelFaces->itemFromIndex(index)->setChild(row, 0, item); } else if (i == stored.record().indexOf("par_code")){ modelFaces->itemFromIndex(index)->setChild(row, 1, item); } else if (i == stored.record().indexOf("par_actual")){ modelFaces->itemFromIndex(index)->setChild(row, 2, item); } } row++; } } #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif }
void OntologyClassView::onAddChildClass(){ if(!OBJECTLEVELMANAGER->count()) { return; } QStandardItemModel *omodel = qobject_cast<QStandardItemModel*>(model()); if(!omodel) return; ClassDescriptionDialog *pClassDescriptionDialog = new ClassDescriptionDialog(this); QModelIndex index = selectionModel()->currentIndex(); if(index.isValid()){ pClassDescriptionDialog->setParentClassId(omodel->data(index).toString()); } if(pClassDescriptionDialog->exec() == QDialog::Rejected) return; QString classId = pClassDescriptionDialog->classId(); if(index.isValid()){ QStandardItem *pItem = new QStandardItem(); pItem->setData(classId,Qt::DisplayRole); pItem->setData(classId); OntologyClass *pClass = ONTOLOGYCLASSIFICATIONMANAGER->ontologyClassById(classId); if(pClass){ QColor color = pClass->color(); pItem->setData(color,Qt::DecorationRole); } QList<QStandardItem*> parentItemList = omodel->findItems(pClassDescriptionDialog->parentClassId(),Qt::MatchExactly | Qt::MatchRecursive); if(!parentItemList.isEmpty()) { QStandardItem *pParentItem = parentItemList.first(); pParentItem->setChild(pParentItem->rowCount(),pItem); }else omodel->setItem(omodel->rowCount(index),pItem); expand(index); }else{ int childMax = omodel->rowCount(); QStandardItem *pItem = new QStandardItem(); pItem->setData(classId,Qt::DisplayRole); pItem->setData(classId); OntologyClass *pClass = ONTOLOGYCLASSIFICATIONMANAGER->ontologyClassById(classId); if(pClass){ QColor color = pClass->color(); pItem->setData(color,Qt::DecorationRole); } omodel->setItem(omodel->rowCount(),pItem); expand(index); setCurrentIndex(omodel->index(childMax,0)); } }