void MainWin::OnTreeViewContextMenu(const QPoint &point) { if (point.isNull()) return; QStandardItem *item = connections->itemFromIndex( ui.serversTreeView->indexAt(point) ); QPoint currentPoint = QCursor::pos(); if (!item || currentPoint.isNull() || treeViewUILocked) return; int type = item->type(); if (type == RedisServerItem::TYPE) { if (((RedisServerItem*)item)->isLocked()) { QMessageBox::warning(ui.serversTreeView, "Warning", "Performing operations. Please Keep patience."); return; } QAction * action = serverMenu->exec(currentPoint); if (action == nullptr) return; if (action->text() == "Reload") treeViewUILocked = true; } else if (type == RedisKeyItem::TYPE) { keyMenu->exec(currentPoint); } }
void RepoTreeView::onItemDoubleClicked(const QModelIndex& index) { QStandardItem *item = getRepoItem(index); if (!item) { return; } if (item->type() == REPO_ITEM_TYPE) { RepoItem *it = (RepoItem *)item; const LocalRepo& local_repo = it->localRepo(); if (local_repo.isValid()) { // open local folder for downloaded repo QDesktopServices::openUrl(QUrl::fromLocalFile(local_repo.worktree)); } else { // open seahub repo page for not downloaded repo // if (seafApplet->isPro()) { FileBrowserDialog* dialog = new FileBrowserDialog(it->repo(), this); const QRect screen = QApplication::desktop()->screenGeometry(); dialog->setAttribute(Qt::WA_DeleteOnClose, true); dialog->show(); dialog->move(screen.center() - dialog->rect().center()); dialog->raise(); // } else { // const Account& account = seafApplet->accountManager()->accounts()[0]; // if (account.isValid()) { // QUrl url = account.getAbsoluteUrl("repo/" + it->repo().id); // QDesktopServices::openUrl(url); // } // } } } }
bool LibraryFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (filterAcceptsRowItself(sourceRow, sourceParent)) { return true; } // Accept if any of the parents is accepted on it's own merits QModelIndex parent = sourceParent; while (parent.isValid()) { if (filterAcceptsRowItself(parent.row(), parent.parent())) { return true; } parent = parent.parent(); } // Accept if any of the children is accepted on it's own merits if (hasAcceptedChildren(sourceRow, sourceParent)) { return true; } // Accept separators if any top level items and its children are accepted QStandardItemModel *model = qobject_cast<QStandardItemModel*>(sourceModel()); QStandardItem *item = model->itemFromIndex(model->index(sourceRow, 0, sourceParent)); if (item && item->type() == Miam::IT_Separator) { for (QModelIndex index : _topLevelItems.values(static_cast<SeparatorItem*>(item))) { if (filterAcceptsRow(index.row(), sourceParent)) { return true; } } } return (SettingsPrivate::instance()->librarySearchMode() == SettingsPrivate::LSM_HighlightOnly); }
void MainWin::OnConnectionTreeClick(const QModelIndex & index) { if (treeViewUILocked || !index.isValid()) return; QStandardItem * item = connections->itemFromIndex(index); int type = item->type(); switch (type) { case RedisServerItem::TYPE: { RedisServerItem * server = (RedisServerItem *)item; server->runDatabaseLoading(); ui.serversTreeView->setExpanded(index, true); } break; case RedisServerDbItem::TYPE: { performanceTimer.start(); RedisServerDbItem * db = (RedisServerDbItem *)item; connections->blockSignals(true); statusBar()->showMessage(QString("Loading keys ...")); db->loadKeys(); ui.serversTreeView->setExpanded(index, true); } break; case RedisKeyItem::TYPE: ui.tabWidget->openKeyTab((RedisKeyItem *)item); break; } }
bool RepoTreeView::viewportEvent(QEvent *event) { if (event->type() != QEvent::ToolTip && event->type() != QEvent::WhatsThis) { return QTreeView::viewportEvent(event); } QPoint global_pos = QCursor::pos(); QPoint viewport_pos = viewport()->mapFromGlobal(global_pos); QModelIndex index = indexAt(viewport_pos); if (!index.isValid()) { return true; } QStandardItem *item = getRepoItem(index); if (!item) { return true; } QRect item_rect = visualRect(index); if (item->type() == REPO_ITEM_TYPE) { showRepoItemToolTip((RepoItem *)item, global_pos, item_rect); } else { showRepoCategoryItemToolTip((RepoCategoryItem *)item, global_pos, item_rect); } return true; }
void MainWin::OnKeyOpenInNewTab() { QStandardItem * item = ui.serversTreeView->getSelectedItem(); if (item == nullptr || item->type() != RedisKeyItem::TYPE) return; ui.tabWidget->openKeyTab((RedisKeyItem *)item, true); }
bool RedisServerDbItem::operator<(const QStandardItem & other) const { if (other.type() == TYPE) { const RedisServerDbItem * another = dynamic_cast<const RedisServerDbItem *>(&other); return this->dbIndex < another->getDbIndex(); } return this->text() < other.text(); }
void RepoTreeView::collapse(const QModelIndex& index, bool remember) { QTreeView::collapse(index); if (remember) { QStandardItem *item = getRepoItem(index); if (item->type() == REPO_CATEGORY_TYPE) { expanded_categroies_.remove(item->data(Qt::DisplayRole).toString()); } } }
void MainWin::OnConnectionTreeWheelClick(const QModelIndex & index) { if (!index.isValid()) return; QStandardItem * item = connections->itemFromIndex(index); if (item->type() == RedisKeyItem::TYPE) { ui.tabWidget->openKeyTab((RedisKeyItem *)item, true); } }
/// Vergleich zwischen zwei Items für Sortierung. /// Ordner haben Vorrang vor Dateien und sonst wird alphabetisch sortiert. bool Structureelement::operator< (const QStandardItem& other) const { if ((typeEX != fileItem) && (other.type() == fileItem)) { return true; } else if ((typeEX == fileItem) && (other.type() != fileItem)) { return false; } else if (typeEX == messageItem) { return (data(dateRole) < other.data(dateRole)); } else { return (text().toLower() < other.text().toLower()); } }
bool RepoFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const { RepoTreeModel *tree_model = (RepoTreeModel *)(sourceModel()); QModelIndex index = tree_model->index(source_row, 0, source_parent); QStandardItem *item = tree_model->itemFromIndex(index); if (item->type() == REPO_CATEGORY_TYPE) { // RepoCategoryItem *category = (RepoCategoryItem *)item; // We don't filter repo categories, only filter repos by name. return true; } else if (item->type() == REPO_ITEM_TYPE) { // Use default filtering (filter by item DisplayRole, i.e. repo name) bool match = QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); // if (match) { // RepoCategoryItem *category = (RepoCategoryItem *)(item->parent()); // } return match; } return false; }
/** Redefined to always display the same height for albums, even for those without one. */ QSize LibraryItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); QStandardItem *item = _libraryModel->itemFromIndex(_proxy->mapToSource(index)); if (item->type() == Miam::IT_Album) { QFontMetrics fmf(settingsPrivate->font(SettingsPrivate::FF_Library)); return QSize(option.rect.width(), qMax(fmf.height(), Settings::instance()->coverSizeLibraryTree() + 2)); } else { QFontMetrics fmf(settingsPrivate->font(SettingsPrivate::FF_Library)); return QSize(option.rect.width(), fmf.height()); } }
void LazyStandardItemModel::fetchMore(QModelIndex const &parent) { QStandardItemModel *m = &visualizer_->model_; QStandardItem *item = m->itemFromIndex(parent); if(item && item->type() == S_Leaf) { LeafTreeItem *tnd = static_cast<LeafTreeItem *>(item); if(tnd->object_) tnd->cloneChildrenFrom(tnd->object_->node_list_.front()); tnd->setExpanded(true); } }
/** Redefined from MiamSortFilterProxyModel. */ bool UniqueLibraryFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QStandardItem *item = _model->itemFromIndex(_model->index(sourceRow, 1, sourceParent)); if (!item) { return false; } bool result = false; switch (item->type()) { case Miam::IT_Artist: if (MiamSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) { result = true; } else { QSqlQuery getArtist(*SqlDatabase::instance()); getArtist.prepare("SELECT * FROM tracks WHERE title LIKE ? AND artistId = ?"); getArtist.addBindValue("%" + filterRegExp().pattern() + "%"); getArtist.addBindValue(item->data(Miam::DF_ID).toUInt()); result = getArtist.exec() && getArtist.next(); } break; case Miam::IT_Album: if (MiamSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) { result = true; } else if (filterRegExp().indexIn(item->data(Miam::DF_Artist).toString()) != -1) { result = true; } else { QSqlQuery getAlbum(*SqlDatabase::instance()); getAlbum.prepare("SELECT * FROM tracks WHERE title LIKE ? AND albumId = ?"); getAlbum.addBindValue("%" + filterRegExp().pattern() + "%"); getAlbum.addBindValue(item->data(Miam::DF_ID).toUInt()); result = getAlbum.exec() && getAlbum.next(); } break; case Miam::IT_Track: if (MiamSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) { result = true; } else { result = filterRegExp().indexIn(item->data(Miam::DF_Artist).toString()) != -1 || filterRegExp().indexIn(item->data(Miam::DF_Album).toString()) != -1; } break; case Miam::IT_Separator: for (QModelIndex index : _topLevelItems.values(static_cast<SeparatorItem*>(item))) { if (filterAcceptsRow(index.row(), sourceParent)) { result = true; } } break; default: break; } return result; }
QStandardItem* RepoItemDelegate::getItem(const QModelIndex &index) const { if (!index.isValid()) { return NULL; } const RepoTreeModel *model = (const RepoTreeModel*)index.model(); QStandardItem *item = model->itemFromIndex(index); if (item->type() != REPO_ITEM_TYPE && item->type() != REPO_CATEGORY_TYPE) { return NULL; } return item; }
EventItem* EventsListView::getItem(const QModelIndex &index) const { if (!index.isValid()) { return NULL; } const EventsListModel *model = (const EventsListModel*)index.model(); QStandardItem *qitem = model->itemFromIndex(index); if (qitem->type() == EVENT_ITEM_TYPE) { return (EventItem *)qitem; } return NULL; }
void LibraryItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->save(); auto settings = SettingsPrivate::instance(); painter->setFont(settings->font(SettingsPrivate::FF_Library)); QStandardItem *item = _libraryModel->itemFromIndex(_proxy->mapToSource(index)); QStyleOptionViewItem o = option; initStyleOption(&o, index); o.palette = QApplication::palette(); if (QGuiApplication::isLeftToRight()) { o.rect.adjust(0, 0, -_libraryTreeView->jumpToWidget()->width(), 0); } else { o.rect.adjust(_libraryTreeView->jumpToWidget()->width(), 0, 0, 0); } // Removes the dotted rectangle to the focused item o.state &= ~QStyle::State_HasFocus; switch (item->type()) { case Miam::IT_Album: this->paintRect(painter, o); this->drawAlbum(painter, o, item); break; case Miam::IT_Artist: this->paintRect(painter, o); this->drawArtist(painter, o, item); break; case Miam::IT_Disc: this->paintRect(painter, o); this->drawDisc(painter, o, item); break; case Miam::IT_Separator: this->drawLetter(painter, o, item); break; case Miam::IT_Track: { SettingsPrivate::LibrarySearchMode lsm = settings->librarySearchMode(); if (Settings::instance()->isCoverBelowTracksEnabled() && ((_proxy->filterRegExp().isEmpty() && lsm == SettingsPrivate::LSM_Filter) || lsm == SettingsPrivate::LSM_HighlightOnly)) { this->paintCoverOnTrack(painter, o, item); } else { this->paintRect(painter, o); } this->drawTrack(painter, o, item); break; } default: QStyledItemDelegate::paint(painter, o, index); break; } painter->restore(); }
SymbolLayerItem* QgsSymbolV2PropertiesDialog::currentLayerItem() { int index = currentRowIndex(); if ( index < 0 ) return NULL; QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listLayers->model() ); if ( model == NULL ) return NULL; QStandardItem* item = model->item( index ); if ( item->type() != SymbolLayerItemType ) return NULL; return static_cast<SymbolLayerItem*>( item ); }
bool UniqueLibrary::playSingleTrack(const QModelIndex &index) { if (_currentTrack) { _currentTrack->setData(false, Miam::DF_Highlighted); } QStandardItem *item = _model->itemFromIndex(_proxy->mapToSource(index)); if (item && item->type() == Miam::IT_Track) { _mediaPlayer->playMediaContent(QUrl::fromLocalFile(index.data(Miam::DF_URI).toString())); _currentTrack = item; return true; } else { return false; } }
bool LazyStandardItemModel::canFetchMore(QModelIndex const &parent) const { QStandardItem *item = visualizer_->model_.itemFromIndex(parent); /*qDebug() << __func__ << parent << item << (item ? item->type() : 0) << (item && item->type() == S_Leaf ? static_cast<LeafTreeItem *>(item)->is_expanded_ : false); */ return item && item->type() == S_Leaf && !static_cast<LeafTreeItem *>(item)->is_expanded_; }
void RepoTreeView::onItemDoubleClicked(const QModelIndex& index) { QStandardItem *item = getRepoItem(index); if (!item) { return; } if (item->type() == REPO_ITEM_TYPE) { RepoItem *it = (RepoItem *)item; const LocalRepo& local_repo = it->localRepo(); if (local_repo.isValid()) { QDesktopServices::openUrl(QUrl::fromLocalFile(local_repo.worktree)); } } }
QSize RepoItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QStandardItem *item = getItem(index); if (!item) { return QStyledItemDelegate::sizeHint(option, index); } if (item->type() == REPO_ITEM_TYPE) { return sizeHintForRepoItem(option, (const RepoItem *)item); } else { // return QStyledItemDelegate::sizeHint(option, index); return sizeHintForRepoCategoryItem(option, (const RepoCategoryItem *)item); } }
MoveItem *MovesModel::lastMove() const { int pos = game()->position() - 1; int r = pos / 2; int c = pos % 2 ? 1 : 0; if (pos != -1) { QStandardItem *i = item(r, c); if (i->type() == QStandardItem::UserType + 1) //moveitem return static_cast<MoveItem*>(i); else return 0; } return 0; }
QStandardItem* RepoTreeView::getRepoItem(const QModelIndex &index) const { if (!index.isValid()) { return NULL; } QSortFilterProxyModel *proxy = (QSortFilterProxyModel *)model(); RepoTreeModel *tree_model = (RepoTreeModel *)(proxy->sourceModel()); QStandardItem *item = tree_model->itemFromIndex(proxy->mapToSource(index)); if (item->type() != REPO_ITEM_TYPE && item->type() != REPO_CATEGORY_TYPE) { return NULL; } return item; }
QChar UniqueLibraryItemModel::currentLetter(const QModelIndex &index) const { QStandardItem *item = itemFromIndex(_proxy->mapToSource(index)); if (item && item->type() == Miam::IT_Separator && index.data(Miam::DF_NormalizedString).toString() == "0") { return QChar(); } else if (!index.isValid()) { return QChar(); } else { // An item without a valid parent is a top level item, therefore we can extract the letter. if (!index.data(Miam::DF_NormalizedString).toString().isEmpty()) { return index.data(Miam::DF_NormalizedString).toString().toUpper().at(0); } else { return QChar(); } } }
void RepoItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStandardItem *item = getItem(index); if (!item) { QStyledItemDelegate::paint(painter, option, index); return; } if (item->type() == REPO_ITEM_TYPE) { paintRepoItem(painter, option, (RepoItem *)item); } else { // QStyledItemDelegate::paint(painter, option, index); paintRepoCategoryItem(painter, option, (RepoCategoryItem *)item); } }
void EventsListModel::onAvatarUpdated(const QString& email, const QImage& img) { int i, n = rowCount(); for (i = 0; i < n; i++) { QStandardItem *qitem = item(i); if (qitem->type() != EVENT_ITEM_TYPE) { return; } EventItem *item = (EventItem *)qitem; if (item->event().author == email) { QModelIndex index = indexFromItem(item); emit dataChanged(index, index); } } }
void RepoTreeView::onItemClicked(const QModelIndex& index) { QStandardItem *item = getRepoItem(index); if (!item) { return; } if (item->type() == REPO_ITEM_TYPE) { return; } else { // A repo category item if (isExpanded(index)) { collapse(index); } else { expand(index); } } }
void RepoTreeView::contextMenuEvent(QContextMenuEvent *event) { QPoint pos = event->pos(); QModelIndex index = indexAt(pos); if (!index.isValid()) { // Not clicked at a repo item return; } QStandardItem *item = getRepoItem(index); if (!item || item->type() != REPO_ITEM_TYPE) { return; } QMenu *menu = prepareContextMenu((RepoItem *)item); pos = viewport()->mapToGlobal(pos); menu->exec(pos); }
// -------------------------------------------------------------------------- voDataModelItem* voDataModel::inputTargetForAnalysis(voAnalysis * analysis)const { voDataModelItem * analysisItem = this->itemForAnalysis(analysis); if (!analysisItem) { return 0; } QStandardItem * item = analysisItem->parent(); while(item) { if (item->type() == voDataModelItem::InputType) { return dynamic_cast<voDataModelItem*>(item); } item = item->parent(); } return 0; }