本文整理汇总了C++中QStandardItemModel::findItems方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel::findItems方法的具体用法?C++ QStandardItemModel::findItems怎么用?C++ QStandardItemModel::findItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel::findItems方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dropEvent
void BookmarkList::dropEvent(QDropEvent *event)
{
const QMimeData* data = event->mimeData();
if(data->hasUrls())
{
//TODO: Add insert to the dropped row, except row 0
QStandardItemModel* mod = (QStandardItemModel*)model();
QString path = data->urls()[0].path();
QFileInfo f(path);
if(mod)
{
QList<QStandardItem*> items = mod->findItems(f.fileName());
if(f.isDir() && items.isEmpty())
{
QStandardItem *it = new QStandardItem();
it->setText(f.fileName());
it->setData(path);
#if QT_VERSION >= 0x040600
// Todo: Use a "favorites folder" icon instead
it->setIcon(*globalIcon);
#else
it->setIcon(QIcon(":/images/icons/clip-folder-bookmark.png"));
#endif
it->setDropEnabled(true);
mod->appendRow(it);
emit bookmarkAdded();
}
}
}
event->acceptProposedAction();
}
示例2: expandItems
void BookmarkWidget::expandItems()
{
QStandardItemModel *model = bookmarkManager->treeBookmarkModel();
QList<QStandardItem*>list = model->findItems(QLatin1String("*"),
Qt::MatchWildcard | Qt::MatchRecursive, 0);
foreach (const QStandardItem* item, list) {
const QModelIndex& index = model->indexFromItem(item);
treeView->setExpanded(filterBookmarkModel->mapFromSource(index),
item->data(Qt::UserRole + 11).toBool());
}
}
示例3: onAddSiblingClass
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()));
// }
}
示例4: outputTextBrowserAnchorClicked
/*
* This SLOT is called whenever user clicks a url inside output's textBrowser
*/
void MainWindow::outputTextBrowserAnchorClicked(const QUrl &link)
{
if (link.toString().contains("goto:"))
{
QString pkgName = link.toString().mid(5);
QStandardItemModel * sim = _getCurrentSelectedModel();
QList<QStandardItem*> foundItems =
sim->findItems(pkgName, Qt::MatchExactly, ctn_PACKAGE_NAME_COLUMN);
if (foundItems.count() > 0)
{
/*QStandardItem * si = foundItems.first();
QModelIndex indexIcon = sim->index(si->row(), ctn_PACKAGE_ICON_COLUMN);
QModelIndex proxyIndex = m_proxyModelPackages->mapFromSource(indexIcon);
ui->tvPackages->scrollTo(proxyIndex, QAbstractItemView::PositionAtCenter);
ui->tvPackages->setCurrentIndex(proxyIndex);
_changeTabWidgetPropertiesIndex(ctn_TABINDEX_INFORMATION);*/
QStandardItem * si = foundItems.first();
QModelIndex indexIcon = sim->index(si->row(), ctn_PACKAGE_ICON_COLUMN);
QModelIndex proxyIndex = m_proxyModelPackages->mapFromSource(indexIcon);
if(proxyIndex.isValid())
{
ui->tvPackages->scrollTo(proxyIndex, QAbstractItemView::PositionAtCenter);
ui->tvPackages->setCurrentIndex(proxyIndex);
_changeTabWidgetPropertiesIndex(ctn_TABINDEX_INFORMATION);
}
else
{
refreshTabInfo(pkgName);
disconnect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex()));
_ensureTabVisible(ctn_TABINDEX_INFORMATION);
connect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex()));
}
}
示例5: onAddChildClass
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));
}
}
示例6: helpEvent
/*
* Called every time user positions mouse over package's treeview items
*/
bool TreeViewPackagesItemDelegate::helpEvent ( QHelpEvent *event, QAbstractItemView*,
const QStyleOptionViewItem&, const QModelIndex &index )
{
if (this->parent()->objectName() == "tvPackages")
{
QTreeView* tvPackages = qobject_cast<QTreeView*>(this->parent());
QSortFilterProxyModel *sfp = qobject_cast<QSortFilterProxyModel*>(tvPackages->model());
QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(sfp->sourceModel());
if (sim->rowCount() == 0) return false;
QModelIndex ind = sfp->mapToSource(index);
QStandardItem *si = sim->itemFromIndex(ind);
if (si)
{
//If the user's mouse is not positioned above the name column, let's give him a little help...
if (si->column() != ctn_PACKAGE_NAME_COLUMN)
{
QModelIndex miName = sim->index(si->row(), ctn_PACKAGE_NAME_COLUMN);
si = sim->itemFromIndex(miName);
}
QPoint p;
gPoint = tvPackages->mapToGlobal(event->pos());
QFuture<QString> f;
disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
f = QtConcurrent::run(showPackageInfo, si->text());
g_fwToolTip.setFuture(f);
connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
}
else return false;
}
else if (this->parent()->objectName() == "tvTransaction")
{
QTreeView* tvTransaction = qobject_cast<QTreeView*>(this->parent());
QStandardItemModel *sim = qobject_cast<QStandardItemModel*>(tvTransaction->model());
if (sim->rowCount() == 0) return false;
QStandardItem *si = sim->itemFromIndex(index);
if (si)
{
//If it's really a package in the Transaction treeview...
QString pkgName=si->text();
//We have to separate Repository from Package Name, first
int slash = pkgName.indexOf("/");
if (slash != -1)
{
pkgName = pkgName.mid(slash+1);
}
if (si->icon().pixmap(22, 22).toImage() ==
IconHelper::getIconInstallItem().pixmap(22, 22).toImage() ||
si->icon().pixmap(22, 22).toImage() ==
IconHelper::getIconRemoveItem().pixmap(22, 22).toImage())
{
QStandardItemModel *modelPackages = MainWindow::returnMainWindow()->getModelPackages();
QList<QStandardItem*> foundItems =
modelPackages->findItems(pkgName, Qt::MatchExactly, ctn_PACKAGE_NAME_COLUMN);
if (foundItems.count() > 0)
{
QStandardItem *siFound = foundItems.at(0);
QPoint p;
gPoint = tvTransaction->mapToGlobal(event->pos());
QFuture<QString> f;
disconnect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
f = QtConcurrent::run(showPackageInfo, siFound->text());
g_fwToolTip.setFuture(f);
connect(&g_fwToolTip, SIGNAL(finished()), this, SLOT(execToolTip()));
}
}
else
{
QToolTip::hideText();
}
}
}
return true;
}
示例7: loadGeometry
void StitcherWorkspace::loadGeometry() {
/*
This is a prefix to distinguish Hawk Geometry properties from the
normal widget properties
*/
const QString tag("HawkGeometry_");
QList<QGraphicsItem *> ii = _stitcherView->items();
QMap<QString,ImageItem *> sortMap;
for(int i = 0; i<ii.size(); i++) {
if(ImageItem * imageItem = qgraphicsitem_cast<ImageItem *>(ii[i])) {
if(imageItem->isVisible()) {
sortMap.insert(imageItem->identifier(),imageItem);
}
}
}
QList<ImageItem *>sortedItems = sortMap.values();
QStandardItemModel * model = qobject_cast<QStandardItemModel *>(geometryTree->model());
model->clear();
model->setHorizontalHeaderLabels(QStringList() << "Parameter" << "Value" << "Locked");
for(int i = 0; i<sortedItems.size(); i++) {
ImageItem * imageItem = sortedItems[i];
const QMetaObject *metaobject = imageItem->metaObject();
int count = metaobject->propertyCount();
QStandardItem * itemName = new QStandardItem(imageItem->identifier());
QStandardItem * itemValue = new QStandardItem();
QStandardItem * itemLocked = new QStandardItem();
itemLocked->setFlags(itemLocked->flags() & ~Qt::ItemIsEditable);
QStandardItem *parentItem = model->invisibleRootItem();
itemName->setFlags(itemName->flags() & ~Qt::ItemIsEditable);
itemValue->setFlags(itemValue->flags() & ~Qt::ItemIsEditable);
if(model->findItems(itemName->text()).empty()) {
parentItem->appendRow(QList<QStandardItem *>() << itemName << itemValue << itemLocked);
parentItem = itemName;
} else {
parentItem = model->findItems(itemName->text()).first();
}
for (int j=0; j<count; ++j) {
QMetaProperty metaproperty = metaobject->property(j);
const char *name = metaproperty.name();
if(!QString(name).startsWith(tag)) {
continue;
}
QVariant var = imageItem->property(name);
Qt::ItemFlags itemValueFlags = Qt::ItemIsSelectable|Qt::ItemIsEnabled;
if(metaproperty.isWritable()) {
itemValueFlags |= Qt::ItemIsEditable;
}
if(var.type() == QVariant::Double) {
double value = var.toDouble();
if(QString(name).endsWith("_theta") || QString(name).endsWith("_alpha")) {
/* convert to degrees */
value *= 180/M_PI;
}
if(QString(name).endsWith("_dy")) {
/* swap axis */
value = -value;
}
QStandardItem * itemName = new QStandardItem(_stitcherView->propertyNameToDisplayName(name,tag));
QStandardItem * itemValue = new QStandardItem(QString("%0").arg(value));
itemValue->setData(value,Qt::UserRole + 1);
itemValue->setData(QString(name),Qt::UserRole + 2);
itemValue->setData(QVariant::fromValue(imageItem),Qt::UserRole + 3);
itemName->setFlags(itemName->flags() & ~Qt::ItemIsEditable);
itemValue->setFlags(itemValueFlags);
QStandardItem * itemLocked = new QStandardItem();
itemLocked->setFlags(itemLocked->flags() & ~Qt::ItemIsEditable);
/* check for lock property */
QString lockedPropertyName = name + QString("_locked");
if(imageItem->property(lockedPropertyName.toAscii().data()).isValid()) {
bool locked = imageItem->property(lockedPropertyName.toAscii().data()).toBool();
itemLocked->setCheckable(true);
itemLocked->setData(locked,Qt::UserRole + 1);
itemLocked->setData(QString(lockedPropertyName),Qt::UserRole + 2);
itemLocked->setData(QVariant::fromValue(imageItem),Qt::UserRole + 3);
if(locked) {
itemLocked->setCheckState(Qt::Checked);
itemValue->setEnabled(false);
}
}
/* Temporarily disable Dz and Alpha */
if(itemName->text() == "Dz" ||
itemName->text() == "Alpha") {
itemLocked->setCheckState(Qt::Checked);
itemName->setEnabled(false);
itemValue->setEnabled(false);
itemLocked->setEnabled(false);
itemName->setToolTip("Currently disabled");
itemValue->setToolTip("Currently disabled");
itemLocked->setToolTip("Currently disabled");
}
parentItem->appendRow(QList<QStandardItem *>() << itemName << itemValue << itemLocked);
}
}
}
geometryTree->expandAll();
geometryTree->resizeColumnToContents(0);
geometryTree->sortByColumn(0,Qt::AscendingOrder);
}