def testBookmarksById(self):
        project = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(project)

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager.addBookmark(b3)

        self.assertFalse(manager.bookmarkById('asdf').name())
        self.assertEqual(manager.bookmarkById('1'), b)
        self.assertEqual(manager.bookmarkById('2'), b2)
        self.assertEqual(manager.bookmarkById('3'), b3)
    def testRemoveBookmark(self):
        project = QgsProject()

        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        self.manager = QgsBookmarkManager.createProjectBasedManager(project)
        bookmark_removed_spy = QSignalSpy(self.manager.bookmarkRemoved)
        bookmark_about_to_be_removed_spy = QSignalSpy(
            self.manager.bookmarkAboutToBeRemoved)
        # tests that bookmark still exists when bookmarkAboutToBeRemoved is fired
        self.manager.bookmarkAboutToBeRemoved.connect(
            self.bookmarkAboutToBeRemoved)

        # not added, should fail
        self.assertFalse(self.manager.removeBookmark(b.id()))
        self.assertEqual(len(bookmark_removed_spy), 0)
        self.assertEqual(len(bookmark_about_to_be_removed_spy), 0)

        self.assertTrue(self.manager.addBookmark(b)[1])
        self.assertEqual(self.manager.bookmarks(), [b])
        self.assertTrue(self.manager.removeBookmark(b.id()))
        self.assertEqual(len(self.manager.bookmarks()), 0)
        self.assertEqual(len(bookmark_removed_spy), 1)
        self.assertEqual(bookmark_removed_spy[0][0], '1')
        self.assertEqual(len(bookmark_about_to_be_removed_spy), 1)
        self.assertEqual(bookmark_about_to_be_removed_spy[0][0], '1')
        self.assertTrue(self.aboutFired)
        self.manager = None
    def testBookmarkGroups(self):
        project = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(project)

        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        manager.addBookmark(b)
        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setGroup('group1')
        manager.addBookmark(b2)
        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setGroup('group2')
        manager.addBookmark(b3)

        # test that groups are adjusted when bookmarks are added
        self.assertEqual(manager.groups(), ['', 'group1', 'group2'])

        manager.removeBookmark('3')

        # test that groups are adjusted when a bookmark is removed
        self.assertEqual(manager.groups(), ['', 'group1'])

        b2.setGroup('groupmodified')
        manager.updateBookmark(b2)

        # test that groups are adjusted when a bookmark group is edited
        self.assertEqual(manager.groups(), ['', 'groupmodified'])
    def testBookmarks(self):
        project = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(project)

        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        self.assertEqual(manager.bookmarks(), [b])
        manager.addBookmark(b2)
        self.assertEqual(manager.bookmarks(), [b, b2])
        manager.addBookmark(b3)
        self.assertEqual(manager.bookmarks(), [b, b2, b3])
    def testReadWriteXml(self):
        """
        Test reading and writing bookmark manager state to XML
        """
        project = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(project)

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager.addBookmark(b3)

        # save to xml
        doc = QDomDocument("testdoc")
        elem = manager.writeXml(doc)
        doc.appendChild(elem)

        # restore from xml
        project2 = QgsProject()
        manager2 = QgsBookmarkManager.createProjectBasedManager(project2)
        self.assertTrue(manager2.readXml(elem, doc))

        self.assertEqual(len(manager2.bookmarks()), 3)
        names = [c.name() for c in manager2.bookmarks()]
        self.assertCountEqual(names, ['b1', 'b2', 'b3'])
    def testExportImport(self):
        p = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(p)
        manager2 = QgsBookmarkManager.createProjectBasedManager(p)
        manager3 = QgsBookmarkManager.createProjectBasedManager(p)

        tmpDir = QTemporaryDir()
        tmpFile = "{}/bookmarks.xml".format(tmpDir.path())

        # no managers
        self.assertTrue(QgsBookmarkManager.exportToFile(tmpFile, []))
        self.assertTrue(manager3.importFromFile(tmpFile))
        self.assertFalse(manager3.bookmarks())

        # no bookmarks
        self.assertTrue(QgsBookmarkManager.exportToFile(tmpFile, [manager]))
        self.assertTrue(manager3.importFromFile(tmpFile))
        self.assertFalse(manager3.bookmarks())

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager2.addBookmark(b3)

        # export one manager's bookmarks
        self.assertTrue(QgsBookmarkManager.exportToFile(tmpFile, [manager]))
        self.assertTrue(manager3.importFromFile(tmpFile))
        self.assertEqual([(b.name(), b.extent())
                          for b in manager3.bookmarks()],
                         [(b.name(), b.extent()) for b in [b, b2]])

        manager3.clear()
        # export both manager's bookmarks
        self.assertTrue(
            QgsBookmarkManager.exportToFile(tmpFile, [manager, manager2]))
        self.assertTrue(manager3.importFromFile(tmpFile))
        self.assertEqual([(b.name(), b.extent())
                          for b in manager3.bookmarks()],
                         [(b.name(), b.extent()) for b in [b, b2, b3]])
    def testAddBookmark(self):
        project = QgsProject()
        b = QgsBookmark()
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem('EPSG:3111')))

        manager = QgsBookmarkManager.createProjectBasedManager(project)

        bookmark_about_to_be_added_spy = QSignalSpy(
            manager.bookmarkAboutToBeAdded)
        bookmark_added_spy = QSignalSpy(manager.bookmarkAdded)
        id, res = manager.addBookmark(b)
        self.assertTrue(res)
        self.assertEqual(len(bookmark_about_to_be_added_spy), 1)
        self.assertEqual(bookmark_about_to_be_added_spy[0][0], id)
        self.assertEqual(len(bookmark_added_spy), 1)
        self.assertEqual(bookmark_added_spy[0][0], id)

        b = manager.bookmarkById(id)
        self.assertEqual(b.name(), 'b1')
        self.assertEqual(
            b.extent(),
            QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4),
                                   QgsCoordinateReferenceSystem('EPSG:3111')))

        # adding it again should fail
        id, res = manager.addBookmark(b)
        self.assertFalse(res)

        # try adding a second bookmark
        b2 = QgsBookmark()
        b2.setId('my id')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        id2, res = manager.addBookmark(b2)
        self.assertTrue(res)
        self.assertEqual(id2, 'my id')
        self.assertEqual(len(bookmark_added_spy), 2)
        self.assertEqual(bookmark_about_to_be_added_spy[1][0], 'my id')
        self.assertEqual(len(bookmark_about_to_be_added_spy), 2)
        self.assertEqual(bookmark_added_spy[1][0], 'my id')

        # adding a bookmark with duplicate id should fail
        b3 = QgsBookmark()
        b3.setId('my id')

        id, res = manager.addBookmark(b3)
        self.assertFalse(res)
    def testApplicationInstance(self):
        """
        Test storage in the application instance
        """
        manager = QgsApplication.bookmarkManager()

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager.addBookmark(b3)

        manager2 = QgsApplication.bookmarkManager()
        self.assertEqual(manager2.bookmarks(), [b, b2, b3])

        manager3 = QgsBookmarkManager(QgsProject.instance())
        self.assertEqual(manager3.bookmarks(), [])
    def testUpdateBookmark(self):
        project = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(project)
        changed_spy = QSignalSpy(manager.bookmarkChanged)

        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        self.assertFalse(manager.updateBookmark(b))
        self.assertEqual(len(changed_spy), 0)
        manager.addBookmark(b)

        b.setName('new b1')
        self.assertTrue(manager.updateBookmark(b))
        self.assertEqual(manager.bookmarkById('1').name(), 'new b1')
        self.assertEqual(len(changed_spy), 1)
        self.assertEqual(changed_spy[-1][0], '1')

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))
        manager.addBookmark(b2)

        b.setName('new b1 2')
        b2.setName('new b2 2')
        self.assertTrue(manager.updateBookmark(b))
        self.assertEqual(manager.bookmarkById('1').name(), 'new b1 2')
        self.assertEqual(manager.bookmarkById('2').name(), 'b2')
        self.assertEqual(len(changed_spy), 2)
        self.assertEqual(changed_spy[-1][0], '1')
        self.assertTrue(manager.updateBookmark(b2))
        self.assertEqual(manager.bookmarkById('1').name(), 'new b1 2')
        self.assertEqual(manager.bookmarkById('2').name(), 'new b2 2')
        self.assertEqual(len(changed_spy), 3)
        self.assertEqual(changed_spy[-1][0], '2')
    def testClear(self):
        project = QgsProject()
        manager = QgsBookmarkManager.createProjectBasedManager(project)

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager.addBookmark(b3)

        bookmark_removed_spy = QSignalSpy(manager.bookmarkRemoved)
        bookmark_about_to_be_removed_spy = QSignalSpy(
            manager.bookmarkAboutToBeRemoved)
        manager.clear()
        self.assertEqual(len(manager.bookmarks()), 0)
        self.assertEqual(len(bookmark_removed_spy), 3)
        self.assertEqual(len(bookmark_about_to_be_removed_spy), 3)
    def testMoveBookmark(self):
        """
        Test moving a bookmark from one manager to another
        """
        p = QgsProject()
        manager = QgsBookmarkManager(p)
        manager2 = QgsBookmarkManager(p)

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager2.addBookmark(b3)

        self.assertEqual(manager.bookmarks(), [b, b2])
        self.assertEqual(manager2.bookmarks(), [b3])

        self.assertFalse(manager.moveBookmark('bbbb', manager2))
        self.assertFalse(manager.moveBookmark(b3.id(), manager2))
        self.assertEqual(manager.bookmarks(), [b, b2])
        self.assertEqual(manager2.bookmarks(), [b3])
        self.assertTrue(manager.moveBookmark(b.id(), manager2))
        self.assertEqual(manager.bookmarks(), [b2])
        self.assertEqual(manager2.bookmarks(), [b3, b])
        self.assertFalse(manager.moveBookmark(b.id(), manager2))
        self.assertTrue(manager2.moveBookmark(b3.id(), manager))
        self.assertEqual(manager.bookmarks(), [b2, b3])
        self.assertEqual(manager2.bookmarks(), [b])
    def testFileStorage(self):
        """
        Test file bound manager
        """
        manager = QgsBookmarkManager()

        tmpDir = QTemporaryDir()
        tmpFile = "{}/bookmarks.xml".format(tmpDir.path())

        manager.initialize(tmpFile)

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager.addBookmark(b3)

        # destroy manager, causes write to disk
        manager.deleteLater()
        QCoreApplication.sendPostedEvents(None, QEvent.DeferredDelete)
        del manager

        # create another new manager with same key, should contain existing bookmarks
        manager2 = QgsBookmarkManager()
        self.assertFalse(manager2.bookmarks())
        manager2.initialize(tmpFile)
        self.assertEqual(manager2.bookmarks(), [b, b2, b3])

        # but a manager with a different key should not...
        tmpFile2 = "{}/bookmarks2.xml".format(tmpDir.path())
        manager3 = QgsBookmarkManager()
        manager3.initialize(tmpFile2)
        self.assertEqual(manager3.bookmarks(), [])
