本文整理汇总了C++中QStandardItemModel::index方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel::index方法的具体用法?C++ QStandardItemModel::index怎么用?C++ QStandardItemModel::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel::index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDialog
FilterDlgImpl::FilterDlgImpl(QWidget* parent)
: QDialog(parent)
{
_setupUi();
m_query->setRootIsDecorated(false);
m_query->setSelectionMode(QAbstractItemView::NoSelection);
QStandardItemModel *model = new QStandardItemModel(0, 5, this);
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Column"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Condition1"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Pattern1"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Condition2"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Pattern2"));
model->insertRow(0);
model->insertRow(1);
model->insertRow(2);
model->setData(model->index(0, 0), tr("Date"));
model->setData(model->index(0, 1), "=");
model->setData(model->index(1, 0), tr("Count"));
model->setData(model->index(1, 1), "=");
model->setData(model->index(2, 0), tr("Description"));
m_query->setModel(model);
setMinimumSize(680,100);
}
示例2: model
void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
{
QStandardItemModel model(3, 1);
for (int i = 0; i < 3; ++i) {
QStandardItem *item = new QStandardItem(QLatin1String("Item ") + QString::number(i));
item->setCheckable(true);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
model.setItem(i, item);
}
QTableView view;
view.setModel(&model);
view.setItemDelegate(new TestItemDelegate);
view.show();
view.selectAll();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QStyleOptionViewItem option;
option.rect = view.visualRect(model.index(0, 0));
// mimic QStyledItemDelegate::initStyleOption logic
option.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
option.checkState = Qt::CheckState(model.index(0, 0).data(Qt::CheckStateRole).toInt());
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center()
+ QPoint(checkMargin, 0);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos);
QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex()));
QCOMPARE(model.item(0)->checkState(), Qt::Checked);
}
示例3: selection
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStandardItemModel *model = new QStandardItemModel(7, 4, this);
for (int row = 0; row < 7; ++row) {
for (int column = 0; column < 4; ++column) {
QStandardItem *item = new QStandardItem(QString("%1")
.arg(row * 4 + column));
model->setItem(row, column, item);
}
}
tableView = new QTableView;
tableView->setModel(model);
setCentralWidget(tableView);
// 获取视图的项目选择模型
QItemSelectionModel *selectionModel = tableView->selectionModel();
// 定义左上角和右下角的索引,然后使用这两个索引创建选择
QModelIndex topLeft;
QModelIndex bottomRight;
topLeft = model->index(1, 1, QModelIndex());
bottomRight = model->index(5, 2, QModelIndex());
QItemSelection selection(topLeft, bottomRight);
// 使用指定的选择模式来选择项目
selectionModel->select(selection, QItemSelectionModel::Select);
}
示例4: changeEvent
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgFilletEdges::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
int index = ui->shapeObject->currentIndex();
// only get the items from index 1 on since the first one will be added automatically
int count = ui->shapeObject->count() - 1;
QStringList text;
QList<QVariant> data;
for (int i=0; i<count; i++) {
text << ui->shapeObject->itemText(i+1);
data << ui->shapeObject->itemData(i+1);
}
ui->retranslateUi(this);
for (int i=0; i<count; i++) {
ui->shapeObject->addItem(text.at(i));
ui->shapeObject->setItemData(i+1, data.at(i));
}
ui->shapeObject->setCurrentIndex(index);
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
count = model->rowCount();
for (int i=0; i<count; i++) {
int id = model->data(model->index(i, 0), Qt::UserRole).toInt();
model->setData(model->index(i, 0), QVariant(tr("Edge%1").arg(id)));
}
}
else {
QWidget::changeEvent(e);
}
}
示例5: setupFillet
void DlgFilletEdges::setupFillet(const std::vector<App::DocumentObject*>& objs)
{
App::DocumentObject* base = d->fillet->Base.getValue();
const std::vector<Part::FilletElement>& e = d->fillet->Edges.getValues();
std::vector<App::DocumentObject*>::const_iterator it = std::find(objs.begin(), objs.end(), base);
if (it != objs.end()) {
// toggle visibility
Gui::ViewProvider* vp;
vp = Gui::Application::Instance->getViewProvider(d->fillet);
if (vp) vp->hide();
vp = Gui::Application::Instance->getViewProvider(base);
if (vp) vp->show();
int current_index = (it - objs.begin()) + 1;
ui->shapeObject->setCurrentIndex(current_index);
on_shapeObject_activated(current_index);
ui->shapeObject->setEnabled(false);
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
for (std::vector<Part::FilletElement>::const_iterator et = e.begin(); et != e.end(); ++et) {
std::vector<int>::iterator it = std::find(d->edge_ids.begin(), d->edge_ids.end(), et->edgeid);
if (it != d->edge_ids.end()) {
int index = it - d->edge_ids.begin();
model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole);
model->setData(model->index(index, 1), QVariant(QLocale::system().toString(et->radius1,'f',2)));
model->setData(model->index(index, 2), QVariant(QLocale::system().toString(et->radius2,'f',2)));
}
}
}
}
示例6: split
void split(int argc, char** argv) {
//Syntax: split [source_file] [total_parts] [destination_dir]
if (argc >= 3) {
QStandardItemModel* fileModel = new QStandardItemModel(1, 6);
fileModel->deleteLater();
SplitterCore* core = new SplitterCore(fileModel);
core->deleteLater();
//TODO: connect signals and implement them to show progress in terminal
QString filePath(argv[0]);
int parts = QString(argv[1]).toInt();
QString destPath(argv[2]);
QFileInfo fileinfo(filePath);
if (fileinfo.isFile()) {
fileModel->setData(fileModel->index(0, 0), filePath);
fileModel->setData(fileModel->index(0, 1), destPath);
fileModel->setData(fileModel->index(0, 2), 0);
fileModel->setData(fileModel->index(0, 3), parts);
fileModel->setData(fileModel->index(0, 4), fileinfo.size());
}
core->start();
core->wait();
} else {
help(PartProcessor::kSplit);
}
}
示例7: on_shapeObject_activated
void DlgFilletEdges::on_shapeObject_activated(int index)
{
d->object = 0;
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
model->removeRows(0, model->rowCount());
QByteArray name = ui->shapeObject->itemData(index).toByteArray();
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc)
return;
App::DocumentObject* part = doc->getObject((const char*)name);
if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
d->object = part;
TopoDS_Shape myShape = static_cast<Part::Feature*>(part)->Shape.getValue();
// build up map edge->face
TopTools_IndexedDataMapOfShapeListOfShape edge2Face;
TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, edge2Face);
TopTools_IndexedMapOfShape mapOfShape;
TopExp::MapShapes(myShape, TopAbs_EDGE, mapOfShape);
// populate the model
d->edge_ids.clear();
for (int i=1; i<= edge2Face.Extent(); ++i) {
// set the index value as user data to use it in accept()
const TopTools_ListOfShape& los = edge2Face.FindFromIndex(i);
if (los.Extent() == 2) {
// set the index value as user data to use it in accept()
const TopoDS_Shape& edge = edge2Face.FindKey(i);
// Now check also the continuity to only allow C0-continious
// faces
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont == GeomAbs_C0) {
int id = mapOfShape.FindIndex(edge);
d->edge_ids.push_back(id);
}
}
}
model->insertRows(0, d->edge_ids.size());
int index = 0;
for (std::vector<int>::iterator it = d->edge_ids.begin(); it != d->edge_ids.end(); ++it) {
model->setData(model->index(index, 0), QVariant(tr("Edge%1").arg(*it)));
model->setData(model->index(index, 0), QVariant(*it), Qt::UserRole);
model->setData(model->index(index, 1), QVariant(QLocale::system().toString(1.0,'f',2)));
model->setData(model->index(index, 2), QVariant(QLocale::system().toString(1.0,'f',2)));
std::stringstream element;
element << "Edge" << *it;
if (Gui::Selection().isSelected(part, element.str().c_str()))
model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole);
else
model->setData(model->index(index, 0), Qt::Unchecked, Qt::CheckStateRole);
index++;
}
}
}
示例8: uintEdit
void tst_QItemDelegate::uintEdit()
{
QListView view;
QStandardItemModel model;
{
QStandardItem *data=new QStandardItem;
data->setEditable(true);
data->setData(QVariant((uint)1), Qt::DisplayRole);
model.setItem(0, 0, data);
}
{
QStandardItem *data=new QStandardItem;
data->setEditable(true);
data->setData(QVariant((uint)1), Qt::DisplayRole);
model.setItem(1, 0, data);
}
view.setModel(&model);
view.setEditTriggers(QAbstractItemView::AllEditTriggers);
const QModelIndex firstCell = model.index(0, 0);
QCOMPARE(firstCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
view.selectionModel()->setCurrentIndex(model.index(0, 0), QItemSelectionModel::Select);
view.edit(firstCell);
QSpinBox *sb = view.findChild<QSpinBox*>();
QVERIFY(sb);
sb->stepUp();
// Select another index to trigger the end of editing.
const QModelIndex secondCell = model.index(1, 0);
view.selectionModel()->setCurrentIndex(secondCell, QItemSelectionModel::Select);
QCOMPARE(firstCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
QCOMPARE(firstCell.data(Qt::DisplayRole).toUInt(), static_cast<uint>(2));
view.edit(secondCell);
// The first spinbox is deleted with deleteLater, so it is still there.
QList<QSpinBox*> sbList = view.findChildren<QSpinBox*>();
QCOMPARE(sbList.size(), 2);
sb = sbList.at(1);
sb->stepDown(); // 1 -> 0
sb->stepDown(); // 0 (no effect)
sb->stepDown(); // 0 (no effect)
// Select another index to trigger the end of editing.
view.selectionModel()->setCurrentIndex(firstCell, QItemSelectionModel::Select);
QCOMPARE(secondCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
QCOMPARE(secondCell.data(Qt::DisplayRole).toUInt(), static_cast<uint>(0));
}
示例9: f
bool DB2TableModel::load(const QString &filename)
{
bool ret = true;
QFile f(filename);
if (!f.open(QIODevice::ReadOnly))
return false;
char magic[5] = {0};
f.read(magic, 4);
if (QString(magic) == "WDB2")
{
clearDbInfo();
DB2Header hdr;
memset(&hdr, 0, sizeof(DB2Header));
f.seek(0);
f.read((char*)&hdr, sizeof(DB2Header));
loadDB2(&hdr, &f);
}
else if (QString(magic) == "WDBC")
{
clearDbInfo();
DBCHeader hdr;
memset(&hdr, 0, sizeof(DBCHeader));
f.seek(0);
f.read((char*)&hdr, sizeof(DBCHeader));
loadDBC(&hdr, &f);
}
else
{
return false;
}
defDlg->fillDefenition(filename, dbbuild);
if (defDlg->exec() == QDialog::Accepted)
{
QAbstractTableModel::beginResetModel();
QStandardItemModel *st = defDlg->defenition();
for (int i = 0; i < st->rowCount(); i++)
{
if (i < fieldCount)
{
fieldsOffsets[i].title = st->data(st->index(i, 0)).toString();
fieldsOffsets[i].type = (FldType)FindTypeForName(st->data(st->index(i, 1)).toString());
}
}
QAbstractTableModel::endResetModel();
}
return ret;
}
示例10: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// 创建标准项模型
QStandardItemModel model;
// 获取模型的根项(Root Item),根项是不可见的
QStandardItem *parentItem = model.invisibleRootItem();
// 创建标准项item0,并设置显示文本,图标和工具提示
QStandardItem *item0 = new QStandardItem;
item0->setText("A");
QPixmap pixmap0(50,50);
pixmap0.fill("red");
item0->setIcon(QIcon(pixmap0));
item0->setToolTip("indexA");
// 将创建的标准项作为根项的子项
parentItem->appendRow(item0);
// 将创建的标准项作为新的父项
parentItem = item0;
// 创建新的标准项,它将作为item0的子项
QStandardItem *item1 = new QStandardItem;
item1->setText("B");
QPixmap pixmap1(50,50);
pixmap1.fill("blue");
item1->setIcon(QIcon(pixmap1));
item1->setToolTip("indexB");
parentItem->appendRow(item1);
// 创建新的标准项,这里使用了另一种方法来设置文本、图标和工具提示
QStandardItem *item2 = new QStandardItem;
QPixmap pixmap2(50,50);
pixmap2.fill("green");
item2->setData("C", Qt::EditRole);
item2->setData("indexC", Qt::ToolTipRole);
item2->setData(QIcon(pixmap2), Qt::DecorationRole);
parentItem->appendRow(item2);
// 在树视图中显示模型
QTreeView view;
view.setModel(&model);
view.show();
// 获取item0的索引并输出item0的子项数目,然后输出了item1的显示文本和工具提示
QModelIndex indexA = model.index(0, 0, QModelIndex());
qDebug() << "indexA row count: " << model.rowCount(indexA);
QModelIndex indexB = model.index(0, 0, indexA);
qDebug() << "indexB text: " << model.data(indexB, Qt::EditRole).toString();
qDebug() << "indexB toolTip: " << model.data(indexB, Qt::ToolTipRole).toString();
return app.exec();
}
示例11: QWidget
Widget::Widget(QWidget *parentWidget)
: QWidget(parentWidget)
{
QStandardItemModel *model = new QStandardItemModel();
QModelIndex parent;
for (int i = 0; i < 4; ++i) {
parent = model->index(0, 0, parent);
model->insertRows(0, 1, parent);
model->insertColumns(0, 1, parent);
QModelIndex index = model->index(0, 0, parent);
model->setData(index, i);
}
}
示例12: loadBodies
static void loadBodies(QStandardItemModel &model, QString path)
{
QSettings ini(path, QSettings::IniFormat);
if (ini.status() != QSettings::NoError)
{
qFatal("%s could not be opened", path.toUtf8().constData());
}
QStringList list = ini.childGroups();
model.setRowCount(list.size());
for (int i = 0; i < list.size(); ++i)
{
ini.beginGroup(list[i]);
model.setData(model.index(i, 0, QModelIndex()), ini.value("name").toString(), Qt::DisplayRole);
model.setData(model.index(i, 1, QModelIndex()), ini.value("size").toString(), Qt::DisplayRole);
model.setData(model.index(i, 2, QModelIndex()), ini.value("buildPower", 0).toString(), Qt::DisplayRole);
model.setData(model.index(i, 3, QModelIndex()), ini.value("buildPoints", 0).toString(), Qt::DisplayRole);
model.setData(model.index(i, 4, QModelIndex()), ini.value("weight").toString(), Qt::DisplayRole);
model.setData(model.index(i, 5, QModelIndex()), ini.value("hitpoints").toString(), Qt::DisplayRole);
model.setData(model.index(i, 6, QModelIndex()), ini.value("model").toString(), Qt::DisplayRole);
model.setData(model.index(i, 7, QModelIndex()), ini.value("weaponSlots").toString(), Qt::DisplayRole);
model.setData(model.index(i, 8, QModelIndex()), ini.value("powerOutput").toString(), Qt::DisplayRole);
model.setData(model.index(i, 9, QModelIndex()), ini.value("armourKinetic").toString(), Qt::DisplayRole);
model.setData(model.index(i, 10, QModelIndex()), ini.value("armourHeat").toString(), Qt::DisplayRole);
model.setData(model.index(i, 11, QModelIndex()), ini.value("flameModel").toString(), Qt::DisplayRole);
model.setData(model.index(i, 12, QModelIndex()), ini.value("designable", false).toString(), Qt::DisplayRole);
model.setData(model.index(i, 13, QModelIndex()), ini.value("droidType", "DROID").toString(), Qt::DisplayRole);
model.setData(model.index(i, 14, QModelIndex()), list[i], Qt::DisplayRole);
ini.endGroup();
}
}
示例13: addMessage
void CMessageDock::addMessage(const QUuid& uuid, int lineNo, CategoryType category, const QString& description)
{
QString iconPath, categoryName;
switch(category)
{
case InfomationCategory:
iconPath = ":/images/tango/small/dialog-information.png";
categoryName = tr("Information");
m_countOfInfomationMessages++;
break;
case WarningCategory:
iconPath = ":/images/icons/small/software-update-urgent-yellow.png";
categoryName = tr("Warning");
m_countOfWarningMessages++;
break;
case ErrorCategory:
iconPath = ":/images/tango/small/dialog-error.png";
categoryName = tr("Error");
m_countOfErrorMessages++;
break;
default:
break;
}
QStandardItemModel* model
= static_cast<QStandardItemModel*>(
static_cast<QSortFilterProxyModel*>(m_listWidget->model())->sourceModel()) ;
int row = model->rowCount();
model->insertRow(row);
if( !iconPath.isEmpty() ) {
model->setData(model->index(row, CategoryColumn ), QIcon(iconPath), Qt::DecorationRole);
model->setData(model->index(row, CategoryColumn ), categoryName);
}
model->setData(model->index(row, RefIndexColumn ), m_messages.size(), Qt::UserRole + 1);
model->setData(model->index(row, DescriptionColumn), description);
model->setData(model->index(row, FileNameColumn ), theFile->fileName(uuid));
model->setData(model->index(row, LineNoColumn ), 0 < lineNo ? QString("%1").arg(lineNo) : "");
model->setData(model->index(row, LineNoColumn ), Qt::AlignRight, Qt::TextAlignmentRole);
MessageInfoType info;
info.description= description;
info.category = category;
info.uuid = uuid;
info.lineNo = lineNo;
m_messages.push_back(info);
updateMessagesCount();
}
示例14: main
int main(int argc, char** argv) {
QApplication app(argc, argv);
#if GUI
checkScansDirectoryExists();
MainWindow window;
window.show();
#endif
#if PIE
QStandardItemModel* model = new QStandardItemModel(0, 2);
model->setHeaderData(0, Qt::Horizontal, "Label");
model->setHeaderData(1, Qt::Horizontal, "Quantity");
QDir scanDirectory("/home/valentin/Images/Scans");
QStringList mangasList = scanDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
int row = 0;
for (const QString& manga: mangasList) {
model->insertRow(row, QModelIndex());
QDir mangaDirectory(scanDirectory.path()+"/"+manga);
QString nbChapters = QString::number(mangaDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot).size());
int r = (16*(row+1))%256;
int g = (32*(row+1))%256;
int b = (64*(row+1))%256;
model->setData(model->index(row, 0, QModelIndex()), manga);
model->setData(model->index(row, 1, QModelIndex()), nbChapters);
model->setData(model->index(row, 0, QModelIndex()), QColor(r, g, b), Qt::DecorationRole);
row++;
}
PieView* view = new PieView;
//QTableView* view = new QTableView;
view->setModel(model);
//QHeaderView* headerView = view->horizontalHeader();
//headerView->setStretchLastSection(true);
view->show();
#endif
return app.exec();
}
示例15: slotCompletePackageNameFinished
void DsWidget::slotCompletePackageNameFinished(QNetworkReply* reply)
{
QUrl replyUrl = reply->url();
QApplication::restoreOverrideCursor();
// Check if this is the reply for the last request, or a delayed reply we are receiving just now
if( QString::compare(replyUrl.toString(), m_lastQueryUrl.toString(), Qt::CaseInsensitive) != 0 )
{
kDebug() << "Received a delayed reply, discarding it";
return; // It was a delayed reply, discard it
}
if ( reply->error() )
{
kDebug() << "Didn't receive a reply for request " << replyUrl.toEncoded().constData() << " - " << qPrintable(reply->errorString());
}
else
{
QByteArray ba = reply->readAll();
if( ba.isEmpty() )
{
kDebug() << "No completion data received for request " << replyUrl.toEncoded().constData() << "(probably no package matches that pattern)";
return;
}
QList<QByteArray> pkgSuggestions = ba.split('\n');
QStandardItemModel *m = new QStandardItemModel(pkgSuggestions.count(), 2, m_pkgLineEdit->completer());
for( int i = 0; i < pkgSuggestions.count(); ++i)
{
QModelIndex pkgIdx = m->index(i, 0);
QModelIndex descIdx = m->index(i, 1);
QList<QByteArray> pkgDescSplit = pkgSuggestions.at(i).split('|');
QString pkg = pkgDescSplit.at(0);
QString desc =pkgDescSplit.at(1);
m->setData(pkgIdx, pkg);
m->setData(descIdx, desc);
}
m_pkgLineEdit->completer()->setModel(m);
}
m_pkgLineEdit->completer()->complete();
reply->deleteLater();
}