Exemple #1
0
void Qtilities::Testing::TestObserver::testTreeChildrenContainment() {
    // Example tree using tree node classes to simplify test:
    QList<QObject*> children;
    TreeNode* rootNode = new TreeNode("Root");
    TreeNode* parentNode1 = rootNode->addNode("Parent 1");
    children << parentNode1;
    TreeNode* parentNode2 = rootNode->addNode("Parent 2");
    children << parentNode2;
    children << parentNode1->addItem("Child 1");
    children << parentNode1->addItem("Child 2");
    children << parentNode2->addItem("Child 3");
    children << parentNode2->addItem("Child 4");
    TreeItem* item = parentNode2->addItem("Child 5");
    children << item;

    // Now create and add a contained observer:
    TreeNode* containedNode = new TreeNode("Contained Node");
    children << containedNode;
    children << containedNode->addItem("Contained Item 1");
    children << containedNode->addItem("Contained Item 2");
    children << containedNode->addItem("Contained Item 3");

    containedNode->setParent(item);

    QList<QObject*> children_verify = rootNode->treeChildren();
    foreach (QObject* obj, children)
        QVERIFY(children_verify.contains(obj) == true);
}
Exemple #2
0
void Qtilities::Testing::TestObserver::testSubjectLimit() {
    TreeNode node;
    node.setSubjectLimit(2);

    QVERIFY(node.addItem("Item 1") != 0);
    QVERIFY(node.addItem("Item 2") != 0);
    QVERIFY(node.addItem("Item 3") == 0);
    QVERIFY(node.setSubjectLimit(1) == false);
    QVERIFY(node.setSubjectLimit(3) == true);
    QVERIFY(node.addItem("Item 3") != 0);
}
void Qtilities::Testing::TestSubjectIterator::testIterationConst() {
    TreeNode* node = new TreeNode;
    node->addItem("1");
    node->addItem("2");
    node->addItem("3");
    node->addItem("4");

    SubjectIterator<QObject> itr(node);
    itr.current()->setObjectName("Test");
    // The following should not compile:
    //ConstSubjectIterator<QObject> constItr(node);
    //constItr.current()->setObjectName("Test");
}
void Qtilities::Testing::TestSubjectIterator::testIterationSimpleFromMiddle() {
    TreeNode node;
    node.addItem("1");
    TreeItem* item2 = node.addItem("2");
    node.addItem("3");

    SubjectIterator<QObject> itr(item2);

    QStringList testList;
    testList << itr.current()->objectName();
    while (itr.hasNext()) {
        testList << itr.next()->objectName();
    }

    QCOMPARE(testList.count(), 2);
    QCOMPARE(testList.at(0), QString("2"));
    QCOMPARE(testList.at(1), QString("3"));
}
Exemple #5
0
void Qtilities::Testing::TestObserver::testCountModificationStateChanges() {
    TreeNode node("testCountModificationStateChangesNode");
    QSignalSpy spy(&node, SIGNAL(modificationStateChanged(bool)));

    node.addItem("1");
    node.setModificationState(false);
    node.addItem("2");
    node.addItem("3");
    //LOG_INFO("testCountModificationStateChanges: Signal Spy: modificationStateChanged(bool) -> count: " + QString::number(spy.count()));
    QCOMPARE(spy.count(), 3);

    spy.clear();

    node.startProcessingCycle();
    node.addItem("4");
    node.addItem("5");
    node.addItem("6");
    TreeNode* nodeA = node.addNode("A");
    nodeA->addItem("7");
    TreeNode* nodeB = node.addNode("B");
    nodeB->addItem("8");

    node.endProcessingCycle();
    //LOG_INFO("testCountModificationStateChanges: Signal Spy: modificationStateChanged(bool) -> count: " + QString::number(spy.count()));
    QCOMPARE(spy.count(), 1);

    node.saveToFile("testCountModificationStateChanges.xml");
    node.deleteAll();
    spy.clear();
    node.loadFromFile("testCountModificationStateChanges.xml");
    //LOG_INFO("testCountModificationStateChanges: Signal Spy: modificationStateChanged(bool) -> count: " + QString::number(spy.count()));
    QCOMPARE(spy.count(), 1);
    spy.clear();

    node.deleteAll();
    spy.clear();
    //node.startProcessingCycle();
    node.loadFromFile("testCountModificationStateChanges.xml");
    //node.endProcessingCycle();
    //LOG_INFO("testCountModificationStateChanges: Signal Spy: modificationStateChanged(bool) -> count: " + QString::number(spy.count()));
    QCOMPARE(spy.count(), 1);
    spy.clear();
}
Exemple #6
0
void Qtilities::Testing::TestObserver::testRecursiveAttachmentContained() {
    // Example tree using tree node classes to simplify test:
    TreeNode* rootNode = new TreeNode("Root");
    TreeNode* childNode = rootNode->addNode("Parent Node");
    TreeItem* item = childNode->addItem("Child Item");

    // Now create and add a contained observer:
    TreeNode* containedNode = new TreeNode("Contained Node");
    containedNode->setParent(item);
    QVERIFY(containedNode->attachSubject(rootNode) == false);
}
void Qtilities::Testing::TestSubjectIterator::testIterationSimpleFromStart() {
    TreeNode node;
    TreeItem* item1 = node.addItem("1");
    node.addItem("2");
    node.addItem("3");
    node.addItem("4");

    SubjectIterator<Qtilities::CoreGui::TreeItem> itr(item1);

    QStringList testList;
    testList << itr.current()->objectName();
    while (itr.hasNext()) {
        testList << itr.next()->objectName();
    }

    QCOMPARE(testList.count(), 4);
    QCOMPARE(testList.at(0), QString("1"));
    QCOMPARE(testList.at(1), QString("2"));
    QCOMPARE(testList.at(2), QString("3"));
    QCOMPARE(testList.at(3), QString("4"));
}
Exemple #8
0
void Qtilities::Testing::TestObserver::testTreeAtContainment() {
    // Example tree using tree node classes to simplify test:
    TreeNode* rootNode = new TreeNode("Root");
    TreeNode* parentNode1 = rootNode->addNode("Parent 1");
    TreeNode* parentNode2 = rootNode->addNode("Parent 2");
    parentNode1->addItem("Child 1");
    parentNode1->addItem("Child 2");
    parentNode2->addItem("Child 3");
    parentNode2->addItem("Child 4");
    TreeItem* item = parentNode2->addItem("Child 5");

    // Now create and add a contained observer:
    TreeNode* containedNode = new TreeNode("Contained Node");
    containedNode->addItem("Contained Item 1");
    containedNode->addItem("Contained Item 2");
    TreeItem* test_item = containedNode->addItem("Contained Item 3");
    containedNode->setParent(item);

    LOG_INFO(QString::number(rootNode->treeCount()));
    QVERIFY(rootNode->treeAt(10) == test_item);
}
void Qtilities::Testing::TestSubjectIterator::testIterationComplex() {
    TreeNode node;
    TreeNode* nodeA = node.addNode("A");
    TreeNode* nodeB = node.addNode("B");
    nodeA->addItem("1");
    TreeItem* shared_item = nodeA->addItem("2");
    nodeA->addItem("3");
    nodeB->addItem("4");
    nodeB->addItem("5");
    nodeB->attachSubject(shared_item);
    nodeB->addItem("6");

    // If we want to iterate through the subjects in nodeA:
    SubjectIterator<QObject> itrA(nodeA,SubjectIterator<QObject>::IterateChildren);
    QVERIFY(itrA.current() != 0);

    // In this case item1 will be skipped:
    QStringList testListA;
    testListA << itrA.current()->objectName();
    while (itrA.hasNext()) {
        testListA << itrA.next()->objectName();
    }

    QCOMPARE(testListA.count(), 3);
    QCOMPARE(testListA.at(0), QString("1"));
    QCOMPARE(testListA.at(1), QString("2"));
    QCOMPARE(testListA.at(2), QString("3"));

    // If we want to iterate through the subjects in nodeB:
    SubjectIterator<QObject> itrB(nodeB,SubjectIterator<QObject>::IterateChildren);

    // In this case item1 will be skipped:
    QStringList testListB;
    testListB << itrB.current()->objectName();
    while (itrB.hasNext()) {
        testListB << itrB.next()->objectName();
    }

    QCOMPARE(testListB.count(), 4);
    QCOMPARE(testListB.at(0), QString("4"));
    QCOMPARE(testListB.at(1), QString("5"));
    QCOMPARE(testListB.at(2), QString("2"));
    QCOMPARE(testListB.at(3), QString("6"));

    // If we want to iterate through the subjects in nodeB:
    SubjectIterator<QObject> itrC(shared_item,nodeB);

    // In this case item1 will be skipped:
    QStringList testListC;
    testListC << itrC.current()->objectName();
    while (itrC.hasNext()) {
        testListC << itrC.next()->objectName();
    }

    QCOMPARE(testListC.count(), 2);
    QCOMPARE(testListC.at(0), QString("2"));
    QCOMPARE(testListC.at(1), QString("6"));

    // If we want to iterate through the subjects in nodeB:
    SubjectIterator<QObject> itrD(shared_item,nodeA);

    // In this case item1 will be skipped:
    QStringList testListD;
    testListD << itrD.current()->objectName();
    while (itrD.hasNext()) {
        testListD << itrD.next()->objectName();
    }

    QCOMPARE(testListD.count(), 2);
    QCOMPARE(testListD.at(0), QString("2"));
    QCOMPARE(testListD.at(1), QString("3"));
}
Exemple #10
0
int main(int argc, char *argv[])
{
    QtilitiesApplication a(argc, argv);
    QtilitiesApplication::setOrganizationName("Jaco Naude");
    QtilitiesApplication::setOrganizationDomain("Qtilities");
    QtilitiesApplication::setApplicationName("Qtilities Tester");
    QtilitiesApplication::setApplicationVersion(QtilitiesApplication::qtilitiesVersionString());

    // Create the observer widget in tree mode:
    ObserverWidget* observer_widget = new ObserverWidget;
    observer_widget->resize(600,850);
    QtilitiesApplication::setMainWindow(observer_widget);

    Log->setLoggerSessionConfigPath(QtilitiesApplication::applicationSessionPath());
    LOG_INITIALIZE();

    TreeNode* rootNodeCategorized = new TreeNode("Root");
    rootNodeCategorized->enableCategorizedDisplay();
    // TODO: This breaks the toolbar for some reason... Looks like a display issue since it only happens in QTabWidget:
    rootNodeCategorized->displayHints()->setDisplayFlagsHint(ObserverHints::ItemView | ObserverHints::ActionToolBar);
    rootNodeCategorized->displayHints()->setActionHints(ObserverHints::ActionAllHints);
    rootNodeCategorized->displayHints()->setCategoryEditingFlags(ObserverHints::CategoriesEditableAllLevels | ObserverHints::CategoriesAcceptSubjectDrops);
    rootNodeCategorized->displayHints()->setDragDropHint(ObserverHints::AllowDrags);
    rootNodeCategorized->addItem("Child 1",QtilitiesCategory("Category 1::A",QString("::")));
    rootNodeCategorized->addItem("Child 2",QtilitiesCategory("Category 1::B",QString("::")));
    rootNodeCategorized->addItem("Child 3");
    rootNodeCategorized->addItem("Child 4",QtilitiesCategory("Category 2"));
    TreeItem* modified_item = rootNodeCategorized->addItem("Child 5",QtilitiesCategory("Category 2"));
    rootNodeCategorized->displayHints()->setModificationStateDisplayHint(ObserverHints::CharacterModificationStateDisplay);
    modified_item->setModificationState(true);

    // Init and show the observer widget:
    observer_widget->setObserverContext(rootNodeCategorized);
    observer_widget->initialize();

    // Test the tree model:
    new ModelTest(observer_widget->proxyModel());
    // Test the table model:
    //new ModelTest(observer_widget->tableModel());

    observer_widget->show();

    QStringList items;
    items << "A" << "B" << "C";
    rootNodeCategorized->addItems(items);

    TreeNode* nodeA = rootNodeCategorized->addNode("Node A");
    nodeA->copyHints(rootNodeCategorized->displayHints());
    TreeNode* nodeB = rootNodeCategorized->addNode("Node B");
    nodeB->copyHints(rootNodeCategorized->displayHints());

    nodeA->addItem("Child 1",QtilitiesCategory("Category 3::A",QString("::")));
    nodeA->addItem("Child 2",QtilitiesCategory("Category 4::B",QString("::")));
    nodeA->addItem("Child 3");
    nodeA->addItem("Child 4",QtilitiesCategory("Category 5"));

    nodeB->addItem("Child 1",QtilitiesCategory("Category 6::A",QString("::")));
    nodeB->addItem("Child 2",QtilitiesCategory("Category 7::B",QString("::")));
    nodeB->addItem("Child 3");
    nodeB->addItem("Child 4",QtilitiesCategory("Category 8"));

    return a.exec();
}