本文整理汇总了C++中QAbstractItemModel::insertColumn方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::insertColumn方法的具体用法?C++ QAbstractItemModel::insertColumn怎么用?C++ QAbstractItemModel::insertColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::insertColumn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertChild
void MainWindow::insertChild()
{
QModelIndex index = view->selectionModel()->currentIndex();
QAbstractItemModel *model = view->model();
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
return;
}
if (!model->insertRow(0, index))
return;
for (int column = 0; column < model->columnCount(index); ++column) {
QModelIndex child = model->index(0, column, index);
model->setData(child, QVariant("[No data]"), Qt::EditRole);
if (!model->headerData(column, Qt::Horizontal).isValid())
model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"),
Qt::EditRole);
}
view->selectionModel()->setCurrentIndex(model->index(0, 0, index),
QItemSelectionModel::ClearAndSelect);
updateActions();
}
示例2: on_clicked
void Button::on_clicked()
{
QTableView* table = qobject_cast<QTableView*>(this->parent());
if (!table)
return;
QAbstractItemModel* model = table->model();
if (!model)
return;
if (_type == InsertRemove::Insert)
{
if (_orientation == Qt::Horizontal)
model->insertColumn(_modelIndex);
else
model->insertRow(_modelIndex);
}
else // _type == InsertRemove::Remove
{
if (_orientation == Qt::Horizontal)
model->removeColumn(_modelIndex);
else
model->removeRow(_modelIndex);
}
}
示例3: insertColumn
bool MainWindow::insertColumn(const QModelIndex &parent)
{
QAbstractItemModel *model = view->model();
int column = view->selectionModel()->currentIndex().column();
// Insert a column in the parent item.
bool changed = model->insertColumn(column + 1, parent);
if (changed)
model->setHeaderData(column + 1, Qt::Horizontal, QVariant("[No header]"), Qt::EditRole);
updateActions();
return changed;
}
示例4: slotInsertColumnPressed
void TableEditorDialog::slotInsertColumnPressed()
{
Q_ASSERT( m_tableView->model() );
QAbstractItemModel *model = m_tableView->model();
QModelIndex currIndex = m_tableView->currentIndex();
int selectedColumn;
if ( model->columnCount() == 0 )
// +1 is added below.
selectedColumn = -1;
if ( currIndex.isValid() )
selectedColumn = currIndex.column();
else
selectedColumn = m_tableView->model()->columnCount() - 1;
// Insert the column *after* the selection, thus +1
model->insertColumn( selectedColumn + 1 );
}
示例5: insertChild
void MetaEditor::insertChild(QString code, QString contents)
{
QModelIndex index = view->selectionModel()->currentIndex();
QAbstractItemModel *model = view->model();
// restrict children to be a grandchild of the root item
// and make sure you are in column 0 when inserting a child
if (index.parent() != QModelIndex()) {
index = index.parent();
}
int row = index.row();
index = index.sibling(row,0);
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
return;
}
if (!model->insertRow(0, index))
return;
QModelIndex child = model->index(0, 0, index);
model->setData(child, QVariant(code), Qt::EditRole);
for (int column = 1; column < model->columnCount(index); ++column) {
QModelIndex child = model->index(0, column, index);
if (!contents.isEmpty()) {
model->setData(child, QVariant(contents), Qt::EditRole);
} else {
model->setData(child, QVariant(tr("[Place value here]")), Qt::EditRole);
}
if (!model->headerData(column, Qt::Horizontal).isValid())
model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"), Qt::EditRole);
}
view->selectionModel()->setCurrentIndex(model->index(0, 0, index),
QItemSelectionModel::ClearAndSelect);
updateActions();
}
示例6: onAddShop
void CComputerConfViewPrivate::onAddShop()
{
QAbstractItemModel * ptrModel = m_ptrPublic->model();
ptrModel->insertColumn(-1);
}