本文整理汇总了C++中QStandardItemModel::data方法的典型用法代码示例。如果您正苦于以下问题:C++ QStandardItemModel::data方法的具体用法?C++ QStandardItemModel::data怎么用?C++ QStandardItemModel::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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);
}
}
示例4: getProductBoxID
uint32 getProductBoxID(QComboBox* pBox, int32 index)
{
QStandardItemModel* pProductModel =
static_cast<QStandardItemModel*>(pBox->model());
QModelIndex id_index = pProductModel->index(index, 0);
return pProductModel->data(id_index).toUInt();
}
示例5: showAllCites
void OnyxMainWindow::showAllCites()
{
QStandardItemModel model;
QModelIndex selected = model.invisibleRootItem()->index();
citeModel(model, selected);
TreeViewDialog bookmark_view(this);
bookmark_view.setModel(&model);
QVector<int> percentages;
percentages.push_back(80);
percentages.push_back(20);
bookmark_view.tree().setColumnWidth(percentages);
int ret = bookmark_view.popup(QCoreApplication::tr("Citations"));
// Returned from the bookmark view.
onyx::screen::watcher().enqueue(this, onyx::screen::ScreenProxy::GC);
this->update();
if (ret != QDialog::Accepted)
{
onyx::screen::watcher().enqueue(this, onyx::screen::ScreenProxy::GU);
return;
}
CRBookmark *pos = (CRBookmark *)(model.data(bookmark_view.selectedItem(), Qt::UserRole + 1).toInt());
view_->goToBookmark(pos);
}
示例6: mouseDoubleClickEvent
void OntologyClassView::mouseDoubleClickEvent(QMouseEvent *event){
// QTreeView::mouseDoubleClickEvent(event);
QModelIndex index = indexAt(event->pos());
if(index.isValid()){
QStandardItemModel *omodel = qobject_cast<QStandardItemModel*>(model());
if(!omodel)
return;
QStandardItem *pItem = omodel->itemFromIndex(index);
if(pItem){
ClassDescriptionDialog *pClassDescriptionDialog = new ClassDescriptionDialog(this);
QString classId = pItem->data(Qt::DisplayRole).toString();
pClassDescriptionDialog->setClassId(classId);
pClassDescriptionDialog->setupData();
QModelIndex parentindex = index.parent();
if(parentindex.isValid()){
pClassDescriptionDialog->setParentClassId(omodel->data(parentindex).toString());
}
if(pClassDescriptionDialog->exec() == QDialog::Rejected){
// QTreeView::mouseDoubleClickEvent(event);
return;
}
QString className = pClassDescriptionDialog->classId();
pItem->setData(className,Qt::DisplayRole);
pItem->setData(className);
}
}
}
示例7: main
int main(int argc, char **argv) {
QApplication app(argc, argv);
QStandardItemModel model;
QStandardItem *parentItem = model.invisibleRootItem();
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;
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();
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();
}
示例8: filterAcceptsRow
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
// Holen des Items
QStandardItemModel* source = (QStandardItemModel*) sourceModel();
QModelIndex index = source->index(sourceRow, 0, sourceParent);
// Prüfen der Filterbedingungen
if (maxSizeFilter)
return (source->data(index, sizeRole).toInt() <= maxSize);
return true;
}
示例9: flagChanged
void ModelsManager::flagChanged(const QModelIndex& idx)
{
QAbstractItemView* view = static_cast<QAbstractItemView*>(sender());
int row = idx.row();
QStandardItemModel* model = m_models->modelForView(view);
QStandardItem* item = model->item(row, 0);
Register r;
r.name = item->text();
r.value = model->data(idx).toString();
emit registerChanged(r);
}
示例10: pathFromIndex
QString ExpressionCompleter::pathFromIndex ( const QModelIndex & index ) const
{
QStandardItemModel * m = static_cast<QStandardItemModel*>(model());
if (m->data(index, Qt::UserRole).canConvert<App::ObjectIdentifier>()) {
App::ObjectIdentifier p = m->data(index, Qt::UserRole).value<App::ObjectIdentifier>();
QString pStr = Base::Tools::fromStdString(p.toString());
QString parentStr;
QModelIndex parent = index.parent();
while (parent.isValid()) {
QString thisParentStr = m->data(parent, Qt::UserRole).toString();
parentStr = thisParentStr + parentStr;
parent = parent.parent();
}
return parentStr + pStr;
}
else if (m->data(index, Qt::UserRole).canConvert<QString>()) {
QModelIndex parent = index;
QString parentStr;
while (parent.isValid()) {
QString thisParentStr = m->data(parent, Qt::UserRole).toString();
parentStr = thisParentStr + parentStr;
parent = parent.parent();
}
return parentStr;
}
else
return QString();
}
示例11: setProductBoxID
void setProductBoxID(QComboBox* pBox, uint32 product_id)
{
QStandardItemModel* pProductModel
= static_cast<QStandardItemModel*>(pBox->model());
int32 rowCount = pProductModel->rowCount();
for( int32 row = 0; row < rowCount; ++row )
{
QModelIndex id_index = pProductModel->index(row, 0);
if( product_id == pProductModel->data(id_index).toUInt() )
{
pBox->setCurrentIndex(row);
break;
}
}
}
示例12: dropEvent
void DataSetValuesView::dropEvent(QDropEvent *event)
{
QStandardItemModel model;
model.dropMimeData(event->mimeData(), Qt::CopyAction, 0,0, QModelIndex());
int numRows = model.rowCount();
for (int row = 0; row < numRows; ++row)
{
QModelIndex index = model.index(row, 0);
DataClassAutoId_t id = model.data(index, Qt::UserRole).toUInt();
m_bufferValues->ApplyInput(id);
}
event->acceptProposedAction();
}
示例13: yearDateChanged
void AssetsViewer::yearDateChanged(const QDate & year){
double sumOfYearlyValues = 0.00;
QString yearString = year.toString("yyyy");
AssetsManager manager;
QStandardItemModel *model = new QStandardItemModel(this);
model = manager.getYearlyValues(year);
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__)<< "model in viewer = "<< model->rowCount();
for (int i = 0; i < model->rowCount(); i += 1)
{
double yearlyValue = model->data(model->index(i,YEARLY_VALUE),Qt::DisplayRole).toDouble();
if (WarnDebugMessage)
qDebug() << __FILE__ << QString::number(__LINE__) << " yearlyValue =" << QString::number(yearlyValue) ;
sumOfYearlyValues += yearlyValue;
}
QString textLabel = "Total value to declare for "+yearString+" = "+QString::number(sumOfYearlyValues);
ui->declareLabel->setText(textLabel);
}
示例14: onAddSiblingClass
void OntologyClassView::onAddSiblingClass(){
if(!OBJECTLEVELMANAGER->count())
return;
QModelIndex index = selectionModel()->currentIndex();
if(!index.isValid())
return;
QStandardItemModel *omodel = qobject_cast<QStandardItemModel*>(model());
if(!omodel)
return;
ClassDescriptionDialog *pClassDescriptionDialog = new ClassDescriptionDialog(this);
pClassDescriptionDialog->setParentClassId(omodel->data(index.parent()).toString());
if(pClassDescriptionDialog->exec() == QDialog::Rejected)
return;
QString classId = pClassDescriptionDialog->classId();
// if(omodel->insertRows(omodel->rowCount(index.parent()),1,index.parent())){
QStandardItem *pItem = new QStandardItem();
pItem->setData(classId,Qt::DisplayRole);
pItem->setData(classId);
QList<QStandardItem*> parentItemList = omodel->findItems(pClassDescriptionDialog->parentClassId(),Qt::MatchExactly | Qt::MatchRecursive);
if(!parentItemList.isEmpty())
{
QStandardItem *pParentItem = parentItemList.first();
pParentItem->setChild(pParentItem->rowCount(),pItem);
}else
omodel->setItem(omodel->rowCount(index.parent()),pItem);
setCurrentIndex(omodel->index(omodel->rowCount(index.parent()),0,index.parent()));
// }
}
示例15: onRemoveCurrentClass
void OntologyClassView::onRemoveCurrentClass(){
QModelIndex index = selectionModel()->currentIndex();
if(!index.isValid())
return;
int ret = QMessageBox::question(this,tr("Class delete"),tr("You are going to delete this Class, all sub classes and rules related to this class will be also deleted. If you want to delete this Class click Yes else click No."),QMessageBox::Yes,QMessageBox::No);
if(ret == QMessageBox::No)
return;
if(ret == QMessageBox::Yes){
QStandardItemModel *omodel = qobject_cast<QStandardItemModel*>(model());
if(!omodel)
return;
QString id = omodel->data(index,Qt::DisplayRole).toString();
OntologyClass *pClass = ONTOLOGYCLASSIFICATIONMANAGER->ontologyClassById(id);
if(!pClass)
return;
if(pClass->childCount()){
QMessageBox::critical(this,tr("Delete Failed"),tr("Failed to delete the class. Delete all sub classes first and then try again."));
return;
}
OntologyClass *pParentClass = ONTOLOGYCLASSIFICATIONMANAGER->ontologyClassById(pClass->parentId());
if(pParentClass)
pParentClass->removeChild(pClass);
pClass->clearFuzzyRuleHash();
ONTOLOGYCLASSIFICATIONMANAGER->removeOntologyClass(pClass);
omodel->removeRows(index.row(),1,index.parent());
}
}