本文整理汇总了C++中QStandardItem::hasChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItem::hasChildren方法的具体用法?C++ QStandardItem::hasChildren怎么用?C++ QStandardItem::hasChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItem
的用法示例。
在下文中一共展示了QStandardItem::hasChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCurrentItem
QStandardItem* ProjectSelectionPage::getCurrentItem() const
{
QStandardItem* item = m_templatesModel->itemFromIndex( m_listView->currentIndex() );
if ( item && item->hasChildren() )
{
const int currect = ui->templateType->currentIndex();
const QModelIndex idx = m_templatesModel->index( currect, 0, ui->templateType->rootModelIndex() );
item = m_templatesModel->itemFromIndex(idx);
}
return item;
}
示例2: flags
Qt::ItemFlags Project::flags(const QModelIndex& index) const
{
if (index==editable) {
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
} else {
QStandardItem* item = itemFromIndex(index);
if (!item->hasChildren() && (item==mzn || item==dzn || item==other) )
return Qt::ItemIsSelectable;
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
}
示例3: walkTree
void Switcher::walkTree(QStandardItem* item_, const QString& text_){
for(int i = 0; i < item_->rowCount(); i++) {
QStandardItem* item = item_->child(i);
if(item->hasChildren())
walkTree(item, text_);
else{
bool hide = !item->text().contains(text_, Qt::CaseInsensitive);
QModelIndex index = _model->indexFromItem(item);
switcherList->setRowHidden(index.row(), index.parent(), hide);
}
}
}
示例4: iterate
void NotesItemView::iterate(QStandardItem *item = 0)
{
//DEBUG_FUNC_NAME
if(item == NULL)
return;
const QString parentID = item->data().toString();
for(int i = 0; i < item->rowCount(); ++i) {
QStandardItem *m = item->child(i);
m_notes->setRef(m->data().toString(), "parent", parentID);
if(m->hasChildren())
iterate(m);
}
}
示例5: paint
void PreferencesItemDelegate::paint(QPainter *pPainter,
const QStyleOptionViewItem &pOption,
const QModelIndex &pIndex) const
{
// Paint the item as normal, if it is selectable, or bold, if it is a
// category
QStandardItem *pluginItem = qobject_cast<const QStandardItemModel *>(pIndex.model())->itemFromIndex(pIndex);
QStyleOptionViewItem option(pOption);
initStyleOption(&option, pIndex);
if (pluginItem->hasChildren()) {
option.font.setBold(true);
}
QStyledItemDelegate::paint(pPainter, option, pIndex);
}
示例6: select
void CodeEditor::select(QStandardItem *parent,const QStandardItem *sourceParent)
{
for (int i=0; i<sourceParent->rowCount(); ++i)
{
QStandardItem *child = sourceParent->child(i);
QStandardItem *item = child->QStandardItem::clone();
item->setToolTip(child->toolTip());
assert(item);
QString text = child->data(Item::DescriptionRole).toStringList().join('\n');
QStandardItem *desitem = new QStandardItem(text);
desitem->setForeground(Qt::darkGreen);
desitem->setEditable(false);
parent->appendRow(QList<QStandardItem *>() << item << desitem);
if(child->hasChildren())
select(item,child);
}
}
示例7: patchDoubleClicked
void InstrumentTree::patchDoubleClicked(QModelIndex index)/*{{{*/
{
if(!m_instrument)
return;
QStandardItem* nItem = _patchModel->itemFromIndex(index);
if(nItem->hasChildren()) //Its a folder perform expand collapse
{
setExpanded(index, !isExpanded(index));
}
else
{
int row = nItem->row();
QStandardItem* p = nItem->parent();
QStandardItem *idItem;
QString pg = "";
if(p && p != _patchModel->invisibleRootItem() && p->columnCount() == 2)
{
//We are in group mode
idItem = p->child(row, 1);
pg = p->text();
}
else
{
idItem = _patchModel->item(row, 1);
}
int id = idItem->text().toInt();
QString name = nItem->text();
//printf("Found patch Name: %s - ID: %d\n",name.toUtf8().constData(), id);
if (!name.isEmpty() && id >= 0)
{
emit patchSelected(id, name);
if(m_popup)
{
hide();
}
}
}
}/*}}}*/
示例8: removeFile
void Project::removeFile(const QString &fileName)
{
if (fileName.isEmpty())
return;
if (!_files.contains(fileName)) {
qDebug() << "Internal error: file " << fileName << " not in project";
return;
}
setModified(true, true);
QModelIndex index = _files[fileName];
_files.remove(fileName);
QStandardItem* cur = itemFromIndex(index);
while (cur->parent() != NULL && cur->parent() != invisibleRootItem() && !cur->hasChildren()) {
int row = cur->row();
cur = cur->parent();
cur->removeRow(row);
}
QFileInfo fi(fileName);
if (fi.fileName()=="_coursera") {
delete _courseraProject;
_courseraProject = NULL;
ui->actionSubmit_to_Coursera->setVisible(false);
}
}
示例9: fileAtIndex
QString Project::fileAtIndex(const QModelIndex &index)
{
QStandardItem* item = itemFromIndex(index);
if (item==NULL || item->hasChildren())
return "";
QString fileName;
while (item != NULL && item->parent() != NULL && item->parent() != invisibleRootItem() ) {
if (fileName.isEmpty())
fileName = item->text();
else
fileName = item->text()+"/"+fileName;
item = item->parent();
}
if (fileName.isEmpty())
return "";
if (!projectRoot.isEmpty()) {
fileName = QFileInfo(projectRoot).absolutePath()+"/"+fileName;
}
QFileInfo fi(fileName);
if (fi.canonicalFilePath().isEmpty())
fileName = "/"+fileName;
fileName = QFileInfo(fileName).canonicalFilePath();
return fileName;
}
示例10: addAvailability
void DayAvailabilityModel::addAvailability(const DayAvailability &availability)
{
Q_ASSERT(d->m_UserCalendar);
Q_ASSERT(IN_RANGE(availability.weekDay(), Qt::Monday, Qt::Sunday));
d->m_UserCalendar->addAvailabilities(availability);
// find the day item
QStandardItem *dayItem = 0;
for(int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
if (invisibleRootItem()->child(i)->data(WeekDayRole).toInt() == availability.weekDay()) {
dayItem = invisibleRootItem()->child(i);
break;
}
}
// at this point there MUST be a valid dayItem. If not, something really bad happened.
Q_ASSERT(dayItem);
// delete the placeholder item, if exists
if (dayItem->hasChildren() && dayItem->child(0)->data(AvailIdRole).toInt() == -1)
dayItem->removeRow(0);
// Insert the TimeRanges
for(int i = 0; i < availability.timeRangeCount(); ++i) {
TimeRange range = availability.timeRangeAt(i);
QStandardItem *timeItem = new QStandardItem(tkTr(Trans::Constants::FROM_1_TO_2).arg(range.from.toString()).arg(range.to.toString()));
timeItem->setData(availability.weekDay(), WeekDayRole);
timeItem->setData(range.from, HourFromRole);
timeItem->setData(range.to, HourToRole);
timeItem->setToolTip(timeItem->text());
dayItem->appendRow(timeItem);
}
dayItem->sortChildren(0);
}
示例11: ctor
void tst_QStandardItem::ctor()
{
QStandardItem item;
QVERIFY(!item.hasChildren());
}
示例12: FillTreeList
//.........这里部分代码省略.........
}
std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems);
for (unsigned int i=0; i<categoryItems.size(); i++)
perspectiveRootItem->appendRow(categoryItems.at(i));
// get all available views
berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry();
QList<berry::IViewDescriptor::Pointer> viewDescriptors(viewRegistry->GetViews());
QList<berry::IViewPart::Pointer> viewParts(page->GetViews());
qSort(viewDescriptors.begin(), viewDescriptors.end(), compareViews);
auto emptyItem = new QStandardItem();
emptyItem->setFlags(Qt::ItemIsEnabled);
treeRootItem->appendRow(emptyItem);
//QStringList viewExcludeList = berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetViewExcludeList();
//There currently is no way to get the list of excluded views at application start
QStringList viewExcludeList;
// internal view used for the intro screen, will crash when opened directly, see T22352
viewExcludeList.append(QString("org.blueberry.ui.internal.introview"));
viewExcludeList.append(QString("org.mitk.views.controlvisualizationpropertiesview"));
viewExcludeList.append(QString("org.mitk.views.modules"));
viewExcludeList.append(QString("org.mitk.views.viewnavigatorview"));
QStandardItem* viewRootItem = new QStandardItem(QIcon(),"Views");
viewRootItem->setFont(QFont("", 12, QFont::Normal));
viewRootItem->setEditable(false);
treeRootItem->appendRow(viewRootItem);
categoryItems.clear();
QStandardItem* noCategoryItem = new QStandardItem(QIcon(),"Miscellaneous");
noCategoryItem->setEditable(false);
noCategoryItem->setFont(QFont("", 12, QFont::Normal));
for (int i = 0; i < viewDescriptors.size(); ++i)
{
berry::IViewDescriptor::Pointer v = viewDescriptors[i];
bool skipView = false;
for(int e=0; e<viewExcludeList.size(); e++)
if(viewExcludeList.at(e)==v->GetId())
{
skipView = true;
break;
}
if (skipView)
continue;
QStringList catPath = v->GetCategoryPath();
QIcon icon = v->GetImageDescriptor();
mitk::QtViewItem* vItem = new mitk::QtViewItem(icon, v->GetLabel());
vItem->m_View = v;
vItem->setToolTip(v->GetDescription());
vItem->m_Description = v->GetDescription();
QStringList keylist = v->GetKeywordReferences();
vItem->m_Tags = keywordRegistry.GetKeywords(keylist);
vItem->setEditable(false);
for (int i=0; i<viewParts.size(); i++)
if(viewParts[i]->GetPartName()==v->GetLabel())
{
QFont font; font.setBold(true);
vItem->setFont(font);
break;
}
if (catPath.empty())
noCategoryItem->appendRow(vItem);
else
{
QStandardItem* categoryItem = nullptr;
for (unsigned int c=0; c<categoryItems.size(); c++)
if (categoryItems.at(c)->text() == catPath.front())
{
categoryItem = categoryItems.at(c);
break;
}
if (categoryItem==nullptr)
{
categoryItem = new QStandardItem(QIcon(),catPath.front());
categoryItems.push_back(categoryItem);
}
categoryItem->setEditable(false);
categoryItem->appendRow(vItem);
categoryItem->setFont(QFont("", 12, QFont::Normal));
}
}
std::sort(categoryItems.begin(), categoryItems.end(), compareQStandardItems);
for (unsigned int i=0; i<categoryItems.size(); i++)
viewRootItem->appendRow(categoryItems.at(i));
if (noCategoryItem->hasChildren())
viewRootItem->appendRow(noCategoryItem);
m_Controls.m_PluginTreeView->expandAll();
return true;
}
示例13: processParsedData
void ViewerModel::processParsedData(ParseJobFiles* parser)
{
Data::Bank& bank(parser->data());
if (bank.isEmpty()) return;
QString name(parser->name());
// Determine if we need to replace an existing Molecule in the Model View.
bool overwrite(parser->flags() & ParseJobFiles::Overwrite);
bool makeActive(parser->flags() & ParseJobFiles::MakeActive);
bool addStar(parser->flags() & ParseJobFiles::AddStar);
bool found(false);
Layer::Molecule* molecule(newMolecule());
molecule->setCheckState(Qt::Unchecked);
molecule->setText(name);
molecule->appendData(bank);
if (addStar) molecule->setIcon(QIcon(":/resources/icons/Favourites.png"));
QStandardItem* child;
QStandardItem* root(invisibleRootItem());
void* moleculePointer(parser->moleculePointer());
if (overwrite && moleculePointer) {
for (int row = 0; row < root->rowCount(); ++row) {
child = root->child(row);
if (child->text() == name) {
Layer::Base* base = QVariantPointer<Layer::Base>::toPointer(child->data());
Layer::Molecule* mol = qobject_cast<Layer::Molecule*>(base);
if (mol && mol == moleculePointer) {
molecule->setCheckState(mol->checkState());
// makeActive = makeActive || (mol->checkState() == Qt::Checked);
// This may result in a memory leak, but we need the Molecule
// to remain lying around in case of an undo action.
takeRow(row);
insertRow(row, molecule);
found = true;
qDebug() << "found existing molecule";
break;
}
}
}
}
// If we didn't find an existing Molecule to overwrite, we check the last
// Molecule on the list and if that is still 'Untitled' and empty, use it.
if (!found) {
child = root->child(root->rowCount()-1);
if (child->text() == DefaultMoleculeName && !child->hasChildren()) {
Layer::Base* base = QVariantPointer<Layer::Base>::toPointer(child->data());
Layer::Molecule* mol = qobject_cast<Layer::Molecule*>(base);
makeActive = makeActive || (mol->checkState() == Qt::Checked);
// This may result in a memory leak, but we need the Molecule
// to remain lying around in case of an undo action.
takeRow(child->row());
}
Command::AddMolecule* cmd = new Command::AddMolecule(molecule, root);
postCommand(cmd);
}
if (makeActive) {
forAllMolecules(boost::bind(&Layer::Molecule::setCheckState, _1, Qt::Unchecked));
molecule->setCheckState(Qt::Checked);
sceneRadiusChanged(sceneRadius());
changeActiveViewerMode(Viewer::Manipulate);
}
fileOpened(parser->filePath());
}
示例14: validateData
void ProjectSelectionPage::validateData()
{
QUrl url = ui->locationUrl->url();
if( !url.isLocalFile() || url.isEmpty() )
{
ui->locationValidWidget->setText( i18n("Invalid location") );
ui->locationValidWidget->animatedShow();
emit invalid();
return;
}
if( appName().isEmpty() )
{
ui->locationValidWidget->setText( i18n("Empty project name") );
ui->locationValidWidget->animatedShow();
emit invalid();
return;
}
if( !appName().isEmpty() )
{
QString appname = appName();
QString templatefile = m_wizardDialog->appInfo().appTemplate;
// Read template file
KConfig config(templatefile);
KConfigGroup configgroup(&config, "General");
QString pattern = configgroup.readEntry( "ValidProjectName" , "^[a-zA-Z][a-zA-Z0-9_]+$" );
// Validation
int pos = 0;
QRegExp regex( pattern );
QRegExpValidator validator( regex );
if( validator.validate(appname, pos) == QValidator::Invalid )
{
ui->locationValidWidget->setText( i18n("Invalid project name") );
emit invalid();
return;
}
}
QDir tDir(url.toLocalFile());
while (!tDir.exists() && !tDir.isRoot()) {
if (!tDir.cdUp()) {
break;
}
}
if (tDir.exists())
{
QFileInfo tFileInfo(tDir.absolutePath());
if (!tFileInfo.isWritable() || !tFileInfo.isExecutable())
{
ui->locationValidWidget->setText( i18n("Unable to create subdirectories, "
"missing permissions on: %1", tDir.absolutePath()) );
ui->locationValidWidget->animatedShow();
emit invalid();
return;
}
}
QStandardItem* item = getCurrentItem();
if( item && !item->hasChildren() )
{
ui->locationValidWidget->animatedHide();
emit valid();
} else
{
ui->locationValidWidget->setText( i18n("Invalid project template, please choose a leaf item") );
ui->locationValidWidget->animatedShow();
emit invalid();
return;
}
// Check for non-empty target directory. Not an error, but need to display a warning.
url.setPath( url.path() + '/' + encodedAppName() );
QFileInfo fi( url.toLocalFile() );
if( fi.exists() && fi.isDir() )
{
if( !QDir( fi.absoluteFilePath()).entryList( QDir::NoDotAndDotDot | QDir::AllEntries ).isEmpty() )
{
ui->locationValidWidget->setText( i18n("Path already exists and contains files. Open it as a project.") );
ui->locationValidWidget->animatedShow();
emit invalid();
return;
}
}
}
示例15: validateData
void ProjectSelectionPage::validateData()
{
KUrl url = ui->locationUrl->url();
if( !url.isLocalFile() || url.isEmpty() )
{
ui->locationValidLabel->setText( i18n("Invalid location") );
setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
emit invalid();
return;
}
if( appName().isEmpty() )
{
ui->locationValidLabel->setText( i18n("Empty project name") );
setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
emit invalid();
return;
}
if( appName() == "." || appName() == "..")
{
ui->locationValidLabel->setText( i18n("Invalid project name") );
setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
emit invalid();
return;
}
QDir tDir(url.toLocalFile( KUrl::RemoveTrailingSlash ));
while (!tDir.exists() && !tDir.isRoot())
tDir.setPath( pathUp( tDir.absolutePath() ));
if (tDir.exists())
{
QFileInfo tFileInfo(tDir.absolutePath());
if (!tFileInfo.isWritable() || !tFileInfo.isExecutable())
{
ui->locationValidLabel->setText( i18n("Unable to create subdirectories, "
"missing permissions on: %1", tDir.absolutePath()) );
setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
emit invalid();
return;
}
}
QStandardItem* item = m_templatesModel->itemFromIndex( ui->templateView->currentIndex() );
if( item && !item->hasChildren() )
{
ui->locationValidLabel->setText( QString(" ") );
setForeground(ui->locationValidLabel, KColorScheme::NormalText);
emit valid();
} else
{
ui->locationValidLabel->setText( i18n("Invalid project template, please choose a leaf item") );
setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
emit invalid();
return;
}
// Check for non-empty target directory. Not an error, but need to display a warning.
url.addPath( encodedAppName() );
QFileInfo fi( url.toLocalFile( KUrl::RemoveTrailingSlash ) );
if( fi.exists() && fi.isDir() )
{
if( !QDir( fi.absoluteFilePath()).entryList( QDir::NoDotAndDotDot | QDir::AllEntries ).isEmpty() )
{
ui->locationValidLabel->setText( i18n("Path already exists and contains files") );
setForeground(ui->locationValidLabel, KColorScheme::NegativeText);
}
}
}