Beispiel #13
0
    def testRenameGroup(self):
        """
        Test renaming a bookmark group
        """
        p = QgsProject()
        manager = QgsBookmarkManager(p)

        # add a bunch of bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setName('b1')
        b.setGroup('g1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setName('b2')
        b2.setGroup('g1')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setGroup('g3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        manager.addBookmark(b)
        manager.addBookmark(b2)
        manager.addBookmark(b3)

        changed_spy = QSignalSpy(manager.bookmarkChanged)
        self.assertEqual([b.group() for b in manager.bookmarks()],
                         ['g1', 'g1', 'g3'])

        manager.renameGroup('xxxxx', 'yyyyy')
        self.assertEqual([b.group() for b in manager.bookmarks()],
                         ['g1', 'g1', 'g3'])
        self.assertEqual(len(changed_spy), 0)
        manager.renameGroup('', '')
        self.assertEqual([b.group() for b in manager.bookmarks()],
                         ['g1', 'g1', 'g3'])
        self.assertEqual(len(changed_spy), 0)
        manager.renameGroup('g1', 'g2')
        self.assertEqual([b.group() for b in manager.bookmarks()],
                         ['g2', 'g2', 'g3'])
        self.assertEqual(len(changed_spy), 2)
        self.assertEqual(changed_spy[0][0], '1')
        self.assertEqual(changed_spy[1][0], '2')
        manager.renameGroup('g3', 'g2')
        self.assertEqual([b.group() for b in manager.bookmarks()],
                         ['g2', 'g2', 'g2'])
        self.assertEqual(len(changed_spy), 3)
        self.assertEqual(changed_spy[2][0], '3')
        manager.renameGroup('g2', 'g')
        self.assertEqual([b.group() for b in manager.bookmarks()],
                         ['g', 'g', 'g'])
        self.assertEqual(len(changed_spy), 6)
        self.assertEqual(changed_spy[3][0], '1')
        self.assertEqual(changed_spy[4][0], '2')
        self.assertEqual(changed_spy[5][0], '3')
    def testBookmarkModel(self):
        p = QgsProject()
        project_manager = QgsBookmarkManager.createProjectBasedManager(p)
        app_manager = QgsBookmarkManager()

        # initially no bookmarks
        model = QgsBookmarkManagerModel(app_manager, project_manager)
        self.assertEqual(model.rowCount(), 0)
        self.assertEqual(model.columnCount(), 8)
        self.assertFalse(model.data(model.index(-1, 0)))
        self.assertFalse(model.data(model.index(1, 0)))
        self.assertFalse(model.data(model.index(0, 0)))
        self.assertFalse(
            model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleName))

        self.assertEqual(model.headerData(0, Qt.Horizontal), 'Name')
        self.assertEqual(model.headerData(9, Qt.Horizontal), 10)
        self.assertEqual(model.headerData(-1, Qt.Horizontal), 0)

        self.assertFalse(model.setData(model.index(-1, 0), 4, Qt.EditRole))
        self.assertFalse(model.setData(model.index(0, 0), 4, Qt.EditRole))

        self.assertFalse(
            int(model.flags(model.index(0, 0)) & Qt.ItemIsEnabled))
        self.assertFalse(
            int(model.flags(model.index(0, 0)) & Qt.ItemIsEditable))

        # add some bookmarks
        b = QgsBookmark()
        b.setId('1')
        b.setGroup('group 1')
        b.setName('b1')
        b.setExtent(
            QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        b2 = QgsBookmark()
        b2.setId('2')
        b2.setGroup('group 2')
        b2.setName('b2')
        b2.setExtent(
            QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42),
                                   QgsCoordinateReferenceSystem('EPSG:4326')))

        app_manager.addBookmark(b)
        app_manager.addBookmark(b2)

        self.assertEqual(model.rowCount(), 2)
        self.assertFalse(model.data(model.index(-1, 0)))
        self.assertEqual(model.data(model.index(0, 0)), 'b1')
        self.assertEqual(model.data(model.index(0, 1)), 'group 1')
        self.assertEqual(model.data(model.index(0, 2)), 11.0)
        self.assertEqual(model.data(model.index(0, 3)), 21.0)
        self.assertEqual(model.data(model.index(0, 4)), 31.0)
        self.assertEqual(model.data(model.index(0, 5)), 41.0)
        self.assertEqual(model.data(model.index(0, 6)), 'EPSG:4326')
        self.assertEqual(model.data(model.index(0, 7)), None)
        self.assertEqual(model.data(model.index(0, 7), Qt.CheckStateRole),
                         Qt.Unchecked)
        self.assertEqual(
            model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleName),
            'b1')
        self.assertEqual(
            model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleGroup),
            'group 1')
        id = model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleId)
        self.assertEqual(app_manager.bookmarkById(id).name(), 'b1')
        self.assertEqual(
            model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleExtent),
            app_manager.bookmarkById(id).extent())

        self.assertEqual(model.data(model.index(1, 0)), 'b2')
        self.assertEqual(model.data(model.index(1, 1)), 'group 2')
        self.assertEqual(model.data(model.index(1, 2)), 12.0)
        self.assertEqual(model.data(model.index(1, 3)), 22.0)
        self.assertEqual(model.data(model.index(1, 4)), 32.0)
        self.assertEqual(model.data(model.index(1, 5)), 42.0)
        self.assertEqual(model.data(model.index(1, 6)), 'EPSG:4326')
        self.assertEqual(model.data(model.index(1, 7)), None)
        self.assertEqual(model.data(model.index(1, 7), Qt.CheckStateRole),
                         Qt.Unchecked)
        self.assertEqual(
            model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleName),
            'b2')
        self.assertEqual(
            model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleGroup),
            'group 2')
        id = model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleId)
        self.assertEqual(app_manager.bookmarkById(id).name(), 'b2')
        self.assertEqual(
            model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleExtent),
            app_manager.bookmarkById(id).extent())
        self.assertFalse(model.data(model.index(2, 0)))

        self.assertFalse(model.setData(model.index(-1, 0), 4, Qt.EditRole))
        self.assertTrue(
            model.setData(model.index(0, 0), 'new name', Qt.EditRole))
        self.assertEqual(model.data(model.index(0, 0)), 'new name')
        self.assertEqual(app_manager.bookmarks()[0].name(), 'new name')
        self.assertTrue(
            model.setData(model.index(1, 1), 'new group', Qt.EditRole))
        self.assertEqual(model.data(model.index(1, 1)), 'new group')
        self.assertEqual(app_manager.bookmarks()[1].group(), 'new group')
        self.assertTrue(model.setData(model.index(0, 2), 1, Qt.EditRole))
        self.assertEqual(model.data(model.index(0, 2)), 1.0)
        self.assertEqual(app_manager.bookmarks()[0].extent().xMinimum(), 1.0)
        self.assertTrue(model.setData(model.index(0, 3), 2, Qt.EditRole))
        self.assertEqual(model.data(model.index(0, 3)), 2.0)
        self.assertEqual(app_manager.bookmarks()[0].extent().yMinimum(), 2.0)
        self.assertTrue(model.setData(model.index(0, 4), 3, Qt.EditRole))
        self.assertEqual(model.data(model.index(0, 4)), 3.0)
        self.assertEqual(app_manager.bookmarks()[0].extent().xMaximum(), 3.0)
        self.assertTrue(model.setData(model.index(0, 5), 4, Qt.EditRole))
        self.assertEqual(model.data(model.index(0, 5)), 4.0)
        self.assertEqual(app_manager.bookmarks()[0].extent().yMaximum(), 4.0)
        self.assertFalse(model.setData(model.index(2, 0), 4, Qt.EditRole))

        self.assertTrue(int(model.flags(model.index(0, 0)) & Qt.ItemIsEnabled))
        self.assertTrue(
            int(model.flags(model.index(0, 0)) & Qt.ItemIsEditable))
        self.assertTrue(
            int(model.flags(model.index(0, 7)) & Qt.ItemIsUserCheckable))
        self.assertTrue(
            int(model.flags(model.index(1, 7)) & Qt.ItemIsUserCheckable))
        self.assertTrue(int(model.flags(model.index(1, 0)) & Qt.ItemIsEnabled))
        self.assertTrue(
            int(model.flags(model.index(1, 0)) & Qt.ItemIsEditable))
        self.assertFalse(
            int(model.flags(model.index(2, 0)) & Qt.ItemIsEnabled))
        self.assertFalse(
            int(model.flags(model.index(2, 0)) & Qt.ItemIsEditable))
        self.assertFalse(
            int(model.flags(model.index(2, 7)) & Qt.ItemIsUserCheckable))

        # add bookmark to project manager
        b3 = QgsBookmark()
        b3.setId('3')
        b3.setName('b3')
        b3.setGroup('group 3')
        b3.setExtent(
            QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43),
                                   QgsCoordinateReferenceSystem('EPSG:28355')))
        project_manager.addBookmark(b3)

        self.assertEqual(model.rowCount(), 3)
        self.assertFalse(model.data(model.index(-1, 0)))
        self.assertEqual(model.data(model.index(0, 0)), 'new name')
        self.assertEqual(model.data(model.index(0, 1)), 'group 1')
        self.assertEqual(model.data(model.index(0, 2)), 1.0)
        self.assertEqual(model.data(model.index(0, 3)), 2.0)
        self.assertEqual(model.data(model.index(0, 4)), 3.0)
        self.assertEqual(model.data(model.index(0, 5)), 4.0)
        self.assertEqual(model.data(model.index(0, 6)), 'EPSG:4326')
        self.assertEqual(model.data(model.index(0, 7)), None)
        self.assertEqual(model.data(model.index(0, 7), Qt.CheckStateRole),
                         Qt.Unchecked)
        self.assertEqual(model.data(model.index(1, 0)), 'b2')
        self.assertEqual(model.data(model.index(1, 1)), 'new group')
        self.assertEqual(model.data(model.index(1, 2)), 12.0)
        self.assertEqual(model.data(model.index(1, 3)), 22.0)
        self.assertEqual(model.data(model.index(1, 4)), 32.0)
        self.assertEqual(model.data(model.index(1, 5)), 42.0)
        self.assertEqual(model.data(model.index(1, 6)), 'EPSG:4326')
        self.assertEqual(model.data(model.index(1, 7)), None)
        self.assertEqual(model.data(model.index(1, 7), Qt.CheckStateRole),
                         Qt.Unchecked)
        self.assertEqual(model.data(model.index(2, 0)), 'b3')
        self.assertEqual(model.data(model.index(2, 1)), 'group 3')
        self.assertEqual(model.data(model.index(2, 2)), 32.0)
        self.assertEqual(model.data(model.index(2, 3)), 32.0)
        self.assertEqual(model.data(model.index(2, 4)), 33.0)
        self.assertEqual(model.data(model.index(2, 5)), 43.0)
        self.assertEqual(model.data(model.index(2, 6)), 'EPSG:28355')
        self.assertEqual(model.data(model.index(2, 7)), None)
        self.assertEqual(model.data(model.index(2, 7), Qt.CheckStateRole),
                         Qt.Checked)
        self.assertEqual(
            model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleName),
            'b3')
        self.assertEqual(
            model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleGroup),
            'group 3')
        id = model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleId)
        self.assertEqual(project_manager.bookmarkById(id).name(), 'b3')
        self.assertEqual(
            model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleExtent),
            project_manager.bookmarkById(id).extent())
        self.assertFalse(model.data(model.index(3, 0)))

        self.assertTrue(
            model.setData(model.index(2, 0), 'new name 2', Qt.EditRole))
        self.assertEqual(model.data(model.index(2, 0)), 'new name 2')
        self.assertEqual(project_manager.bookmarks()[0].name(), 'new name 2')
        self.assertTrue(
            model.setData(model.index(2, 1), 'new group', Qt.EditRole))
        self.assertEqual(model.data(model.index(2, 1)), 'new group')
        self.assertEqual(project_manager.bookmarks()[0].group(), 'new group')
        self.assertTrue(model.setData(model.index(2, 2), 1, Qt.EditRole))
        self.assertEqual(model.data(model.index(2, 2)), 1.0)
        self.assertEqual(project_manager.bookmarks()[0].extent().xMinimum(),
                         1.0)
        self.assertTrue(model.setData(model.index(2, 3), 2, Qt.EditRole))
        self.assertEqual(model.data(model.index(2, 3)), 2.0)
        self.assertEqual(project_manager.bookmarks()[0].extent().yMinimum(),
                         2.0)
        self.assertTrue(model.setData(model.index(2, 4), 3, Qt.EditRole))
        self.assertEqual(model.data(model.index(2, 4)), 3.0)
        self.assertEqual(project_manager.bookmarks()[0].extent().xMaximum(),
                         3.0)
        self.assertTrue(model.setData(model.index(2, 5), 4, Qt.EditRole))
        self.assertEqual(model.data(model.index(2, 5)), 4.0)
        self.assertEqual(project_manager.bookmarks()[0].extent().yMaximum(),
                         4.0)
        self.assertFalse(model.setData(model.index(3, 0), 4, Qt.EditRole))

        self.assertTrue(int(model.flags(model.index(0, 0)) & Qt.ItemIsEnabled))
        self.assertTrue(
            int(model.flags(model.index(0, 0)) & Qt.ItemIsEditable))
        self.assertTrue(
            int(model.flags(model.index(0, 7)) & Qt.ItemIsUserCheckable))
        self.assertTrue(
            int(model.flags(model.index(1, 7)) & Qt.ItemIsUserCheckable))
        self.assertTrue(int(model.flags(model.index(1, 0)) & Qt.ItemIsEnabled))
        self.assertTrue(
            int(model.flags(model.index(1, 0)) & Qt.ItemIsEditable))
        self.assertTrue(int(model.flags(model.index(2, 0)) & Qt.ItemIsEnabled))
        self.assertTrue(
            int(model.flags(model.index(2, 0)) & Qt.ItemIsEditable))
        self.assertTrue(
            int(model.flags(model.index(2, 7)) & Qt.ItemIsUserCheckable))
        self.assertFalse(
            int(model.flags(model.index(3, 0)) & Qt.ItemIsEnabled))
        self.assertFalse(
            int(model.flags(model.index(3, 0)) & Qt.ItemIsEditable))
        self.assertFalse(
            int(model.flags(model.index(3, 7)) & Qt.ItemIsUserCheckable))

        # try transferring bookmark from app->project
        self.assertTrue(
            model.setData(model.index(1, 7), Qt.Checked, Qt.CheckStateRole))
        self.assertEqual([b.name() for b in project_manager.bookmarks()],
                         ['new name 2', 'b2'])
        self.assertEqual([b.name() for b in app_manager.bookmarks()],
                         ['new name'])
        self.assertFalse(
            model.setData(model.index(1, 7), Qt.Checked, Qt.CheckStateRole))

        # try transferring bookmark from project->app
        self.assertTrue(
            model.setData(model.index(1, 7), Qt.Unchecked, Qt.CheckStateRole))
        self.assertEqual([b.name() for b in project_manager.bookmarks()],
                         ['b2'])
        self.assertEqual([b.name() for b in app_manager.bookmarks()],
                         ['new name', 'new name 2'])
        self.assertFalse(
            model.setData(model.index(1, 7), Qt.Unchecked, Qt.CheckStateRole))

        # remove rows
        model.removeRows(0, 1)
        self.assertEqual([b.name() for b in project_manager.bookmarks()],
                         ['b2'])
        self.assertEqual([b.name() for b in app_manager.bookmarks()],
                         ['new name 2'])
        model.removeRows(0, 2)
        self.assertEqual([b.name() for b in project_manager.bookmarks()], [])
        self.assertEqual([b.name() for b in app_manager.bookmarks()], [])