本文整理汇总了C++中QAbstractItemModel::insertRows方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::insertRows方法的具体用法?C++ QAbstractItemModel::insertRows怎么用?C++ QAbstractItemModel::insertRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::insertRows方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Unindented for quoting purposes:
//! [1]
QStringList numbers;
numbers << "One" << "Two" << "Three" << "Four" << "Five";
QAbstractItemModel *model = new StringListModel(numbers);
//! [0] //! [1] //! [2] //! [3]
QListView *view = new QListView;
//! [2]
view->setWindowTitle("View onto a string list model");
//! [4]
view->setModel(model);
//! [3] //! [4]
model->insertRows(5, 7, QModelIndex());
for (int row = 5; row < 12; ++row) {
QModelIndex index = model->index(row, 0, QModelIndex());
model->setData(index, QString::number(row+1));
}
//! [5]
view->show();
return app.exec();
}
示例2: mapToSource
bool Utils::ModelListModel::insertRows(int row, int count, const QModelIndex& parent)
{
Utils::ModelListModel::SubModelIndex smi = mapToSource(parent);
if (smi.first == m_metaModel && smi.second.parent().isValid())
{
QAbstractItemModel* subModel = m_subModels.value(smi.second.row());
if (subModel)
return subModel->insertRows(row, count);
}
return smi.first->insertRows(row, count, smi.second);
}
示例3: on_addButton_clicked
void QgsTableWidgetBase::on_addButton_clicked()
{
const QItemSelectionModel *select = tableView->selectionModel();
const int pos = select->hasSelection() ? select->selectedRows()[0].row() : 0;
QAbstractItemModel* model = tableView->model();
model->insertRows( pos, 1 );
const QModelIndex index = model->index( pos, 0 );
tableView->scrollTo( index );
tableView->edit( index );
tableView->selectRow( pos );
}
示例4: learnEntry
void LineEdit::learnEntry()
{
QAbstractItemModel *m = completer()->model();
int rows = m->rowCount();
for (int i = 0; i < rows; ++i) {
if (m->index(i,0).data() == text()) {
m->removeRow(i);
--rows;
break;
}
}
m->insertRows(rows, 1);
m->setData(m->index(rows, 0), text(), Qt::DisplayRole);
m_historyPosition = rows + 1;
}
示例5: insertRow
void DefectsEditor::insertRow()
{
QModelIndex index = tableView->selectionModel()->currentIndex();
QAbstractItemModel* model = tableView->model();
if (!model->insertRows(index.row() + 1, 1, index.parent()))
return;
//updateActions();
updateData(index, index);
/*for (int column = 0; column < model->columnCount( index.parent() ); ++column) {
QModelIndex child = model->index( index.row() + 1, column, index.parent() );
model->setData( child, QVariant( "[No data]" ), Qt::EditRole );
}*/
}
示例6: insertRow
void PathPlanningWidget::insertRow(const tf::Transform& point_pos,const int count)
{
/*! Whenever we have a new Way-Point insereted either from the RViz or the RQT Widget the the TreeView needs to update the information and insert new row that corresponds to the new insered point.
This function takes care of parsing the data recieved from the RViz or the RQT widget and creating new row with the appropriate data format and Children. One for the position giving us the current position of the Way-Point in all the axis.
One child for the orientation giving us the Euler Angles of each axis.
*/
ROS_INFO("inserting new row in the TreeView");
QAbstractItemModel *model = ui_.treeView->model();
//convert the quartenion to roll pitch yaw angle
tf::Vector3 p = point_pos.getOrigin();
tfScalar rx,ry,rz;
point_pos.getBasis().getRPY(rx,ry,rz,1);
if(count == 0)
{
model->insertRow(count,model->index(count, 0));
model->setData(model->index(0,0,QModelIndex()),QVariant("add_point_button"),Qt::EditRole);
pointRange();
}
else
{
//ROS_INFO_STREAM("Quartenion at add_row: "<<orientation.x()<<"; "<<orientation.y()<<"; "<<orientation.z()<<"; "<<orientation.w()<<";");
if(!model->insertRow(count,model->index(count, 0))) //&& count==0
{
return;
}
//set the strings of each axis of the position
QString pos_x = QString::number(p.x());
QString pos_y = QString::number(p.y());
QString pos_z = QString::number(p.z());
//repeat that with the orientation
QString orient_x = QString::number(RAD2DEG(rx));
QString orient_y = QString::number(RAD2DEG(ry));
QString orient_z = QString::number(RAD2DEG(rz));
model->setData(model->index(count,0),QVariant(count),Qt::EditRole);
//add a child to the last inserted item. First add children in the treeview that
//are just telling the user that if he expands them he can see details about the position and orientation of each point
QModelIndex ind = model->index(count, 0);
model->insertRows(0, 2, ind);
QModelIndex chldind_pos = model->index(0, 0, ind);
QModelIndex chldind_orient = model->index(1, 0, ind);
model->setData(chldind_pos, QVariant("Position"), Qt::EditRole);
model->setData(chldind_orient, QVariant("Orientation"), Qt::EditRole);
//*****************************Set the children for the position**********************************************************
//now add information about each child separately. For the position we have coordinates for X,Y,Z axis.
//therefore we add 3 rows of information
model->insertRows(0, 3, chldind_pos);
//next we set up the data for each of these columns. First the names
model->setData(model->index(0, 0, chldind_pos), QVariant("X:"), Qt::EditRole);
model->setData(model->index(1, 0, chldind_pos), QVariant("Y:"), Qt::EditRole);
model->setData(model->index(2, 0, chldind_pos), QVariant("Z:"), Qt::EditRole);
//second we add the current position information, for each position axis separately
model->setData(model->index(0, 1, chldind_pos), QVariant(pos_x), Qt::EditRole);
model->setData(model->index(1, 1, chldind_pos), QVariant(pos_y), Qt::EditRole);
model->setData(model->index(2, 1, chldind_pos), QVariant(pos_z), Qt::EditRole);
//***************************************************************************************************************************
//*****************************Set the children for the orientation**********************************************************
//now we repeat everything again,similar as the position for adding the children for the orientation
model->insertRows(0, 3, chldind_orient);
//next we set up the data for each of these columns. First the names
model->setData(model->index(0, 0, chldind_orient), QVariant("Rx:"), Qt::EditRole);
model->setData(model->index(1, 0, chldind_orient), QVariant("Ry:"), Qt::EditRole);
model->setData(model->index(2, 0, chldind_orient), QVariant("Rz:"), Qt::EditRole);
//second we add the current position information, for each position axis separately
model->setData(model->index(0, 2, chldind_orient), QVariant(orient_x), Qt::EditRole);
model->setData(model->index(1, 2, chldind_orient), QVariant(orient_y), Qt::EditRole);
model->setData(model->index(2, 2, chldind_orient), QVariant(orient_z), Qt::EditRole);
//****************************************************************************************************************************
pointRange();
}
}
示例7: populateTestArea
/*!
Fills model with some test data at least twenty rows and if possible twenty or more columns.
Return the parent of a row/column that can be tested.
NOTE: If readOnly is true tests will try to remove and add rows and columns.
If you have a tree model returning not the root index will help catch more errors.
*/
QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
{
if (QStringListModel *stringListModel = qobject_cast<QStringListModel *>(model)) {
QString alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
stringListModel->setStringList( alphabet.split(",") );
return QModelIndex();
}
if (qobject_cast<QStandardItemModel *>(model)) {
// Basic tree StandardItemModel
QModelIndex parent;
QVariant blue = QVariant(QColor(Qt::blue));
#ifndef Q_OS_WINCE
for (int i = 0; i < 4; ++i) {
#else
for (int i = 0; i < 2; ++i) {
#endif
parent = model->index(0, 0, parent);
model->insertRows(0, 26 + i, parent);
#ifndef Q_OS_WINCE
model->insertColumns(0, 26 + i, parent);
#else
model->insertColumns(0, 4 + i, parent);
#endif
// Fill in some values to make it easier to debug
/*
for (int x = 0; x < 26 + i; ++x) {
QString xval = QString::number(x);
for (int y = 0; y < 26 + i; ++y) {
QString val = xval + QString::number(y) + QString::number(i);
QModelIndex index = model->index(x, y, parent);
model->setData(index, val);
model->setData(index, blue, Qt::TextColorRole);
}
}
*/
}
return model->index(0,0);
}
if (qobject_cast<QSortFilterProxyModel *>(model)) {
QAbstractItemModel *realModel = (qobject_cast<QSortFilterProxyModel *>(model))->sourceModel();
// Basic tree StandardItemModel
QModelIndex parent;
QVariant blue = QVariant(QColor(Qt::blue));
#ifndef Q_OS_WINCE
for (int i = 0; i < 4; ++i) {
#else
for (int i = 0; i < 2; ++i) {
#endif
parent = realModel->index(0, 0, parent);
realModel->insertRows(0, 26+i, parent);
#ifndef Q_OS_WINCE
realModel->insertColumns(0, 26+i, parent);
#else
realModel->insertColumns(0, 4, parent);
#endif
// Fill in some values to make it easier to debug
/*
for (int x = 0; x < 26+i; ++x) {
QString xval = QString::number(x);
for (int y = 0; y < 26 + i; ++y) {
QString val = xval + QString::number(y) + QString::number(i);
QModelIndex index = realModel->index(x, y, parent);
realModel->setData(index, val);
realModel->setData(index, blue, Qt::TextColorRole);
}
}
*/
}
QModelIndex returnIndex = model->index(0,0);
if (!returnIndex.isValid())
qFatal("%s: model index to be returned is invalid", Q_FUNC_INFO);
return returnIndex;
}
if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
if (!QDir::current().mkdir("test"))
qFatal("%s: cannot create directory %s",
Q_FUNC_INFO,
qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/test")));
for (int i = 0; i < 26; ++i) {
QString subdir = QString("test/foo_%1").arg(i);
if (!QDir::current().mkdir(subdir))
qFatal("%s: cannot create directory %s",
Q_FUNC_INFO,
qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/"+subdir)));
}
return dirModel->index(QDir::currentPath()+"/test");
}
if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
QSqlQuery q;
//.........这里部分代码省略.........