TEST(FilePersistence, LoadingList) { QString testDir = ":/FilePersistence/test/persisted"; Model::Model model; FileStore store; store.setBaseFolder(testDir); model.load(&store, "partial"); TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.root()); CHECK_CONDITION(root != nullptr); Model::List* list = root->list(); CHECK_CONDITION(list != nullptr); CHECK_STR_EQUAL("List", list->typeName() ); CHECK_CONDITION(list->isFullyLoaded() == false); CHECK_INT_EQUAL(1, list->id()); list->loadFully(store); CHECK_CONDITION(list->isFullyLoaded()); CHECK_INT_EQUAL(4, list->size()); Model::Text* one = list->at<Model::Text>(0); Model::Text* two = list->at<Model::Text>(1); Model::Text* three = list->at<Model::Text>(2); Model::Text* four = list->at<Model::Text>(3); CHECK_CONDITION(one != nullptr); CHECK_STR_EQUAL("one", one->get()); CHECK_INT_EQUAL(2, one->id()); CHECK_CONDITION(two != nullptr); CHECK_STR_EQUAL("two", two->get()); CHECK_INT_EQUAL(3, two->id()) CHECK_CONDITION(three != nullptr); CHECK_STR_EQUAL("three", three->get()); CHECK_INT_EQUAL(4, three->id()) CHECK_CONDITION(four != nullptr); CHECK_STR_EQUAL("four", four->get()); CHECK_INT_EQUAL(5, four->id()); }
TEST(FilePersistence, LoadingTypedList) { QString testDir = ":/FilePersistence/test/persisted"; Model::Model model; FileStore store; store.setBaseFolder(testDir); model.load(&store, "typedList"); Model::TypedList<Model::Text>* list = dynamic_cast<Model::TypedList<Model::Text>*> (model.root()); CHECK_CONDITION(list != nullptr); CHECK_STR_EQUAL("TypedListOfText", list->typeName() ); CHECK_INT_EQUAL(2, list->size()); Model::Text* one = list->at(0); Model::Text* two = list->at(1); CHECK_CONDITION(one != nullptr); CHECK_STR_EQUAL("one", one->get()); CHECK_CONDITION(two != nullptr); CHECK_STR_EQUAL("two", two->get()); }
void VUnfinishedOperator::determineChildren() { // TODO: find a better way and place to determine the style of children. Is doing this causing too many updates? // TODO: consider the performance of this. Possibly introduce a style updated boolean for all items so that they know // what's the reason they are being updated. // The style needs to be updated every time since if our own style changes, so will that of the children. layout()->setStyle( &style()->layout()); int delimIndex = 0; int operandIndex = 0; QList<Model::Node*> nodes; bool prefixEmpty = false; while (delimIndex < node()->delimiters()->size() || operandIndex < node()->operands()->size()) { if (delimIndex == operandIndex) { Model::Text* delim = node()->delimiters()->at(delimIndex); if (!delim->get().isEmpty()) nodes.append(delim); else if (delimIndex == 0) prefixEmpty = true; delimIndex++; } else { nodes.append(node()->operands()->at(operandIndex)); operandIndex++; } } layout()->synchronizeWithNodes(nodes, renderer()); for (int i = prefixEmpty ? 1 : 0; i < layout()->length(); i+=2 ) { layout()->at<VText>(i)->setStyle(&style()->delimiters()); // We set these to read-only since that will make keyboard events pass though and allow these events to be handled // by the expression handler. layout()->at<VText>(i)->setEditable(false); } }