本文整理汇总了C++中QAbstractItemModel类的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel类的具体用法?C++ QAbstractItemModel怎么用?C++ QAbstractItemModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAbstractItemModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: model
QModelIndexList
PartitionLabelsView::getIndexesToDraw( const QModelIndex& parent ) const
{
QModelIndexList list;
QAbstractItemModel* modl = model();
if ( !modl )
return list;
for ( int row = 0; row < modl->rowCount( parent ); ++row )
{
QModelIndex index = modl->index( row, 0, parent );
//HACK: horrible special casing follows.
// To save vertical space, we choose to hide short instances of free space.
// Arbitrary limit: 10MB.
const qint64 maxHiddenB = 10'000'000;
if ( index.data( PartitionModel::IsFreeSpaceRole ).toBool() &&
index.data( PartitionModel::SizeRole ).toLongLong() < maxHiddenB )
continue;
list.append( index );
if ( modl->hasChildren( index ) )
list.append( getIndexesToDraw( index ) );
}
return list;
}
示例2: testModel
void tst_QDataWidgetMapper::setData()
{
QDataWidgetMapper mapper;
QAbstractItemModel *model = testModel(&mapper);
mapper.setModel(model);
QLineEdit edit1;
QLineEdit edit2;
QLineEdit edit3;
mapper.addMapping(&edit1, 0);
mapper.addMapping(&edit2, 1);
mapper.addMapping(&edit3, 0, "text");
mapper.toFirst();
QCOMPARE(edit1.text(), QString("item 0 0"));
QCOMPARE(edit2.text(), QString("item 0 1"));
QCOMPARE(edit3.text(), QString("item 0 0"));
edit1.setText("new text");
mapper.submit();
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("new text"));
edit3.setText("more text");
mapper.submit();
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("more text"));
}
示例3: on_acSelect_triggered
void KTracks::on_acSelect_triggered()
{
QModelIndexList selection = ui->tvTracks->selectionModel()->selectedRows();
QAbstractItemModel *model = ui->tvTracks->model();
if (!selection.isEmpty()) {
QList<QGeoPositionInfo> trackList;
trackList.clear();
trackList = sql.selTrack(model->data(model->index(selection.at(0).row(),0)).toInt());
ui->cpPlot->clearGraphs();
ui->cpPlot->addGraph();
QGeoPositionInfo tp;
QVector<double> x;
QVector<double> y;
int cnt = trackList.count();
x.resize(cnt);
y.resize(cnt);
//options
int pType;
if (ui->miAltitude->isChecked()) {
ui->cpPlot->yAxis->setLabel("Altitude [m]");
pType = 1; }
if (ui->miDistance->isChecked()) {
ui->cpPlot->yAxis->setLabel("Distance [m]");
pType = 2; }
if (ui->miSpeed->isChecked()) {
ui->cpPlot->yAxis->setLabel("Speed [m/s]");
pType = 3; }
ui->cpPlot->xAxis->setLabel("time [hh:mm:ss]");
for (int i=0; i<cnt; i++) {
tp = trackList.value(i);
x[i] = tp.timestamp().toTime_t();
switch (pType) {
case 1: {
y[i] = tp.coordinate().altitude();
break; }
case 2: {
y[i] = tp.coordinate().distanceTo(trackList.value(0).coordinate());
break; }
case 3: {
y[i] = tp.attribute(QGeoPositionInfo::GroundSpeed);
break; }
} //switch
} //for to
ui->cpPlot->graph(0)->setData(x,y);
// set axes ranges, so we see all data:
ui->cpPlot->xAxis->setRange(x[0],x[cnt-1]);
qSort(y.begin(), y.end());
ui->cpPlot->yAxis->setRange(y.first(),y.last());
//repaint
ui->cpPlot->replot();
} //selection.isempty
}
示例4: roleIndexByName
void Element::setRoleValueByName(QString const &roleName, QString const &value)
{
int roleIndex = roleIndexByName(roleName);
if (roleIndex < roles::customPropertiesBeginRole)
return;
QAbstractItemModel *itemModel = const_cast<QAbstractItemModel*>(mDataIndex.model());
itemModel->setData(mDataIndex, value, roleIndex);
}
示例5: pageRight
void Desktopwidget::pageRight (const QModelIndex &index)
{
QAbstractItemModel *model = (QAbstractItemModel *)index.model ();
int pagenum = model->data (index, Desktopmodel::Role_pagenum).toInt ();
QVariant v = pagenum + 1;
model->setData (index, v, Desktopmodel::Role_pagenum);
}
示例6: invalidateWidgetPositions
void PackagesDelegate::invalidateWidgetPositions ()
{
QTreeView *view = qobject_cast<QTreeView*> (parent ());
QAbstractItemModel *model = view->model ();
for (int i = 0, rows = model->rowCount ();
i < rows; ++i)
emit sizeHintChanged (model->index (i, 0));
}
示例7: mapToSource
bool KConcatenateRowsProxyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
const QModelIndex sourceIndex = mapToSource(index);
if (!sourceIndex.isValid()) {
return false;
}
QAbstractItemModel *sourceModel = const_cast<QAbstractItemModel *>(sourceIndex.model());
return sourceModel->setData(sourceIndex, value, role);
}
示例8: sourceModel
QStringList SummaryTagsFilter::GetTagsForIndex (int index) const
{
QAbstractItemModel *model = sourceModel ();
if (!model)
return QStringList ();
return model->data (model->index (index, 0),
RoleTags).toStringList ();
}
示例9: slotCurrentIndexChanged
void ComboFilterItemWidget::slotCurrentIndexChanged(int row)
{
if(_valueColumn<0)
return;
QAbstractItemModel * model = _comboBox->model();
QModelIndex index = model->index(row, _valueColumn);
const QVariant value = model->data(index, _valueRole);
emit valueChanged(_filterTag, value);
}
示例10: checkLogItem
void MainWindow::checkLogItem( const QModelIndex& rIndex )
{
QAbstractItemModel* model = mUI.logListWidget->model();
if( !model->data( rIndex, Qt::UserRole + 2 ).toBool() ||
!model->data( rIndex, Qt::UserRole + 3 ).toBool() )
mUI.logListWidget->item( rIndex.row() )->setHidden( true );
else
mUI.logListWidget->item( rIndex.row() )->setHidden( false );
}
示例11: flags
Qt::ItemFlags TodoNode::flags(int column) const
{
if (m_rowSourceIndex.isValid()) {
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(m_rowSourceIndex.model());
return model->flags(m_rowSourceIndex.sibling(m_rowSourceIndex.row(), column));
} else {
return m_flags;
}
}
示例12:
void MainWindow::on_pushButton_5_clicked()
{
int row= ui->tableView->currentIndex().row();
QAbstractItemModel *model = ui->tableView->model ();
QModelIndex index = model->index(row,0);//选中行第一列的内容
QVariant data = model->data(index);
ui->le_ExeFile->setText(data.toString());
}
示例13: slotImportAll
void ThumbnailPage::slotImportAll()
{
QModelIndexList list;
QAbstractItemModel* model = d->mThumbnailView->model();
for (int row = model->rowCount() - 1; row >= 0; --row) {
list << model->index(row, 0);
}
importList(list);
}
示例14: setRowData
void TodoNode::setRowData(const QVariant &value, int role)
{
if (m_rowSourceIndex.isValid()) {
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(m_rowSourceIndex.model());
model->setData(m_rowSourceIndex, value, role);
} else {
m_data[QPair<int, int>(-1, role)] = value;
}
}
示例15: removeRow
void DefectsEditor::removeRow()
{
QModelIndex index = tableView->selectionModel()->currentIndex();
QAbstractItemModel* model = tableView->model();
if (model->removeRows(index.row(), 1, index.parent())) {
//updateActions();
updateData(index, index);
}
}