本文整理汇总了C++中QStandardItem::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItem::parent方法的具体用法?C++ QStandardItem::parent怎么用?C++ QStandardItem::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItem
的用法示例。
在下文中一共展示了QStandardItem::parent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateChaptersInfo
void MangaListWidget::updateChaptersInfo(QModelIndex index) {
QStandardItem* currentItem = _model->itemFromIndex(index);
QDir chapterDir = _scansDirectory;
if (!currentItem->parent())
return;
chapterDir.cd(currentItem->parent()->text());
chapterDir.cd(currentItem->text());
QStringList pagesList = Utils::filesList(chapterDir);
if (pagesList.size() == 0)
return;
qint64 totalSize = 0;
for (const QString& pageName: pagesList) {
QFile currFile(chapterDir.path()+"/"+pageName);
totalSize += currFile.size();
}
double chapterSize = totalSize/(1024.*1024.);
QFileInfo chapterDirInfo(chapterDir.path());
_chapterInfoWidget->setNumberFiles(QString::number(pagesList.size()));
_chapterInfoWidget->setTotalSize(QString::number(chapterSize, 'f', 2)+"MB");
_chapterInfoWidget->setLastModification(chapterDirInfo.lastModified().toString("ddd dd MMM yyyy"));
_chapterInfoWidget->setLastRead(chapterDirInfo.lastRead().toString("ddd dd MMM yyyy"));
if (pagesList.size() > 0)
_chapterInfoWidget->setImgPreview(QPixmap(chapterDir.path()+"/"+pagesList.at(0)));
else
_chapterInfoWidget->setImgPreview(QPixmap());
}
示例2: ShowContextMenu
void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
EnsureMenuCreated();
QStandardItem* item = model()->itemFromIndex(model()->current_index());
if (item) {
int type = item->data(InternetModel::Role_Type).toInt();
if (type == Type_InboxPlaylist || type == Type_StarredPlaylist ||
type == InternetModel::Type_UserPlaylist) {
playlist_sync_action_->setData(qVariantFromValue(item));
playlist_context_menu_->popup(global_pos);
current_playlist_url_ = item->data(InternetModel::Role_Url).toUrl();
get_url_to_share_playlist_->setVisible(type ==
InternetModel::Type_UserPlaylist);
return;
} else if (type == InternetModel::Type_Track) {
current_song_url_ = item->data(InternetModel::Role_Url).toUrl();
// Is this track contained in a playlist we can modify?
bool is_playlist_modifiable =
item->parent() &&
item->parent()->data(InternetModel::Role_CanBeModified).toBool();
remove_from_playlist_->setVisible(is_playlist_modifiable);
song_context_menu_->popup(global_pos);
return;
}
}
context_menu_->popup(global_pos);
}
示例3: data
QVariant Project::data(const QModelIndex &index, int role) const
{
if (role==Qt::UserRole) {
QStandardItem* item = itemFromIndex(index);
if (item->parent()==NULL || item->parent()==invisibleRootItem()) {
if (item==projectFile) {
return "00 - project";
}
//if (item==mzn) {
// return "01 - mzn";
//}
if (item==zinc) {
return "01 - zinc";
}
if (item==dzn) {
return "02 - dzn";
}
if (item==other) {
return "03 - other";
}
}
return QStandardItemModel::data(index,Qt::DisplayRole);
} else {
return QStandardItemModel::data(index,role);
}
}
示例4: dropMimeData
bool TrialTreeModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
if (QStandardItemModel::dropMimeData(mimeData, action, row, column, parent))
return true;
if (mimeData->hasUrls())
{
const QList<QUrl> urls = mimeData->urls();
QStandardItem * dropInto = itemFromIndex(parent);
if (dropInto && !dropInto->data().isNull())
{
// printf("Dropping onto '%s'\n", dropInto->data().toString().toAscii().data());
QStandardItem * const tmp = new QStandardItem("Group");
QStandardItem * const p = (dropInto->parent() ? dropInto->parent() : invisibleRootItem());
p->insertRow(dropInto->row(), tmp);
tmp->setChild(0, 0, dropInto->clone());
p->removeRow(dropInto->row());
dropInto = tmp;
}
if (!dropInto)
dropInto = invisibleRootItem();
int i = 0;
for (QList<QUrl>::const_iterator it = urls.begin(); it != urls.end(); ++it, i++)
{
QFileInfo fileInfo(it->toLocalFile());
QStandardItem * const newItem = new QStandardItem(fileInfo.fileName());
newItem->setData(QDir::current().relativeFilePath(fileInfo.filePath()));
newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled/* | Qt::ItemIsDropEnabled*/);
dropInto->appendRow(newItem);
}
return true;
}
return false;
}
示例5: highlightMatchingText
/** Highlight items in the Tree when one has activated this option in settings. */
void MiamSortFilterProxyModel::highlightMatchingText(const QString &text)
{
// Clear highlight on every call
std::function<void(QStandardItem *item)> recursiveClearHighlight;
recursiveClearHighlight = [&recursiveClearHighlight] (QStandardItem *item) -> void {
if (item->hasChildren()) {
item->setData(false, Miam::DF_Highlighted);
for (int i = 0; i < item->rowCount(); i++) {
recursiveClearHighlight(item->child(i, 0));
}
} else {
item->setData(false, Miam::DF_Highlighted);
}
};
QStandardItemModel *_libraryModel = qobject_cast<QStandardItemModel*>(this->sourceModel());
for (int i = 0; i < _libraryModel->rowCount(); i++) {
recursiveClearHighlight(_libraryModel->item(i, 0));
}
// Adapt filter if one is typing '*'
QString filter;
Qt::MatchFlags flags;
if (text.contains(QRegExp("^(\\*){1,5}$"))) {
this->setFilterRole(Miam::DF_Rating);
filter = "[" + QString::number(text.size()) + "-5]";
flags = Qt::MatchRecursive | Qt::MatchRegExp;
} else {
this->setFilterRole(Qt::DisplayRole);
filter = text;
flags = Qt::MatchRecursive | Qt::MatchContains;
}
// Mark items with a bold font
QSet<QChar> lettersToHighlight;
if (!text.isEmpty()) {
QModelIndexList indexes = _libraryModel->match(_libraryModel->index(0, 0, QModelIndex()), this->filterRole(), filter, -1, flags);
QList<QStandardItem*> items;
for (int i = 0; i < indexes.size(); ++i) {
items.append(_libraryModel->itemFromIndex(indexes.at(i)));
}
for (QStandardItem *item : items) {
item->setData(true, Miam::DF_Highlighted);
QStandardItem *parent = item->parent();
// For every item marked, mark also the top level item
while (parent != nullptr) {
parent->setData(true, Miam::DF_Highlighted);
if (parent->parent() == nullptr) {
lettersToHighlight << parent->data(Miam::DF_NormalizedString).toString().toUpper().at(0);
}
parent = parent->parent();
}
}
}
qDebug() << Q_FUNC_INFO << lettersToHighlight;
emit aboutToHighlightLetters(lettersToHighlight);
}
示例6: removeExistingItem
void removeExistingItem(const QString& path)
{
if (!itemsByPath.contains(path)) {
return;
}
QStandardItem *existingItem = itemsByPath[path];
//kDebug() << "Removing existing item" << existingItem;
Q_ASSERT(existingItem->parent());
existingItem->parent()->removeRow(existingItem->row());
itemsByPath.remove(path);
}
示例7: activated
void Model::activated(const QModelIndex& index)
{
//TODO optimize
QStandardItem* item = itemFromIndex(index);
Q_ASSERT(item);
Contact *contact = item->data().value<Contact*>();
if(!contact)
return;
if(!(item->parent() == m_metaRoot))
addContact(contact, m_metaRoot);
item->parent()->removeRow(index.row());
}
示例8: goToDownload
void MangaListWidget::goToDownload(void) {
QStandardItem* currentItem = _model->itemFromIndex(_view->currentIndex());
if (!currentItem) {
QMessageBox::warning(this, "Warning", "No manga selected.");
return;
}
QString mangaName;
currentItem->parent() == nullptr ? mangaName = currentItem->text() : mangaName = currentItem->parent()->text();
emit mangaSelected(mangaName);
}
示例9: flags
Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
{
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if ( !index.isValid() )
{
flags |= Qt::ItemIsDropEnabled;
return flags;
}
QStandardItem* item = itemFromIndex( index );
QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );
if ( cItem )
{
QgsComposerLegendItem::ItemType type = cItem->itemType();
if ( type == QgsComposerLegendItem::GroupItem )
{
flags |= Qt::ItemIsDragEnabled;
flags |= Qt::ItemIsDropEnabled;
}
else if ( type == QgsComposerLegendItem::LayerItem )
{
flags |= Qt::ItemIsDragEnabled;
}
}
if ( index.column() == 1 && item )
{
// Style
QStandardItem* firstColumnItem = 0;
if ( item->parent() )
{
firstColumnItem = item->parent()->child( index.row(), 0 );
}
else
{
firstColumnItem = QgsLegendModel::item( index.row(), 0 );
}
cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );
if ( cItem )
{
if ( cItem->itemType() == QgsComposerLegendItem::GroupItem ||
cItem->itemType() == QgsComposerLegendItem::LayerItem )
{
flags |= Qt::ItemIsEditable;
}
}
}
return flags;
}
示例10: setCurrentChild
// private slot
void FilesWidget::setCurrentChild(Document *document)
{
// Set current child and parent back to normal
if (m_currentChild != NULL) {
markItemAsCurrent(m_currentChild, false);
QStandardItem *parent = m_currentChild->parent();
m_currentChild = NULL;
updateParentItemMarkers(parent);
}
// Mark new current child as current
if (document != NULL) {
QStandardItem *child = m_children.value(document, NULL);
Q_ASSERT(child != NULL);
QStandardItem *parent = child->parent();
Q_ASSERT(parent != NULL);
m_treeFiles->expand(parent->index());
m_treeFiles->scrollTo(child->index());
m_treeFiles->selectionModel()->select(child->index(), QItemSelectionModel::ClearAndSelect);
m_currentChild = child;
markItemAsCurrent(m_currentChild, true);
updateParentItemMarkers(parent);
}
}
示例11: removeDocument
// private slot
void FilesWidget::removeDocument(Document *document)
{
Q_ASSERT(document != NULL);
disconnect(document, &Document::modificationChanged, this, &FilesWidget::updateModificationMarkerOfSender);
disconnect(document, &Document::locationChanged, this, &FilesWidget::updateLocationOfSender);
QStandardItem *child = m_children.value(document, NULL);
Q_ASSERT(child != NULL);
Q_ASSERT(child != m_currentChild);
QStandardItem *parent = child->parent();
Q_ASSERT(parent != NULL);
parent->removeRow(child->row());
if (parent->rowCount() > 0) {
updateParentItemMarkers(parent);
} else {
m_model.removeRow(parent->row());
}
m_children.remove(document);
if (m_currentChild != NULL) {
m_treeFiles->selectionModel()->select(m_currentChild->index(), QItemSelectionModel::ClearAndSelect);
}
}
示例12: MoveRight
void EditTOC::MoveRight()
{
QModelIndex index = CheckSelection(0);
if (!index.isValid()) {
return;
}
QStandardItem *item = m_TableOfContents->itemFromIndex(index);
int item_row = item->row();
// Can't indent if row above is already parent
if (item_row == 0) {
return;
}
QStandardItem *parent_item = item->parent();
if (!parent_item) {
parent_item = m_TableOfContents->invisibleRootItem();
}
// Make the item above the parent of this item
QList<QStandardItem *> row_items = parent_item->takeRow(item_row);
QStandardItem *new_parent = parent_item->child(item_row - 1, 0);
new_parent->insertRow(new_parent->rowCount(), row_items);
QStandardItem *new_item = new_parent->child(new_parent->rowCount() - 1, 0);
// Reselect the item
ui.TOCTree->selectionModel()->clear();
ui.TOCTree->setCurrentIndex(item->index());
ui.TOCTree->selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
ExpandChildren(new_item);
}
示例13: dropMimeData
bool PlacesModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) {
QStandardItem* item = itemFromIndex(parent);
if(data->hasFormat("application/x-bookmark-row")) { // the data being dopped is a bookmark row
// decode it and do bookmark reordering
QByteArray buf = data->data("application/x-bookmark-row");
QDataStream stream(&buf, QIODevice::ReadOnly);
int oldPos = -1;
char* pathStr = NULL;
stream >> oldPos >> pathStr;
// find the source bookmark item being dragged
GList* allBookmarks = fm_bookmarks_get_all(bookmarks);
FmBookmarkItem* draggedItem = static_cast<FmBookmarkItem*>(g_list_nth_data(allBookmarks, oldPos));
// If we cannot find the dragged bookmark item at position <oldRow>, or we find an item,
// but the path of the item is not the same as what we expected, than it's the wrong item.
// This means that the bookmarks are changed during our dnd processing, which is an extremely rare case.
if(!draggedItem || !fm_path_equal_str(draggedItem->path, pathStr, -1)) {
delete []pathStr;
return false;
}
delete []pathStr;
int newPos = -1;
if(row == -1 && column == -1) { // drop on an item
// we only allow dropping on an bookmark item
if(item && item->parent() == bookmarksRoot)
newPos = parent.row();
}
else { // drop on a position between items
if(item == bookmarksRoot) // we only allow dropping on a bookmark item
newPos = row;
}
if(newPos != -1 && newPos != oldPos) // reorder the bookmark item
fm_bookmarks_reorder(bookmarks, draggedItem, newPos);
}
示例14: AddEntry
void EditTOC::AddEntry(bool above)
{
QModelIndex index = CheckSelection(0);
if (!index.isValid()) {
return;
}
QStandardItem *item = m_TableOfContents->itemFromIndex(index);
QStandardItem *parent_item = item->parent();
if (!parent_item) {
parent_item = m_TableOfContents->invisibleRootItem();
}
// Add a new empty row of items
QStandardItem *entry_item = new QStandardItem();
QStandardItem *target_item = new QStandardItem();
QList<QStandardItem *> row_items;
row_items << entry_item << target_item ;
int location = 1;
if (above) {
location = 0;
}
parent_item->insertRow(item->row() + location,row_items);
// Select the new row
ui.TOCTree->selectionModel()->clear();
ui.TOCTree->setCurrentIndex(entry_item->index());
ui.TOCTree->selectionModel()->select(entry_item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
示例15: MoveDown
void EditTOC::MoveDown()
{
QModelIndex index = CheckSelection(0);
if (!index.isValid()) {
return;
}
QStandardItem *item = m_TableOfContents->itemFromIndex(index);
QStandardItem *parent_item = item->parent();
if (!parent_item) {
parent_item = m_TableOfContents->invisibleRootItem();
}
int item_row = item->row();
// Can't move down if this row is already the last one of its parent
if (item_row == parent_item->rowCount() - 1) {
return;
}
QList<QStandardItem *> row_items = parent_item->takeRow(item_row);
parent_item->insertRow(item_row + 1, row_items);
// Reselect the item
ui.TOCTree->selectionModel()->clear();
ui.TOCTree->setCurrentIndex(item->index());
ui.TOCTree->selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
ExpandChildren(item);
}