本文整理汇总了C++中model::Model::save方法的典型用法代码示例。如果您正苦于以下问题:C++ Model::save方法的具体用法?C++ Model::save怎么用?C++ Model::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model::Model
的用法示例。
在下文中一共展示了Model::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(FilePersistence, SaveList)
{
QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.createRoot("PartialList"));
model.beginModification(root, "create ");
Model::Text* one = new Model::Text();
one->set("one");
root->list()->append(one);
Model::Text* two = new Model::Text();
two->set("two");
root->list()->append(two);
Model::Text* three = new Model::Text();
three->set("three");
root->list()->append(three);
Model::Text* four = new Model::Text();
four->set("four");
root->list()->append(four);
model.endModification();
model.setName("partial");
model.save(&store);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/partial/partial", testDir + "/partial/partial");
}
示例2:
TEST(FilePersistence, SaveMultipleUnits)
{
QString testDir = QDir::tempPath() + QDir::toNativeSeparators("/Envision/FilePersistence/tests");
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));
model.beginModification(root, "set title");
root->name()->set("Root");
TestNodes::BinaryNode* left = root->setLeft<TestNodes::BinaryNodePersistenceUnit>();
TestNodes::BinaryNode* right = root->setRight<TestNodes::BinaryNode>();
left->name()->set("Left child");
TestNodes::BinaryNode* leftleft = left->setLeft<TestNodes::BinaryNode>();
leftleft->name()->set("in a new unit");
right->name()->set("Right child");
model.endModification();
model.setName("units");
model.save(&store);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/units", testDir + "/units/units");
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/2", testDir + "/units/2");
}
示例3: srcDir
TEST(FilePersistence, ReSaveList)
{
QString srcDir(":/FilePersistence/test/persisted");
QString destDir(QDir::tempPath() + "/Envision/FilePersistence/tests");
QFile src(srcDir + "/partial/partial");
QFile dest(destDir + "/partialResave/partialResave");
if (dest.exists())
{
bool removed = dest.remove();
CHECK_CONDITION(removed);
}
if (!QDir(destDir + "/partialResave").exists())
{
bool createdDir = QDir().mkpath(destDir + "/partialResave");
CHECK_CONDITION(createdDir);
}
bool copied = src.copy(dest.fileName());
CHECK_CONDITION(copied);
bool permissionOk = dest.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
CHECK_CONDITION(permissionOk);
Model::Model model;
FileStore store;
store.setBaseFolder(destDir);
model.load(&store, "partialResave");
TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.root());
CHECK_CONDITION(root->list()->isFullyLoaded() == false);
model.beginModification(root->list(), "fake modification ");
model.endModification();
CHECK_CONDITION(root->list()->isFullyLoaded() == false);
model.setName("partialResave");
model.save(&store);
CHECK_CONDITION(root->list()->isFullyLoaded() == false);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/partialResave/partialResave", destDir + "/partialResave/partialResave");
}
示例4:
TEST(FilePersistence, SavingTypedList)
{
QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
Model::TypedList<Model::Text>* list = dynamic_cast<Model::TypedList<Model::Text>*> (model.createRoot("TypedListOfText"));
model.beginModification(list, "create");
Model::Text* one = new Model::Text();
one->set("one");
list->append(one);
Model::Text* two = new Model::Text();
two->set("two");
list->append(two);
model.endModification();
model.setName("typedList");
model.save(&store);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/typedList/typedList", testDir + "/typedList/typedList");
}