本文整理汇总了C++中QSortFilterProxyModel::mapFromSource方法的典型用法代码示例。如果您正苦于以下问题:C++ QSortFilterProxyModel::mapFromSource方法的具体用法?C++ QSortFilterProxyModel::mapFromSource怎么用?C++ QSortFilterProxyModel::mapFromSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSortFilterProxyModel
的用法示例。
在下文中一共展示了QSortFilterProxyModel::mapFromSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDialog
SpeedLimitsDlg::SpeedLimitsDlg(bt::TorrentInterface* current, Core* core, QWidget* parent)
: QDialog(parent), core(core), current(current)
{
setupUi(this);
setWindowIcon(QIcon::fromTheme("kt-speed-limits"));
setWindowTitle(i18n("Speed Limits"));
model = new SpeedLimitsModel(core, this);
QSortFilterProxyModel* pm = new QSortFilterProxyModel(this);
pm->setSourceModel(model);
pm->setSortRole(Qt::UserRole);
m_speed_limits_view->setModel(pm);
m_speed_limits_view->setItemDelegate(new SpinBoxDelegate(this));
m_speed_limits_view->setUniformRowHeights(true);
m_speed_limits_view->setSortingEnabled(true);
m_speed_limits_view->sortByColumn(0, Qt::AscendingOrder);
m_speed_limits_view->header()->setSortIndicatorShown(true);
m_speed_limits_view->header()->setClickable(true);
m_speed_limits_view->setAlternatingRowColors(true);
QPushButton* apply_btn = m_buttonBox->button(QDialogButtonBox::Apply);
apply_btn->setEnabled(false);
connect(model, &SpeedLimitsModel::enableApply, apply_btn, &QPushButton::setEnabled);
connect(apply_btn, &QPushButton::clicked, this, &SpeedLimitsDlg::apply);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
m_upload_rate->setValue(Settings::maxUploadRate());
m_download_rate->setValue(Settings::maxDownloadRate());
connect(m_upload_rate, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)));
connect(m_download_rate, SIGNAL(valueChanged(int)), this, SLOT(spinBoxValueChanged(int)));
connect(m_filter, SIGNAL(textChanged(QString)), pm, SLOT(setFilterFixedString(QString)));
loadState();
// if current is specified, select it and scroll to it
if (current)
{
kt::QueueManager* qman = core->getQueueManager();
int idx = 0;
QList<bt::TorrentInterface*>::iterator itr = qman->begin();
while (itr != qman->end())
{
if (*itr == current)
break;
idx++;
itr++;
}
if (itr != qman->end())
{
QItemSelectionModel* sel = m_speed_limits_view->selectionModel();
QModelIndex midx = pm->mapFromSource(model->index(idx, 0));
QModelIndex midx2 = pm->mapFromSource(model->index(idx, 4));
sel->select(QItemSelection(midx, midx2), QItemSelectionModel::Select);
m_speed_limits_view->scrollTo(midx);
}
}
}
示例2: setDefaultEngine
void FilterOptions::setDefaultEngine(int index)
{
QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_dlg.cmbDefaultEngine->model());
if (index == -1)
index = proxy->rowCount()-1;//"None" is the last
const QModelIndex modelIndex = proxy->mapFromSource(proxy->sourceModel()->index(index,0));
m_dlg.cmbDefaultEngine->setCurrentIndex(modelIndex.row());
m_dlg.cmbDefaultEngine->view()->setCurrentIndex(modelIndex); //TODO: remove this when Qt bug is fixed
}