本文整理汇总了C++中QVariantList::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantList::replace方法的具体用法?C++ QVariantList::replace怎么用?C++ QVariantList::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantList
的用法示例。
在下文中一共展示了QVariantList::replace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: changePOTCAR
void TabEdit::changePOTCAR(QListWidgetItem *item)
{
QSettings settings; // Already set up in avogadro/src/main.cpp
// Get symbol and filename
QStringList strl = item->text().split(":");
QString symbol = strl.at(0).trimmed();
QString filename = strl.at(1).trimmed();
QStringList files;
QString path = settings.value("xtalopt/templates/potcarPath", "").toString();
QFileDialog dialog (NULL, QString("Select pot file for atom %1").arg(symbol), path);
dialog.selectFile(filename);
dialog.setFileMode(QFileDialog::ExistingFile);
if (dialog.exec()) {
files = dialog.selectedFiles();
if (files.size() != 1) { return;} // Only one file per element
filename = files.first();
settings.setValue("xtalopt/templates/potcarPath", dialog.directory().absolutePath());
}
else { return;} // User cancel file selection.
// "POTCAR info" is of type
// QList<QHash<QString, QString> >
// e.g. a list of hashes containing
// [atomic symbol : pseudopotential file] pairs
QVariantList potcarInfo = m_opt->optimizer()->getData("POTCAR info").toList();
QVariantHash hash = potcarInfo.at(ui_list_optStep->currentRow()).toHash();
hash.insert(symbol,QVariant(filename));
potcarInfo.replace(ui_list_optStep->currentRow(), hash);
m_opt->optimizer()->setData("POTCAR info", potcarInfo);
qobject_cast<VASPOptimizer*>(m_opt->optimizer())->buildPOTCARs();
updateEditWidget();
}
示例2: deleteRecord
void QuotesApp::deleteRecord()
{
QVariantList indexPath = mListView->selected();
if (!indexPath.isEmpty()) {
QVariantMap map = mDataModel->data(indexPath).toMap();
// Delete the item from the database based on unique ID. If successful, remove it
// from the data model (which will remove the data from the list).
if (mQuotesDbHelper->deleteById(map["id"])) {
// Delete is the only operation where the logics for updating which item
// is selected is handled in code.
// Before the item is removed, we store how many items there are in the
// category that the item is removed from, we need this to select a new item.
QVariantList categoryIndexPath;
categoryIndexPath.append(indexPath.first());
int childrenInCategory = mDataModel->childCount(categoryIndexPath);
mDataModel->remove(map);
// After removing the selected item, we want another quote to be shown.
// So we select the next quote relative to the removed one in the list.
if (childrenInCategory > 1) {
// If the Category still has items, select within the category.
int itemInCategory = indexPath.last().toInt();
if (itemInCategory < childrenInCategory - 1) {
mListView->select(indexPath);
} else {
// The last item in the category was removed, select the previous item relative to the removed item.
indexPath.replace(1, QVariant(itemInCategory - 1));
mListView->select(indexPath);
}
} else {
// If no items left in the category, move to the next category.
// If there are no more categories below(next), select the previous category.
// If no items left at all, navigate to the list.
QVariantList lastIndexPath = mDataModel->last();
if (!lastIndexPath.isEmpty()) {
if (indexPath.first().toInt() <= lastIndexPath.first().toInt()) {
mListView->select(indexPath);
} else {
mListView->select(mDataModel->last());
}
}
} // else statment
} //if statement
} // top if statement
} // deleteRecord()
示例3: initPickerValues
void CustomItemProvider::initPickerValues(DataModel* pickerModel)
{
QVariantList indexPath;
indexPath << 0;
// Get the number of columns by checking the child count of the models root element.
mColumnCount = pickerModel->childCount(QVariantList());
// The column range correspond to the child count of the models column data elements,
// this information is reported back in the range function above.
for (int i = 0; i < mColumnCount; i++) {
indexPath.replace(0, i);
mUpperRanges.insert(i, pickerModel->childCount(indexPath) - 1);
}
}
示例4: fieldData
//.........这里部分代码省略.........
}
case FieldTextValue:
{
QStringList list;
for (int i = 0; i < data.sources_size(); i++)
list.append(QHostAddress(data.sources(i).v4()).toString());
return list.join(", ");
}
default:
break;
}
break;
}
case kGroupRecords:
{
switch(attrib)
{
case FieldValue:
{
QVariantList grpRecords = GmpProtocol::fieldData(
index, attrib, streamIndex).toList();
for (int i = 0; i < data.group_records_size(); i++)
{
QVariantMap grpRec = grpRecords.at(i).toMap();
OstProto::Gmp::GroupRecord rec = data.group_records(i);
grpRec["groupRecordAddress"] = QHostAddress(
rec.group_address().v4()).toString();
QStringList sl;
for (int j = 0; j < rec.sources_size(); j++)
sl.append(QHostAddress(rec.sources(j).v4()).toString());
grpRec["groupRecordSourceList"] = sl;
grpRecords.replace(i, grpRec);
}
return grpRecords;
}
case FieldFrameValue:
{
QVariantList list = GmpProtocol::fieldData(
index, attrib, streamIndex).toList();
QByteArray fv;
for (int i = 0; i < data.group_records_size(); i++)
{
OstProto::Gmp::GroupRecord rec = data.group_records(i);
QByteArray rv = list.at(i).toByteArray();
rv.insert(4, QByteArray(4+4*rec.sources_size(), char(0)));
qToBigEndian(rec.group_address().v4(),
(uchar*)(rv.data()+4));
for (int j = 0; j < rec.sources_size(); j++)
{
qToBigEndian(rec.sources(j).v4(),
(uchar*)(rv.data()+8+4*j));
}
fv.append(rv);
}
return fv;
}
case FieldTextValue:
{
QStringList list = GmpProtocol::fieldData(
index, attrib, streamIndex).toStringList();
for (int i = 0; i < data.group_records_size(); i++)
{
OstProto::Gmp::GroupRecord rec = data.group_records(i);
QString recStr = list.at(i);
QString str;
str.append(QString("Group: %1").arg(
QHostAddress(rec.group_address().v4()).toString()));
str.append("; Sources: ");
QStringList sl;
for (int j = 0; j < rec.sources_size(); j++)
sl.append(QHostAddress(rec.sources(j).v4()).toString());
str.append(sl.join(", "));
recStr.replace("XXX", str);
list.replace(i, recStr);
}
return list.join("\n").insert(0, "\n");
}
default:
break;
}
break;
}
default:
break;
}
return GmpProtocol::fieldData(index, attrib, streamIndex);
}