本文整理汇总了C++中QAbstractItemView::model方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView::model方法的具体用法?C++ QAbstractItemView::model怎么用?C++ QAbstractItemView::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemView
的用法示例。
在下文中一共展示了QAbstractItemView::model方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFromCache
/* Load data to corresponding widgets from cache,
* this task SHOULD be performed in GUI thread only: */
void UIMachineSettingsSystem::getFromCache()
{
/* Get system data from cache: */
const UIDataSettingsMachineSystem &systemData = m_cache.base();
/* Repopulate 'pointing HID type' combo.
* We are doing that *now* because it has dynamical content
* which depends on recashed value: */
repopulateComboPointingHIDType();
/* Load motherboard data to page: */
m_pSliderMemorySize->setValue(systemData.m_iMemorySize);
/* Remove any old data in the boot view: */
QAbstractItemView *iv = qobject_cast <QAbstractItemView*> (mTwBootOrder);
iv->model()->removeRows(0, iv->model()->rowCount());
/* Apply internal variables data to QWidget(s): */
for (int i = 0; i < systemData.m_bootItems.size(); ++i)
{
UIBootItemData data = systemData.m_bootItems[i];
QListWidgetItem *pItem = new UIBootTableItem(data.m_type);
pItem->setCheckState(data.m_fEnabled ? Qt::Checked : Qt::Unchecked);
mTwBootOrder->addItem(pItem);
}
/* Load other motherboard data to page: */
int iChipsetTypePosition = m_pComboChipsetType->findData(systemData.m_chipsetType);
m_pComboChipsetType->setCurrentIndex(iChipsetTypePosition == -1 ? 0 : iChipsetTypePosition);
int iHIDTypePosition = m_pComboPointingHIDType->findData(systemData.m_pointingHIDType);
m_pComboPointingHIDType->setCurrentIndex(iHIDTypePosition == -1 ? 0 : iHIDTypePosition);
m_pCheckBoxApic->setChecked(systemData.m_fEnabledIoApic);
m_pCheckBoxEFI->setChecked(systemData.m_fEnabledEFI);
m_pCheckBoxUseUTC->setChecked(systemData.m_fEnabledUTC);
/* Load CPU data to page: */
m_pSliderCPUCount->setValue(systemData.m_cCPUCount);
m_pSliderCPUExecCap->setValue(systemData.m_iCPUExecCap);
m_pCheckBoxPAE->setChecked(systemData.m_fEnabledPAE);
/* Load acceleration data to page: */
m_pCheckBoxVirtualization->setChecked(systemData.m_fEnabledHwVirtEx);
m_pCheckBoxNestedPaging->setChecked(systemData.m_fEnabledNestedPaging);
/* Polish page finally: */
polishPage();
/* Revalidate: */
revalidate();
}
示例2: showRecentFoldersViewContextMenu
void StartMainPage::showRecentFoldersViewContextMenu(const QPoint& pos)
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(sender());
KUrl url;
QModelIndex index = view->indexAt(pos);
if (index.isValid()) {
QVariant data = index.data(KFilePlacesModel::UrlRole);
url = data.toUrl();
}
// Create menu
QMenu menu(this);
bool fromRecentUrls = view == d->mRecentUrlsView;
QAction* addToPlacesAction = fromRecentUrls ? 0 : menu.addAction(KIcon("bookmark-new"), i18n("Add to Places"));
QAction* removeAction = menu.addAction(KIcon("edit-delete"), fromRecentUrls ? i18n("Forget this URL") : i18n("Forget this Folder"));
menu.addSeparator();
QAction* clearAction = menu.addAction(KIcon("edit-delete-all"), i18n("Forget All"));
if (!index.isValid()) {
if (addToPlacesAction) {
addToPlacesAction->setEnabled(false);
}
removeAction->setEnabled(false);
}
// Handle menu
QAction* action = menu.exec(view->mapToGlobal(pos));
if (!action) {
return;
}
if (action == addToPlacesAction) {
QString text = url.fileName();
if (text.isEmpty()) {
text = url.pathOrUrl();
}
d->mBookmarksModel->addPlace(text, url);
} else if (action == removeAction) {
view->model()->removeRow(index.row());
} else if (action == clearAction) {
view->model()->removeRows(0, view->model()->rowCount());
}
}
示例3: eventFilter
bool TableViewTooltip::eventFilter(QObject * obj, QEvent * event)
{
if (event->type() != QEvent::ToolTip) {
return false;
}
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view) {
return false;
}
QHelpEvent * helpEvent = static_cast<QHelpEvent*>(event);
QPoint pos = helpEvent->pos();
QModelIndex index = view->indexAt(pos);
if (!index.isValid()) {
return false;
}
QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
if (itemTooltip.isEmpty()) {
QToolTip::hideText();
return true;
}
QString itemText = view->model()->data(index).toString();
QFontMetrics fm(view->font());
int textIdentWidth =6;// fm.width('r'); // don't know how to calculate an ident for text in an item :-(
int itemTextWidth = fm.width(itemText) + textIdentWidth;
QRect rect = view->visualRect(index);
int rectWidth = rect.width();
if (itemTextWidth > rectWidth) {
QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
}
else {
QToolTip::hideText();
}
return true;
}
示例4: showPopup
void QGraphicsCompleter::showPopup(const QRect& rect)
{
Qt::LayoutDirection dir = Qt::LeftToRight;
const int maxVisibleItems = 7;
QPointF pos;
int rh, w;
const QRect screen = p_proxyPopup->scene()->views().at(0)->viewport()->geometry();
QAbstractItemView *popup = static_cast<QAbstractItemView *>(p_proxyPopup->widget());
int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3;
QScrollBar *hsb = popup->horizontalScrollBar();
if (hsb && hsb->isVisible())
h += popup->horizontalScrollBar()->sizeHint().height();
if (rect.isValid()) {
rh = rect.height();
w = rect.width();
pos = rect.bottomLeft();
} else {
rh = graphicsItem()->boundingRect().height();
pos = graphicsItem()->mapRectToScene(
graphicsItem()->boundingRect()).bottomLeft();
w = popup->width();
}
if (w > screen.width())
w = screen.width();
if ((pos.x() + w) > (screen.x() + screen.width()))
pos.setX(screen.x() + screen.width() - w);
if (pos.x() < screen.x())
pos.setX(screen.x());
int top = pos.y() - rh - screen.top() + 2;
int bottom = screen.bottom() - pos.y();
h = qMax(h, popup->minimumHeight());
if (h > bottom) {
h = qMin(qMax(top, bottom), h);
if (top > bottom)
pos.setY(pos.y() - h - rh+ 2);
}
popup->setGeometry(pos.x(), pos.y(), w, h+5);
p_proxyPopup->update();
if (!p_proxyPopup->isVisible())
p_proxyPopup->show();
}
示例5: widgetSelected
void ModelInspectorWidget::widgetSelected(QWidget *widget)
{
QAbstractItemView *view = Util::findParentOfType<QAbstractItemView>(widget);
if (view && view->model()) {
QAbstractItemModel *model = ui->modelView->model();
const QModelIndexList indexList =
model->match(model->index(0, 0),
ObjectModel::ObjectRole,
QVariant::fromValue<QObject*>(view->model()), 1,
Qt::MatchExactly | Qt::MatchRecursive);
if (indexList.isEmpty()) {
return;
}
const QModelIndex index = indexList.first();
ui->modelView->selectionModel()->select(
index,
QItemSelectionModel::Select | QItemSelectionModel::Clear |
QItemSelectionModel::Rows | QItemSelectionModel::Current);
ui->modelView->scrollTo(index);
modelSelected(index);
}
}
示例6: eventFilter
bool TooltipFilter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ToolTip)
{
QWidget *w = static_cast<QWidget *>(obj);
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QPoint pos = helpEvent->globalPos();
QString itemTooltip = w->toolTip();
QRect rect = w->rect();
// case of instrument tables inside a scrollarea viewport
if (w->objectName() == QLatin1String("qt_scrollarea_viewport"))
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view)
{
return false;
}
w = view;
QPoint position = helpEvent->pos();
QModelIndex index = view->indexAt(position);
if (!index.isValid())
{
return false;
}
rect = view->visualRect(index);
itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
}
switch (tooltipType_)
{
case TooltipType::NoTooltip:
QToolTip::hideText();
return true;
case TooltipType::StdTooltip:
QToolTip::showText(pos, itemTooltip, w, rect);
return true;
case TooltipType::CustomTooltip:
break;
default:
QToolTip::hideText();
emit updateTooltipRequest(itemTooltip);
return true;
}
}
return QObject::eventFilter(obj, event);
}
示例7: getFromCache
/* Load data to corresponding widgets from cache,
* this task SHOULD be performed in GUI thread only: */
void UIMachineSettingsSystem::getFromCache()
{
/* Get system data from cache: */
const UIDataSettingsMachineSystem &systemData = m_cache.base();
/* Remove any old data in the boot view: */
QAbstractItemView *iv = qobject_cast <QAbstractItemView*> (mTwBootOrder);
iv->model()->removeRows(0, iv->model()->rowCount());
/* Apply internal variables data to QWidget(s): */
for (int i = 0; i < systemData.m_bootItems.size(); ++i)
{
UIBootItemData data = systemData.m_bootItems[i];
QListWidgetItem *pItem = new UIBootTableItem(data.m_type);
pItem->setCheckState(data.m_fEnabled ? Qt::Checked : Qt::Unchecked);
mTwBootOrder->addItem(pItem);
}
/* Load other system data to page: */
mCbApic->setChecked(systemData.m_fIoApicEnabled);
mCbEFI->setChecked(systemData.m_fEFIEnabled);
mCbTCUseUTC->setChecked(systemData.m_fUTCEnabled);
mCbUseAbsHID->setChecked(systemData.m_fUseAbsHID);
mCbPae->setChecked(systemData.m_fPAEEnabled);
mCbVirt->setChecked(systemData.m_fHwVirtExEnabled);
mCbNestedPaging->setChecked(systemData.m_fNestedPagingEnabled);
mSlMemory->setValue(systemData.m_iRAMSize);
mSlCPU->setValue(systemData.m_cCPUCount);
mSlCPUExecCap->setValue(systemData.m_cCPUExecCap);
int iChipsetPositionPos = mCbChipset->findData(systemData.m_chipsetType);
mCbChipset->setCurrentIndex(iChipsetPositionPos == -1 ? 0 : iChipsetPositionPos);
/* Polish page finally: */
polishPage();
/* Revalidate if possible: */
if (mValidator)
mValidator->revalidate();
}
示例8: complete
void QGraphicsCompleter::complete(const QRect &rect)
{
if (p_proxyPopup->scene() == 0)
p_graphicsItem->scene()->addItem(p_proxyPopup);
QAbstractItemView *popup = static_cast<QAbstractItemView *>(p_proxyPopup->widget());
if (popup->model()->rowCount() == 0)
{
popup->hide();
p_graphicsItem->setFocus();
return;
}
showPopup(rect);
}
示例9: eventFilter
bool ColumnToolTip::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::ToolTip)
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view)
{
return false;
}
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
QPoint pos = helpEvent->pos();
QModelIndex index = view->indexAt(pos);
if (!index.isValid())
return false;
QString itemText = view->model()->data(index).toString();
QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
QFontMetrics fm(view->font());
int itemTextWidth = fm.width(itemText);
QRect rect = view->visualRect(index);
int rectWidth = rect.width();
if ((itemTextWidth > rectWidth) && !itemTooltip.isEmpty())
{
QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
}
else
{
QToolTip::hideText();
}
return true;
}
return false;
}
示例10: showPopup
void DDateEdit::showPopup()
{
if ( d->readOnly )
{
return;
}
QRect desk = KGlobalSettings::desktopGeometry( this );
QPoint popupPoint = mapToGlobal( QPoint( 0,0 ) );
int dateFrameHeight = d->popup->sizeHint().height();
if ( popupPoint.y() + height() + dateFrameHeight > desk.bottom() )
{
popupPoint.setY( popupPoint.y() - dateFrameHeight );
}
else
{
popupPoint.setY( popupPoint.y() + height() );
}
int dateFrameWidth = d->popup->sizeHint().width();
if ( popupPoint.x() + dateFrameWidth > desk.right() )
{
popupPoint.setX( desk.right() - dateFrameWidth );
}
if ( popupPoint.x() < desk.left() )
{
popupPoint.setX( desk.left() );
}
if ( popupPoint.y() < desk.top() )
{
popupPoint.setY( desk.top() );
}
if ( d->date.isValid() )
{
d->popup->setDate( d->date );
}
else
{
d->popup->setDate( QDate::currentDate() );
}
d->popup->popup( popupPoint );
// The combo box is now shown pressed. Make it show not pressed again
// by causing its (invisible) list box to emit a 'selected' signal.
// First, ensure that the list box contains the date currently displayed.
QDate date = parseDate();
assignDate( date );
updateView();
// Now, simulate an Enter to unpress it
QAbstractItemView* lb = view();
if (lb)
{
lb->setCurrentIndex( lb->model()->index( 0, 0 ) );
QKeyEvent* keyEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
QApplication::postEvent(lb, keyEvent);
}
}