def test_init_deinit(qApp): model = LayerModel() assert model.rowCount() == 0 document = Document() layer1 = Layer(name='Layer 1') layer2 = Layer(name='Layer 2', active=True) layer3 = Layer(name='Layer 3', active=True) document.addItems(layer1, layer2, layer3) model.document = document assert model.rowCount() == 3 assert model.data(model.index(0, 0), model.IdRole) == layer1.id assert model.data(model.index(1, 0), model.IdRole) == layer2.id assert model.data(model.index(2, 0), model.IdRole) == layer3.id assert model.data(model.index(0, 0)) == 'Layer 1' assert model.data(model.index(1, 0)) == 'Layer 2' assert model.data(model.index(2, 0)) == 'Layer 3' assert model.data(model.index(0, 0), model.ActiveRole) == Qt.Unchecked assert model.data(model.index(1, 0), model.ActiveRole) == Qt.Checked assert model.data(model.index(2, 0), model.ActiveRole) == Qt.Checked model.resetDocument() assert model.rowCount() == 0 with pytest.raises(IndexError): model.data(model.index(0, 0))
def test_update_set_tag_on_inspected_items_out_of_layer(qApp): """ Show layer with people that have emotional process symbols that don’t have the layer’s tags, inspect those symbols from personal timeline, add tag for the layer -> symbols don’t appear. """ tags = ['here'] s = Document() s.setTags(tags) layer1 = Layer(tags=tags) s.addItem(layer1) p1 = Person(name='p1', tags=tags) p2 = Person(name='p2', tags=tags) s.addItems(p1, p2) cutoff = Emotion(kind=util.ITEM_CUTOFF, personA=p1, personB=p2) s.addItems(cutoff) layer1.setActive(True) date = QDate.currentDate() assert p1.shouldShowFor(date, tags) == True assert p2.shouldShowFor(date, tags) == True assert cutoff.shouldShowFor(date, tags) == False assert cutoff.isVisible() == False # Simulate inspecting a hidden emotion from person props cutoff.setTags(tags) assert cutoff.shouldShowFor(date, tags) == True assert cutoff.isVisible() == True
def test_hasActiveLayers(qApp): document = Document() assert document.hasActiveLayers == False layer = Layer(active=True) document.addItem(layer) assert document.hasActiveLayers == True layer.setActive(False) assert document.hasActiveLayers == False
def test_hasActiveLayers(qApp): document = Document() model = DocumentModel() model.document = document assert model.hasActiveLayers == document.hasActiveLayers layer = Layer(active=True) document.addItem(layer) assert model.hasActiveLayers == document.hasActiveLayers layer.setActive(False) assert model.hasActiveLayers == document.hasActiveLayers
def test_reset_layered_props(qApp): """ Item.write was not explicitly requesting non-layered prop values. """ document = Document() person = Person() layer = Layer(name='Layer 1', active=True, storeGeometry=True) document.addItems(person, layer) person.setItemPos(QPointF(10, 10)) assert layer.active() == True assert person.pos() == QPointF(10, 10) document.resetAll() # was throwing exception in commands.py assert person.itemPos() == QPointF() assert person.pos() == QPointF()
def test_layered_property(qApp): document = Document() item = LayeredItem() layer = Layer(name='Layer 1') document.addItem(item) document.addItem(layer) assert item.num() == -1 assert item.count == 0 assert item.layeredCount == 0 item.setNum(1) assert item.num() == 1 assert item.count == 1 assert item.layeredCount == 0 layer.setActive(True) assert item.num() == 1 assert item.count == 1 assert item.layeredCount == 0 item.prop('num').set(2) # item.setNum(2) assert item.num() == 2 assert item.count == 2 assert item.layeredCount == 1 layer.setActive(False) assert item.num() == 1 assert item.count == 3 assert item.layeredCount == 1 layer.setActive(True) assert item.num() == 2 assert item.count == 4 assert item.layeredCount == 2 item.prop('num').reset() assert item.num() == 1 assert item.count == 5 assert item.layeredCount == 2 layer.setActive(False) assert item.num() == 1 assert item.count == 5 assert item.layeredCount == 2
def test_new_items_have_current_tags(qApp): s = Document() s.setTags(['are', 'here', 'you']) layer1 = Layer(tags=['here']) s.addItem(layer1) p1 = Person(name='p1') assert p1.tags() == [] layer1.setActive(True) assert p1.tags() == [] p2 = Person(name='p2') s.addItem(p2) assert p1.tags() == [] assert p2.tags() == ['here'] layer2 = Layer(tags=['you'], active=True) s.addItem(layer2) assert p1.tags() == [] assert p2.tags() == ['here'] p3 = Person(name='p3') s.addItem(p3) assert p1.tags() == [] assert p2.tags() == ['here'] assert p3.tags() == ['here', 'you'] layer1.setActive(False) p4 = Person(name='p4') s.addItem(p4) assert p1.tags() == [] assert p2.tags() == ['here'] assert p3.tags() == ['here', 'you'] assert p4.tags() == ['you']
def test_exclusiveLayerSelection(qApp): document = Document() layerModel = LayerModel() layerModel.document = document layer1 = Layer(name='Layer 1', active=True) layer2 = Layer(name='Layer 2') document.addItems(layer1, layer2) assert layer1.active() == True layerModel.setActiveExclusively(1) assert layer2.active() == True assert layer1.active() == False
def test_read_write_layered_props(qApp): """ Item.write was not explicitly requesting non-layered prop values. """ document = Document() person = Person() layer = Layer(name='Layer 1', active=True) document.addItems(person, layer) person.setItemPos(QPointF(10, 10)) person.setColor('#ff0000') # data = {} document.write(data) document = Document() document.read(data) assert document.people()[0].pos() == QPointF(10, 10) assert document.people()[0].color() == '#ff0000' assert document.people()[0].pen().color().name() == '#ff0000' document.layers()[0].setActive(False) assert document.people()[0].color() == None assert document.people()[0].pen().color().name() == util.PEN.color().name() document.layers()[0].setActive(True) assert document.people()[0].color() == '#ff0000' assert document.people()[0].pen().color().name() == '#ff0000'
def test_layered_property_undo_redo(qApp): """ commands.SetItemProperty wasn't working for non-layered properties. """ document = Document() item = LayeredItem() layer = Layer(name='Layer 1') document.addItems(layer, item) # 0 assert item.num() == -1 assert item.count == 0 assert item.layeredCount == 0 item.setNum(1, undo=True) # 1 assert item.num() == 1 assert item.count == 1 assert item.layeredCount == 0 commands.stack().undo() # 0 assert item.num() == -1 assert item.count == 2 assert item.layeredCount == 0 commands.stack().redo() # 1 assert item.num() == 1 assert item.count == 3 assert item.layeredCount == 0
def test_undo_add_remove_layered_item_props(qtbot, qApp): document = Document() male = Person(name='Male', kind='male') female = Person(name='Female', kind='female') marriage = Marriage(personA=male, personB=female) divorcedEvent = Event(parent=marriage, uniqueId='divorced', date=QDate(1900, 1, 1)) layer = Layer(name='Layer 1') document.addItems(male, female, marriage, layer) # unlayered = { 'male': QPointF(-100, -50), 'maleDetails': QPointF(100, 100), 'female': QPointF(100, -50), 'femaleDetails': QPointF(-100,-200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(-25, 0), } layered = { 'male': QPointF(-200, -150), 'maleDetails': QPointF(-100, -100), 'female': QPointF(100, 50), 'femaleDetails': QPointF(100, 200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(25, -100), } # layered layer.setItemProperty(male.id, 'itemPos', layered['male']) layer.setItemProperty(male.detailsText.id, 'itemPos', layered['maleDetails']) layer.setItemProperty(female.id, 'itemPos', layered['female']) layer.setItemProperty(female.detailsText.id, 'itemPos', layered['femaleDetails']) layer.setItemProperty(marriage.detailsText.id, 'itemPos', layered['marriageDetails']) layer.setItemProperty(marriage.separationIndicator.id, 'itemPos', layered['marriageSep']) # unlayered male.setItemPos(unlayered['male'], undo=False) male.detailsText.setItemPos(unlayered['maleDetails'], undo=False) female.setItemPos(unlayered['female'], undo=False) female.detailsText.setItemPos(unlayered['femaleDetails'], undo=False) # marriage.setDivorced(True, undo=False) marriage.separationIndicator.setItemPos(unlayered['marriageSep'], undo=False) marriage.detailsText.setItemPos(unlayered['marriageDetails'], undo=False) assert len(document.items()) == 22 document.selectAll() qtbot.clickYesAfter(lambda: document.removeSelection()) assert len(document.items()) == 0 commands.stack().undo() assert len(document.items()) == 22 commands.stack().redo() assert len(document.items()) == 0
def test_layered_properties(qApp): """ Ensure correct layered prop updates for marriage+marriage-indicators. """ document = Document() male = Person(name='Male', kind='male') female = Person(name='Female', kind='female') marriage = Marriage(personA=male, personB=female) divorcedEvent = Event(parent=marriage, uniqueId='divorced', date=QDate(1900, 1, 1)) layer = Layer(name='Layer 1') document.addItems(male, female, marriage, layer) # unlayered = { 'male': QPointF(-100, -50), 'maleDetails': QPointF(100, 100), 'female': QPointF(100, -50), 'femaleDetails': QPointF(-100,-200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(-25, 0), } layered = { 'male': QPointF(-200, -150), 'maleDetails': QPointF(-100, -100), 'female': QPointF(100, 50), 'femaleDetails': QPointF(100, 200), 'marriageSep': QPointF(100, 0), 'marriageDetails': QPointF(25, -100), } # layered layer.setItemProperty(male.id, 'itemPos', layered['male']) layer.setItemProperty(male.detailsText.id, 'itemPos', layered['maleDetails']) layer.setItemProperty(female.id, 'itemPos', layered['female']) layer.setItemProperty(female.detailsText.id, 'itemPos', layered['femaleDetails']) layer.setItemProperty(marriage.detailsText.id, 'itemPos', layered['marriageDetails']) layer.setItemProperty(marriage.separationIndicator.id, 'itemPos', layered['marriageSep']) # unlayered male.setItemPos(unlayered['male'], undo=False) male.detailsText.setItemPos(unlayered['maleDetails'], undo=False) female.setItemPos(unlayered['female'], undo=False) female.detailsText.setItemPos(unlayered['femaleDetails'], undo=False) # marriage.setDivorced(True, undo=False) marriage.separationIndicator.setItemPos(unlayered['marriageSep'], undo=False) marriage.detailsText.setItemPos(unlayered['marriageDetails'], undo=False) assert male.pos() == unlayered['male'] assert male.detailsText.pos() == unlayered['maleDetails'] assert female.pos() == unlayered['female'] assert female.detailsText.pos() == unlayered['femaleDetails'] assert marriage.detailsText.pos() == unlayered['marriageDetails'] assert marriage.separationIndicator.pos() == unlayered['marriageSep'] layer.setActive(True) assert male.pos() == layered['male'] assert male.detailsText.pos() == layered['maleDetails'] assert female.pos() == layered['female'] assert female.detailsText.pos() == layered['femaleDetails'] assert marriage.detailsText.pos() == layered['marriageDetails'] assert marriage.separationIndicator.pos() == layered['marriageSep'] layer.setActive(False) assert male.pos() == unlayered['male'] assert male.detailsText.pos() == unlayered['maleDetails'] assert female.pos() == unlayered['female'] assert female.detailsText.pos() == unlayered['femaleDetails'] assert marriage.detailsText.pos() == unlayered['marriageDetails'] assert marriage.separationIndicator.pos() == unlayered['marriageSep'] layer.resetItemProperty(male.prop('itemPos')) layer.resetItemProperty(male.detailsText.prop('itemPos')) layer.resetItemProperty(female.prop('itemPos')) layer.resetItemProperty(female.detailsText.prop('itemPos')) layer.resetItemProperty(marriage.detailsText.prop('itemPos')) layer.resetItemProperty(marriage.separationIndicator.prop('itemPos')) layer.setActive(True) assert male.pos() == unlayered['male'] assert male.detailsText.pos() == unlayered['maleDetails'] assert female.pos() == unlayered['female'] assert female.detailsText.pos() == unlayered['femaleDetails'] assert marriage.detailsText.pos() == unlayered['marriageDetails'] assert marriage.separationIndicator.pos() == unlayered['marriageSep']
def test_set_active(qApp): model = LayerModel() document = Document() layer1 = Layer(name='Layer 1') layer2 = Layer(name='Layer 2') layer3 = Layer(name='Layer 3') document.addItems(layer1, layer2, layer3) model.document = document assert layer1.active() == False assert layer2.active() == False assert layer3.active() == False def set(row, value): assert model.setData(model.index(row, 0), value, model.ActiveRole) is True set(0, True) assert layer1.active() == True assert layer2.active() == False assert layer2.active() == False set(2, True) assert layer1.active() == True assert layer2.active() == False assert layer3.active() == True set(0, False) assert layer1.active() == False assert layer2.active() == False assert layer3.active() == True set(2, False) assert layer1.active() == False assert layer2.active() == False assert layer3.active() == False
def test_moveLayer(qApp): document = Document() model = LayerModel() layer0 = Layer(name='Layer 0') layer1 = Layer(name='Layer 1') layer2 = Layer(name='Layer 2') document.addItems(layer0, layer1, layer2) model.document = document assert layer0.order() == 0 assert layer1.order() == 1 assert layer2.order() == 2 model.moveLayer(2, 1) assert layer0.order() == 0 assert layer1.order() == 2 assert layer2.order() == 1 model.moveLayer(0, 2) assert layer0.order() == 2 assert layer1.order() == 1 assert layer2.order() == 0 assert document.layers() == [layer2, layer1, layer0] # test reload file after reordering layers data = {} document.write(data) document2 = Document() document2.read(data) _layer0 = document2.query1(name='Layer 0') _layer1 = document2.query1(name='Layer 1') _layer2 = document2.query1(name='Layer 2') assert _layer0.order() == 2 assert _layer1.order() == 1 assert _layer2.order() == 0 assert document2.layers() == [_layer2, _layer1, _layer0]