Esempio n. 1
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
Esempio n. 2
0
def test_save_load_delete_items(qtbot, qApp):
    """ ItemDetails and SeparationIndicator that were saved to disk were
    not retaining ids stored in the fd, causing addItem() to asign new ids.
    Then item properties in layers would be out of sync, etc.
    Fixed by not adding items until after read().
    """
    document = Document()
    person = Person()
    person.setDiagramNotes('here are some notes')
    document.addItem(person)
    data = {}
    document.write(data)
    bdata = pickle.dumps(data)
    #
    document = Document()
    document.read(data)
    ## added to ensure that ItemDetails|SeparationIndicator id's match the id's in the file
    for id, item in document.itemRegistry.items():
        assert id == item.id
    document.selectAll()
    qtbot.clickYesAfter(lambda: document.removeSelection()) # would throw exception